org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator Java Examples

The following examples show how to use org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator. 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: HistoryServerArchiveFetcher.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * This method replicates the JSON response that would be given by the JobsOverviewHandler when
 * listing both running and finished jobs.
 *
 * <p>Every job archive contains a joboverview.json file containing the same structure. Since jobs are archived on
 * their own however the list of finished jobs only contains a single job.
 *
 * <p>For the display in the HistoryServer WebFrontend we have to combine these overviews.
 */
private static void updateJobOverview(File webOverviewDir, File webDir) {
	try (JsonGenerator gen = jacksonFactory.createGenerator(HistoryServer.createOrGetFile(webDir, JobsOverviewHeaders.URL))) {
		File[] overviews = new File(webOverviewDir.getPath()).listFiles();
		if (overviews != null) {
			Collection<JobDetails> allJobs = new ArrayList<>(overviews.length);
			for (File overview : overviews) {
				MultipleJobsDetails subJobs = mapper.readValue(overview, MultipleJobsDetails.class);
				allJobs.addAll(subJobs.getJobs());
			}
			mapper.writeValue(gen, new MultipleJobsDetails(allJobs));
		}
	} catch (IOException ioe) {
		LOG.error("Failed to update job overview.", ioe);
	}
}
 
Example #2
Source File: HistoryServerArchiveFetcher.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * This method replicates the JSON response that would be given by the JobsOverviewHandler when
 * listing both running and finished jobs.
 *
 * <p>Every job archive contains a joboverview.json file containing the same structure. Since jobs are archived on
 * their own however the list of finished jobs only contains a single job.
 *
 * <p>For the display in the HistoryServer WebFrontend we have to combine these overviews.
 */
private static void updateJobOverview(File webOverviewDir, File webDir) {
	try (JsonGenerator gen = jacksonFactory.createGenerator(HistoryServer.createOrGetFile(webDir, JobsOverviewHeaders.URL))) {
		File[] overviews = new File(webOverviewDir.getPath()).listFiles();
		if (overviews != null) {
			Collection<JobDetails> allJobs = new ArrayList<>(overviews.length);
			for (File overview : overviews) {
				MultipleJobsDetails subJobs = mapper.readValue(overview, MultipleJobsDetails.class);
				allJobs.addAll(subJobs.getJobs());
			}
			mapper.writeValue(gen, new MultipleJobsDetails(allJobs));
		}
	} catch (IOException ioe) {
		LOG.error("Failed to update job overview.", ioe);
	}
}
 
Example #3
Source File: HistoryServer.java    From flink with Apache License 2.0 6 votes vote down vote up
private static String createConfigJson(DashboardConfiguration dashboardConfiguration) throws IOException {
	StringWriter writer = new StringWriter();
	JsonGenerator gen = JsonFactory.JACKSON_FACTORY.createGenerator(writer);

	gen.writeStartObject();
	gen.writeNumberField(DashboardConfiguration.FIELD_NAME_REFRESH_INTERVAL, dashboardConfiguration.getRefreshInterval());
	gen.writeNumberField(DashboardConfiguration.FIELD_NAME_TIMEZONE_OFFSET, dashboardConfiguration.getTimeZoneOffset());
	gen.writeStringField(DashboardConfiguration.FIELD_NAME_TIMEZONE_NAME, dashboardConfiguration.getTimeZoneName());
	gen.writeStringField(DashboardConfiguration.FIELD_NAME_FLINK_VERSION, dashboardConfiguration.getFlinkVersion());
	gen.writeStringField(DashboardConfiguration.FIELD_NAME_FLINK_REVISION, dashboardConfiguration.getFlinkRevision());

	gen.writeEndObject();

	gen.close();

	return writer.toString();
}
 
Example #4
Source File: MutableIOMetrics.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Writes the IO metrics contained in this object to the given {@link JsonGenerator}.
 *
 * <p>The JSON structure written is as follows:
 * "metrics": {
 *     "read-bytes": 1,
 *     "read-bytes-complete": true,
 *     "write-bytes": 2,
 *     "write-bytes-complete": true,
 *     "read-records": 3,
 *     "read-records-complete": true,
 *     "write-records": 4,
 *     "write-records-complete": true
 * }
 *
 * @param gen JsonGenerator to which the metrics should be written
 * @throws IOException
 */
