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);
}
}
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()));
}
}
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;
}
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();
}
}
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));
}
Aggregations