use of com.sun.jersey.api.client.WebResource 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.api.client.WebResource in project hadoop by apache.
the class TestRMWebServicesNodes method testNodesQueryStateLost.
@Test
public void testNodesQueryStateLost() throws JSONException, Exception {
WebResource r = resource();
RMNode rmnode1 = getRunningRMNode("h1", 1234, 5120);
sendLostEvent(rmnode1);
RMNode rmnode2 = getRunningRMNode("h2", 1235, 5121);
sendLostEvent(rmnode2);
ClientResponse response = r.path("ws").path("v1").path("cluster").path("nodes").queryParam("states", NodeState.LOST.toString()).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class);
JSONObject nodes = json.getJSONObject("nodes");
assertEquals("incorrect number of elements", 1, nodes.length());
JSONArray nodeArray = nodes.getJSONArray("node");
assertEquals("incorrect number of elements", 2, nodeArray.length());
for (int i = 0; i < nodeArray.length(); ++i) {
JSONObject info = nodeArray.getJSONObject(i);
String[] node = info.get("id").toString().split(":");
NodeId nodeId = NodeId.newInstance(node[0], Integer.parseInt(node[1]));
RMNode rmNode = rm.getRMContext().getInactiveRMNodes().get(nodeId);
WebServicesTestUtils.checkStringMatch("nodeHTTPAddress", "", info.getString("nodeHTTPAddress"));
if (rmNode != null) {
WebServicesTestUtils.checkStringMatch("state", rmNode.getState().toString(), info.getString("state"));
}
}
}
use of com.sun.jersey.api.client.WebResource in project hadoop by apache.
the class TestRMWebServicesNodes method testNodesHelper.
public void testNodesHelper(String path, String media) throws JSONException, Exception {
WebResource r = resource();
RMNode rmnode1 = getRunningRMNode("h1", 1234, 5120);
RMNode rmnode2 = getRunningRMNode("h2", 1235, 5121);
ClientResponse response = r.path("ws").path("v1").path("cluster").path(path).accept(media).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 nodes = json.getJSONObject("nodes");
assertEquals("incorrect number of elements", 1, nodes.length());
JSONArray nodeArray = nodes.getJSONArray("node");
assertEquals("incorrect number of elements", 2, nodeArray.length());
JSONObject info = nodeArray.getJSONObject(0);
String id = info.get("id").toString();
if (id.matches("h1:1234")) {
verifyNodeInfo(info, rmnode1);
verifyNodeInfo(nodeArray.getJSONObject(1), rmnode2);
} else {
verifyNodeInfo(info, rmnode2);
verifyNodeInfo(nodeArray.getJSONObject(1), rmnode1);
}
}
use of com.sun.jersey.api.client.WebResource in project hadoop by apache.
the class TestRMWebServicesReservation method testInvalidTimeIntervalRequestListReservation.
@Test
public void testInvalidTimeIntervalRequestListReservation() throws Exception {
rm.start();
setupCluster(100);
long time = clock.getTime() + MINIMUM_RESOURCE_DURATION;
ReservationId id1 = getReservationIdTestHelper(1);
ReservationId id2 = getReservationIdTestHelper(2);
reservationSubmissionTestHelper("reservation/submit", MediaType.APPLICATION_JSON, time, "res_1", id1);
reservationSubmissionTestHelper("reservation/submit", MediaType.APPLICATION_JSON, time + MINIMUM_RESOURCE_DURATION, "res_2", id2);
WebResource resource;
resource = constructWebResource(LIST_RESERVATION_PATH).queryParam("start-time", "-100").queryParam("end-time", "-100").queryParam("include-resource-allocations", "true").queryParam("queue", DEFAULT_QUEUE);
JSONObject json = testListReservationHelper(resource);
if (!this.isAuthenticationEnabled() && json == null) {
return;
}
JSONArray reservations = json.getJSONArray("reservations");
assertEquals(2, reservations.length());
testRDLHelper(reservations.getJSONObject(0));
testRDLHelper(reservations.getJSONObject(1));
rm.stop();
}
use of com.sun.jersey.api.client.WebResource in project zookeeper by apache.
the class CreateTest method testCreate.
@Test
public void testCreate() throws Exception {
WebResource wr = znodesr.path(path).queryParam("dataformat", encoding).queryParam("name", name);
if (data == null) {
wr = wr.queryParam("null", "true");
}
if (sequence) {
wr = wr.queryParam("sequence", "true");
}
Builder builder = wr.accept(accept);
ClientResponse cr;
if (data == null) {
cr = builder.post(ClientResponse.class);
} else {
cr = builder.post(ClientResponse.class, data);
}
Assert.assertEquals(expectedStatus, cr.getClientResponseStatus());
if (expectedPath == null) {
return;
}
ZPath zpath = cr.getEntity(ZPath.class);
if (sequence) {
Assert.assertTrue(zpath.path.startsWith(expectedPath.path));
Assert.assertTrue(zpath.uri.startsWith(znodesr.path(path).toString()));
} else {
Assert.assertEquals(expectedPath, zpath);
Assert.assertEquals(znodesr.path(path).toString(), zpath.uri);
}
// use out-of-band method to verify
byte[] data = zk.getData(zpath.path, false, new Stat());
if (data == null && this.data == null) {
return;
} else if (data == null || this.data == null) {
Assert.assertEquals(data, this.data);
} else {
Assert.assertTrue(new String(data) + " == " + new String(this.data), Arrays.equals(data, this.data));
}
}
Aggregations