Search in sources :

Example 1 with StringifiedAccumulatorResult

use of org.apache.flink.runtime.accumulators.StringifiedAccumulatorResult 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 2 with StringifiedAccumulatorResult

use of org.apache.flink.runtime.accumulators.StringifiedAccumulatorResult in project flink by apache.

the class JobVertexAccumulatorsHandler method createVertexAccumulatorsJson.

public static String createVertexAccumulatorsJson(AccessExecutionJobVertex jobVertex) throws IOException {
    StringWriter writer = new StringWriter();
    JsonGenerator gen = JsonFactory.jacksonFactory.createGenerator(writer);
    StringifiedAccumulatorResult[] accs = jobVertex.getAggregatedUserAccumulatorsStringified();
    gen.writeStartObject();
    gen.writeStringField("id", jobVertex.getJobVertexId().toString());
    gen.writeArrayFieldStart("user-accumulators");
    for (StringifiedAccumulatorResult acc : accs) {
        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 3 with StringifiedAccumulatorResult

use of org.apache.flink.runtime.accumulators.StringifiedAccumulatorResult in project flink by apache.

the class ArchivedExecutionGraphBuilder method build.

public ArchivedExecutionGraph build() {
    Preconditions.checkNotNull(tasks, "Tasks must not be null.");
    JobID jobID = this.jobID != null ? this.jobID : new JobID();
    String jobName = this.jobName != null ? this.jobName : "job_" + RANDOM.nextInt();
    return new ArchivedExecutionGraph(jobID, jobName, tasks, verticesInCreationOrder != null ? verticesInCreationOrder : new ArrayList<>(tasks.values()), stateTimestamps != null ? stateTimestamps : new long[JobStatus.values().length], state != null ? state : JobStatus.FINISHED, failureCause != null ? failureCause : "(null)", jsonPlan != null ? jsonPlan : "{\"jobid\":\"" + jobID + "\", \"name\":\"" + jobName + "\", \"nodes\":[]}", archivedUserAccumulators != null ? archivedUserAccumulators : new StringifiedAccumulatorResult[0], serializedUserAccumulators != null ? serializedUserAccumulators : Collections.<String, SerializedValue<Object>>emptyMap(), archivedExecutionConfig != null ? archivedExecutionConfig : new ArchivedExecutionConfigBuilder().build(), isStoppable, null, null);
}
Also used : ArrayList(java.util.ArrayList) StringifiedAccumulatorResult(org.apache.flink.runtime.accumulators.StringifiedAccumulatorResult) ArchivedExecutionGraph(org.apache.flink.runtime.executiongraph.ArchivedExecutionGraph) SerializedValue(org.apache.flink.util.SerializedValue) JobID(org.apache.flink.api.common.JobID)

Example 4 with StringifiedAccumulatorResult

use of org.apache.flink.runtime.accumulators.StringifiedAccumulatorResult in project flink by apache.

the class JobVertexAccumulatorsHandlerTest method compareAccumulators.

private static void compareAccumulators(AccessExecutionJobVertex originalTask, String json) throws IOException {
    JsonNode result = ArchivedJobGenerationUtils.mapper.readTree(json);
    Assert.assertEquals(originalTask.getJobVertexId().toString(), result.get("id").asText());
    ArrayNode accs = (ArrayNode) result.get("user-accumulators");
    StringifiedAccumulatorResult[] expectedAccs = originalTask.getAggregatedUserAccumulatorsStringified();
    ArchivedJobGenerationUtils.compareStringifiedAccumulators(expectedAccs, accs);
}
Also used : StringifiedAccumulatorResult(org.apache.flink.runtime.accumulators.StringifiedAccumulatorResult) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 5 with StringifiedAccumulatorResult

use of org.apache.flink.runtime.accumulators.StringifiedAccumulatorResult in project flink by apache.

the class ArchivedExecutionGraphTest method compareStringifiedAccumulators.

private static void compareStringifiedAccumulators(StringifiedAccumulatorResult[] runtimeAccs, StringifiedAccumulatorResult[] archivedAccs) {
    assertEquals(runtimeAccs.length, archivedAccs.length);
    for (int x = 0; x < runtimeAccs.length; x++) {
        StringifiedAccumulatorResult runtimeResult = runtimeAccs[x];
        StringifiedAccumulatorResult archivedResult = archivedAccs[x];
        assertEquals(runtimeResult.getName(), archivedResult.getName());
        assertEquals(runtimeResult.getType(), archivedResult.getType());
        assertEquals(runtimeResult.getValue(), archivedResult.getValue());
    }
}
Also used : StringifiedAccumulatorResult(org.apache.flink.runtime.accumulators.StringifiedAccumulatorResult)

Aggregations

StringifiedAccumulatorResult (org.apache.flink.runtime.accumulators.StringifiedAccumulatorResult)8 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)4 StringWriter (java.io.StringWriter)4 JobID (org.apache.flink.api.common.JobID)2 TaskManagerLocation (org.apache.flink.runtime.taskmanager.TaskManagerLocation)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)1 AccessExecutionVertex (org.apache.flink.runtime.executiongraph.AccessExecutionVertex)1 ArchivedExecutionGraph (org.apache.flink.runtime.executiongraph.ArchivedExecutionGraph)1 ArchivedExecutionJobVertex (org.apache.flink.runtime.executiongraph.ArchivedExecutionJobVertex)1 JobVertexID (org.apache.flink.runtime.jobgraph.JobVertexID)1 SerializedValue (org.apache.flink.util.SerializedValue)1