public void writeIOMetricsAsJson(JsonGenerator gen) throws IOException {
	/**
	 * As described in {@link addIOMetrics}, we want to distinguish incomplete values from 0.
	 * However, for API backward compatibility, incomplete metrics will still be represented by the 0 value and
	 * a boolean will indicate the completeness.
	 */

	gen.writeObjectFieldStart("metrics");

	Long numBytesIn = this.numBytesInLocal + this.numBytesInRemote;
	gen.writeNumberField("read-bytes", numBytesIn);
	gen.writeBooleanField("read-bytes-complete", (this.numBytesInLocalComplete && this.numBytesInRemoteComplete));
	gen.writeNumberField("write-bytes", this.numBytesOut);
	gen.writeBooleanField("write-bytes-complete", this.numBytesOutComplete);
	gen.writeNumberField("read-records", this.numRecordsIn);
	gen.writeBooleanField("read-records-complete", this.numRecordsInComplete);
	gen.writeNumberField("write-records", this.numRecordsOut);
	gen.writeBooleanField("write-records-complete", this.numRecordsOutComplete);

	gen.writeEndObject();
}
 
Example #5
Source File: JobConfigInfo.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(
		JobConfigInfo jobConfigInfo,
		JsonGenerator jsonGenerator,
		SerializerProvider serializerProvider) throws IOException {
	jsonGenerator.writeStartObject();

	jsonGenerator.writeStringField(FIELD_NAME_JOB_ID, jobConfigInfo.getJobId().toString());
	jsonGenerator.writeStringField(FIELD_NAME_JOB_NAME, jobConfigInfo.getJobName());

	if (jobConfigInfo.getExecutionConfigInfo() != null) {
		jsonGenerator.writeObjectField(FIELD_NAME_EXECUTION_CONFIG, jobConfigInfo.getExecutionConfigInfo());
	}

	jsonGenerator.writeEndObject();
}
 
Example #6
Source File: HistoryServer.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private static String createConfigJson(DashboardConfiguration dashboardConfiguration) throws IOException {
	StringWriter writer = new StringWriter();
	JsonGenerator gen = JsonFactory.JACKSON_FACTORY.createGenerator(writer);

	gen.writeStartObject();
	gen.writeNumberField(DashboardConfiguration.FIELD_NAME_REFRESH_INTERVAL, dashboardConfiguration.getRefreshInterval());
	gen.writeNumberField(DashboardConfiguration.FIELD_NAME_TIMEZONE_OFFSET, dashboardConfiguration.getTimeZoneOffset());
	gen.writeStringField(DashboardConfiguration.FIELD_NAME_TIMEZONE_NAME, dashboardConfiguration.getTimeZoneName());
	gen.writeStringField(DashboardConfiguration.FIELD_NAME_FLINK_VERSION, dashboardConfiguration.getFlinkVersion());
	gen.writeStringField(DashboardConfiguration.FIELD_NAME_FLINK_REVISION, dashboardConfiguration.getFlinkRevision());

	gen.writeEndObject();

	gen.close();

	return writer.toString();
}
 
Example #7
Source File: JobConfigInfo.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(
		JobConfigInfo jobConfigInfo,
		JsonGenerator jsonGenerator,
		SerializerProvider serializerProvider) throws IOException {
	jsonGenerator.writeStartObject();

	jsonGenerator.writeStringField(FIELD_NAME_JOB_ID, jobConfigInfo.getJobId().toString());
	jsonGenerator.writeStringField(FIELD_NAME_JOB_NAME, jobConfigInfo.getJobName());

	if (jobConfigInfo.getExecutionConfigInfo() != null) {
		jsonGenerator.writeObjectField(FIELD_NAME_EXECUTION_CONFIG, jobConfigInfo.getExecutionConfigInfo());
	}

	jsonGenerator.writeEndObject();
}
 
