DashboardConfigHandler extends AbstractJsonRequestHandler implements LegacyRestHandler<DispatcherGateway, DashboardConfiguration, EmptyMessageParameters> { public 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(); } DashboardConfigHandler(Executor executor, long refreshInterval); @Override String[] getPaths(); @Override CompletableFuture<DashboardConfiguration> handleRequest(HandlerRequest<EmptyRequestBody, EmptyMessageParameters> request, DispatcherGateway gateway); @Override CompletableFuture<String> handleJsonRequest(Map<String, String> pathParams, Map<String, String> queryParams, JobManagerGateway jobManagerGateway); static String createConfigJson(DashboardConfiguration dashboardConfiguration); static final String DASHBOARD_CONFIG_REST_PATH; }
@Test public void testJsonGeneration() throws Exception { long refreshInterval = 12345; final ZonedDateTime zonedDateTime = ZonedDateTime.now(); final DashboardConfiguration dashboardConfiguration = DashboardConfiguration.from(refreshInterval, zonedDateTime); String json = DashboardConfigHandler.createConfigJson(dashboardConfiguration); JsonNode result = ArchivedJobGenerationUtils.MAPPER.readTree(json); Assert.assertEquals(refreshInterval, result.get("refresh-interval").asLong()); Assert.assertEquals(dashboardConfiguration.getTimeZoneName(), result.get("timezone-name").asText()); Assert.assertEquals(dashboardConfiguration.getTimeZoneOffset(), result.get("timezone-offset").asInt()); Assert.assertEquals(dashboardConfiguration.getFlinkVersion(), result.get("flink-version").asText()); Assert.assertEquals(dashboardConfiguration.getFlinkRevision(), result.get("flink-revision").asText()); }