Search in sources :

Example 81 with ObjectMapper

use of com.fasterxml.jackson.databind.ObjectMapper in project flink by apache.

the class CheckpointStatsHandlerTest method testArchiver.

@Test
public void testArchiver() throws IOException {
    JsonArchivist archivist = new CheckpointStatsDetailsHandler.CheckpointStatsDetailsJsonArchivist();
    TestCheckpointStats testCheckpointStats = createTestCheckpointStats();
    when(testCheckpointStats.graph.getJobID()).thenReturn(new JobID());
    Collection<ArchivedJson> archives = archivist.archiveJsonWithPath(testCheckpointStats.graph);
    Assert.assertEquals(3, archives.size());
    ObjectMapper mapper = new ObjectMapper();
    Iterator<ArchivedJson> iterator = archives.iterator();
    ArchivedJson archive1 = iterator.next();
    Assert.assertEquals("/jobs/" + testCheckpointStats.graph.getJobID() + "/checkpoints/details/" + testCheckpointStats.inProgress.getCheckpointId(), archive1.getPath());
    compareInProgressCheckpoint(testCheckpointStats.inProgress, mapper.readTree(archive1.getJson()));
    ArchivedJson archive2 = iterator.next();
    Assert.assertEquals("/jobs/" + testCheckpointStats.graph.getJobID() + "/checkpoints/details/" + testCheckpointStats.completedSavepoint.getCheckpointId(), archive2.getPath());
    compareCompletedSavepoint(testCheckpointStats.completedSavepoint, mapper.readTree(archive2.getJson()));
    ArchivedJson archive3 = iterator.next();
    Assert.assertEquals("/jobs/" + testCheckpointStats.graph.getJobID() + "/checkpoints/details/" + testCheckpointStats.failed.getCheckpointId(), archive3.getPath());
    compareFailedCheckpoint(testCheckpointStats.failed, mapper.readTree(archive3.getJson()));
}
Also used : JsonArchivist(org.apache.flink.runtime.webmonitor.history.JsonArchivist) ArchivedJson(org.apache.flink.runtime.webmonitor.history.ArchivedJson) JobID(org.apache.flink.api.common.JobID) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 82 with ObjectMapper

use of com.fasterxml.jackson.databind.ObjectMapper in project flink by apache.

the class JobVertexBackPressureHandlerTest method testResponseStatsAvailable.

/** Tests the response when stats are available */
@Test
public void testResponseStatsAvailable() throws Exception {
    ExecutionJobVertex jobVertex = mock(ExecutionJobVertex.class);
    BackPressureStatsTracker statsTracker = mock(BackPressureStatsTracker.class);
    OperatorBackPressureStats stats = new OperatorBackPressureStats(0, System.currentTimeMillis(), new double[] { 0.31, 0.48, 1.0, 0.0 });
    when(statsTracker.getOperatorBackPressureStats(any(ExecutionJobVertex.class))).thenReturn(Option.apply(stats));
    JobVertexBackPressureHandler handler = new JobVertexBackPressureHandler(mock(ExecutionGraphHolder.class), statsTracker, 9999);
    String response = handler.handleRequest(jobVertex, Collections.<String, String>emptyMap());
    ObjectMapper mapper = new ObjectMapper();
    JsonNode rootNode = mapper.readTree(response);
    // Single element
    assertEquals(4, rootNode.size());
    // Status
    JsonNode status = rootNode.get("status");
    assertNotNull(status);
    assertEquals("ok", status.textValue());
    // Back pressure level
    JsonNode backPressureLevel = rootNode.get("backpressure-level");
    assertNotNull(backPressureLevel);
    assertEquals("high", backPressureLevel.textValue());
    // End time stamp
    JsonNode endTimeStamp = rootNode.get("end-timestamp");
    assertNotNull(endTimeStamp);
    assertEquals(stats.getEndTimestamp(), endTimeStamp.longValue());
    // Subtasks
    JsonNode subTasks = rootNode.get("subtasks");
    assertEquals(stats.getNumberOfSubTasks(), subTasks.size());
    for (int i = 0; i < subTasks.size(); i++) {
        JsonNode subTask = subTasks.get(i);
        JsonNode index = subTask.get("subtask");
        assertEquals(i, index.intValue());
        JsonNode level = subTask.get("backpressure-level");
        assertEquals(JobVertexBackPressureHandler.getBackPressureLevel(stats.getBackPressureRatio(i)), level.textValue());
        JsonNode ratio = subTask.get("ratio");
        assertEquals(stats.getBackPressureRatio(i), ratio.doubleValue(), 0.0);
    }
    // Verify not triggered
    verify(statsTracker, never()).triggerStackTraceSample(any(ExecutionJobVertex.class));
}
Also used : ExecutionGraphHolder(org.apache.flink.runtime.webmonitor.ExecutionGraphHolder) ExecutionJobVertex(org.apache.flink.runtime.executiongraph.ExecutionJobVertex) OperatorBackPressureStats(org.apache.flink.runtime.webmonitor.OperatorBackPressureStats) JsonNode(com.fasterxml.jackson.databind.JsonNode) BackPressureStatsTracker(org.apache.flink.runtime.webmonitor.BackPressureStatsTracker) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 83 with ObjectMapper

