Search in sources :

Example 21 with JSONArray

use of org.codehaus.jettison.json.JSONArray in project hadoop by apache.

the class TestRMWebServicesNodes method testNodesQueryStateLost.

@Test
public void testNodesQueryStateLost() throws JSONException, Exception {
    WebResource r = resource();
    RMNode rmnode1 = getRunningRMNode("h1", 1234, 5120);
    sendLostEvent(rmnode1);
    RMNode rmnode2 = getRunningRMNode("h2", 1235, 5121);
    sendLostEvent(rmnode2);
    ClientResponse response = r.path("ws").path("v1").path("cluster").path("nodes").queryParam("states", NodeState.LOST.toString()).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
    JSONObject json = response.getEntity(JSONObject.class);
    JSONObject nodes = json.getJSONObject("nodes");
    assertEquals("incorrect number of elements", 1, nodes.length());
    JSONArray nodeArray = nodes.getJSONArray("node");
    assertEquals("incorrect number of elements", 2, nodeArray.length());
    for (int i = 0; i < nodeArray.length(); ++i) {
        JSONObject info = nodeArray.getJSONObject(i);
        String[] node = info.get("id").toString().split(":");
        NodeId nodeId = NodeId.newInstance(node[0], Integer.parseInt(node[1]));
        RMNode rmNode = rm.getRMContext().getInactiveRMNodes().get(nodeId);
        WebServicesTestUtils.checkStringMatch("nodeHTTPAddress", "", info.getString("nodeHTTPAddress"));
        if (rmNode != null) {
            WebServicesTestUtils.checkStringMatch("state", rmNode.getState().toString(), info.getString("state"));
        }
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) RMNode(org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNode) JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray) NodeId(org.apache.hadoop.yarn.api.records.NodeId) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Example 22 with JSONArray

use of org.codehaus.jettison.json.JSONArray in project hadoop by apache.

the class TestRMWebServicesNodes method testNodesHelper.

public void testNodesHelper(String path, String media) throws JSONException, Exception {
    WebResource r = resource();
    RMNode rmnode1 = getRunningRMNode("h1", 1234, 5120);
    RMNode rmnode2 = getRunningRMNode("h2", 1235, 5121);
    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 nodes = json.getJSONObject("nodes");
    assertEquals("incorrect number of elements", 1, nodes.length());
    JSONArray nodeArray = nodes.getJSONArray("node");
    assertEquals("incorrect number of elements", 2, nodeArray.length());
    JSONObject info = nodeArray.getJSONObject(0);
    String id = info.get("id").toString();
    if (id.matches("h1:1234")) {
        verifyNodeInfo(info, rmnode1);
        verifyNodeInfo(nodeArray.getJSONObject(1), rmnode2);
    } else {
        verifyNodeInfo(info, rmnode2);
        verifyNodeInfo(nodeArray.getJSONObject(1), rmnode1);
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) RMNode(org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNode) JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray) WebResource(com.sun.jersey.api.client.WebResource)

Example 23 with JSONArray

use of org.codehaus.jettison.json.JSONArray in project hadoop by apache.

the class TestRMWebServicesReservation method testInvalidTimeIntervalRequestListReservation.

@Test
public void testInvalidTimeIntervalRequestListReservation() throws Exception {
    rm.start();
    setupCluster(100);
    long time = clock.getTime() + MINIMUM_RESOURCE_DURATION;
    ReservationId id1 = getReservationIdTestHelper(1);
    ReservationId id2 = getReservationIdTestHelper(2);
    reservationSubmissionTestHelper("reservation/submit", MediaType.APPLICATION_JSON, time, "res_1", id1);
    reservationSubmissionTestHelper("reservation/submit", MediaType.APPLICATION_JSON, time + MINIMUM_RESOURCE_DURATION, "res_2", id2);
    WebResource resource;
    resource = constructWebResource(LIST_RESERVATION_PATH).queryParam("start-time", "-100").queryParam("end-time", "-100").queryParam("include-resource-allocations", "true").queryParam("queue", DEFAULT_QUEUE);
    JSONObject json = testListReservationHelper(resource);
    if (!this.isAuthenticationEnabled() && json == null) {
        return;
    }
    JSONArray reservations = json.getJSONArray("reservations");
    assertEquals(2, reservations.length());
    testRDLHelper(reservations.getJSONObject(0));
    testRDLHelper(reservations.getJSONObject(1));
    rm.stop();
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) ReservationId(org.apache.hadoop.yarn.api.records.ReservationId) JSONArray(org.codehaus.jettison.json.JSONArray) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Example 24 with JSONArray

use of org.codehaus.jettison.json.JSONArray in project hadoop by apache.

the class TestRMWebServiceAppsNodelabel method testAppsRunning.