Example #8
Source File: JobConfigInfo.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(
		JobConfigInfo jobConfigInfo,
		JsonGenerator jsonGenerator,
		SerializerProvider serializerProvider) throws IOException {
	jsonGenerator.writeStartObject();

	jsonGenerator.writeStringField(FIELD_NAME_JOB_ID, jobConfigInfo.getJobId().toString());
	jsonGenerator.writeStringField(FIELD_NAME_JOB_NAME, jobConfigInfo.getJobName());

	if (jobConfigInfo.getExecutionConfigInfo() != null) {
		jsonGenerator.writeObjectField(FIELD_NAME_EXECUTION_CONFIG, jobConfigInfo.getExecutionConfigInfo());
	}

	jsonGenerator.writeEndObject();
}
 
Example #9
Source File: HistoryServerArchiveFetcher.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * This method replicates the JSON response that would be given by the JobsOverviewHandler when
 * listing both running and finished jobs.
 *
 * <p>Every job archive contains a joboverview.json file containing the same structure. Since jobs are archived on
 * their own however the list of finished jobs only contains a single job.
 *
 * <p>For the display in the HistoryServer WebFrontend we have to combine these overviews.
 */
private static void updateJobOverview(File webOverviewDir, File webDir) {
	try (JsonGenerator gen = jacksonFactory.createGenerator(HistoryServer.createOrGetFile(webDir, JobsOverviewHeaders.URL))) {
		File[] overviews = new File(webOverviewDir.getPath()).listFiles();
		if (overviews != null) {
			Collection<JobDetails> allJobs = new ArrayList<>(overviews.length);
			for (File overview : overviews) {
				MultipleJobsDetails subJobs = mapper.readValue(overview, MultipleJobsDetails.class);
				allJobs.addAll(subJobs.getJobs());
			}
			mapper.writeValue(gen, new MultipleJobsDetails(allJobs));
		}
	} catch (IOException ioe) {
		LOG.error("Failed to update job overview.", ioe);
	}
}
 
Example #10
Source File: MetricCollectionResponseBody.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(
		MetricCollectionResponseBody metricCollectionResponseBody,
		JsonGenerator jsonGenerator,
		SerializerProvider serializerProvider) throws IOException {

	jsonGenerator.writeObject(metricCollectionResponseBody.getMetrics());
}
 
Example #11
Source File: JobPlanInfo.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(
		RawJson jobPlanInfo,
		JsonGenerator jsonGenerator,
		SerializerProvider serializerProvider) throws IOException {
	jsonGenerator.writeRawValue(jobPlanInfo.json);
}
 
Example #12
Source File: JobDetails.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(
		JobDetails jobDetails,
		JsonGenerator jsonGenerator,
		SerializerProvider serializerProvider) throws IOException {
	jsonGenerator.writeStartObject();

	jsonGenerator.writeStringField(FIELD_NAME_JOB_ID, jobDetails.getJobId().toString());
	jsonGenerator.writeStringField(FIELD_NAME_JOB_NAME, jobDetails.getJobName());
	jsonGenerator.writeStringField(FIELD_NAME_STATUS, jobDetails.getStatus().name());

	jsonGenerator.writeNumberField(FIELD_NAME_START_TIME, jobDetails.getStartTime());
	jsonGenerator.writeNumberField(FIELD_NAME_END_TIME, jobDetails.getEndTime());
	jsonGenerator.writeNumberField(FIELD_NAME_DURATION, jobDetails.getDuration());
	jsonGenerator.writeNumberField(FIELD_NAME_LAST_MODIFICATION, jobDetails.getLastUpdateTime());

	jsonGenerator.writeObjectFieldStart("tasks");
	jsonGenerator.writeNumberField(FIELD_NAME_TOTAL_NUMBER_TASKS, jobDetails.getNumTasks());

	final int[] perState = jobDetails.getTasksPerState();

	for (ExecutionState executionState : ExecutionState.values()) {
		jsonGenerator.writeNumberField(executionState.name().toLowerCase(), perState[executionState.ordinal()]);
	}

	jsonGenerator.writeEndObject();

	jsonGenerator.writeEndObject();
}
 
