Skip to content

Commit 82651f3

Browse files
committed
Merge branch 'develop' with streams_pe_launchCount added
2 parents 8ac9438 + e7fdca8 commit 82651f3

File tree

9 files changed

+652
-20
lines changed

9 files changed

+652
-20
lines changed

streams-metric-exporter/src/main/java/streams/metric/exporter/error/StreamsTrackerErrorCode.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,30 @@
1717
package streams.metric.exporter.error;
1818

1919
public enum StreamsTrackerErrorCode {
20-
UNSPECIFIED_ERROR(0, "Unspecified Error Code"), JMX_MALFORMED_URL(1,
21-
"A JMX Malformed URL error has occured."), JMX_IOERROR(2,
20+
UNSPECIFIED_ERROR(0, "Unspecified Error Code"),
21+
JMX_MALFORMED_URL(1,
22+
"A JMX Malformed URL error has occured."),
23+
JMX_IOERROR(2,
2224
"A JMX IO Error has occured. Usually means that the connection has been lost."),
2325

2426
DOMAIN_NOT_FOUND(10,
25-
"The specified domain name is not found on the Streams JMX Server specified"), INSTANCE_NOT_FOUND(
27+
"The specified domain name is not found on the Streams JMX Server specified"),
28+
INSTANCE_NOT_FOUND(
2629
11,
27-
"The specified streams instance was not found in the Streams domain"), JOB_NOT_FOUND(
30+
"The specified streams instance was not found in the Streams domain"),
31+
JOB_NOT_FOUND(
2832
12, "Specified Streams job was not found in the Streams instance"),
2933

3034
STREAMS_MONITOR_UNAVAILABLE(50,
31-
"The Streams Monitor has not been created and initialized."), ALL_JOBS_NOT_AVAILABLE(
35+
"The Streams Monitor has not been created and initialized."),
36+
ALL_JOBS_NOT_AVAILABLE(
3237
51,
33-
"The Streams jobs are not available at this time. The Streams instance does not exist."), ALL_METRICS_NOT_AVAILABLE(
38+
"The Streams jobs are not available at this time. The Streams instance does not exist."),
39+
ALL_METRICS_NOT_AVAILABLE(
3440
52,
35-
"The Metrics for all jobs is not available at this time. Either the JMX Connection or the Instance is not avaiable."),
41+
"The Metrics for all jobs is not available at this time. Either the JMX Connection or the Instance is not avaiable."),
42+
ALL_SNAPSHOTS_NOT_AVAILABLE(53,
43+
"The Snapshots for all jobs is not available at thjis time. Either the JMX Connection or the Instance is not available."),
3644

3745
OTHER_ERROR(99, "Unspecified Error Code");
3846

streams-metric-exporter/src/main/java/streams/metric/exporter/rest/resources/JobResource.java

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ public Response getJobHealth() throws StreamsTrackerException,
8686

8787
}
8888

89-
@Path("snapshot")
89+
@Path("snapshotnow")
9090
@GET
9191
@Produces(MediaType.APPLICATION_JSON)
92-
public Response getJobSnapshot(
92+
public Response getJobSnapshotNow(
9393
@DefaultValue("1") @QueryParam("depth") int maximumDepth,
9494
@DefaultValue("true") @QueryParam("static") boolean includeStaticAttributes)
9595
throws StreamsTrackerException, WebApplicationException {
@@ -137,6 +137,34 @@ public Response getJobMetrics() throws StreamsTrackerException,
137137
return r;
138138

139139
}
140+
141+
@Path("snapshot")
142+
@GET
143+
@Produces(MediaType.APPLICATION_JSON)
144+
public Response getJobSnapshot() throws StreamsTrackerException,
145+
WebApplicationException, JsonProcessingException {
146+
ObjectMapper om = new ObjectMapper();
147+
148+
Response r = null;
149+
150+
// Create return format
151+
JobSnapshotBody body = new JobSnapshotBody(ji.getLastSnapshotRefresh(),
152+
ji.getLastSnapshotFailure(), ji.isLastSnapshotRefreshFailed(),
153+
ji.getJobSnapshot());
154+
155+
// If the metrics refresh failed, use NOT_MODIFIED so client can
156+
// understand we are sending cached info
157+
// More cached than it usually is :)
158+
if (ji.isLastSnapshotRefreshFailed()) {
159+
r = Response.status(Response.Status.NOT_MODIFIED)
160+
.entity(om.writeValueAsString(body)).build();
161+
} else {
162+
r = Response.status(Response.Status.OK)
163+
.entity(om.writeValueAsString(body)).build();
164+
}
165+
return r;
166+
167+
}
140168

141169
/******** SUPPORTING CLASSES FOR OUTPUT FORMATTING ********/
142170
private class JobMetricsBody {
@@ -154,4 +182,21 @@ public JobMetricsBody(Date lastMetricsRefresh, Date lastMetricsFailure,
154182
this.jobMetrics = jobMetrics;
155183
}
156184
}
185+
186+
/******** SUPPORTING CLASSES FOR OUTPUT FORMATTING ********/
187+
private class JobSnapshotBody {
188+
public Date lastSnapshotRefresh = null;
189+
public Date lastSnapshotFailure = null;
190+
public boolean lastSnapshotRefreshFailed = false;
191+
@JsonRawValue
192+
public String jobSnapshot;
193+
194+
public JobSnapshotBody(Date lastSnapshotRefresh, Date lastSnapshotFailure,
195+
boolean lastSnapshotRefreshFailed, String jobSnapshot) {
196+
this.lastSnapshotRefresh = lastSnapshotRefresh;
197+
this.lastSnapshotFailure = lastSnapshotFailure;
198+
this.lastSnapshotRefreshFailed = lastSnapshotRefreshFailed;
199+
this.jobSnapshot = jobSnapshot;
200+
}
201+
}
157202
}

