private static String mapMetricListToJson(Collection<String> metrics) throws IOException { StringWriter writer = new StringWriter(); JsonGenerator gen = JsonFactory.JACKSON_FACTORY.createGenerator(writer); gen.writeStartArray(); for (String m : metrics) { gen.writeStartObject(); gen.writeStringField("id", m); gen.writeEndObject(); } gen.writeEndArray(); gen.close(); return writer.toString(); }
JsonGenerator gen = JsonFactory.JACKSON_FACTORY.createGenerator(writer); gen.writeStartArray(); for (String requestedMetric : requestedMetrics) { final Collection<Double> values = new ArrayList<>();
private String getMetricsValues(Map<String, String> pathParams, String requestedMetricsList) throws IOException { if (requestedMetricsList.isEmpty()) { /* * The WebInterface doesn't check whether the list of available metrics was empty. This can lead to a * request for which the "get" parameter is an empty string. */ return ""; } Map<String, String> metrics = getMapFor(pathParams, fetcher.getMetricStore()); if (metrics == null) { return ""; } String[] requestedMetrics = requestedMetricsList.split(","); StringWriter writer = new StringWriter(); JsonGenerator gen = JsonFactory.JACKSON_FACTORY.createGenerator(writer); gen.writeStartArray(); for (String requestedMetric : requestedMetrics) { Object metricValue = metrics.get(requestedMetric); if (metricValue != null) { gen.writeStartObject(); gen.writeStringField("id", requestedMetric); gen.writeStringField("value", metricValue.toString()); gen.writeEndObject(); } } gen.writeEndArray(); gen.close(); return writer.toString(); }
private String getAvailableMetricsList(Map<String, String> pathParams) throws IOException { Map<String, String> metrics = getMapFor(pathParams, fetcher.getMetricStore()); if (metrics == null) { return ""; } StringWriter writer = new StringWriter(); JsonGenerator gen = JsonFactory.JACKSON_FACTORY.createGenerator(writer); gen.writeStartArray(); for (String m : metrics.keySet()) { gen.writeStartObject(); gen.writeStringField("id", m); gen.writeEndObject(); } gen.writeEndArray(); gen.close(); return writer.toString(); } }
private static String createConfigJson(Configuration config) { try { StringWriter writer = new StringWriter(); JsonGenerator gen = JsonFactory.JACKSON_FACTORY.createGenerator(writer); gen.writeStartArray(); for (String key : config.keySet()) { gen.writeStartObject(); gen.writeStringField(ClusterConfigurationInfoEntry.FIELD_NAME_CONFIG_KEY, key); String value = config.getString(key, null); // Mask key values which contain sensitive information if (value != null && GlobalConfiguration.isSensitive(key)) { value = GlobalConfiguration.HIDDEN_CONTENT; } gen.writeStringField(ClusterConfigurationInfoEntry.FIELD_NAME_CONFIG_VALUE, value); gen.writeEndObject(); } gen.writeEndArray(); gen.close(); return writer.toString(); } catch (IOException e) { throw new CompletionException(new FlinkException("Could not write configuration.", e)); } } }