use of com.fasterxml.jackson.core.JsonGenerator in project flink by apache.
the class AbstractMetricsHandler method getMetricsValues.
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 "";
}
MetricStore metricStore = fetcher.getMetricStore();
synchronized (metricStore) {
Map<String, String> metrics = getMapFor(pathParams, metricStore);
if (metrics == null) {
return "";
}
String[] requestedMetrics = requestedMetricsList.split(",");
StringWriter writer = new StringWriter();
JsonGenerator gen = JsonFactory.jacksonFactory.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();
}
}
use of com.fasterxml.jackson.core.JsonGenerator in project flink by apache.
the class JarListHandler method handleJsonRequest.
@Override
public String handleJsonRequest(Map<String, String> pathParams, Map<String, String> queryParams, ActorGateway jobManager) throws Exception {
try {
StringWriter writer = new StringWriter();
JsonGenerator gen = JsonFactory.jacksonFactory.createGenerator(writer);
gen.writeStartObject();
gen.writeStringField("address", queryParams.get(RuntimeMonitorHandler.WEB_MONITOR_ADDRESS_KEY));
gen.writeArrayFieldStart("files");
File[] list = jarDir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.endsWith(".jar");
}
});
for (File f : list) {
// separate the uuid and the name parts.
String id = f.getName();
int startIndex = id.indexOf("_");
if (startIndex < 0) {
continue;
}
String name = id.substring(startIndex + 1);
if (name.length() < 5 || !name.endsWith(".jar")) {
continue;
}
gen.writeStartObject();
gen.writeStringField("id", id);
gen.writeStringField("name", name);
gen.writeNumberField("uploaded", f.lastModified());
gen.writeArrayFieldStart("entry");
String[] classes = new String[0];
try {
JarFile jar = new JarFile(f);
Manifest manifest = jar.getManifest();
String assemblerClass = null;
if (manifest != null) {
assemblerClass = manifest.getMainAttributes().getValue(PackagedProgram.MANIFEST_ATTRIBUTE_ASSEMBLER_CLASS);
if (assemblerClass == null) {
assemblerClass = manifest.getMainAttributes().getValue(PackagedProgram.MANIFEST_ATTRIBUTE_MAIN_CLASS);
}
}
if (assemblerClass != null) {
classes = assemblerClass.split(",");
}
} catch (IOException ignored) {
// we simply show no entries here
}
// show every entry class that can be loaded later on.
for (String clazz : classes) {
clazz = clazz.trim();
PackagedProgram program = null;
try {
program = new PackagedProgram(f, clazz, new String[0]);
} catch (Exception ignored) {
// ignore jar files which throw an error upon creating a PackagedProgram
}
if (program != null) {
gen.writeStartObject();
gen.writeStringField("name", clazz);
String desc = program.getDescription();
gen.writeStringField("description", desc == null ? "No description provided" : desc);
gen.writeEndObject();
}
}
gen.writeEndArray();
gen.writeEndObject();
}
gen.writeEndArray();
gen.writeEndObject();
gen.close();
return writer.toString();
} catch (Exception e) {
throw new RuntimeException("Failed to fetch jar list: " + e.getMessage(), e);
}
}
use of com.fasterxml.jackson.core.JsonGenerator in project flink by apache.
the class JarPlanHandler method handleJsonRequest.
@Override
public String handleJsonRequest(Map<String, String> pathParams, Map<String, String> queryParams, ActorGateway jobManager) throws Exception {
try {
JarActionHandlerConfig config = JarActionHandlerConfig.fromParams(pathParams, queryParams);
JobGraph graph = getJobGraphAndClassLoader(config).f0;
StringWriter writer = new StringWriter();
JsonGenerator gen = JsonFactory.jacksonFactory.createGenerator(writer);
gen.writeStartObject();
gen.writeFieldName("plan");
gen.writeRawValue(JsonPlanGenerator.generatePlan(graph));
gen.writeEndObject();
gen.close();
return writer.toString();
} catch (Exception e) {
return sendError(e);
}
}
use of com.fasterxml.jackson.core.JsonGenerator in project flink by apache.
the class JobAccumulatorsHandler method createJobAccumulatorsJson.
public static String createJobAccumulatorsJson(AccessExecutionGraph graph) throws IOException {
StringWriter writer = new StringWriter();
JsonGenerator gen = JsonFactory.jacksonFactory.createGenerator(writer);
StringifiedAccumulatorResult[] allAccumulators = graph.getAccumulatorResultsStringified();
gen.writeStartObject();
gen.writeArrayFieldStart("job-accumulators");
// empty for now
gen.writeEndArray();
gen.writeArrayFieldStart("user-task-accumulators");
for (StringifiedAccumulatorResult acc : allAccumulators) {
gen.writeStartObject();
gen.writeStringField("name", acc.getName());
gen.writeStringField("type", acc.getType());
gen.writeStringField("value", acc.getValue());
gen.writeEndObject();
}
gen.writeEndArray();
gen.writeEndObject();
gen.close();
return writer.toString();
}
use of com.fasterxml.jackson.core.JsonGenerator in project flink by apache.
the class JobManagerConfigHandler method handleJsonRequest.
@Override
public String handleJsonRequest(Map<String, String> pathParams, Map<String, String> queryParams, ActorGateway jobManager) throws Exception {
StringWriter writer = new StringWriter();
JsonGenerator gen = JsonFactory.jacksonFactory.createGenerator(writer);
gen.writeStartArray();
for (String key : config.keySet()) {
gen.writeStartObject();
gen.writeStringField("key", key);
// Mask key values which contain sensitive information
if (key.toLowerCase().contains("password")) {
String value = config.getString(key, null);
if (value != null) {
value = "******";
}
gen.writeStringField("value", value);
} else {
gen.writeStringField("value", config.getString(key, null));
}
gen.writeEndObject();
}
gen.writeEndArray();
gen.close();
return writer.toString();
}
Aggregations