Search in sources :

Example 6 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 7 with ObjectMapper

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);
    }
}
Also used : QueryDisplay(org.apache.hadoop.hive.ql.QueryDisplay) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) List(java.util.List) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 8 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 9 with ObjectMapper

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);
}
Also used : JsonFactory(org.codehaus.jackson.JsonFactory) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) JsonParser(org.codehaus.jackson.JsonParser)

Example 10 with ObjectMapper

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();
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Aggregations

ObjectMapper (org.codehaus.jackson.map.ObjectMapper)356 IOException (java.io.IOException)75 Test (org.junit.Test)58 JsonNode (org.codehaus.jackson.JsonNode)47 ArrayList (java.util.ArrayList)43 HashMap (java.util.HashMap)43 Test (org.testng.annotations.Test)37 Map (java.util.Map)33 List (java.util.List)25 StringWriter (java.io.StringWriter)22 File (java.io.File)21 JSONObject (org.json.JSONObject)18 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)15 Version (org.codehaus.jackson.Version)14 SimpleModule (org.codehaus.jackson.map.module.SimpleModule)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13 JsonFactory (org.codehaus.jackson.JsonFactory)13 JSONObject (org.codehaus.jettison.json.JSONObject)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 HttpRequest (org.jboss.netty.handler.codec.http.HttpRequest)11