Search in sources :

Example 41 with MultivaluedMapImpl

use of com.sun.jersey.core.util.MultivaluedMapImpl in project hadoop by apache.

the class TestRMWebServicesSchedulerActivities method testAppNoNM.

@Test
public void testAppNoNM() throws Exception {
    //Start RM so that it accepts app submissions
    rm.start();
    try {
        RMApp app1 = rm.submitApp(1024, "app1", "user1", null, "b1");
        //Get JSON
        WebResource r = resource();
        MultivaluedMapImpl params = new MultivaluedMapImpl();
        params.add("appId", app1.getApplicationId().toString());
        ClientResponse response = r.path("ws").path("v1").path("cluster").path("scheduler/app-activities").queryParams(params).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
        assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
        JSONObject json = response.getEntity(JSONObject.class);
        //Get JSON
        response = r.path("ws").path("v1").path("cluster").path("scheduler/app-activities").queryParams(params).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
        assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
        json = response.getEntity(JSONObject.class);
        verifyNumberOfAllocations(json, 0);
    } finally {
        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) WebResource(com.sun.jersey.api.client.WebResource) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) Test(org.junit.Test)

Example 42 with MultivaluedMapImpl

use of com.sun.jersey.core.util.MultivaluedMapImpl in project hadoop by apache.

the class TestRMWebServicesSchedulerActivities method testAppReserveNewContainer.

@Test
public void testAppReserveNewContainer() throws Exception {
    //Start RM so that it accepts app submissions
    rm.start();
    MockNM nm1 = new MockNM("127.0.0.1:1234", 4 * 1024, rm.getResourceTrackerService());
    MockNM nm2 = new MockNM("127.0.0.2:1234", 4 * 1024, rm.getResourceTrackerService());
    nm1.registerNode();
    nm2.registerNode();
    try {
        RMApp app1 = rm.submitApp(10, "app1", "user1", null, "b1");
        MockAM am1 = MockRM.launchAndRegisterAM(app1, rm, nm1);
        RMApp app2 = rm.submitApp(10, "app2", "user1", null, "b2");
        MockAM am2 = MockRM.launchAndRegisterAM(app2, rm, nm2);
        am1.allocate(Arrays.asList(ResourceRequest.newInstance(Priority.UNDEFINED, "*", Resources.createResource(4096), 10)), null);
        // Reserve new container
        WebResource r = resource();
        MultivaluedMapImpl params = new MultivaluedMapImpl();
        params.add("appId", app1.getApplicationId().toString());
        ClientResponse response = r.path("ws").path("v1").path("cluster").path("scheduler/app-activities").queryParams(params).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
        assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
        JSONObject json = response.getEntity(JSONObject.class);
        nm2.nodeHeartbeat(true);
        Thread.sleep(1000);
        response = r.path("ws").path("v1").path("cluster").path("scheduler/app-activities").queryParams(params).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
        assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
        json = response.getEntity(JSONObject.class);
        verifyNumberOfAllocations(json, 1);
        // Do a node heartbeat again without releasing container from app2
        r = resource();
        params = new MultivaluedMapImpl();
        params.add("appId", app1.getApplicationId().toString());
        response = r.path("ws").path("v1").path("cluster").path("scheduler/app-activities").queryParams(params).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
        assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
        json = response.getEntity(JSONObject.class);
        nm2.nodeHeartbeat(true);
        Thread.sleep(1000);
        response = r.path("ws").path("v1").path("cluster").path("scheduler/app-activities").queryParams(params).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
        assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
        json = response.getEntity(JSONObject.class);
        verifyNumberOfAllocations(json, 2);
        // Finish application 2
        CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler();
        ContainerId containerId = ContainerId.newContainerId(am2.getApplicationAttemptId(), 1);
        cs.completedContainer(cs.getRMContainer(containerId), ContainerStatus.newInstance(containerId, ContainerState.COMPLETE, "", 0), RMContainerEventType.FINISHED);
        // Do a node heartbeat again
        r = resource();
        params = new MultivaluedMapImpl();
        params.add("appId", app1.getApplicationId().toString());
        response = r.path("ws").path("v1").path("cluster").path("scheduler/app-activities").queryParams(params).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
        assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
        json = response.getEntity(JSONObject.class);
        nm2.nodeHeartbeat(true);
        Thread.sleep(1000);
        response = r.path("ws").path("v1").path("cluster").path("scheduler/app-activities").queryParams(params).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
        assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
        json = response.getEntity(JSONObject.class);
        verifyNumberOfAllocations(json, 3);
    } finally {
        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) MockAM(org.apache.hadoop.yarn.server.resourcemanager.MockAM) WebResource(com.sun.jersey.api.client.WebResource) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) CapacityScheduler(org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler) Test(org.junit.Test)

