Search in sources :

Example 36 with MultivaluedMapImpl

use of com.sun.jersey.core.util.MultivaluedMapImpl in project ORCID-Source by ORCID.

the class InternalAPITest method testGetLastModifiedDate.

@Test
public void testGetLastModifiedDate() throws JSONException {
    MultivaluedMap<String, String> params = new MultivaluedMapImpl();
    params.add("client_id", client1ClientId);
    params.add("client_secret", client1ClientSecret);
    params.add("grant_type", "client_credentials");
    params.add("scope", ScopePathType.INTERNAL_PERSON_LAST_MODIFIED.value());
    ClientResponse clientResponse = oauthHelper.getResponse(params, APIRequestType.INTERNAL);
    assertNotNull(clientResponse);
    assertEquals(Response.Status.OK.getStatusCode(), clientResponse.getStatus());
    String body = clientResponse.getEntity(String.class);
    JSONObject jsonObject = new JSONObject(body);
    String accessToken = (String) jsonObject.get("access_token");
    assertNotNull(accessToken);
    assertFalse(PojoUtil.isEmpty(accessToken));
    ClientResponse lastModifiedResponse = internalApiClient.viewPersonLastModified(user1OrcidId, accessToken);
    assertNotNull(lastModifiedResponse);
    String lastModified = lastModifiedResponse.getEntity(String.class);
    jsonObject = new JSONObject(lastModified);
    assertNotNull(jsonObject);
    assertEquals(user1OrcidId, (String) jsonObject.getString("orcid"));
    assertNotNull((String) jsonObject.getString("last-modified"));
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) JSONObject(org.codehaus.jettison.json.JSONObject) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) Test(org.junit.Test)

Example 37 with MultivaluedMapImpl

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

the class TestRMWebServicesSchedulerActivities method testWrongNodeId.

@Test
public void testWrongNodeId() 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(1024, "app1", "user1", null, "b1");
        MockAM am1 = MockRM.launchAndRegisterAM(app1, rm, nm);
        am1.allocate(Arrays.asList(ResourceRequest.newInstance(Priority.UNDEFINED, "127.0.0.1", Resources.createResource(1024), 10), ResourceRequest.newInstance(Priority.UNDEFINED, "/default-rack", Resources.createResource(1024), 10), ResourceRequest.newInstance(Priority.UNDEFINED, "*", Resources.createResource(1024), 10)), null);
        //Get JSON
        WebResource r = resource();
        MultivaluedMapImpl params = new MultivaluedMapImpl();
        params.add("nodeId", "127.0.0.0");
        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, 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) 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) Test(org.junit.Test)

Example 38 with MultivaluedMapImpl

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

the class TestRMWebServicesSchedulerActivities method testAppActivityJSON.

@Test
public void testAppActivityJSON() 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("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);
        nm.nodeHeartbeat(true);
        Thread.sleep(5000);
        //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, 1);
        JSONObject allocations = json.getJSONObject("allocations");
        verifyStateOfAllocations(allocations, "allocationState", "ACCEPTED");
        verifyNumberOfAllocationAttempts(allocations, 1);
    } 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 39 with MultivaluedMapImpl

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

the class TestRMWebServicesSchedulerActivities method testAssignMultipleContainersPerNodeHeartbeat.

@Test
public void testAssignMultipleContainersPerNodeHeartbeat() 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");
        MockAM am1 = MockRM.launchAndRegisterAM(app1, rm, nm);
        am1.allocate(Arrays.asList(ResourceRequest.newInstance(Priority.UNDEFINED, "127.0.0.1", Resources.createResource(1024), 10), ResourceRequest.newInstance(Priority.UNDEFINED, "/default-rack", Resources.createResource(1024), 10), ResourceRequest.newInstance(Priority.UNDEFINED, "*", Resources.createResource(1024), 10)), null);
        //Get JSON
        WebResource r = resource();
        MultivaluedMapImpl params = new MultivaluedMapImpl();
        params.add("nodeId", "127.0.0.1:1234");
        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, 11);
        JSONArray allocations = json.getJSONArray("allocations");
        for (int i = 0; i < allocations.length(); i++) {
            if (i != allocations.length() - 1) {
                verifyStateOfAllocations(allocations.getJSONObject(i), "finalAllocationState", "ALLOCATED");
                verifyQueueOrder(allocations.getJSONObject(i), "root-a-b-b2-b3-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) JSONArray(org.codehaus.jettison.json.JSONArray) MockAM(org.apache.hadoop.yarn.server.resourcemanager.MockAM) WebResource(com.sun.jersey.api.client.WebResource) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) Test(org.junit.Test)

Example 40 with MultivaluedMapImpl

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

the class TestRMWebServicesSchedulerActivities method testAppAssignMultipleContainersPerNodeHeartbeat.

@Test
public void testAppAssignMultipleContainersPerNodeHeartbeat() 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(1024, "app1", "user1", null, "b1");
        MockAM am1 = MockRM.launchAndRegisterAM(app1, rm, nm);
        am1.allocate(Arrays.asList(ResourceRequest.newInstance(Priority.UNDEFINED, "127.0.0.1", Resources.createResource(1024), 10), ResourceRequest.newInstance(Priority.UNDEFINED, "/default-rack", Resources.createResource(1024), 10), ResourceRequest.newInstance(Priority.UNDEFINED, "*", Resources.createResource(1024), 10)), null);
        //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);
        nm.nodeHeartbeat(true);
        Thread.sleep(5000);
        //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, 10);
        JSONArray allocations = json.getJSONArray("allocations");
        for (int i = 0; i < allocations.length(); i++) {
            verifyStateOfAllocations(allocations.getJSONObject(i), "allocationState", "ACCEPTED");
        }
    } 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) JSONArray(org.codehaus.jettison.json.JSONArray) MockAM(org.apache.hadoop.yarn.server.resourcemanager.MockAM) 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