private static Optional<Metric> getJobMetric( final RestClusterClient<ApplicationId> restClusterClient, final JobID jobId, final String metricName) throws Exception { final JobMetricsMessageParameters messageParameters = new JobMetricsMessageParameters(); messageParameters.jobPathParameter.resolve(jobId); messageParameters.metricsFilterParameter.resolveFromString(metricName); final Collection<Metric> metrics = restClusterClient.sendRequest( JobMetricsHeaders.getInstance(), messageParameters, EmptyRequestBody.getInstance()).get().getMetrics(); final Metric metric = Iterables.getOnlyElement(metrics, null); checkState(metric == null || metric.getId().equals(metricName)); return Optional.ofNullable(metric); } }
@Override public MetricCollectionResponseBody deserialize( JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { return new MetricCollectionResponseBody(jsonParser.readValueAs( new TypeReference<List<Metric>>() { })); } }
@Override public MetricCollectionResponseBody deserialize( JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { return new MetricCollectionResponseBody(jsonParser.readValueAs( new TypeReference<List<Metric>>() { })); } }
@Override public void serialize( MetricCollectionResponseBody metricCollectionResponseBody, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { jsonGenerator.writeObject(metricCollectionResponseBody.getMetrics()); } }
@Override public MetricCollectionResponseBody deserialize( JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { return new MetricCollectionResponseBody(jsonParser.readValueAs( new TypeReference<List<Metric>>() { })); } }
@Override public void serialize( MetricCollectionResponseBody metricCollectionResponseBody, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { jsonGenerator.writeObject(metricCollectionResponseBody.getMetrics()); } }
@Override protected final CompletableFuture<MetricCollectionResponseBody> handleRequest( @Nonnull HandlerRequest<EmptyRequestBody, M> request, @Nonnull RestfulGateway gateway) throws RestHandlerException { metricFetcher.update(); final MetricStore.ComponentMetricStore componentMetricStore = getComponentMetricStore( request, metricFetcher.getMetricStore()); if (componentMetricStore == null || componentMetricStore.metrics == null) { return CompletableFuture.completedFuture( new MetricCollectionResponseBody(Collections.emptyList())); } final Set<String> requestedMetrics = new HashSet<>(request.getQueryParameter( MetricsFilterParameter.class)); if (requestedMetrics.isEmpty()) { return CompletableFuture.completedFuture( new MetricCollectionResponseBody(getAvailableMetrics(componentMetricStore))); } else { final List<Metric> metrics = getRequestedMetrics(componentMetricStore, requestedMetrics); return CompletableFuture.completedFuture(new MetricCollectionResponseBody(metrics)); } }
@Override public void serialize( MetricCollectionResponseBody metricCollectionResponseBody, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { jsonGenerator.writeObject(metricCollectionResponseBody.getMetrics()); } }
@Override protected final CompletableFuture<MetricCollectionResponseBody> handleRequest( @Nonnull HandlerRequest<EmptyRequestBody, M> request, @Nonnull RestfulGateway gateway) throws RestHandlerException { metricFetcher.update(); final MetricStore.ComponentMetricStore componentMetricStore = getComponentMetricStore( request, metricFetcher.getMetricStore()); if (componentMetricStore == null || componentMetricStore.metrics == null) { return CompletableFuture.completedFuture( new MetricCollectionResponseBody(Collections.emptyList())); } final Set<String> requestedMetrics = new HashSet<>(request.getQueryParameter( MetricsFilterParameter.class)); if (requestedMetrics.isEmpty()) { return CompletableFuture.completedFuture( new MetricCollectionResponseBody(getAvailableMetrics(componentMetricStore))); } else { final List<Metric> metrics = getRequestedMetrics(componentMetricStore, requestedMetrics); return CompletableFuture.completedFuture(new MetricCollectionResponseBody(metrics)); } }
@Override protected final CompletableFuture<MetricCollectionResponseBody> handleRequest( @Nonnull HandlerRequest<EmptyRequestBody, M> request, @Nonnull RestfulGateway gateway) throws RestHandlerException { metricFetcher.update(); final MetricStore.ComponentMetricStore componentMetricStore = getComponentMetricStore( request, metricFetcher.getMetricStore()); if (componentMetricStore == null || componentMetricStore.metrics == null) { return CompletableFuture.completedFuture( new MetricCollectionResponseBody(Collections.emptyList())); } final Set<String> requestedMetrics = new HashSet<>(request.getQueryParameter( MetricsFilterParameter.class)); if (requestedMetrics.isEmpty()) { return CompletableFuture.completedFuture( new MetricCollectionResponseBody(getAvailableMetrics(componentMetricStore))); } else { final List<Metric> metrics = getRequestedMetrics(componentMetricStore, requestedMetrics); return CompletableFuture.completedFuture(new MetricCollectionResponseBody(metrics)); } }