Search in sources :

Example 41 with WebResource

use of com.sun.jersey.api.client.WebResource in project zookeeper by apache.

the class SessionTest method testSendHeartbeat.

@Test
public void testSendHeartbeat() throws InterruptedException {
    ZSession session = createSession("2");
    Thread.sleep(1000);
    WebResource wr = sessionsr.path(session.id);
    Builder b = wr.accept(MediaType.APPLICATION_JSON);
    ClientResponse cr = b.put(ClientResponse.class, null);
    Assert.assertEquals(ClientResponse.Status.OK, cr.getClientResponseStatus());
    Thread.sleep(1500);
    Assert.assertTrue(ZooKeeperService.isConnected(CONTEXT_PATH, session.id));
    Thread.sleep(1000);
    Assert.assertFalse(ZooKeeperService.isConnected(CONTEXT_PATH, session.id));
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Builder(com.sun.jersey.api.client.WebResource.Builder) WebResource(com.sun.jersey.api.client.WebResource) ZSession(org.apache.zookeeper.server.jersey.jaxb.ZSession) Test(org.junit.Test)

Example 42 with WebResource

use of com.sun.jersey.api.client.WebResource in project zookeeper by apache.

the class SessionTest method createSession.

private ZSession createSession(String expire) {
    WebResource wr = sessionsr.queryParam("op", "create").queryParam("expire", expire);
    Builder b = wr.accept(MediaType.APPLICATION_JSON);
    ClientResponse cr = b.post(ClientResponse.class, null);
    Assert.assertEquals(ClientResponse.Status.CREATED, cr.getClientResponseStatus());
    return cr.getEntity(ZSession.class);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Builder(com.sun.jersey.api.client.WebResource.Builder) WebResource(com.sun.jersey.api.client.WebResource)

Example 43 with WebResource

use of com.sun.jersey.api.client.WebResource in project zookeeper by apache.

the class SessionTest method testDeleteSession.

@Test
public void testDeleteSession() {
    ZSession session = createSession("30");
    WebResource wr = sessionsr.path(session.id);
    Builder b = wr.accept(MediaType.APPLICATION_JSON);
    Assert.assertTrue(ZooKeeperService.isConnected(CONTEXT_PATH, session.id));
    ClientResponse cr = b.delete(ClientResponse.class, null);
    Assert.assertEquals(ClientResponse.Status.NO_CONTENT, cr.getClientResponseStatus());
    Assert.assertFalse(ZooKeeperService.isConnected(CONTEXT_PATH, session.id));
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Builder(com.sun.jersey.api.client.WebResource.Builder) WebResource(com.sun.jersey.api.client.WebResource) ZSession(org.apache.zookeeper.server.jersey.jaxb.ZSession) Test(org.junit.Test)

Example 44 with WebResource

use of com.sun.jersey.api.client.WebResource in project hadoop by apache.

the class LogsCLI method getAMContainerInfoForRMWebService.

protected List<JSONObject> getAMContainerInfoForRMWebService(Configuration conf, String appId) throws ClientHandlerException, UniformInterfaceException, JSONException {
    Client webServiceClient = Client.create();
    String webAppAddress = WebAppUtils.getRMWebAppURLWithScheme(conf);
    WebResource webResource = webServiceClient.resource(webAppAddress);
    ClientResponse response = webResource.path("ws").path("v1").path("cluster").path("apps").path(appId).path("appattempts").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    JSONObject json = response.getEntity(JSONObject.class).getJSONObject("appAttempts");
    JSONArray requests = json.getJSONArray("appAttempt");
    List<JSONObject> amContainersList = new ArrayList<JSONObject>();
    for (int i = 0; i < requests.length(); i++) {
        amContainersList.add(requests.getJSONObject(i));
    }
    return amContainersList;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray) ArrayList(java.util.ArrayList) WebResource(com.sun.jersey.api.client.WebResource) YarnClient(org.apache.hadoop.yarn.client.api.YarnClient) Client(com.sun.jersey.api.client.Client)

Example 45 with WebResource

use of com.sun.jersey.api.client.WebResource in project hadoop by apache.

the class LogsCLI method getContainerLogFiles.

private List<Pair<PerContainerLogFileInfo, String>> getContainerLogFiles(Configuration conf, String containerIdStr, String nodeHttpAddress) throws IOException {
    List<Pair<PerContainerLogFileInfo, String>> logFileInfos = new ArrayList<>();
    Client webServiceClient = Client.create();
    try {
        WebResource webResource = webServiceClient.resource(WebAppUtils.getHttpSchemePrefix(conf) + nodeHttpAddress);
        ClientResponse response = webResource.path("ws").path("v1").path("node").path("containers").path(containerIdStr).path("logs").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
        if (response.getStatusInfo().getStatusCode() == ClientResponse.Status.OK.getStatusCode()) {
            try {
                JSONArray array = new JSONArray();
                JSONObject json = response.getEntity(JSONObject.class);
                Object logsInfoObj = json.get("containerLogsInfo");
                if (logsInfoObj instanceof JSONObject) {
                    array.put((JSONObject) logsInfoObj);
                } else if (logsInfoObj instanceof JSONArray) {
                    JSONArray logsArray = (JSONArray) logsInfoObj;
                    for (int i = 0; i < logsArray.length(); i++) {
                        array.put(logsArray.getJSONObject(i));
                    }
                }
                for (int i = 0; i < array.length(); i++) {
                    JSONObject log = array.getJSONObject(i);
                    String aggregateType = log.has("logAggregationType") ? log.getString("logAggregationType") : "N/A";
                    Object ob = log.get("containerLogInfo");
                    if (ob instanceof JSONArray) {
                        JSONArray obArray = (JSONArray) ob;
                        for (int j = 0; j < obArray.length(); j++) {
                            logFileInfos.add(new Pair<PerContainerLogFileInfo, String>(generatePerContainerLogFileInfoFromJSON(obArray.getJSONObject(j)), aggregateType));
                        }
                    } else if (ob instanceof JSONObject) {
                        logFileInfos.add(new Pair<PerContainerLogFileInfo, String>(generatePerContainerLogFileInfoFromJSON((JSONObject) ob), aggregateType));
                    }
                }
            } catch (Exception e) {
                System.err.println("Unable to parse json from webservice. Error:");
                System.err.println(e.getMessage());
                throw new IOException(e);
            }
        }
    } catch (ClientHandlerException | UniformInterfaceException ex) {
        System.err.println("Unable to fetch log files list");
        throw new IOException(ex);
    }
    return logFileInfos;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) ArrayList(java.util.ArrayList) JSONArray(org.codehaus.jettison.json.JSONArray) WebResource(com.sun.jersey.api.client.WebResource) IOException(java.io.IOException) PerContainerLogFileInfo(org.apache.hadoop.yarn.logaggregation.PerContainerLogFileInfo) ParseException(org.apache.commons.cli.ParseException) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) IOException(java.io.IOException) JSONException(org.codehaus.jettison.json.JSONException) ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) JSONObject(org.codehaus.jettison.json.JSONObject) JSONObject(org.codehaus.jettison.json.JSONObject) YarnClient(org.apache.hadoop.yarn.client.api.YarnClient) Client(com.sun.jersey.api.client.Client) Pair(org.apache.commons.math3.util.Pair)

Aggregations

WebResource (com.sun.jersey.api.client.WebResource)504 ClientResponse (com.sun.jersey.api.client.ClientResponse)439 Test (org.junit.Test)389 JSONObject (org.codehaus.jettison.json.JSONObject)296 Job (org.apache.hadoop.mapreduce.v2.app.job.Job)110 JobId (org.apache.hadoop.mapreduce.v2.api.records.JobId)103 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)67 JSONArray (org.codehaus.jettison.json.JSONArray)65 Document (org.w3c.dom.Document)46 StringReader (java.io.StringReader)43 DocumentBuilder (javax.xml.parsers.DocumentBuilder)43 NodeList (org.w3c.dom.NodeList)43 InputSource (org.xml.sax.InputSource)43 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)42 Task (org.apache.hadoop.mapreduce.v2.app.job.Task)42 MockNM (org.apache.hadoop.yarn.server.resourcemanager.MockNM)39 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)29 Application (org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application)22 MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)21 Client (com.sun.jersey.api.client.Client)19