Search in sources :

Example 1 with ObjectMapper

use of org.codehaus.jackson.map.ObjectMapper in project hive by apache.

the class LlapStatusServiceDriver method outputJson.

public void outputJson(PrintWriter writer) throws LlapStatusCliException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false);
    mapper.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
    mapper.setSerializationInclusion(JsonSerialize.Inclusion.NON_EMPTY);
    try {
        writer.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(appStatusBuilder));
    } catch (IOException e) {
        LOG.warn("Failed to create JSON", e);
        throw new LlapStatusCliException(ExitCode.LLAP_JSON_GENERATION_ERROR, "Failed to create JSON", e);
    }
}
Also used : IOException(java.io.IOException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 2 with ObjectMapper

use of org.codehaus.jackson.map.ObjectMapper in project crate by crate.

the class PingTaskTest method testSuccessfulPingTaskRun.

@Test
public void testSuccessfulPingTaskRun() throws Exception {
    testServer = new HttpTestServer(18080, false);
    testServer.run();
    PingTask task = new PingTask(clusterService, clusterIdService, extendedNodeInfo, "http://localhost:18080/", Settings.EMPTY);
    task.run();
    assertThat(testServer.responses.size(), is(1));
    task.run();
    assertThat(testServer.responses.size(), is(2));
    for (long i = 0; i < testServer.responses.size(); i++) {
        String json = testServer.responses.get((int) i);
        Map<String, String> map = new HashMap<>();
        ObjectMapper mapper = new ObjectMapper();
        try {
            //convert JSON string to Map
            map = mapper.readValue(json, new TypeReference<HashMap<String, String>>() {
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
        assertThat(map, hasKey("kernel"));
        assertThat(map.get("kernel"), is(notNullValue()));
        assertThat(map, hasKey("cluster_id"));
        assertThat(map.get("cluster_id"), is(notNullValue()));
        assertThat(map, hasKey("master"));
        assertThat(map.get("master"), is(notNullValue()));
        assertThat(map, hasKey("ping_count"));
        assertThat(map.get("ping_count"), is(notNullValue()));
        Map<String, Long> pingCountMap;
        pingCountMap = mapper.readValue(map.get("ping_count"), new TypeReference<Map<String, Long>>() {
        });
        assertThat(pingCountMap.get("success"), is(i));
        assertThat(pingCountMap.get("failure"), is(0L));
        if (task.getHardwareAddress() != null) {
            assertThat(map, hasKey("hardware_address"));
            assertThat(map.get("hardware_address"), is(notNullValue()));
        }
        assertThat(map, hasKey("crate_version"));
        assertThat(map.get("crate_version"), is(notNullValue()));
        assertThat(map, hasKey("java_version"));
        assertThat(map.get("java_version"), is(notNullValue()));
    }
}
Also used : HashMap(java.util.HashMap) HttpTestServer(io.crate.http.HttpTestServer) TypeReference(org.codehaus.jackson.type.TypeReference) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 3 with ObjectMapper

use of org.codehaus.jackson.map.ObjectMapper in project hive by apache.

the class SQLOperation method getTaskStatus.

@Override
public String getTaskStatus() throws HiveSQLException {
    if (driver != null) {
        List<QueryDisplay.TaskDisplay> statuses = driver.getQueryDisplay().getTaskDisplays();
        if (statuses != null) {
            ByteArrayOutputStream out = null;
            try {
                ObjectMapper mapper = new ObjectMapper();
                out = new ByteArrayOutputStream();
                mapper.writeValue(out, statuses);
                return out.toString("UTF-8");
            } catch (JsonGenerationException e) {
                throw new HiveSQLException(e);
            } catch (JsonMappingException e) {
                throw new HiveSQLException(e);
            } catch (IOException e) {
                throw new HiveSQLException(e);
            } finally {
                if (out != null) {
                    try {
                        out.close();
                    } catch (IOException e) {
                        throw new HiveSQLException(e);
                    }
                }
            }
        }
    }
    // Driver not initialized
    return null;
}
Also used : HiveSQLException(org.apache.hive.service.cli.HiveSQLException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 4 with ObjectMapper

use of org.codehaus.jackson.map.ObjectMapper in project hive by apache.

the class JIRAService method publishComments.

void publishComments(String comments) {
    DefaultHttpClient httpClient = new DefaultHttpClient();
    try {
        String url = String.format("%s/rest/api/2/issue/%s/comment", mUrl, mName);
        URL apiURL = new URL(mUrl);
        httpClient.getCredentialsProvider().setCredentials(new AuthScope(apiURL.getHost(), apiURL.getPort(), AuthScope.ANY_REALM), new UsernamePasswordCredentials(mUser, mPassword));
        BasicHttpContext localcontext = new BasicHttpContext();
        localcontext.setAttribute("preemptive-auth", new BasicScheme());
        httpClient.addRequestInterceptor(new PreemptiveAuth(), 0);
        HttpPost request = new HttpPost(url);
        ObjectMapper mapper = new ObjectMapper();
        StringEntity params = new StringEntity(mapper.writeValueAsString(new Body(comments)));
        request.addHeader("Content-Type", "application/json");
        request.setEntity(params);
        HttpResponse httpResponse = httpClient.execute(request, localcontext);
        StatusLine statusLine = httpResponse.getStatusLine();
        if (statusLine.getStatusCode() != 201) {
            throw new RuntimeException(statusLine.getStatusCode() + " " + statusLine.getReasonPhrase());
        }
        mLogger.info("JIRA Response Metadata: " + httpResponse);
    } catch (Exception e) {
        mLogger.error("Encountered error attempting to post comment to " + mName, e);
    } finally {
        httpClient.getConnectionManager().shutdown();
    }
}
Also used : BasicScheme(org.apache.http.impl.auth.BasicScheme) HttpPost(org.apache.http.client.methods.HttpPost) BasicHttpContext(org.apache.http.protocol.BasicHttpContext) HttpResponse(org.apache.http.HttpResponse) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) URL(java.net.URL) IOException(java.io.IOException) HttpException(org.apache.http.HttpException) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) StatusLine(org.apache.http.StatusLine) StringEntity(org.apache.http.entity.StringEntity) AuthScope(org.apache.http.auth.AuthScope) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 5 with ObjectMapper

use of org.codehaus.jackson.map.ObjectMapper in project pinot by linkedin.

the class IndexingConfigTest method testIgnoreUnknown.

@Test
public void testIgnoreUnknown() throws JSONException, IOException {
    JSONObject json = new JSONObject();
    json.put("invertedIndexColumns", Arrays.asList("a", "b", "c"));
    json.put("sortedColumn", Arrays.asList("d", "e", "f"));
    json.put("loadMode", "MMAP");
    json.put("keyThatIsUnknown", "randomValue");
    ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonNode = mapper.readTree(json.toString());
    IndexingConfig indexingConfig = mapper.readValue(jsonNode, IndexingConfig.class);
    Assert.assertEquals("MMAP", indexingConfig.getLoadMode());
    List<String> invertedIndexColumns = indexingConfig.getInvertedIndexColumns();
    Assert.assertEquals(3, invertedIndexColumns.size());
    Assert.assertEquals("a", invertedIndexColumns.get(0));
    Assert.assertEquals("b", invertedIndexColumns.get(1));
    Assert.assertEquals("c", invertedIndexColumns.get(2));
    List<String> sortedIndexColumns = indexingConfig.getSortedColumn();
    Assert.assertEquals(3, sortedIndexColumns.size());
    Assert.assertEquals("d", sortedIndexColumns.get(0));
    Assert.assertEquals("e", sortedIndexColumns.get(1));
    Assert.assertEquals("f", sortedIndexColumns.get(2));
}
Also used : JSONObject(org.json.JSONObject) JsonNode(org.codehaus.jackson.JsonNode) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.testng.annotations.Test)

Aggregations

ObjectMapper (org.codehaus.jackson.map.ObjectMapper)763 IOException (java.io.IOException)205 JsonNode (org.codehaus.jackson.JsonNode)151 Test (org.junit.Test)148 ArrayList (java.util.ArrayList)106 HashMap (java.util.HashMap)101 StringWriter (java.io.StringWriter)57 Map (java.util.Map)57 Test (org.testng.annotations.Test)56 List (java.util.List)51 File (java.io.File)44 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)39 InputStream (java.io.InputStream)36 JsonParseException (org.codehaus.jackson.JsonParseException)31 ObjectNode (org.codehaus.jackson.node.ObjectNode)28 JaxbAnnotationIntrospector (org.codehaus.jackson.xc.JaxbAnnotationIntrospector)25 ZNRecord (org.apache.helix.ZNRecord)24 DatasetImpl (org.eol.globi.service.DatasetImpl)24 AnnotationIntrospector (org.codehaus.jackson.map.AnnotationIntrospector)23 JsonFactory (org.codehaus.jackson.JsonFactory)22