Example #13
Source File: MetricCollectionResponseBody.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(
		MetricCollectionResponseBody metricCollectionResponseBody,
		JsonGenerator jsonGenerator,
		SerializerProvider serializerProvider) throws IOException {

	jsonGenerator.writeObject(metricCollectionResponseBody.getMetrics());
}
 
Example #14
Source File: TriggerId.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(
		final TriggerId value,
		final JsonGenerator gen,
		final SerializerProvider provider) throws IOException {
	gen.writeString(value.toString());
}
 
Example #15
Source File: SerializedValueSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(
		final SerializedValue<?> value,
		final JsonGenerator gen,
		final SerializerProvider provider) throws IOException {
	gen.writeBinary(value.getByteArray());
}
 
Example #16
Source File: SerializedThrowableSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(final SerializedThrowable value, final JsonGenerator gen, final SerializerProvider provider) throws IOException {
	gen.writeStartObject();
	gen.writeStringField(FIELD_NAME_CLASS, value.getOriginalErrorClassName());
	gen.writeStringField(FIELD_NAME_STACK_TRACE, value.getFullStringifiedStackTrace());
	gen.writeBinaryField(FIELD_NAME_SERIALIZED_THROWABLE, InstantiationUtil.serializeObject(value));
	gen.writeEndObject();
}
 
Example #17
Source File: AggregatedMetricsResponseBody.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(
	AggregatedMetricsResponseBody metricCollectionResponseBody,
	JsonGenerator jsonGenerator,
	SerializerProvider serializerProvider) throws IOException {

	jsonGenerator.writeObject(metricCollectionResponseBody.getMetrics());
}
 
Example #18
Source File: AggregatedMetricsResponseBody.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(
	AggregatedMetricsResponseBody metricCollectionResponseBody,
	JsonGenerator jsonGenerator,
	SerializerProvider serializerProvider) throws IOException {

	jsonGenerator.writeObject(metricCollectionResponseBody.getMetrics());
}
 
Example #19
Source File: SerializedThrowableSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(final SerializedThrowable value, final JsonGenerator gen, final SerializerProvider provider) throws IOException {
	gen.writeStartObject();
	gen.writeStringField(FIELD_NAME_CLASS, value.getOriginalErrorClassName());
	gen.writeStringField(FIELD_NAME_STACK_TRACE, value.getFullStringifiedStackTrace());
	gen.writeBinaryField(FIELD_NAME_SERIALIZED_THROWABLE, InstantiationUtil.serializeObject(value));
	gen.writeEndObject();
}
 
Example #20
Source File: JobPlanInfo.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(
		RawJson jobPlanInfo,
		JsonGenerator jsonGenerator,
		SerializerProvider serializerProvider) throws IOException {
	jsonGenerator.writeRawValue(jobPlanInfo.json);
}
 
Example #21
Source File: SerializedValueSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(
		final SerializedValue<?> value,
		final JsonGenerator gen,
		final SerializerProvider provider) throws IOException {
	gen.writeBinary(value.getByteArray());
}
 
Example #22
Source File: JobDetails.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(
		JobDetails jobDetails,
		JsonGenerator jsonGenerator,
		SerializerProvider serializerProvider) throws IOException {
	jsonGenerator.writeStartObject();

	jsonGenerator.writeStringField(FIELD_NAME_JOB_ID, jobDetails.getJobId().toString());
	jsonGenerator.writeStringField(FIELD_NAME_JOB_NAME, jobDetails.getJobName());
	jsonGenerator.writeStringField(FIELD_NAME_STATUS, jobDetails.getStatus().name());

	jsonGenerator.writeNumberField(FIELD_NAME_START_TIME, jobDetails.getStartTime());
	jsonGenerator.writeNumberField(FIELD_NAME_END_TIME, jobDetails.getEndTime());
	jsonGenerator.writeNumberField(FIELD_NAME_DURATION, jobDetails.getDuration());
	jsonGenerator.writeNumberField(FIELD_NAME_LAST_MODIFICATION, jobDetails.getLastUpdateTime());

	jsonGenerator.writeObjectFieldStart("tasks");
	jsonGenerator.writeNumberField(FIELD_NAME_TOTAL_NUMBER_TASKS, jobDetails.getNumTasks());

	final int[] perState = jobDetails.getTasksPerState();

	for (ExecutionState executionState : ExecutionState.values()) {
		jsonGenerator.writeNumberField(executionState.name().toLowerCase(), perState[executionState.ordinal()]);
	}

	jsonGenerator.writeEndObject();

	jsonGenerator.writeEndObject();
}
 
