Search in sources :

Example 71 with MultivaluedMapImpl

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

the class TestRMWebServicesSchedulerActivities method testAppAssignWithoutAvailableResource.

@Test
public void testAppAssignWithoutAvailableResource() throws Exception {
    //Start RM so that it accepts app submissions
    rm.start();
    MockNM nm = new MockNM("127.0.0.1:1234", 1 * 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, 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 72 with MultivaluedMapImpl

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

the class TestRMWebServicesApps method testAppsQueryStatesComma.

@Test
public void testAppsQueryStatesComma() throws JSONException, Exception {
    rm.start();
    MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
    rm.submitApp(CONTAINER_MB);
    RMApp killedApp = rm.submitApp(CONTAINER_MB);
    rm.killApp(killedApp.getApplicationId());
    amNodeManager.nodeHeartbeat(true);
    WebResource r = resource();
    MultivaluedMapImpl params = new MultivaluedMapImpl();
    params.add("states", YarnApplicationState.ACCEPTED.toString());
    ClientResponse response = r.path("ws").path("v1").path("cluster").path("apps").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);
    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("state not equal to ACCEPTED", "ACCEPTED", array.getJSONObject(0).getString("state"));
    r = resource();
    params = new MultivaluedMapImpl();
    params.add("states", YarnApplicationState.ACCEPTED.toString() + "," + YarnApplicationState.KILLED.toString());
    response = r.path("ws").path("v1").path("cluster").path("apps").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);
    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("both app states of ACCEPTED and KILLED are not present", (array.getJSONObject(0).getString("state").equals("ACCEPTED") && array.getJSONObject(1).getString("state").equals("KILLED")) || (array.getJSONObject(0).getString("state").equals("KILLED") && array.getJSONObject(1).getString("state").equals("ACCEPTED")));
    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) WebResource(com.sun.jersey.api.client.WebResource) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) Test(org.junit.Test)

Example 73 with MultivaluedMapImpl

use of com.sun.jersey.core.util.MultivaluedMapImpl in project OpenAM by OpenRock.

the class MultipleResourceRestTest method testEntitlements.

@Test
public void testEntitlements() throws Exception {
    MultivaluedMap params = new MultivaluedMapImpl();
    params.add("resource", RESOURCE_NAME);
    params.add("realm", REALM);
    params.add("subject", hashedTokenId);
    String json = entitlementsClient.queryParams(params).accept("application/json").header(RestServiceManager.SUBJECT_HEADER_NAME, tokenIdHeader).cookie(cookie).get(String.class);
    List<JSONEntitlement> entitlements = JSONEntitlement.getEntitlements(new JSONObject(json));
    for (JSONEntitlement e : entitlements) {
        String res = e.getResourceName();
        Map<String, Boolean> actionValues = e.getActionValues();
        if (res.equals(RESOURCE_NAME)) {
            if (!actionValues.isEmpty()) {
                throw new Exception("MultipleResourceRestTest.testEntitlements: incorrect result for root");
            }
        } else if (res.equals(RESOURCE_NAME + ":80/index.html")) {
            if (actionValues.get("GET")) {
                throw new Exception("MultipleResourceRestTest.testEntitlements: incorrect result for /index.html");
            }
        } else if (res.equals(RESOURCE_NAME + ":80/*")) {
            if (!actionValues.get("GET")) {
                throw new Exception("MultipleResourceRestTest.testEntitlements: incorrect result for /*");
            }
        }
    }
}
Also used : JSONEntitlement(com.sun.identity.entitlement.JSONEntitlement) JSONObject(org.json.JSONObject) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) Test(org.testng.annotations.Test)

Example 74 with MultivaluedMapImpl

use of com.sun.jersey.core.util.MultivaluedMapImpl in project OpenAM by OpenRock.

the class MultipleResourceRestTest method testDecisions.

@Test
public void testDecisions() throws Exception {
    MultivaluedMap params = new MultivaluedMapImpl();
    params.add("resources", RESOURCE_NAME + "/index.html");
    params.add("resources", RESOURCE_NAME + "/a");
    params.add("action", "GET");
    params.add("realm", REALM);
    params.add("subject", hashedTokenId);
    String json = decisionsClient.queryParams(params).accept("application/json").header(RestServiceManager.SUBJECT_HEADER_NAME, tokenIdHeader).cookie(cookie).get(String.class);
    List<JSONEntitlement> entitlements = JSONEntitlement.getEntitlements(new JSONObject(json));
    for (JSONEntitlement e : entitlements) {
        String res = e.getResourceName();
        Map<String, Boolean> actionValues = e.getActionValues();
        if (res.equals(RESOURCE_NAME + "/index.html")) {
            if (actionValues.get("GET")) {
                throw new Exception("MultipleResourceRestTest.testDecisions: incorrect result for /index.html");
            }
        } else if (res.equals(RESOURCE_NAME + "/a")) {
            if (!actionValues.get("GET")) {
                throw new Exception("MultipleResourceRestTest.testDecisions: incorrect result for /a");
            }
        }
    }
}
Also used : JSONEntitlement(com.sun.identity.entitlement.JSONEntitlement) JSONObject(org.json.JSONObject) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) Test(org.testng.annotations.Test)

Example 75 with MultivaluedMapImpl

use of com.sun.jersey.core.util.MultivaluedMapImpl in project OpenAM by OpenRock.

the class OAuthServiceUtils method getUUIDByTokenId.

public static String getUUIDByTokenId(String tokenId) throws OAuthServiceException {
    String uuid;
    MultivaluedMapImpl params = new MultivaluedMapImpl();
    params.add(SUBJECT_ID, tokenId);
    params.add("attributenames", UUID_SESSION_PROPERTY_NAME);
    String response;
    try {
        response = attributesResource.queryParams(params).get(String.class);
    } catch (UniformInterfaceException uie) {
        throw new OAuthServiceException("Get uuid failed", uie);
    }
    if (response == null) {
        return null;
    }
    int index = response.indexOf(USERDETAILS_NAME_KEY + "=" + UUID_SESSION_PROPERTY_NAME);
    index = response.indexOf(USERDETAILS_VALUE_KEY + "=", index);
    int startIdx = index + USERDETAILS_VALUE_KEY.length() + 1;
    int idx = response.indexOf(USERDETAILS_NAME_KEY + "=", startIdx);
    int endIdx;
    if (idx > 0) {
        endIdx = idx;
    } else {
        endIdx = response.length() - 1;
    }
    uuid = response.substring(startIdx, endIdx).trim();
    return uuid;
}
Also used : UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) OAuthServiceException(com.sun.identity.oauth.service.OAuthServiceException) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl)

Aggregations

MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)131 Test (org.junit.Test)55 ClientResponse (com.sun.jersey.api.client.ClientResponse)48 WebResource (com.sun.jersey.api.client.WebResource)39 JSONObject (org.codehaus.jettison.json.JSONObject)39 Test (org.testng.annotations.Test)35 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)13 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)12 List (java.util.List)11 MockNM (org.apache.hadoop.yarn.server.resourcemanager.MockNM)11 JSONArray (org.codehaus.jettison.json.JSONArray)9 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)8 Client (com.sun.jersey.api.client.Client)7 SearchFilter (org.apache.atlas.model.SearchFilter)7 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)7 WebDriverHelper (org.orcid.api.common.WebDriverHelper)7 Response (javax.ws.rs.core.Response)6 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)6 AtlasLineageInfo (org.apache.atlas.model.lineage.AtlasLineageInfo)6 MockAM (org.apache.hadoop.yarn.server.resourcemanager.MockAM)6