Skip to content

Commit

Permalink
[FLINK-15085][hs] Simplify dashboard config generation
Browse files Browse the repository at this point in the history
  • Loading branch information
zentol committed Dec 6, 2019
1 parent 0d1bfeb commit 1b0b289
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.apache.flink.runtime.history.FsJobArchivist;
import org.apache.flink.runtime.io.network.netty.SSLHandlerFactory;
import org.apache.flink.runtime.net.SSLUtils;
import org.apache.flink.runtime.rest.handler.legacy.JsonFactory;
import org.apache.flink.runtime.rest.handler.router.Router;
import org.apache.flink.runtime.rest.messages.DashboardConfiguration;
import org.apache.flink.runtime.security.SecurityConfiguration;
Expand All @@ -42,7 +41,7 @@
import org.apache.flink.util.Preconditions;
import org.apache.flink.util.ShutdownHookUtil;

import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -52,7 +51,6 @@
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringWriter;
import java.lang.reflect.UndeclaredThrowableException;
import java.nio.file.Files;
import java.time.ZonedDateTime;
Expand Down Expand Up @@ -86,6 +84,7 @@
public class HistoryServer {

private static final Logger LOG = LoggerFactory.getLogger(HistoryServer.class);
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

private final Configuration config;

Expand Down Expand Up @@ -300,21 +299,7 @@ private void createDashboardConfigFile() throws IOException {
}

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();
return OBJECT_MAPPER.writeValueAsString(dashboardConfiguration);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.apache.flink.runtime.history.FsJobArchivist;
import org.apache.flink.runtime.messages.webmonitor.JobDetails;
import org.apache.flink.runtime.messages.webmonitor.MultipleJobsDetails;
import org.apache.flink.runtime.rest.messages.DashboardConfiguration;
import org.apache.flink.runtime.rest.messages.DashboardConfigurationHeaders;
import org.apache.flink.runtime.rest.messages.JobsOverviewHeaders;
import org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
Expand All @@ -36,6 +38,7 @@

import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonFactory;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.DeserializationFeature;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper;

import org.apache.commons.io.IOUtils;
Expand Down Expand Up @@ -73,7 +76,8 @@ public class HistoryServerTest extends TestLogger {
private static final JsonFactory JACKSON_FACTORY = new JsonFactory()
.enable(JsonGenerator.Feature.AUTO_CLOSE_TARGET)
.disable(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT);
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper()
.enable(DeserializationFeature.FAIL_ON_MISSING_CREATOR_PROPERTIES);

@Rule
public final TemporaryFolder tmpFolder = new TemporaryFolder();
Expand Down Expand Up @@ -141,6 +145,9 @@ public void testHistoryServerIntegration() throws Exception {
numExpectedArchivedJobs.await(10L, TimeUnit.SECONDS);

Assert.assertEquals(numJobs + numLegacyJobs, getJobsOverview(baseUrl).getJobs().size());

// checks whether the dashboard configuration contains all expected fields
getDashboardConfiguration(baseUrl);
} finally {
hs.stop();
}
Expand Down Expand Up @@ -236,6 +243,12 @@ private Configuration createTestConfiguration(boolean cleanupExpiredJobs) {
return historyServerConfig;
}

private static DashboardConfiguration getDashboardConfiguration(String baseUrl) throws Exception {
String response = getFromHTTP(baseUrl + DashboardConfigurationHeaders.INSTANCE.getTargetRestEndpointURL());
return OBJECT_MAPPER.readValue(response, DashboardConfiguration.class);

}

private static MultipleJobsDetails getJobsOverview(String baseUrl) throws Exception {
String response = getFromHTTP(baseUrl + JobsOverviewHeaders.URL);
return OBJECT_MAPPER.readValue(response, MultipleJobsDetails.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
public final class DashboardConfigurationHeaders implements MessageHeaders<EmptyRequestBody, DashboardConfiguration, EmptyMessageParameters> {

private static final DashboardConfigurationHeaders INSTANCE = new DashboardConfigurationHeaders();
public static final DashboardConfigurationHeaders INSTANCE = new DashboardConfigurationHeaders();

// make the constructor private since we want it to be a singleton
private DashboardConfigurationHeaders() {}
Expand Down

0 comments on commit 1b0b289

Please sign in to comment.