private void dump(Plan p) { try { List<DataSinkNode> sinks = Optimizer.createPreOptimizedPlan(p); PlanJSONDumpGenerator dumper = new PlanJSONDumpGenerator(); String json = dumper.getPactPlanAsJSON(sinks); try (JsonParser parser = new JsonFactory().createParser(json)) { while (parser.nextToken() != null) {} } } catch (JsonParseException e) { e.printStackTrace(); Assert.fail("JSON Generator produced malformatted output: " + e.getMessage()); } catch (Exception e) { e.printStackTrace(); Assert.fail("An error occurred in the test: " + e.getMessage()); } } }
@SuppressWarnings("unchecked") private Map<String, SerializedValue<OptionalFailure<Object>>> parseAccumulatorResults( final JsonParser p, final DeserializationContext ctxt) throws IOException { final Map<String, SerializedValue<OptionalFailure<Object>>> accumulatorResults = new HashMap<>(); while (true) { final JsonToken jsonToken = p.nextToken(); assertNotEndOfInput(p, jsonToken); if (jsonToken == JsonToken.END_OBJECT) { break; } final String accumulatorName = p.getValueAsString(); p.nextValue(); accumulatorResults.put( accumulatorName, (SerializedValue<OptionalFailure<Object>>) serializedValueDeserializer.deserialize(p, ctxt)); } return accumulatorResults; }
final JsonToken jsonToken = p.nextToken(); assertNotEndOfInput(p, jsonToken); if (jsonToken == JsonToken.END_OBJECT) { final String fieldName = p.getValueAsString(); switch (fieldName) { case JobResultSerializer.FIELD_NAME_JOB_ID: case JobResultSerializer.FIELD_NAME_APPLICATION_STATUS: assertNextToken(p, JsonToken.VALUE_STRING); applicationStatus = ApplicationStatus.valueOf(p.getValueAsString().toUpperCase()); break; case JobResultSerializer.FIELD_NAME_NET_RUNTIME: assertNextToken(p, JsonToken.VALUE_NUMBER_INT); netRuntime = p.getLongValue(); break; case JobResultSerializer.FIELD_NAME_ACCUMULATOR_RESULTS:
@Override public JobID deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { return JobID.fromHexString(p.getValueAsString()); } }
@Override public SerializedThrowable deserialize( final JsonParser p, final DeserializationContext ctxt) throws IOException { final JsonNode root = p.readValueAsTree(); final byte[] serializedException = root.get(FIELD_NAME_SERIALIZED_THROWABLE).binaryValue(); try { return InstantiationUtil.deserializeObject(serializedException, ClassLoader.getSystemClassLoader()); } catch (ClassNotFoundException e) { throw new IOException("Failed to deserialize " + SerializedThrowable.class.getCanonicalName(), e); } }
@Override public MetricCollectionResponseBody deserialize( JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { return new MetricCollectionResponseBody(jsonParser.readValueAs( new TypeReference<List<Metric>>() { })); } }
/** * Asserts that the provided JsonToken is not null, i.e., not at the end of the input. */ private static void assertNotEndOfInput( final JsonParser p, @Nullable final JsonToken jsonToken) { checkState(jsonToken != null, "Unexpected end of input at %s", p.getCurrentLocation()); }
@Override public SerializedValue<?> deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException { return SerializedValue.fromBytes(p.getBinaryValue()); }
@SuppressWarnings("unchecked") private Map<String, SerializedValue<OptionalFailure<Object>>> parseAccumulatorResults( final JsonParser p, final DeserializationContext ctxt) throws IOException { final Map<String, SerializedValue<OptionalFailure<Object>>> accumulatorResults = new HashMap<>(); while (true) { final JsonToken jsonToken = p.nextToken(); assertNotEndOfInput(p, jsonToken); if (jsonToken == JsonToken.END_OBJECT) { break; } final String accumulatorName = p.getValueAsString(); p.nextValue(); accumulatorResults.put( accumulatorName, (SerializedValue<OptionalFailure<Object>>) serializedValueDeserializer.deserialize(p, ctxt)); } return accumulatorResults; }
final JsonToken jsonToken = p.nextToken(); assertNotEndOfInput(p, jsonToken); if (jsonToken == JsonToken.END_OBJECT) { final String fieldName = p.getValueAsString(); switch (fieldName) { case JobResultSerializer.FIELD_NAME_JOB_ID: case JobResultSerializer.FIELD_NAME_APPLICATION_STATUS: assertNextToken(p, JsonToken.VALUE_STRING); applicationStatus = ApplicationStatus.valueOf(p.getValueAsString().toUpperCase()); break; case JobResultSerializer.FIELD_NAME_NET_RUNTIME: assertNextToken(p, JsonToken.VALUE_NUMBER_INT); netRuntime = p.getLongValue(); break; case JobResultSerializer.FIELD_NAME_ACCUMULATOR_RESULTS:
@Override public JobVertexID deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { return JobVertexID.fromHexString(p.getValueAsString()); } }
@Override public SerializedThrowable deserialize( final JsonParser p, final DeserializationContext ctxt) throws IOException { final JsonNode root = p.readValueAsTree(); final byte[] serializedException = root.get(FIELD_NAME_SERIALIZED_THROWABLE).binaryValue(); try { return InstantiationUtil.deserializeObject(serializedException, ClassLoader.getSystemClassLoader()); } catch (ClassNotFoundException e) { throw new IOException("Failed to deserialize " + SerializedThrowable.class.getCanonicalName(), e); } }
@Override public AggregatedMetricsResponseBody deserialize( JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { return new AggregatedMetricsResponseBody(jsonParser.readValueAs( new TypeReference<List<AggregatedMetric>>() { })); } }
/** * Asserts that the provided JsonToken is not null, i.e., not at the end of the input. */ private static void assertNotEndOfInput( final JsonParser p, @Nullable final JsonToken jsonToken) { checkState(jsonToken != null, "Unexpected end of input at %s", p.getCurrentLocation()); }
@Override public SerializedValue<?> deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException { return SerializedValue.fromBytes(p.getBinaryValue()); }
@SuppressWarnings("unchecked") private Map<String, SerializedValue<OptionalFailure<Object>>> parseAccumulatorResults( final JsonParser p, final DeserializationContext ctxt) throws IOException { final Map<String, SerializedValue<OptionalFailure<Object>>> accumulatorResults = new HashMap<>(); while (true) { final JsonToken jsonToken = p.nextToken(); assertNotEndOfInput(p, jsonToken); if (jsonToken == JsonToken.END_OBJECT) { break; } final String accumulatorName = p.getValueAsString(); p.nextValue(); accumulatorResults.put( accumulatorName, (SerializedValue<OptionalFailure<Object>>) serializedValueDeserializer.deserialize(p, ctxt)); } return accumulatorResults; }
final JsonToken jsonToken = p.nextToken(); assertNotEndOfInput(p, jsonToken); if (jsonToken == JsonToken.END_OBJECT) { final String fieldName = p.getValueAsString(); switch (fieldName) { case JobResultSerializer.FIELD_NAME_JOB_ID: case JobResultSerializer.FIELD_NAME_NET_RUNTIME: assertNextToken(p, JsonToken.VALUE_NUMBER_INT); netRuntime = p.getLongValue(); break; case JobResultSerializer.FIELD_NAME_ACCUMULATOR_RESULTS:
@Override public TriggerId deserialize( final JsonParser p, final DeserializationContext ctxt) throws IOException { return TriggerId.fromHexString(p.getValueAsString()); } }
@Override public SerializedThrowable deserialize( final JsonParser p, final DeserializationContext ctxt) throws IOException { final JsonNode root = p.readValueAsTree(); final byte[] serializedException = root.get(FIELD_NAME_SERIALIZED_THROWABLE).binaryValue(); try { return InstantiationUtil.deserializeObject(serializedException, ClassLoader.getSystemClassLoader()); } catch (ClassNotFoundException e) { throw new IOException("Failed to deserialize " + SerializedThrowable.class.getCanonicalName(), e); } }
private void dump(Plan p) { p.setExecutionConfig(new ExecutionConfig()); try { OptimizedPlan op = compileNoStats(p); PlanJSONDumpGenerator dumper = new PlanJSONDumpGenerator(); String json = dumper.getOptimizerPlanAsJSON(op); JsonParser parser = new JsonFactory().createJsonParser(json); while (parser.nextToken() != null) {} } catch (JsonParseException e) { e.printStackTrace(); Assert.fail("JSON Generator produced malformatted output: " + e.getMessage()); } catch (Exception e) { e.printStackTrace(); Assert.fail("An error occurred in the test: " + e.getMessage()); } } }