Search in sources :

Example 11 with JsonGenerator

use of org.apache.flink.shaded.jackson2.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);
    }
}
Also used : JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) StringWriter(java.io.StringWriter) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator)

Example 12 with JsonGenerator

use of org.apache.flink.shaded.jackson2.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();
}
Also used : StringWriter(java.io.StringWriter) StringifiedAccumulatorResult(org.apache.flink.runtime.accumulators.StringifiedAccumulatorResult) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator)

Example 13 with JsonGenerator

use of org.apache.flink.shaded.jackson2.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();
}
Also used : StringWriter(java.io.StringWriter) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator)

Example 14 with JsonGenerator

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project flink by apache.

the class SubtasksTimesHandler method createSubtaskTimesJson.

public static String createSubtaskTimesJson(AccessExecutionJobVertex jobVertex) throws IOException {
    final long now = System.currentTimeMillis();
    StringWriter writer = new StringWriter();
    JsonGenerator gen = JsonFactory.jacksonFactory.createGenerator(writer);
    gen.writeStartObject();
    gen.writeStringField("id", jobVertex.getJobVertexId().toString());
    gen.writeStringField("name", jobVertex.getName());
    gen.writeNumberField("now", now);
    gen.writeArrayFieldStart("subtasks");
    int num = 0;
    for (AccessExecutionVertex vertex : jobVertex.getTaskVertices()) {
        long[] timestamps = vertex.getCurrentExecutionAttempt().getStateTimestamps();
        ExecutionState status = vertex.getExecutionState();
        long scheduledTime = timestamps[ExecutionState.SCHEDULED.ordinal()];
        long start = scheduledTime > 0 ? scheduledTime : -1;
        long end = status.isTerminal() ? timestamps[status.ordinal()] : now;
        long duration = start >= 0 ? end - start : -1L;
        gen.writeStartObject();
        gen.writeNumberField("subtask", num++);
        TaskManagerLocation location = vertex.getCurrentAssignedResourceLocation();
        String locationString = location == null ? "(unassigned)" : location.getHostname();
        gen.writeStringField("host", locationString);
        gen.writeNumberField("duration", duration);
        gen.writeObjectFieldStart("timestamps");
        for (ExecutionState state : ExecutionState.values()) {
            gen.writeNumberField(state.name(), timestamps[state.ordinal()]);
        }
        gen.writeEndObject();
        gen.writeEndObject();
    }
    gen.writeEndArray();
    gen.writeEndObject();
    gen.close();
    return writer.toString();
}
Also used : ExecutionState(org.apache.flink.runtime.execution.ExecutionState) StringWriter(java.io.StringWriter) TaskManagerLocation(org.apache.flink.runtime.taskmanager.TaskManagerLocation) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) AccessExecutionVertex(org.apache.flink.runtime.executiongraph.AccessExecutionVertex)

Example 15 with JsonGenerator

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project flink by apache.

the class CheckpointStatsHandler method createCheckpointStatsJson.

private static String createCheckpointStatsJson(AccessExecutionGraph graph) throws IOException {
    StringWriter writer = new StringWriter();
    JsonGenerator gen = JsonFactory.jacksonFactory.createGenerator(writer);
    CheckpointStatsSnapshot snapshot = graph.getCheckpointStatsSnapshot();
    if (snapshot == null) {
        return "{}";
    }
    gen.writeStartObject();
    // Counts
    writeCounts(gen, snapshot.getCounts());
    // Summary
    writeSummary(gen, snapshot.getSummaryStats());
    CheckpointStatsHistory history = snapshot.getHistory();
    // Latest
    writeLatestCheckpoints(gen, history.getLatestCompletedCheckpoint(), history.getLatestSavepoint(), history.getLatestFailedCheckpoint(), snapshot.getLatestRestoredCheckpoint());
    // History
    writeHistory(gen, snapshot.getHistory());
    gen.writeEndObject();
    gen.close();
    return writer.toString();
}
Also used : StringWriter(java.io.StringWriter) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) CheckpointStatsHistory(org.apache.flink.runtime.checkpoint.CheckpointStatsHistory) CheckpointStatsSnapshot(org.apache.flink.runtime.checkpoint.CheckpointStatsSnapshot)

Aggregations

JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)711 KriptonJsonContext (com.abubusoft.kripton.KriptonJsonContext)257 KriptonByteArrayOutputStream (com.abubusoft.kripton.common.KriptonByteArrayOutputStream)257 KriptonRuntimeException (com.abubusoft.kripton.exception.KriptonRuntimeException)257 JacksonWrapperSerializer (com.abubusoft.kripton.persistence.JacksonWrapperSerializer)257 IOException (java.io.IOException)170 StringWriter (java.io.StringWriter)145 JsonFactory (com.fasterxml.jackson.core.JsonFactory)101 ByteArrayOutputStream (java.io.ByteArrayOutputStream)66 Map (java.util.Map)57 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)54 HashMap (java.util.HashMap)41 Test (org.junit.Test)30 File (java.io.File)27 ArrayList (java.util.ArrayList)26 OutputStream (java.io.OutputStream)25 Writer (java.io.Writer)22 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)21 SerializerProvider (com.fasterxml.jackson.databind.SerializerProvider)20 FileOutputStream (java.io.FileOutputStream)19