Example 43 with MultivaluedMapImpl

use of com.sun.jersey.core.util.MultivaluedMapImpl in project hadoop by apache.

the class TestRMWebServicesSchedulerActivities method testReserveNewContainer.

@Test
public void testReserveNewContainer() throws Exception {
    //Start RM so that it accepts app submissions
    rm.start();
    MockNM nm1 = new MockNM("127.0.0.1:1234", 4 * 1024, rm.getResourceTrackerService());
    MockNM nm2 = new MockNM("127.0.0.2:1234", 4 * 1024, rm.getResourceTrackerService());
    nm1.registerNode();
    nm2.registerNode();
    try {
        RMApp app1 = rm.submitApp(10, "app1", "user1", null, "b1");
        MockAM am1 = MockRM.launchAndRegisterAM(app1, rm, nm1);
        RMApp app2 = rm.submitApp(10, "app2", "user1", null, "b2");
        MockAM am2 = MockRM.launchAndRegisterAM(app2, rm, nm2);
        am1.allocate(Arrays.asList(ResourceRequest.newInstance(Priority.UNDEFINED, "*", Resources.createResource(4096), 10)), null);
        // Reserve new container
        WebResource r = resource();
        MultivaluedMapImpl params = new MultivaluedMapImpl();
        params.add("nodeId", "127.0.0.2");
        ClientResponse response = r.path("ws").path("v1").path("cluster").path("scheduler/activities").queryParams(params).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
        assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
        JSONObject json = response.getEntity(JSONObject.class);
        nm2.nodeHeartbeat(true);
        Thread.sleep(1000);
        response = r.path("ws").path("v1").path("cluster").path("scheduler/activities").queryParams(params).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
        assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
        json = response.getEntity(JSONObject.class);
        verifyNumberOfAllocations(json, 1);
        verifyQueueOrder(json.getJSONObject("allocations"), "root-a-b-b3-b1");
        JSONObject allocations = json.getJSONObject("allocations");
        verifyStateOfAllocations(allocations, "finalAllocationState", "RESERVED");
        // Do a node heartbeat again without releasing container from app2
        r = resource();
        params = new MultivaluedMapImpl();
        params.add("nodeId", "127.0.0.2");
        response = r.path("ws").path("v1").path("cluster").path("scheduler/activities").queryParams(params).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
        assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
        json = response.getEntity(JSONObject.class);
        nm2.nodeHeartbeat(true);
        Thread.sleep(1000);
        response = r.path("ws").path("v1").path("cluster").path("scheduler/activities").queryParams(params).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
        assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
        json = response.getEntity(JSONObject.class);
        verifyNumberOfAllocations(json, 1);
        verifyQueueOrder(json.getJSONObject("allocations"), "b1");
        allocations = json.getJSONObject("allocations");
        verifyStateOfAllocations(allocations, "finalAllocationState", "SKIPPED");
        // Finish application 2
        CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler();
        ContainerId containerId = ContainerId.newContainerId(am2.getApplicationAttemptId(), 1);
        cs.completedContainer(cs.getRMContainer(containerId), ContainerStatus.newInstance(containerId, ContainerState.COMPLETE, "", 0), RMContainerEventType.FINISHED);
        // Do a node heartbeat again
        r = resource();
        params = new MultivaluedMapImpl();
        params.add("nodeId", "127.0.0.2");
        response = r.path("ws").path("v1").path("cluster").path("scheduler/activities").queryParams(params).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
        assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
        json = response.getEntity(JSONObject.class);
        nm2.nodeHeartbeat(true);
        Thread.sleep(1000);
        response = r.path("ws").path("v1").path("cluster").path("scheduler/activities").queryParams(params).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
        assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
        json = response.getEntity(JSONObject.class);
        verifyNumberOfAllocations(json, 1);
        verifyQueueOrder(json.getJSONObject("allocations"), "b1");
        allocations = json.getJSONObject("allocations");
        verifyStateOfAllocations(allocations, "finalAllocationState", "ALLOCATED_FROM_RESERVED");
    } finally {
        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) MockAM(org.apache.hadoop.yarn.server.resourcemanager.MockAM) WebResource(com.sun.jersey.api.client.WebResource) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) CapacityScheduler(org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler) Test(org.junit.Test)

