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 CLIServiceTest method testTaskStatus.
@Test
public void testTaskStatus() throws Exception {
HashMap<String, String> confOverlay = new HashMap<String, String>();
String tableName = "TEST_EXEC_ASYNC";
String columnDefinitions = "(ID STRING)";
// Open a session and set up the test data
SessionHandle sessionHandle = setupTestData(tableName, columnDefinitions, confOverlay);
assertNotNull(sessionHandle);
// nonblocking execute
String select = "select a.id, b.id from (SELECT ID + ' ' `ID` FROM TEST_EXEC_ASYNC) a full outer join " + "(SELECT ID + ' ' `ID` FROM TEST_EXEC_ASYNC) b on a.ID=b.ID";
OperationHandle ophandle = client.executeStatementAsync(sessionHandle, select, confOverlay);
OperationStatus status = null;
int count = 0;
while (true) {
status = client.getOperationStatus(ophandle, false);
checkOperationTimes(ophandle, status);
OperationState state = status.getState();
System.out.println("Polling: " + ophandle + " count=" + (++count) + " state=" + state);
String jsonTaskStatus = status.getTaskStatus();
assertNotNull(jsonTaskStatus);
ObjectMapper mapper = new ObjectMapper();
ByteArrayInputStream in = new ByteArrayInputStream(jsonTaskStatus.getBytes("UTF-8"));
List<QueryDisplay.TaskDisplay> taskStatuses = mapper.readValue(in, new TypeReference<List<QueryDisplay.TaskDisplay>>() {
});
// TaskDisplay doesn't have a toString, using json
System.out.println("task statuses: " + jsonTaskStatus);
checkTaskStatuses(taskStatuses);
if (OperationState.CANCELED == state || state == OperationState.CLOSED || state == OperationState.FINISHED || state == OperationState.ERROR) {
for (QueryDisplay.TaskDisplay display : taskStatuses) {
assertNotNull(display.getReturnValue());
}
break;
}
Thread.sleep(1000);
}
}
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 hive by apache.
the class JSONMessageFactory method getJsonTree.
public static ObjectNode getJsonTree(String eventMessage) throws Exception {
JsonParser jsonParser = (new JsonFactory()).createJsonParser(eventMessage);
ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(jsonParser, ObjectNode.class);
}
use of org.codehaus.jackson.map.ObjectMapper in project hive by apache.
the class JsonBuilder method mapToJson.
/**
* Convert a map to a json string.
*/
public static String mapToJson(Object obj) throws IOException {
ObjectMapper mapper = new ObjectMapper();
ByteArrayOutputStream out = new ByteArrayOutputStream();
mapper.writeValue(out, obj);
return out.toString();
}
Aggregations