streams-metric-exporter/src/main/java/streams/metric/exporter/rest/resources/RootResource.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,19 @@ public Response getAllJobMetrics() throws StreamsTrackerException,
9696
return Response.status(200).entity(jobTracker.getAllJobMetrics())
9797
.build();
9898
}
99+
100+
// If instance is not started or exists, then returns 404
101+
@Path("snapshots")
102+
@GET
103+
@Produces(MediaType.APPLICATION_JSON)
104+
public Response getAllJobSnapshots() throws StreamsTrackerException,
105+
WebApplicationException {
106+
StreamsInstanceTracker jobTracker = StreamsInstanceTracker
107+
.getInstance();
108+
109+
return Response.status(200).entity(jobTracker.getAllJobSnapshots())
110+
.build();
111+
}
99112

100113
@Path("joblist/")
101114
@GET
@@ -130,11 +143,15 @@ public Response getJobList() throws StreamsTrackerException,
130143
UriBuilder mub = jub.clone();
131144
URI metricsUri = mub.path("metrics").build();
132145
j.put("metrics", metricsUri.toASCIIString());
133-
146+
134147
UriBuilder sub = jub.clone();
135148
URI snapshotUri = sub.path("snapshot").build();
136149
j.put("snapshot", snapshotUri.toASCIIString());
137150

151+
UriBuilder snub = jub.clone();
152+
URI snapshotNowUri = snub.path("snapshotnow").build();
153+
j.put("snapshotnow", snapshotNowUri.toASCIIString());
154+
138155
jlist.add(j);
139156
}
140157

streams-metric-exporter/src/main/java/streams/metric/exporter/rest/serializers/StreamsInstanceJobMonitorSerializer.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ public void serialize(StreamsInstanceTracker monitor,
6767
jgen.writeBooleanField("jobMetricsAvailable",
6868
monitor.metricsAvailable());
6969
jgen.writeStringField("instanceResourceMetricsLastUpdateTime", convertTime(monitor.getInstanceResourceMetricsLastUpdated()));
70-
70+
jgen.writeBooleanField("jobSnapshotsAvailable",
71+
monitor.snapshotsAvailable());
72+
7173
if (monitor.jobsAvailable()) {
7274
Iterator<Map.Entry<BigInteger, JobInfo>> it = monitor
7375
.getCurrentJobMap().entrySet().iterator();
@@ -84,8 +86,14 @@ public void serialize(StreamsInstanceTracker monitor,
8486
.toString());
8587
jgen.writeStringField("applicationName", entry.getValue()
8688
.getApplicationName());
87-
jgen.writeStringField("metrics", entry.getValue()
88-
.getJobMetrics());
89+
// jgen.writeStringField("metrics", entry.getValue()
90+
// .getJobMetrics());
91+
// jgen.writeStringField("snapshot", entry.getValue()
92+
// .getJobSnapshot());
93+
jgen.writeFieldName("metrics");
94+
jgen.writeRawValue(entry.getValue().getJobMetrics());
95+
jgen.writeFieldName("snapshot");
96+
jgen.writeRawValue(entry.getValue().getJobSnapshot());
8997

9098
jgen.writeEndObject();
9199
jgen.writeEndObject();

0 commit comments

Comments
 (0)