Search in sources :

Example 6 with StringifiedAccumulatorResult

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

the class SubtaskExecutionAttemptAccumulatorsHandler method createAttemptAccumulatorsJson.

public static String createAttemptAccumulatorsJson(AccessExecution execAttempt) throws IOException {
    StringWriter writer = new StringWriter();
    JsonGenerator gen = JsonFactory.jacksonFactory.createGenerator(writer);
    final StringifiedAccumulatorResult[] accs = execAttempt.getUserAccumulatorsStringified();
    gen.writeStartObject();
    gen.writeNumberField("subtask", execAttempt.getParallelSubtaskIndex());
    gen.writeNumberField("attempt", execAttempt.getAttemptNumber());
    gen.writeStringField("id", execAttempt.getAttemptId().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 7 with StringifiedAccumulatorResult

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

the class SubtasksAllAccumulatorsHandler method createSubtasksAccumulatorsJson.

public static String createSubtasksAccumulatorsJson(AccessExecutionJobVertex jobVertex) throws IOException {
    StringWriter writer = new StringWriter();
    JsonGenerator gen = JsonFactory.jacksonFactory.createGenerator(writer);
    gen.writeStartObject();
    gen.writeStringField("id", jobVertex.getJobVertexId().toString());
    gen.writeNumberField("parallelism", jobVertex.getParallelism());
    gen.writeArrayFieldStart("subtasks");
    int num = 0;
    for (AccessExecutionVertex vertex : jobVertex.getTaskVertices()) {
        TaskManagerLocation location = vertex.getCurrentAssignedResourceLocation();
        String locationString = location == null ? "(unassigned)" : location.getHostname();
        gen.writeStartObject();
        gen.writeNumberField("subtask", num++);
        gen.writeNumberField("attempt", vertex.getCurrentExecutionAttempt().getAttemptNumber());
        gen.writeStringField("host", locationString);
        StringifiedAccumulatorResult[] accs = vertex.getCurrentExecutionAttempt().getUserAccumulatorsStringified();
        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.writeEndArray();
    gen.writeEndObject();
    gen.close();
    return writer.toString();
}
Also used : StringWriter(java.io.StringWriter) TaskManagerLocation(org.apache.flink.runtime.taskmanager.TaskManagerLocation) StringifiedAccumulatorResult(org.apache.flink.runtime.accumulators.StringifiedAccumulatorResult) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) AccessExecutionVertex(org.apache.flink.runtime.executiongraph.AccessExecutionVertex)

Example 8 with StringifiedAccumulatorResult

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

the class ArchivedJobGenerationUtils method generateArchivedJob.

private static void generateArchivedJob() throws Exception {
    // Attempt
    StringifiedAccumulatorResult acc1 = new StringifiedAccumulatorResult("name1", "type1", "value1");
    StringifiedAccumulatorResult acc2 = new StringifiedAccumulatorResult("name2", "type2", "value2");
    TaskManagerLocation location = new TaskManagerLocation(new ResourceID("hello"), InetAddress.getLocalHost(), 1234);
    originalAttempt = new ArchivedExecutionBuilder().setStateTimestamps(new long[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }).setParallelSubtaskIndex(1).setAttemptNumber(0).setAssignedResourceLocation(location).setUserAccumulators(new StringifiedAccumulatorResult[] { acc1, acc2 }).setState(ExecutionState.FINISHED).setFailureCause("attemptException").build();
    // Subtask
    originalSubtask = new ArchivedExecutionVertexBuilder().setSubtaskIndex(originalAttempt.getParallelSubtaskIndex()).setTaskNameWithSubtask("hello(1/1)").setCurrentExecution(originalAttempt).build();
    // Task
    originalTask = new ArchivedExecutionJobVertexBuilder().setTaskVertices(new ArchivedExecutionVertex[] { originalSubtask }).build();
    // Job
    Map<JobVertexID, ArchivedExecutionJobVertex> tasks = new HashMap<>();
    tasks.put(originalTask.getJobVertexId(), originalTask);
    originalJob = new ArchivedExecutionGraphBuilder().setJobID(new JobID()).setTasks(tasks).setFailureCause("jobException").setState(JobStatus.FINISHED).setStateTimestamps(new long[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }).setArchivedUserAccumulators(new StringifiedAccumulatorResult[] { acc1, acc2 }).build();
}
Also used : ArchivedExecutionJobVertex(org.apache.flink.runtime.executiongraph.ArchivedExecutionJobVertex) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) HashMap(java.util.HashMap) TaskManagerLocation(org.apache.flink.runtime.taskmanager.TaskManagerLocation) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) StringifiedAccumulatorResult(org.apache.flink.runtime.accumulators.StringifiedAccumulatorResult) JobID(org.apache.flink.api.common.JobID)

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