private static void addProperty(JsonGenerator gen, String name, String value) throws IOException { gen.writeStartObject(); gen.writeStringField("name", name); gen.writeStringField("value", value); gen.writeEndObject(); } }
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(); }
@Override public void close() throws IOException { gen.writeEndArray(); } }
try (JsonGenerator json = new JsonFactory().createGenerator(jsonFile, JsonEncoding.UTF8)) { json.writeStartObject(); json.writeObjectFieldStart("Apache Flink"); json.writeStringField("version", EnvironmentInformation.getVersion()); json.writeStringField("commit ID", EnvironmentInformation.getRevisionInformation().commitId); json.writeStringField("commit date", EnvironmentInformation.getRevisionInformation().commitDate); json.writeEndObject(); json.writeStringField("job_id", result.getJobID().toString()); json.writeNumberField("runtime_ms", result.getNetRuntime()); json.writeObjectFieldStart("parameters"); for (Map.Entry<String, String> entry : env.getConfig().getGlobalJobParameters().toMap().entrySet()) { json.writeStringField(entry.getKey(), entry.getValue()); json.writeEndObject(); json.writeObjectFieldStart("accumulators"); for (Map.Entry<String, Object> entry : result.getAllAccumulatorResults().entrySet()) { json.writeStringField(entry.getKey(), entry.getValue().toString()); json.writeEndObject(); json.writeEndObject();
public static String getOptimizerPropertiesJson(JsonFactory jsonFactory, PlanNode node) { try { final StringWriter writer = new StringWriter(256); final JsonGenerator gen = jsonFactory.createGenerator(writer); gen.writeStartObject(); gen.writeArrayFieldStart("global_properties"); gen.writeEndArray(); gen.writeArrayFieldStart("local_properties"); gen.writeEndArray(); gen.writeArrayFieldStart("estimates"); gen.writeEndArray(); gen.writeArrayFieldStart("costs"); gen.writeEndArray(); gen.writeArrayFieldStart("compiler_hints"); gen.writeEndArray(); gen.writeEndObject(); gen.close();
try (JsonGenerator gen = JACKSON_FACTORY.createGenerator(sw)) { try (JsonObject root = new JsonObject(gen)) { try (JsonArray finished = new JsonArray(gen, "finished")) { try (JsonObject job = new JsonObject(gen)) { gen.writeStringField("jid", jobID.toString()); gen.writeStringField("name", "testjob"); gen.writeStringField("state", JobStatus.FINISHED.name()); gen.writeNumberField("start-time", 0L); gen.writeNumberField("end-time", 1L); gen.writeNumberField("duration", 1L); gen.writeNumberField("last-modification", 1L); gen.writeNumberField("total", 0); gen.writeNumberField("pending", 0); gen.writeNumberField("running", 0); gen.writeNumberField("finished", 0); gen.writeNumberField("canceling", 0); gen.writeNumberField("canceled", 0); gen.writeNumberField("failed", 0);
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()); } } }
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()); } } }
@Override public void close() throws IOException { gen.writeEndObject(); } }
JsonObject(JsonGenerator gen) throws IOException { this.gen = gen; gen.writeStartObject(); }
@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(); }
/** * 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); } } }
JsonArray(JsonGenerator gen, String name) throws IOException { this.gen = gen; gen.writeArrayFieldStart(name); }
private void attachOperatorNamesAndDescriptions() { JsonFactory jsonFactory = new JsonFactory();
private JsonObject(JsonGenerator gen, String name) throws IOException { this.gen = gen; gen.writeObjectFieldStart(name); }
@Override public void serialize( RawJson jobPlanInfo, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { jsonGenerator.writeRawValue(jobPlanInfo.json); } }
/** * Converts a JSON schema into Flink's type information. Throws an exception if the schema * cannot converted because of loss of precision or too flexible schema. * * <p>The converter can resolve simple schema references to solve those cases where entities * are defined at the beginning and then used throughout a document. */ @SuppressWarnings("unchecked") public static <T> TypeInformation<T> convert(String jsonSchema) { Preconditions.checkNotNull(jsonSchema, "JSON schema"); final ObjectMapper mapper = new ObjectMapper(); mapper.getFactory() .enable(JsonParser.Feature.ALLOW_COMMENTS) .enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES) .enable(JsonParser.Feature.ALLOW_SINGLE_QUOTES); final JsonNode node; try { node = mapper.readTree(jsonSchema); } catch (IOException e) { throw new IllegalArgumentException( "Invalid JSON schema.", e); } return (TypeInformation<T>) convertType("<root>", node, node); }
private static void addProperty(JsonGenerator gen, String name, String value) throws IOException { gen.writeStartObject(); gen.writeStringField("name", name); gen.writeStringField("value", value); gen.writeEndObject(); } }
@Override public void serialize( RawJson jobPlanInfo, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { jsonGenerator.writeRawValue(jobPlanInfo.json); } }
@Override public void serialize( RawJson jobPlanInfo, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { jsonGenerator.writeRawValue(jobPlanInfo.json); } }