Example 44 with MultivaluedMapImpl

use of com.sun.jersey.core.util.MultivaluedMapImpl in project hadoop by apache.

the class TestRMWebServicesSchedulerActivities method testActivityJSON.

@Test
public void testActivityJSON() throws Exception {
    //Start RM so that it accepts app submissions
    rm.start();
    MockNM nm = new MockNM("127.0.0.1:1234", 24 * 1024, rm.getResourceTrackerService());
    nm.registerNode();
    try {
        RMApp app1 = rm.submitApp(10, "app1", "user1", null, "b1");
        //Get JSON
        WebResource r = resource();
        MultivaluedMapImpl params = new MultivaluedMapImpl();
        params.add("nodeId", "127.0.0.1");
        ClientResponse response = r.path("ws").path("v1").path("cluster").path("scheduler/activities").queryParams(params).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
        assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
        JSONObject json = response.getEntity(JSONObject.class);
        nm.nodeHeartbeat(true);
        Thread.sleep(1000);
        //Get JSON
        response = r.path("ws").path("v1").path("cluster").path("scheduler/activities").queryParams(params).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
        assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
        json = response.getEntity(JSONObject.class);
        verifyNumberOfAllocations(json, 1);
        JSONObject allocations = json.getJSONObject("allocations");
        verifyStateOfAllocations(allocations, "finalAllocationState", "ALLOCATED");
        verifyNumberOfNodes(allocations, 5);
        verifyQueueOrder(json.getJSONObject("allocations"), "root-b-b1");
    } finally {
        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) WebResource(com.sun.jersey.api.client.WebResource) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) Test(org.junit.Test)

Example 45 with MultivaluedMapImpl

use of com.sun.jersey.core.util.MultivaluedMapImpl in project hadoop by apache.

the class TestRMWebServicesNodeLabels method testLabelInvalidRemove.

@Test
public void testLabelInvalidRemove() throws UniformInterfaceException, Exception {
    WebResource r = resource();
    ClientResponse response;
    MultivaluedMapImpl params = new MultivaluedMapImpl();
    params.add("labels", "irealldontexist");
    response = r.path("ws").path("v1").path("cluster").path("remove-node-labels").queryParam("user.name", userName).queryParams(params).accept(MediaType.APPLICATION_JSON).post(ClientResponse.class);
    String expectedmessage = "java.io.IOException: Node label=irealldontexist to be" + " removed doesn't existed in cluster node labels" + " collection.";
    validateJsonExceptionContent(response, expectedmessage);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) WebResource(com.sun.jersey.api.client.WebResource) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) Test(org.junit.Test)

Aggregations

MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)72 JSONObject (org.codehaus.jettison.json.JSONObject)33 Test (org.junit.Test)32 ClientResponse (com.sun.jersey.api.client.ClientResponse)29 WebResource (com.sun.jersey.api.client.WebResource)21 Test (org.testng.annotations.Test)19 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)12 MockNM (org.apache.hadoop.yarn.server.resourcemanager.MockNM)11 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)9 JSONArray (org.codehaus.jettison.json.JSONArray)9 MockAM (org.apache.hadoop.yarn.server.resourcemanager.MockAM)7 Response (javax.ws.rs.core.Response)6 BridgePort (org.midonet.client.resource.BridgePort)5 Router (org.midonet.client.resource.Router)5 Bridge (org.midonet.client.resource.Bridge)4 Route (org.midonet.client.resource.Route)4 OAuthServiceException (com.sun.identity.oauth.service.OAuthServiceException)3 Client (com.sun.jersey.api.client.Client)3 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)3 ArrayList (java.util.ArrayList)3