Java Code Examples for org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParser#nextToken()

The following examples show how to use org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParser#nextToken() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsonJobGraphGenerationTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public JobExecutionResult execute(String jobName) throws Exception {
	Plan plan = createProgramPlan(jobName);

	Optimizer pc = new Optimizer(new Configuration());
	OptimizedPlan op = pc.compile(plan);

	JobGraphGenerator jgg = new JobGraphGenerator();
	JobGraph jobGraph = jgg.compileJobGraph(op);

	String jsonPlan = JsonPlanGenerator.generatePlan(jobGraph);

	// first check that the JSON is valid
	JsonParser parser = new JsonFactory().createJsonParser(jsonPlan);
	while (parser.nextToken() != null) {}

	validator.validateJson(jsonPlan);

	throw new AbortError();
}
 
Example 2
Source File: JobResultDeserializer.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 3
Source File: JsonJobGraphGenerationTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public JobExecutionResult execute(String jobName) throws Exception {
	Plan plan = createProgramPlan(jobName);

	Optimizer pc = new Optimizer(new Configuration());
	OptimizedPlan op = pc.compile(plan);

	JobGraphGenerator jgg = new JobGraphGenerator();
	JobGraph jobGraph = jgg.compileJobGraph(op);

	String jsonPlan = JsonPlanGenerator.generatePlan(jobGraph);

	// first check that the JSON is valid
	JsonParser parser = new JsonFactory().createJsonParser(jsonPlan);
	while (parser.nextToken() != null) {}

	validator.validateJson(jsonPlan);

	throw new AbortError();
}
 
Example 4
Source File: JobResultDeserializer.java    From flink with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 5
Source File: JsonJobGraphGenerationTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public JobExecutionResult execute(String jobName) throws Exception {
	Plan plan = createProgramPlan(jobName);

	Optimizer pc = new Optimizer(new Configuration());
	OptimizedPlan op = pc.compile(plan);

	JobGraphGenerator jgg = new JobGraphGenerator();
	JobGraph jobGraph = jgg.compileJobGraph(op);

	String jsonPlan = JsonPlanGenerator.generatePlan(jobGraph);

	// first check that the JSON is valid
	JsonParser parser = new JsonFactory().createJsonParser(jsonPlan);
	while (parser.nextToken() != null) {}

	validator.validateJson(jsonPlan);

	throw new AbortError();
}
 
Example 6
Source File: JobResultDeserializer.java    From flink with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 7
Source File: JobResultDeserializer.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Advances the token and asserts that it matches the required {@link JsonToken}.
 */
private static void assertNextToken(
		final JsonParser p,
		final JsonToken requiredJsonToken) throws IOException {
	final JsonToken jsonToken = p.nextToken();
	if (jsonToken != requiredJsonToken) {
		throw new JsonMappingException(p, String.format("Expected token %s (was %s)", requiredJsonToken, jsonToken));
	}
}
 
Example 8
Source File: JobResultDeserializer.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Advances the token and asserts that it matches the required {@link JsonToken}.
 */
private static void assertNextToken(
		final JsonParser p,
		final JsonToken requiredJsonToken) throws IOException {
	final JsonToken jsonToken = p.nextToken();
	if (jsonToken != requiredJsonToken) {
		throw new JsonMappingException(p, String.format("Expected token %s (was %s)", requiredJsonToken, jsonToken));
	}
}
 
Example 9
Source File: JobResultDeserializer.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Advances the token and asserts that it matches the required {@link JsonToken}.
 */
private static void assertNextToken(
		final JsonParser p,
		final JsonToken requiredJsonToken) throws IOException {
	final JsonToken jsonToken = p.nextToken();
	if (jsonToken != requiredJsonToken) {
		throw new JsonMappingException(p, String.format("Expected token %s (was %s)", requiredJsonToken, jsonToken));
	}
}
 
