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();
}
}
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();
}
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 /*");
}
}
}
}
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");
}
}
}
}
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;
}
Aggregations