Search in sources :

Example 81 with ClientResponse

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

the class TestRMWebServicesApps method testAppsQueryFinishEnd.

@Test
public void testAppsQueryFinishEnd() throws JSONException, Exception {
    rm.start();
    MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
    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("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", 3, 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 82 with ClientResponse

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

the class TestRMWebServicesApps method testAppsQueryAppTypes.

@Test
public void testAppsQueryAppTypes() throws JSONException, Exception {
    rm.start();
    MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
    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, "", UserGroupInformation.getCurrentUser().getShortUserName(), null, false, null, 2, null, "MAPREDUCE");
    rm.submitApp(CONTAINER_MB, "", UserGroupInformation.getCurrentUser().getShortUserName(), null, false, null, 2, null, "NON-YARN");
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1").path("cluster").path("apps").queryParam("applicationTypes", "MAPREDUCE").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());
    assertEquals("MAPREDUCE", array.getJSONObject(0).getString("applicationType"));
    r = resource();
    response = r.path("ws").path("v1").path("cluster").path("apps").queryParam("applicationTypes", "YARN").queryParam("applicationTypes", "MAPREDUCE").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
    json = response.getEntity(JSONObject.class);
    assertEquals("incorrect number of elements", 1, json.length());
    apps = json.getJSONObject("apps");
    assertEquals("incorrect number of elements", 1, apps.length());
    array = apps.getJSONArray("app");
    assertEquals("incorrect number of elements", 2, array.length());
    assertTrue((array.getJSONObject(0).getString("applicationType").equals("YARN") && array.getJSONObject(1).getString("applicationType").equals("MAPREDUCE")) || (array.getJSONObject(1).getString("applicationType").equals("YARN") && array.getJSONObject(0).getString("applicationType").equals("MAPREDUCE")));
    r = resource();
    response = r.path("ws").path("v1").path("cluster").path("apps").queryParam("applicationTypes", "YARN,NON-YARN").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
    json = response.getEntity(JSONObject.class);
    assertEquals("incorrect number of elements", 1, json.length());
    apps = json.getJSONObject("apps");
    assertEquals("incorrect number of elements", 1, apps.length());
    array = apps.getJSONArray("app");
    assertEquals("incorrect number of elements", 2, array.length());
    assertTrue((array.getJSONObject(0).getString("applicationType").equals("YARN") && array.getJSONObject(1).getString("applicationType").equals("NON-YARN")) || (array.getJSONObject(1).getString("applicationType").equals("YARN") && array.getJSONObject(0).getString("applicationType").equals("NON-YARN")));
    r = resource();
    response = r.path("ws").path("v1").path("cluster").path("apps").queryParam("applicationTypes", "").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
    json = response.getEntity(JSONObject.class);
    assertEquals("incorrect number of elements", 1, json.length());
    apps = json.getJSONObject("apps");
    assertEquals("incorrect number of elements", 1, apps.length());
    array = apps.getJSONArray("app");
    assertEquals("incorrect number of elements", 3, array.length());
    r = resource();
    response = r.path("ws").path("v1").path("cluster").path("apps").queryParam("applicationTypes", "YARN,NON-YARN").queryParam("applicationTypes", "MAPREDUCE").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
    json = response.getEntity(JSONObject.class);
    assertEquals("incorrect number of elements", 1, json.length());
    apps = json.getJSONObject("apps");
    assertEquals("incorrect number of elements", 1, apps.length());
    array = apps.getJSONArray("app");
    assertEquals("incorrect number of elements", 3, array.length());
    r = resource();
    response = r.path("ws").path("v1").path("cluster").path("apps").queryParam("applicationTypes", "YARN").queryParam("applicationTypes", "").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
    json = response.getEntity(JSONObject.class);
    assertEquals("incorrect number of elements", 1, json.length());
    apps = json.getJSONObject("apps");
    assertEquals("incorrect number of elements", 1, apps.length());
    array = apps.getJSONArray("app");
    assertEquals("incorrect number of elements", 1, array.length());
    assertEquals("YARN", array.getJSONObject(0).getString("applicationType"));
    r = resource();
    response = r.path("ws").path("v1").path("cluster").path("apps").queryParam("applicationTypes", ",,, ,, YARN ,, ,").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
    json = response.getEntity(JSONObject.class);
    assertEquals("incorrect number of elements", 1, json.length());
    apps = json.getJSONObject("apps");
    assertEquals("incorrect number of elements", 1, apps.length());
    array = apps.getJSONArray("app");
    assertEquals("incorrect number of elements", 1, array.length());
    assertEquals("YARN", array.getJSONObject(0).getString("applicationType"));
    r = resource();
    response = r.path("ws").path("v1").path("cluster").path("apps").queryParam("applicationTypes", ",,, ,,  ,, ,").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
    json = response.getEntity(JSONObject.class);
    assertEquals("incorrect number of elements", 1, json.length());
    apps = json.getJSONObject("apps");
    assertEquals("incorrect number of elements", 1, apps.length());
    array = apps.getJSONArray("app");
    assertEquals("incorrect number of elements", 3, array.length());
    r = resource();
    response = r.path("ws").path("v1").path("cluster").path("apps").queryParam("applicationTypes", "YARN, ,NON-YARN, ,,").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
    json = response.getEntity(JSONObject.class);
    assertEquals("incorrect number of elements", 1, json.length());
    apps = json.getJSONObject("apps");
    assertEquals("incorrect number of elements", 1, apps.length());
    array = apps.getJSONArray("app");
    assertEquals("incorrect number of elements", 2, array.length());
    assertTrue((array.getJSONObject(0).getString("applicationType").equals("YARN") && array.getJSONObject(1).getString("applicationType").equals("NON-YARN")) || (array.getJSONObject(1).getString("applicationType").equals("YARN") && array.getJSONObject(0).getString("applicationType").equals("NON-YARN")));
    r = resource();
    response = r.path("ws").path("v1").path("cluster").path("apps").queryParam("applicationTypes", " YARN, ,  ,,,").queryParam("applicationTypes", "MAPREDUCE , ,, ,").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
    json = response.getEntity(JSONObject.class);
    assertEquals("incorrect number of elements", 1, json.length());
    apps = json.getJSONObject("apps");
    assertEquals("incorrect number of elements", 1, apps.length());
    array = apps.getJSONArray("app");
    assertEquals("incorrect number of elements", 2, array.length());
    assertTrue((array.getJSONObject(0).getString("applicationType").equals("YARN") && array.getJSONObject(1).getString("applicationType").equals("MAPREDUCE")) || (array.getJSONObject(1).getString("applicationType").equals("YARN") && array.getJSONObject(0).getString("applicationType").equals("MAPREDUCE")));
    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 83 with ClientResponse

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

the class TestRMWebServicesApps method testAppsQueryQueue.

@Test
public void testAppsQueryQueue() throws JSONException, Exception {
    rm.start();
    MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
    rm.submitApp(CONTAINER_MB);
    rm.submitApp(CONTAINER_MB);
    amNodeManager.nodeHeartbeat(true);
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1").path("cluster").path("apps").queryParam("queue", "default").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) MockNM(org.apache.hadoop.yarn.server.resourcemanager.MockNM) JSONArray(org.codehaus.jettison.json.JSONArray) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Example 84 with ClientResponse

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

the class TestRMWebServicesApps method testInvalidAppAttemptId.

@Test
public void testInvalidAppAttemptId() 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(app.getApplicationId().toString()).path("appattempts").path("appattempt_invalid_12_000001").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 AppAttemptId:" + " appattempt_invalid_12_000001", 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 85 with ClientResponse

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

the class TestRMWebServicesApps method testAppsQueryStartBeginSome.

@Test
public void testAppsQueryStartBeginSome() throws JSONException, Exception {
    rm.start();
    rm.registerNode("127.0.0.1:1234", 2048);
    rm.submitApp(CONTAINER_MB);
    rm.submitApp(CONTAINER_MB);
    long start = 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)).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) JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray) WebResource(com.sun.jersey.api.client.WebResource) 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