use of com.sun.jersey.core.util.MultivaluedMapImpl in project hadoop by apache.
the class TestRMWebServicesSchedulerActivities method testAssignWithoutAvailableResource.
@Test
public void testAssignWithoutAvailableResource() 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("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, 0);
} finally {
rm.stop();
}
}
use of com.sun.jersey.core.util.MultivaluedMapImpl in project hadoop by apache.
the class TestRMWebServicesApps method testAppsQueryStates.
@Test
public void testAppsQueryStates() 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());
params.add("states", 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 DefaultEntityManagerImpl method searchEntity.
/**
* Searches for entities from the data store.
*
* @param entityType the type of the entity
* @param attributes the attributes to construct the search query
*
* @return a list of entity identifiers that satisfy the search criteria
*/
public List<String> searchEntity(String entityType, Map<String, String> attributes) {
List<String> ids = new ArrayList<String>();
if ((attributes == null) || (attributes.isEmpty())) {
return ids;
}
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
putAll(queryParams, attributes);
if ((entityType != null) && (entityType.trim().length() != 0)) {
queryParams.add(TOKEN_TYPE, entityType);
}
String resp = tokenResource.queryParams(queryParams).cookie(getCookie()).get(String.class);
if (resp != null) {
try {
JSONArray ja = new JSONArray(resp);
if (ja != null) {
for (int i = 0; i < ja.length(); i++) {
String id = ja.getString(i);
ids.add(id);
}
}
} catch (JSONException je) {
Logger.getLogger(DefaultEntityManagerImpl.class.getName()).log(Level.INFO, null, je);
}
}
return ids;
}
use of com.sun.jersey.core.util.MultivaluedMapImpl in project ORCID-Source by ORCID.
the class AccessTokenSecurityChecksTest method testInvalidClientResponse.
@SuppressWarnings("unchecked")
@Test
public void testInvalidClientResponse() throws IOException {
MultivaluedMap<String, String> params = new MultivaluedMapImpl();
params.add("client_id", "APP-0000000000000000");
params.add("client_secret", "clientSecret");
params.add("grant_type", "client_credentials");
params.add("scope", "/read-public");
ClientResponse response = oauthHelper.getResponse(params, APIRequestType.MEMBER);
assertEquals(ClientResponse.Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
String result = response.getEntity(String.class);
assertNotNull(result);
HashMap<String, String> error = JsonUtils.readObjectFromJsonString(result, HashMap.class);
assertNotNull(error);
assertEquals("invalid_client", error.get("error"));
assertEquals("Client not found: APP-0000000000000000", error.get("error_description"));
}
use of com.sun.jersey.core.util.MultivaluedMapImpl in project ORCID-Source by ORCID.
the class InternalAPITest method testGetTokenForInternalScopesFailForMembersAPI.
@Test
public void testGetTokenForInternalScopesFailForMembersAPI() {
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.MEMBER);
assertNotNull(clientResponse);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), clientResponse.getStatus());
}
Aggregations