@Test
public void testAppsRunning() throws JSONException, Exception {
    rm.start();
    MockNM nm1 = rm.registerNode("h1:1234", 2048);
    MockNM nm2 = rm.registerNode("h2:1235", 2048);
    nodeLabelManager.addLabelsToNode(ImmutableMap.of(NodeId.newInstance("h2", 1235), toSet("X")));
    RMApp app1 = rm.submitApp(AM_CONTAINER_MB, "app", "user", null, "default");
    MockAM am1 = MockRM.launchAndRegisterAM(app1, rm, nm1);
    nm1.nodeHeartbeat(true);
    // AM request for resource in partition X
    am1.allocate("*", 1024, 1, new ArrayList<ContainerId>(), "X");
    nm2.nodeHeartbeat(true);
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1").path("cluster").path("apps").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    JSONObject json = response.getEntity(JSONObject.class);
    // Verify apps resource
    JSONObject apps = json.getJSONObject("apps");
    assertEquals("incorrect number of elements", 1, apps.length());
    JSONObject jsonObject = apps.getJSONArray("app").getJSONObject(0).getJSONObject("resourceInfo");
    JSONArray jsonArray = jsonObject.getJSONArray("resourceUsagesByPartition");
    assertEquals("Partition expected is 2", 2, jsonArray.length());
    // Default partition resource
    JSONObject defaultPartition = jsonArray.getJSONObject(0);
    verifyResource(defaultPartition, "", getResource(1024, 1), getResource(1024, 1), getResource(0, 0));
    // verify resource used for parition x
    JSONObject paritionX = jsonArray.getJSONObject(1);
    verifyResource(paritionX, "X", getResource(0, 0), getResource(1024, 1), getResource(0, 0));
    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) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) 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 25 with JSONArray

use of org.codehaus.jettison.json.JSONArray in project hadoop by apache.

the class TestRMWebServicesNodes method testNodesResourceUtilization.

@Test
public void testNodesResourceUtilization() throws JSONException, Exception {
    WebResource r = resource();
    RMNode rmnode1 = getRunningRMNode("h1", 1234, 5120);
    NodeId nodeId1 = rmnode1.getNodeID();
    RMNodeImpl node = (RMNodeImpl) rm.getRMContext().getRMNodes().get(nodeId1);
    NodeHealthStatus nodeHealth = NodeHealthStatus.newInstance(true, "test health report", System.currentTimeMillis());
    ResourceUtilization nodeResource = ResourceUtilization.newInstance(4096, 0, (float) 10.5);
    ResourceUtilization containerResource = ResourceUtilization.newInstance(2048, 0, (float) 5.05);
    NodeStatus nodeStatus = NodeStatus.newInstance(nodeId1, 0, new ArrayList<ContainerStatus>(), null, nodeHealth, containerResource, nodeResource, null);
    node.handle(new RMNodeStatusEvent(nodeId1, nodeStatus, null));
    rm.waitForState(nodeId1, NodeState.RUNNING);
    ClientResponse response = r.path("ws").path("v1").path("cluster").path("nodes").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 nodes = json.getJSONObject("nodes");
    assertEquals("incorrect number of elements", 1, nodes.length());
    JSONArray nodeArray = nodes.getJSONArray("node");
    assertEquals("incorrect number of elements", 1, nodeArray.length());
    JSONObject info = nodeArray.getJSONObject(0);
    // verify the resource utilization
    verifyNodeInfo(info, rmnode1);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) RMNodeStatusEvent(org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNodeStatusEvent) JSONArray(org.codehaus.jettison.json.JSONArray) WebResource(com.sun.jersey.api.client.WebResource) RMNode(org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNode) ContainerStatus(org.apache.hadoop.yarn.api.records.ContainerStatus) JSONObject(org.codehaus.jettison.json.JSONObject) NodeId(org.apache.hadoop.yarn.api.records.NodeId) ResourceUtilization(org.apache.hadoop.yarn.api.records.ResourceUtilization) RMNodeImpl(org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNodeImpl) NodeStatus(org.apache.hadoop.yarn.server.api.records.NodeStatus) NodeHealthStatus(org.apache.hadoop.yarn.server.api.records.NodeHealthStatus) Test(org.junit.Test)

Aggregations

JSONArray (org.codehaus.jettison.json.JSONArray)302 JSONObject (org.codehaus.jettison.json.JSONObject)248 Test (org.junit.Test)111 WebResource (com.sun.jersey.api.client.WebResource)65 ClientResponse (com.sun.jersey.api.client.ClientResponse)64 JSONException (org.codehaus.jettison.json.JSONException)49 ArrayList (java.util.ArrayList)37 Test (org.testng.annotations.Test)30 Vertex (com.tinkerpop.blueprints.Vertex)20 Job (org.apache.hadoop.mapreduce.v2.app.job.Job)20 HashMap (java.util.HashMap)18 Map (java.util.Map)17 Produces (javax.ws.rs.Produces)17 MockNM (org.apache.hadoop.yarn.server.resourcemanager.MockNM)14 GET (javax.ws.rs.GET)13 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)13 JobId (org.apache.hadoop.mapreduce.v2.api.records.JobId)12 IOException (java.io.IOException)11 MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)9 Path (javax.ws.rs.Path)9