Example #23
Source File: TriggerId.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(
		final TriggerId value,
		final JsonGenerator gen,
		final SerializerProvider provider) throws IOException {
	gen.writeString(value.toString());
}
 
Example #24
Source File: AggregatedMetricsResponseBody.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(
	AggregatedMetricsResponseBody metricCollectionResponseBody,
	JsonGenerator jsonGenerator,
	SerializerProvider serializerProvider) throws IOException {

	jsonGenerator.writeObject(metricCollectionResponseBody.getMetrics());
}
 
Example #25
Source File: MetricCollectionResponseBody.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(
		MetricCollectionResponseBody metricCollectionResponseBody,
		JsonGenerator jsonGenerator,
		SerializerProvider serializerProvider) throws IOException {

	jsonGenerator.writeObject(metricCollectionResponseBody.getMetrics());
}
 
Example #26
Source File: TriggerId.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(
		final TriggerId value,
		final JsonGenerator gen,
		final SerializerProvider provider) throws IOException {
	gen.writeString(value.toString());
}
 
Example #27
Source File: JobPlanInfo.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(
		RawJson jobPlanInfo,
		JsonGenerator jsonGenerator,
		SerializerProvider serializerProvider) throws IOException {
	jsonGenerator.writeRawValue(jobPlanInfo.json);
}
 
Example #28
Source File: SerializedValueSerializer.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(
		final SerializedValue<?> value,
		final JsonGenerator gen,
		final SerializerProvider provider) throws IOException {
	gen.writeBinary(value.getByteArray());
}
 
Example #29
Source File: SerializedThrowableSerializer.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(final SerializedThrowable value, final JsonGenerator gen, final SerializerProvider provider) throws IOException {
	gen.writeStartObject();
	gen.writeStringField(FIELD_NAME_CLASS, value.getOriginalErrorClassName());
	gen.writeStringField(FIELD_NAME_STACK_TRACE, value.getFullStringifiedStackTrace());
	gen.writeBinaryField(FIELD_NAME_SERIALIZED_THROWABLE, InstantiationUtil.serializeObject(value));
	gen.writeEndObject();
}
 
Example #30
Source File: JobDetails.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(
		JobDetails jobDetails,
		JsonGenerator jsonGenerator,
		SerializerProvider serializerProvider) throws IOException {
	jsonGenerator.writeStartObject();

	jsonGenerator.writeStringField(FIELD_NAME_JOB_ID, jobDetails.getJobId().toString());
	jsonGenerator.writeStringField(FIELD_NAME_JOB_NAME, jobDetails.getJobName());
	jsonGenerator.writeStringField(FIELD_NAME_STATUS, jobDetails.getStatus().name());

	jsonGenerator.writeNumberField(FIELD_NAME_START_TIME, jobDetails.getStartTime());
	jsonGenerator.writeNumberField(FIELD_NAME_END_TIME, jobDetails.getEndTime());
	jsonGenerator.writeNumberField(FIELD_NAME_DURATION, jobDetails.getDuration());
	jsonGenerator.writeNumberField(FIELD_NAME_LAST_MODIFICATION, jobDetails.getLastUpdateTime());

	jsonGenerator.writeObjectFieldStart("tasks");
	jsonGenerator.writeNumberField(FIELD_NAME_TOTAL_NUMBER_TASKS, jobDetails.getNumTasks());

	final int[] perState = jobDetails.getTasksPerState();

	for (ExecutionState executionState : ExecutionState.values()) {
		jsonGenerator.writeNumberField(executionState.name().toLowerCase(), perState[executionState.ordinal()]);
	}

	jsonGenerator.writeEndObject();

	jsonGenerator.writeEndObject();
}