Search in sources :

Example 86 with ClientResponse

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

the class TestRMWebServicesApps method testAppsQueryStartBeginEnd.

@Test
public void testAppsQueryStartBeginEnd() throws JSONException, Exception {
    rm.start();
    rm.registerNode("127.0.0.1:1234", 2048);
    long start = System.currentTimeMillis();
    Thread.sleep(1);
    rm.submitApp(CONTAINER_MB);
    rm.submitApp(CONTAINER_MB);
    long end = System.currentTimeMillis();
    Thread.sleep(1);
    rm.submitApp(CONTAINER_MB);
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1").path("cluster").path("apps").queryParam("startedTimeBegin", String.valueOf(start)).queryParam("startedTimeEnd", String.valueOf(end)).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
    JSONObject json = response.getEntity(JSONObject.class);
    assertEquals("incorrect number of elements", 1, json.length());
    JSONObject apps = json.getJSONObject("apps");
    assertEquals("incorrect number of elements", 1, apps.length());
    JSONArray array = apps.getJSONArray("app");
    assertEquals("incorrect number of elements", 2, array.length());
    rm.stop();
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Example 87 with ClientResponse

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

the class TestRMWebServicesApps method testInvalidAppIdGetAttempts.

@Test
public void testInvalidAppIdGetAttempts() throws JSONException, Exception {
    rm.start();
    MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
    RMApp app = rm.submitApp(CONTAINER_MB);
    amNodeManager.nodeHeartbeat(true);
    WebResource r = resource();
    try {
        r.path("ws").path("v1").path("cluster").path("apps").path("application_invalid_12").path("appattempts").accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
        fail("should have thrown exception on invalid appAttempt");
    } catch (UniformInterfaceException ue) {
        ClientResponse response = ue.getResponse();
        assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
        assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
        JSONObject msg = response.getEntity(JSONObject.class);
        JSONObject exception = msg.getJSONObject("RemoteException");
        assertEquals("incorrect number of elements", 3, exception.length());
        String message = exception.getString("message");
        String type = exception.getString("exception");
        String classname = exception.getString("javaClassName");
        WebServicesTestUtils.checkStringMatch("exception message", "java.lang.IllegalArgumentException: Invalid ApplicationId:" + " application_invalid_12", message);
        WebServicesTestUtils.checkStringMatch("exception type", "BadRequestException", type);
        WebServicesTestUtils.checkStringMatch("exception classname", "org.apache.hadoop.yarn.webapp.BadRequestException", classname);
    } finally {
        rm.stop();
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) JSONObject(org.codehaus.jettison.json.JSONObject) MockNM(org.apache.hadoop.yarn.server.resourcemanager.MockNM) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Example 88 with ClientResponse

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

the class TestRMWebServicesApps method testAppsHelper.

public void testAppsHelper(String path, RMApp app, String media) throws JSONException, Exception {
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1").path("cluster").path(path).accept(media).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
    JSONObject json = response.getEntity(JSONObject.class);
    assertEquals("incorrect number of elements", 1, json.length());
    JSONObject apps = json.getJSONObject("apps");
    assertEquals("incorrect number of elements", 1, apps.length());
    JSONArray array = apps.getJSONArray("app");
    assertEquals("incorrect number of elements", 1, array.length());
    verifyAppInfo(array.getJSONObject(0), app);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray) WebResource(com.sun.jersey.api.client.WebResource)

Example 89 with ClientResponse

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

the class TestRMWebServicesApps method testAppsQueryFinishBeginEnd.

@Test
public void testAppsQueryFinishBeginEnd() throws JSONException, Exception {
    rm.start();
    MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
    long start = System.currentTimeMillis();
    Thread.sleep(1);
    RMApp app1 = rm.submitApp(CONTAINER_MB);
    amNodeManager.nodeHeartbeat(true);
    // finish App
    MockAM am = rm.sendAMLaunched(app1.getCurrentAppAttempt().getAppAttemptId());
    am.registerAppAttempt();
    am.unregisterAppAttempt();
    amNodeManager.nodeHeartbeat(app1.getCurrentAppAttempt().getAppAttemptId(), 1, ContainerState.COMPLETE);
    rm.submitApp(CONTAINER_MB);
    rm.submitApp(CONTAINER_MB);
    long end = System.currentTimeMillis();
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1").path("cluster").path("apps").queryParam("finishedTimeBegin", String.valueOf(start)).queryParam("finishedTimeEnd", String.valueOf(end)).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
    JSONObject json = response.getEntity(JSONObject.class);
    assertEquals("incorrect number of elements", 1, json.length());
    JSONObject apps = json.getJSONObject("apps");
    assertEquals("incorrect number of elements", 1, apps.length());
    JSONArray array = apps.getJSONArray("app");
    assertEquals("incorrect number of elements", 1, array.length());
    rm.stop();
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) JSONObject(org.codehaus.jettison.json.JSONObject) MockNM(org.apache.hadoop.yarn.server.resourcemanager.MockNM) JSONArray(org.codehaus.jettison.json.JSONArray) MockAM(org.apache.hadoop.yarn.server.resourcemanager.MockAM) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Example 90 with ClientResponse

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

the class TestRMWebServicesApps method testAppsXML.

@Test
public void testAppsXML() throws JSONException, Exception {
    rm.start();
    MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
    RMApp app1 = rm.submitApp(CONTAINER_MB, "testwordcount", "user1");
    amNodeManager.nodeHeartbeat(true);
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1").path("cluster").path("apps").accept(MediaType.APPLICATION_XML).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_XML_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
    String xml = response.getEntity(String.class);
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    InputSource is = new InputSource();
    is.setCharacterStream(new StringReader(xml));
    Document dom = db.parse(is);
    NodeList nodesApps = dom.getElementsByTagName("apps");
    assertEquals("incorrect number of elements", 1, nodesApps.getLength());
    NodeList nodes = dom.getElementsByTagName("app");
    assertEquals("incorrect number of elements", 1, nodes.getLength());
    verifyAppsXML(nodes, app1);
    rm.stop();
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) MockNM(org.apache.hadoop.yarn.server.resourcemanager.MockNM) NodeList(org.w3c.dom.NodeList) StringReader(java.io.StringReader) WebResource(com.sun.jersey.api.client.WebResource) Document(org.w3c.dom.Document) Test(org.junit.Test)

Aggregations

ClientResponse (com.sun.jersey.api.client.ClientResponse)1970 Test (org.junit.Test)1136 WebResource (com.sun.jersey.api.client.WebResource)674 JSONObject (org.codehaus.jettison.json.JSONObject)412 URI (java.net.URI)292 Client (com.sun.jersey.api.client.Client)117 HashMap (java.util.HashMap)112 Job (org.apache.hadoop.mapreduce.v2.app.job.Job)110 JobId (org.apache.hadoop.mapreduce.v2.api.records.JobId)103 ArrayList (java.util.ArrayList)97 JSONArray (org.codehaus.jettison.json.JSONArray)81 IOException (java.io.IOException)78 InputStream (java.io.InputStream)77 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)76 JSONException (org.codehaus.jettison.json.JSONException)58 List (java.util.List)56 Gson (com.google.gson.Gson)52 JavaResult (org.milyn.payload.JavaResult)52 MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)49 MockNM (org.apache.hadoop.yarn.server.resourcemanager.MockNM)47