Example 10
Source File: JobResultDeserializer.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public JobResult deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException {
	JobID jobId = null;
	ApplicationStatus applicationStatus = ApplicationStatus.UNKNOWN;
	long netRuntime = -1;
	SerializedThrowable serializedThrowable = null;
	Map<String, SerializedValue<OptionalFailure<Object>>> accumulatorResults = null;

	while (true) {
		final JsonToken jsonToken = p.nextToken();
		assertNotEndOfInput(p, jsonToken);
		if (jsonToken == JsonToken.END_OBJECT) {
			break;
		}

		final String fieldName = p.getValueAsString();
		switch (fieldName) {
			case JobResultSerializer.FIELD_NAME_JOB_ID:
				assertNextToken(p, JsonToken.VALUE_STRING);
				jobId = jobIdDeserializer.deserialize(p, ctxt);
				break;
			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:
				assertNextToken(p, JsonToken.START_OBJECT);
				accumulatorResults = parseAccumulatorResults(p, ctxt);
				break;
			case JobResultSerializer.FIELD_NAME_FAILURE_CAUSE:
				assertNextToken(p, JsonToken.START_OBJECT);
				serializedThrowable = serializedThrowableDeserializer.deserialize(p, ctxt);
				break;
			default:
				// ignore unknown fields
		}
	}

	try {
		return new JobResult.Builder()
			.jobId(jobId)
			.applicationStatus(applicationStatus)
			.netRuntime(netRuntime)
			.accumulatorResults(accumulatorResults)
			.serializedThrowable(serializedThrowable)
			.build();
	} catch (final RuntimeException e) {
		throw new JsonMappingException(
			null,
			"Could not deserialize " + JobResult.class.getSimpleName(),
			e);
	}
}
 
Example 11
Source File: JobResultDeserializer.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public JobResult deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException {
	JobID jobId = null;
	ApplicationStatus applicationStatus = ApplicationStatus.UNKNOWN;
	long netRuntime = -1;
	SerializedThrowable serializedThrowable = null;
	Map<String, SerializedValue<OptionalFailure<Object>>> accumulatorResults = null;

	while (true) {
		final JsonToken jsonToken = p.nextToken();
		assertNotEndOfInput(p, jsonToken);
		if (jsonToken == JsonToken.END_OBJECT) {
			break;
		}

		final String fieldName = p.getValueAsString();
		switch (fieldName) {
			case JobResultSerializer.FIELD_NAME_JOB_ID:
				assertNextToken(p, JsonToken.VALUE_STRING);
				jobId = jobIdDeserializer.deserialize(p, ctxt);
				break;
			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:
				assertNextToken(p, JsonToken.START_OBJECT);
				accumulatorResults = parseAccumulatorResults(p, ctxt);
				break;
			case JobResultSerializer.FIELD_NAME_FAILURE_CAUSE:
				assertNextToken(p, JsonToken.START_OBJECT);
				serializedThrowable = serializedThrowableDeserializer.deserialize(p, ctxt);
				break;
			default:
				// ignore unknown fields
		}
	}

	try {
		return new JobResult.Builder()
			.jobId(jobId)
			.applicationStatus(applicationStatus)
			.netRuntime(netRuntime)
			.accumulatorResults(accumulatorResults)
			.serializedThrowable(serializedThrowable)
			.build();
	} catch (final RuntimeException e) {
		throw new JsonMappingException(
			null,
			"Could not deserialize " + JobResult.class.getSimpleName(),
			e);
	}
}
 
Example 12
Source File: JobResultDeserializer.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public JobResult deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException {
	JobID jobId = null;
	ApplicationStatus applicationStatus = ApplicationStatus.UNKNOWN;
	long netRuntime = -1;
	SerializedThrowable serializedThrowable = null;
	Map<String, SerializedValue<OptionalFailure<Object>>> accumulatorResults = null;

	while (true) {
		final JsonToken jsonToken = p.nextToken();
		assertNotEndOfInput(p, jsonToken);
		if (jsonToken == JsonToken.END_OBJECT) {
			break;
		}

		final String fieldName = p.getValueAsString();
		switch (fieldName) {
			case JobResultSerializer.FIELD_NAME_JOB_ID:
				assertNextToken(p, JsonToken.VALUE_STRING);
				jobId = jobIdDeserializer.deserialize(p, ctxt);
				break;
			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:
				assertNextToken(p, JsonToken.START_OBJECT);
				accumulatorResults = parseAccumulatorResults(p, ctxt);
				break;
			case JobResultSerializer.FIELD_NAME_FAILURE_CAUSE:
				assertNextToken(p, JsonToken.START_OBJECT);
				serializedThrowable = serializedThrowableDeserializer.deserialize(p, ctxt);
				break;
			default:
				// ignore unknown fields
		}
	}

	try {
		return new JobResult.Builder()
			.jobId(jobId)
			.applicationStatus(applicationStatus)
			.netRuntime(netRuntime)
			.accumulatorResults(accumulatorResults)
			.serializedThrowable(serializedThrowable)
			.build();
	} catch (final RuntimeException e) {
		throw new JsonMappingException(
			null,
			"Could not deserialize " + JobResult.class.getSimpleName(),
			e);
	}
}