use of com.fasterxml.jackson.databind.ObjectMapper in project flink by apache.

the class CheckpointConfigHandlerTest method testAtLeastOnce.

/**
	 * Tests the that the isExactlyOnce flag is respected.
	 */
@Test
public void testAtLeastOnce() throws Exception {
    GraphAndSettings graphAndSettings = createGraphAndSettings(false, false);
    AccessExecutionGraph graph = graphAndSettings.graph;
    CheckpointConfigHandler handler = new CheckpointConfigHandler(mock(ExecutionGraphHolder.class));
    String json = handler.handleRequest(graph, Collections.<String, String>emptyMap());
    ObjectMapper mapper = new ObjectMapper();
    JsonNode rootNode = mapper.readTree(json);
    assertEquals("at_least_once", rootNode.get("mode").asText());
}
Also used : ExecutionGraphHolder(org.apache.flink.runtime.webmonitor.ExecutionGraphHolder) AccessExecutionGraph(org.apache.flink.runtime.executiongraph.AccessExecutionGraph) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 84 with ObjectMapper

use of com.fasterxml.jackson.databind.ObjectMapper in project hadoop by apache.

the class KMSClientProvider method writeJson.

private static void writeJson(Map map, OutputStream os) throws IOException {
    Writer writer = new OutputStreamWriter(os, StandardCharsets.UTF_8);
    ObjectMapper jsonMapper = new ObjectMapper();
    jsonMapper.writerWithDefaultPrettyPrinter().writeValue(writer, map);
}
Also used : OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 85 with ObjectMapper

use of com.fasterxml.jackson.databind.ObjectMapper in project hadoop by apache.

the class KMSClientProvider method call.

private <T> T call(HttpURLConnection conn, Map jsonOutput, int expectedResponse, Class<T> klass, int authRetryCount) throws IOException {
    T ret = null;
    try {
        if (jsonOutput != null) {
            writeJson(jsonOutput, conn.getOutputStream());
        }
    } catch (IOException ex) {
        IOUtils.closeStream(conn.getInputStream());
        throw ex;
    }
    if ((conn.getResponseCode() == HttpURLConnection.HTTP_FORBIDDEN && (conn.getResponseMessage().equals(ANONYMOUS_REQUESTS_DISALLOWED) || conn.getResponseMessage().contains(INVALID_SIGNATURE))) || conn.getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED) {
        // Ideally, this should happen only when there is an Authentication
        // failure. Unfortunately, the AuthenticationFilter returns 403 when it
        // cannot authenticate (Since a 401 requires Server to send
        // WWW-Authenticate header as well)..
        KMSClientProvider.this.authToken = new DelegationTokenAuthenticatedURL.Token();
        if (authRetryCount > 0) {
            String contentType = conn.getRequestProperty(CONTENT_TYPE);
            String requestMethod = conn.getRequestMethod();
            URL url = conn.getURL();
            conn = createConnection(url, requestMethod);
            conn.setRequestProperty(CONTENT_TYPE, contentType);
            return call(conn, jsonOutput, expectedResponse, klass, authRetryCount - 1);
        }
    }
    try {
        AuthenticatedURL.extractToken(conn, authToken);
    } catch (AuthenticationException e) {
    // Ignore the AuthExceptions.. since we are just using the method to
    // extract and set the authToken.. (Workaround till we actually fix
    // AuthenticatedURL properly to set authToken post initialization)
    }
    HttpExceptionUtils.validateResponse(conn, expectedResponse);
    if (conn.getContentType() != null && conn.getContentType().trim().toLowerCase().startsWith(APPLICATION_JSON_MIME) && klass != null) {
        ObjectMapper mapper = new ObjectMapper();
        InputStream is = null;
        try {
            is = conn.getInputStream();
            ret = mapper.readValue(is, klass);
        } finally {
            IOUtils.closeStream(is);
        }
    }
    return ret;
}
Also used : DelegationTokenAuthenticatedURL(org.apache.hadoop.security.token.delegation.web.DelegationTokenAuthenticatedURL) AuthenticationException(org.apache.hadoop.security.authentication.client.AuthenticationException) InputStream(java.io.InputStream) IOException(java.io.IOException) URL(java.net.URL) AuthenticatedURL(org.apache.hadoop.security.authentication.client.AuthenticatedURL) DelegationTokenAuthenticatedURL(org.apache.hadoop.security.token.delegation.web.DelegationTokenAuthenticatedURL) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1706 Test (org.junit.Test)641 JsonNode (com.fasterxml.jackson.databind.JsonNode)270 IOException (java.io.IOException)238 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)183 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)127 Map (java.util.Map)124 HashMap (java.util.HashMap)119 ArrayList (java.util.ArrayList)81 File (java.io.File)72 InputStream (java.io.InputStream)65 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)55 JCodeModel (com.sun.codemodel.JCodeModel)52 List (java.util.List)49 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)47 JPackage (com.sun.codemodel.JPackage)44 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)41 JsonException (jmri.server.json.JsonException)41 JType (com.sun.codemodel.JType)38 Test (org.testng.annotations.Test)37