|
@@ -21,6 +21,7 @@ package org.apache.hadoop.yarn.server.resourcemanager.webapp;
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
import static org.junit.Assert.assertNotNull;
|
|
|
import static org.junit.Assert.assertNull;
|
|
|
+import static org.junit.Assert.assertTrue;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.FileWriter;
|
|
@@ -54,8 +55,11 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairSchedule
|
|
|
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ReservationDeleteRequestInfo;
|
|
|
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ReservationSubmissionRequestInfo;
|
|
|
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ReservationUpdateRequestInfo;
|
|
|
+import org.apache.hadoop.yarn.util.Clock;
|
|
|
+import org.apache.hadoop.yarn.util.UTCClock;
|
|
|
import org.apache.hadoop.yarn.webapp.GenericExceptionHandler;
|
|
|
import org.apache.hadoop.yarn.webapp.JerseyTestBase;
|
|
|
+import org.codehaus.jettison.json.JSONArray;
|
|
|
import org.codehaus.jettison.json.JSONException;
|
|
|
import org.codehaus.jettison.json.JSONObject;
|
|
|
import org.junit.After;
|
|
@@ -82,17 +86,22 @@ import com.sun.jersey.test.framework.WebAppDescriptor;
|
|
|
|
|
|
@RunWith(Parameterized.class)
|
|
|
public class TestRMWebServicesReservation extends JerseyTestBase {
|
|
|
- private static MockRM rm;
|
|
|
|
|
|
- private static Injector injector;
|
|
|
private String webserviceUserName = "testuser";
|
|
|
-
|
|
|
private boolean setAuthFilter = false;
|
|
|
|
|
|
+ private static MockRM rm;
|
|
|
+ private static Injector injector;
|
|
|
+
|
|
|
+ private static final int MINIMUM_RESOURCE_DURATION = 1000000;
|
|
|
+ private static final Clock clock = new UTCClock();
|
|
|
private static final String TEST_DIR = new File(System.getProperty(
|
|
|
"test.build.data", "/tmp")).getAbsolutePath();
|
|
|
private static final String FS_ALLOC_FILE = new File(TEST_DIR,
|
|
|
"test-fs-queues.xml").getAbsolutePath();
|
|
|
+ // This is what is used in the test resource files.
|
|
|
+ private static final String DEFAULT_QUEUE = "dedicated";
|
|
|
+ private static final String LIST_RESERVATION_PATH = "reservation/list";
|
|
|
|
|
|
public static class GuiceServletConfig extends GuiceServletContextListener {
|
|
|
|
|
@@ -318,13 +327,9 @@ public class TestRMWebServicesReservation extends JerseyTestBase {
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void testSubmitReservation() throws JSONException, Exception {
|
|
|
+ public void testSubmitReservation() throws Exception {
|
|
|
rm.start();
|
|
|
- for (int i = 0; i < 100; i++) {
|
|
|
- MockNM amNodeManager =
|
|
|
- rm.registerNode("127.0.0." + i + ":1234", 100 * 1024);
|
|
|
- amNodeManager.nodeHeartbeat(true);
|
|
|
- }
|
|
|
+ setupCluster(100);
|
|
|
ReservationId rid =
|
|
|
testSubmissionReservationHelper("reservation/submit",
|
|
|
MediaType.APPLICATION_JSON);
|
|
@@ -335,14 +340,10 @@ public class TestRMWebServicesReservation extends JerseyTestBase {
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void testFailedSubmitReservation() throws JSONException, Exception {
|
|
|
+ public void testFailedSubmitReservation() throws Exception {
|
|
|
rm.start();
|
|
|
// setup a cluster too small to accept the reservation
|
|
|
- for (int i = 0; i < 1; i++) {
|
|
|
- MockNM amNodeManager =
|
|
|
- rm.registerNode("127.0.0." + i + ":1234", 100 * 1024);
|
|
|
- amNodeManager.nodeHeartbeat(true);
|
|
|
- }
|
|
|
+ setupCluster(1);
|
|
|
ReservationId rid =
|
|
|
testSubmissionReservationHelper("reservation/submit",
|
|
|
MediaType.APPLICATION_JSON);
|
|
@@ -353,11 +354,7 @@ public class TestRMWebServicesReservation extends JerseyTestBase {
|
|
|
@Test
|
|
|
public void testUpdateReservation() throws JSONException, Exception {
|
|
|
rm.start();
|
|
|
- for (int i = 0; i < 100; i++) {
|
|
|
- MockNM amNodeManager =
|
|
|
- rm.registerNode("127.0.0." + i + ":1234", 100 * 1024);
|
|
|
- amNodeManager.nodeHeartbeat(true);
|
|
|
- }
|
|
|
+ setupCluster(100);
|
|
|
ReservationId rid =
|
|
|
testSubmissionReservationHelper("reservation/submit",
|
|
|
MediaType.APPLICATION_JSON);
|
|
@@ -370,6 +367,452 @@ public class TestRMWebServicesReservation extends JerseyTestBase {
|
|
|
rm.stop();
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testTimeIntervalRequestListReservation() throws Exception {
|
|
|
+ rm.start();
|
|
|
+ setupCluster(100);
|
|
|
+
|
|
|
+ long time = clock.getTime() + MINIMUM_RESOURCE_DURATION;
|
|
|
+ testSubmissionReservationHelper("reservation/submit",
|
|
|
+ MediaType.APPLICATION_JSON, time, "res_1", 1);
|
|
|
+ testSubmissionReservationHelper("reservation/submit",
|
|
|
+ MediaType.APPLICATION_JSON, time + MINIMUM_RESOURCE_DURATION,
|
|
|
+ "res_2", 2);
|
|
|
+
|
|
|
+ WebResource resource = constructWebResource(LIST_RESERVATION_PATH)
|
|
|
+ .queryParam("start-time", Long.toString((long) (time * 0.9)))
|
|
|
+ .queryParam("end-time", Long.toString(time + (long) (0.9 *
|
|
|
+ MINIMUM_RESOURCE_DURATION)))
|
|
|
+ .queryParam("include-resource-allocations", "true")
|
|
|
+ .queryParam("queue", DEFAULT_QUEUE);
|
|
|
+
|
|
|
+ JSONObject json = testListReservationHelper(resource);
|
|
|
+
|
|
|
+ if (!this.isAuthenticationEnabled() && json == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject reservations = json.getJSONObject("reservations");
|
|
|
+
|
|
|
+ testRDLHelper(reservations);
|
|
|
+
|
|
|
+ String reservationName = reservations.getJSONObject
|
|
|
+ ("reservation-definition").getString("reservation-name");
|
|
|
+ assertEquals(reservationName, "res_1");
|
|
|
+
|
|
|
+ rm.stop();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testSameTimeIntervalRequestListReservation() throws Exception {
|
|
|
+ rm.start();
|
|
|
+ setupCluster(100);
|
|
|
+
|
|
|
+ long time = clock.getTime() + MINIMUM_RESOURCE_DURATION;
|
|
|
+
|
|
|
+ testSubmissionReservationHelper("reservation/submit",
|
|
|
+ MediaType.APPLICATION_JSON, time, "res_1", 1);
|
|
|
+ testSubmissionReservationHelper("reservation/submit",
|
|
|
+ MediaType.APPLICATION_JSON, time + MINIMUM_RESOURCE_DURATION,
|
|
|
+ "res_2", 2);
|
|
|
+
|
|
|
+ String timeParam = Long.toString(time + MINIMUM_RESOURCE_DURATION / 2);
|
|
|
+ WebResource resource = constructWebResource(LIST_RESERVATION_PATH)
|
|
|
+ .queryParam("start-time", timeParam)
|
|
|
+ .queryParam("end-time", timeParam)
|
|
|
+ .queryParam("include-resource-allocations", "true")
|
|
|
+ .queryParam("queue", DEFAULT_QUEUE);
|
|
|
+
|
|
|
+ JSONObject json = testListReservationHelper(resource);
|
|
|
+
|
|
|
+ if (!this.isAuthenticationEnabled() && json == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject reservations = json.getJSONObject("reservations");
|
|
|
+
|
|
|
+ testRDLHelper(reservations);
|
|
|
+
|
|
|
+ String reservationName = reservations.getJSONObject
|
|
|
+ ("reservation-definition").getString("reservation-name");
|
|
|
+ assertEquals(reservationName, "res_1");
|
|
|
+
|
|
|
+ rm.stop();
|
|
|
+ }
|
|
|
+ @Test
|
|
|
+ public void testInvalidTimeIntervalRequestListReservation() throws
|
|
|
+ Exception {
|
|
|
+ rm.start();
|
|
|
+ setupCluster(100);
|
|
|
+
|
|
|
+ long time = clock.getTime() + MINIMUM_RESOURCE_DURATION;
|
|
|
+
|
|
|
+ ReservationId res1 = testSubmissionReservationHelper("reservation/submit",
|
|
|
+ MediaType.APPLICATION_JSON, time, "res_1", 1);
|
|
|
+ ReservationId res2 = testSubmissionReservationHelper("reservation/submit",
|
|
|
+ MediaType.APPLICATION_JSON, time + MINIMUM_RESOURCE_DURATION,
|
|
|
+ "res_2", 2);
|
|
|
+
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testInvalidEndTimeRequestListReservation() throws Exception {
|
|
|
+ rm.start();
|
|
|
+ setupCluster(100);
|
|
|
+
|
|
|
+ long time = clock.getTime() + MINIMUM_RESOURCE_DURATION;
|
|
|
+
|
|
|
+ testSubmissionReservationHelper("reservation/submit",
|
|
|
+ MediaType.APPLICATION_JSON, time, "res_1", 1);
|
|
|
+ testSubmissionReservationHelper("reservation/submit",
|
|
|
+ MediaType.APPLICATION_JSON, time + MINIMUM_RESOURCE_DURATION,
|
|
|
+ "res_2", 2);
|
|
|
+
|
|
|
+ WebResource resource = constructWebResource(LIST_RESERVATION_PATH)
|
|
|
+ .queryParam("start-time", Long.toString((long) (time +
|
|
|
+ MINIMUM_RESOURCE_DURATION * 1.3)))
|
|
|
+ .queryParam("end-time", "-1")
|
|
|
+ .queryParam("include-resource-allocations", "true")
|
|
|
+ .queryParam("queue", DEFAULT_QUEUE);
|
|
|
+
|
|
|
+ JSONObject json = testListReservationHelper(resource);
|
|
|
+
|
|
|
+ if (!this.isAuthenticationEnabled() && json == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject reservations = json.getJSONObject("reservations");
|
|
|
+
|
|
|
+ testRDLHelper(reservations);
|
|
|
+
|
|
|
+ String reservationName = reservations.getJSONObject
|
|
|
+ ("reservation-definition").getString("reservation-name");
|
|
|
+ assertEquals(reservationName, "res_2");
|
|
|
+
|
|
|
+ rm.stop();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testEmptyEndTimeRequestListReservation() throws Exception {
|
|
|
+ rm.start();
|
|
|
+ setupCluster(100);
|
|
|
+
|
|
|
+ long time = clock.getTime() + MINIMUM_RESOURCE_DURATION;
|
|
|
+
|
|
|
+ testSubmissionReservationHelper("reservation/submit",
|
|
|
+ MediaType.APPLICATION_JSON, time, "res_1", 1);
|
|
|
+ testSubmissionReservationHelper("reservation/submit",
|
|
|
+ MediaType.APPLICATION_JSON, time + MINIMUM_RESOURCE_DURATION,
|
|
|
+ "res_2", 2);
|
|
|
+
|
|
|
+ WebResource resource = constructWebResource(LIST_RESERVATION_PATH)
|
|
|
+ .queryParam("start-time", new Long((long) (time +
|
|
|
+ MINIMUM_RESOURCE_DURATION * 1.3)).toString())
|
|
|
+ .queryParam("include-resource-allocations", "true")
|
|
|
+ .queryParam("queue", DEFAULT_QUEUE);
|
|
|
+
|
|
|
+ JSONObject json = testListReservationHelper(resource);
|
|
|
+
|
|
|
+ if (!this.isAuthenticationEnabled() && json == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject reservations = json.getJSONObject("reservations");
|
|
|
+
|
|
|
+ testRDLHelper(reservations);
|
|
|
+
|
|
|
+ String reservationName = reservations.getJSONObject
|
|
|
+ ("reservation-definition").getString("reservation-name");
|
|
|
+ assertEquals(reservationName, "res_2");
|
|
|
+
|
|
|
+ rm.stop();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testInvalidStartTimeRequestListReservation() throws Exception {
|
|
|
+ rm.start();
|
|
|
+ setupCluster(100);
|
|
|
+
|
|
|
+ long time = clock.getTime() + MINIMUM_RESOURCE_DURATION;
|
|
|
+
|
|
|
+ testSubmissionReservationHelper("reservation/submit",
|
|
|
+ MediaType.APPLICATION_JSON, time, "res_1", 1);
|
|
|
+ testSubmissionReservationHelper("reservation/submit",
|
|
|
+ MediaType.APPLICATION_JSON, time + MINIMUM_RESOURCE_DURATION,
|
|
|
+ "res_2", 2);
|
|
|
+
|
|
|
+ WebResource resource = constructWebResource(LIST_RESERVATION_PATH)
|
|
|
+ .queryParam("start-time", "-1")
|
|
|
+ .queryParam("end-time", new Long((long)(time +
|
|
|
+ MINIMUM_RESOURCE_DURATION * 0.9)).toString())
|
|
|
+ .queryParam("include-resource-allocations", "true")
|
|
|
+ .queryParam("queue", DEFAULT_QUEUE);
|
|
|
+
|
|
|
+ JSONObject json = testListReservationHelper(resource);
|
|
|
+
|
|
|
+ if (!this.isAuthenticationEnabled() && json == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject reservations = json.getJSONObject("reservations");
|
|
|
+
|
|
|
+ testRDLHelper(reservations);
|
|
|
+
|
|
|
+ // only res_1 should fall into the time interval given in the request json.
|
|
|
+ String reservationName = reservations.getJSONObject
|
|
|
+ ("reservation-definition").getString("reservation-name");
|
|
|
+ assertEquals(reservationName, "res_1");
|
|
|
+
|
|
|
+ rm.stop();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testEmptyStartTimeRequestListReservation() throws Exception {
|
|
|
+ rm.start();
|
|
|
+ setupCluster(100);
|
|
|
+
|
|
|
+ long time = clock.getTime() + MINIMUM_RESOURCE_DURATION;
|
|
|
+
|
|
|
+ testSubmissionReservationHelper("reservation/submit",
|
|
|
+ MediaType.APPLICATION_JSON, time, "res_1", 1);
|
|
|
+ testSubmissionReservationHelper("reservation/submit",
|
|
|
+ MediaType.APPLICATION_JSON, time + MINIMUM_RESOURCE_DURATION,
|
|
|
+ "res_2", 2);
|
|
|
+
|
|
|
+ WebResource resource = constructWebResource(LIST_RESERVATION_PATH)
|
|
|
+ .queryParam("end-time", new Long((long)(time +
|
|
|
+ MINIMUM_RESOURCE_DURATION * 0.9)).toString())
|
|
|
+ .queryParam("include-resource-allocations", "true")
|
|
|
+ .queryParam("queue", DEFAULT_QUEUE);
|
|
|
+
|
|
|
+ JSONObject json = testListReservationHelper(resource);
|
|
|
+
|
|
|
+ if (!this.isAuthenticationEnabled() && json == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject reservations = json.getJSONObject("reservations");
|
|
|
+
|
|
|
+ testRDLHelper(reservations);
|
|
|
+
|
|
|
+ // only res_1 should fall into the time interval given in the request json.
|
|
|
+ String reservationName = reservations.getJSONObject
|
|
|
+ ("reservation-definition").getString("reservation-name");
|
|
|
+ assertEquals(reservationName, "res_1");
|
|
|
+
|
|
|
+ rm.stop();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testQueueOnlyRequestListReservation() throws Exception {
|
|
|
+ rm.start();
|
|
|
+ setupCluster(100);
|
|
|
+
|
|
|
+ testSubmissionReservationHelper("reservation/submit",
|
|
|
+ MediaType.APPLICATION_JSON, clock.getTime(), "res_1", 1);
|
|
|
+ testSubmissionReservationHelper("reservation/submit",
|
|
|
+ MediaType.APPLICATION_JSON, clock.getTime(), "res_2", 2);
|
|
|
+
|
|
|
+ WebResource resource = constructWebResource(LIST_RESERVATION_PATH)
|
|
|
+ .queryParam("queue", DEFAULT_QUEUE);
|
|
|
+
|
|
|
+ JSONObject json = testListReservationHelper(resource);
|
|
|
+
|
|
|
+ if (!this.isAuthenticationEnabled() && json == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ assertEquals(json.getJSONArray("reservations").length(), 2);
|
|
|
+
|
|
|
+ testRDLHelper(json.getJSONArray("reservations").getJSONObject(0));
|
|
|
+ testRDLHelper(json.getJSONArray("reservations").getJSONObject(1));
|
|
|
+
|
|
|
+ rm.stop();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testEmptyQueueRequestListReservation() throws Exception {
|
|
|
+ rm.start();
|
|
|
+ setupCluster(100);
|
|
|
+
|
|
|
+ testSubmissionReservationHelper("reservation/submit",
|
|
|
+ MediaType.APPLICATION_JSON, clock.getTime(), "res_1", 1);
|
|
|
+ testSubmissionReservationHelper("reservation/submit",
|
|
|
+ MediaType.APPLICATION_JSON, clock.getTime(), "res_2", 2);
|
|
|
+
|
|
|
+ WebResource resource = constructWebResource(LIST_RESERVATION_PATH);
|
|
|
+
|
|
|
+ testListReservationHelper(resource, Status.BAD_REQUEST);
|
|
|
+
|
|
|
+ rm.stop();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testNonExistentQueueRequestListReservation() throws Exception {
|
|
|
+ rm.start();
|
|
|
+ setupCluster(100);
|
|
|
+
|
|
|
+ testSubmissionReservationHelper("reservation/submit",
|
|
|
+ MediaType.APPLICATION_JSON, clock.getTime(), "res_1", 1);
|
|
|
+ testSubmissionReservationHelper("reservation/submit",
|
|
|
+ MediaType.APPLICATION_JSON, clock.getTime(), "res_2", 2);
|
|
|
+
|
|
|
+ WebResource resource = constructWebResource(LIST_RESERVATION_PATH)
|
|
|
+ .queryParam("queue", DEFAULT_QUEUE + "_invalid");
|
|
|
+
|
|
|
+ testListReservationHelper(resource, Status.BAD_REQUEST);
|
|
|
+
|
|
|
+ rm.stop();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testReservationIdRequestListReservation() throws Exception {
|
|
|
+ rm.start();
|
|
|
+ setupCluster(100);
|
|
|
+
|
|
|
+ ReservationId id1 = testSubmissionReservationHelper("reservation/submit",
|
|
|
+ MediaType.APPLICATION_JSON, clock.getTime(), "res_1", 1);
|
|
|
+ testSubmissionReservationHelper("reservation/submit",
|
|
|
+ MediaType.APPLICATION_JSON, clock.getTime(), "res_2", 2);
|
|
|
+
|
|
|
+ WebResource resource = constructWebResource(LIST_RESERVATION_PATH)
|
|
|
+ .queryParam("include-resource-allocations", "true")
|
|
|
+ .queryParam("queue", DEFAULT_QUEUE);
|
|
|
+
|
|
|
+ if (id1 != null) {
|
|
|
+ resource = resource.queryParam("reservation-id", id1.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject json = testListReservationHelper(resource);
|
|
|
+
|
|
|
+ if (!this.isAuthenticationEnabled() && json == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject reservations = json.getJSONObject("reservations");
|
|
|
+
|
|
|
+ testRDLHelper(reservations);
|
|
|
+
|
|
|
+ long reservationId = reservations.getJSONObject("reservation-id")
|
|
|
+ .getLong("reservation-id");
|
|
|
+ assertEquals(id1.getId(), reservationId);
|
|
|
+
|
|
|
+ rm.stop();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testInvalidReservationIdRequestListReservation() throws
|
|
|
+ Exception {
|
|
|
+ rm.start();
|
|
|
+ setupCluster(100);
|
|
|
+
|
|
|
+ ReservationId id1 = testSubmissionReservationHelper("reservation/submit",
|
|
|
+ MediaType.APPLICATION_JSON, clock.getTime(), "res_1", 1);
|
|
|
+
|
|
|
+ WebResource resource = constructWebResource(LIST_RESERVATION_PATH)
|
|
|
+ .queryParam("queue", DEFAULT_QUEUE);
|
|
|
+
|
|
|
+ if (id1 != null) {
|
|
|
+ resource = resource.queryParam("reservation-id",
|
|
|
+ "invalid" + id1.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject response = testListReservationHelper(resource, Status.NOT_FOUND);
|
|
|
+
|
|
|
+ rm.stop();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testIncludeResourceAllocations() throws Exception {
|
|
|
+ rm.start();
|
|
|
+ setupCluster(100);
|
|
|
+
|
|
|
+ ReservationId id1 = testSubmissionReservationHelper("reservation/submit",
|
|
|
+ MediaType.APPLICATION_JSON, clock.getTime(), "res_1", 1);
|
|
|
+
|
|
|
+ WebResource resource = constructWebResource(LIST_RESERVATION_PATH)
|
|
|
+ .queryParam("include-resource-allocations", "true")
|
|
|
+ .queryParam("queue", DEFAULT_QUEUE);
|
|
|
+
|
|
|
+ if (id1 != null) {
|
|
|
+ resource = resource.queryParam("reservation-id", id1.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject json = testListReservationHelper(resource);
|
|
|
+
|
|
|
+ if (!this.isAuthenticationEnabled() && json == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject reservations = json.getJSONObject("reservations");
|
|
|
+
|
|
|
+ testRDLHelper(reservations);
|
|
|
+
|
|
|
+ long reservationId = reservations.getJSONObject("reservation-id")
|
|
|
+ .getLong("reservation-id");
|
|
|
+ assertEquals(id1.getId(), reservationId);
|
|
|
+
|
|
|
+ assertTrue(reservations.has("resource-allocations"));
|
|
|
+
|
|
|
+ rm.stop();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testExcludeResourceAllocations() throws Exception {
|
|
|
+ rm.start();
|
|
|
+ setupCluster(100);
|
|
|
+
|
|
|
+ ReservationId id1 = testSubmissionReservationHelper("reservation/submit",
|
|
|
+ MediaType.APPLICATION_JSON, clock.getTime(), "res_1", 1);
|
|
|
+
|
|
|
+ WebResource resource = constructWebResource(LIST_RESERVATION_PATH)
|
|
|
+ .queryParam("include-resource-allocations", "false")
|
|
|
+ .queryParam("queue", DEFAULT_QUEUE);
|
|
|
+
|
|
|
+ if (id1 != null) {
|
|
|
+ resource = resource.queryParam("reservation-id", id1.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject json = testListReservationHelper(resource);
|
|
|
+
|
|
|
+ if (!this.isAuthenticationEnabled() && json == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject reservations = json.getJSONObject("reservations");
|
|
|
+
|
|
|
+ testRDLHelper(reservations);
|
|
|
+
|
|
|
+ long reservationId = reservations.getJSONObject("reservation-id")
|
|
|
+ .getLong("reservation-id");
|
|
|
+ assertEquals(id1.getId(), reservationId);
|
|
|
+
|
|
|
+ assertTrue(!reservations.has("resource-allocations"));
|
|
|
+
|
|
|
+ rm.stop();
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void testDeleteReservation() throws JSONException, Exception {
|
|
|
rm.start();
|
|
@@ -391,10 +834,27 @@ public class TestRMWebServicesReservation extends JerseyTestBase {
|
|
|
}
|
|
|
|
|
|
private ReservationId testSubmissionReservationHelper(String path,
|
|
|
- String media) throws JSONException, Exception {
|
|
|
+ String media) throws Exception {
|
|
|
+ long arrival = clock.getTime() + MINIMUM_RESOURCE_DURATION;
|
|
|
+
|
|
|
+ return testSubmissionReservationHelper(path, media, arrival, "res_1", 1);
|
|
|
+ }
|
|
|
|
|
|
+ private ReservationId testSubmissionReservationHelper(String path,
|
|
|
+ String media, Long arrival, String reservationName, int expectedId)
|
|
|
+ throws Exception {
|
|
|
String reservationJson = loadJsonFile("submit-reservation.json");
|
|
|
|
|
|
+ String reservationJsonRequest = String.format(reservationJson, arrival,
|
|
|
+ arrival + MINIMUM_RESOURCE_DURATION, reservationName);
|
|
|
+
|
|
|
+ return submitAndVerifyReservation(path, media, reservationJsonRequest,
|
|
|
+ expectedId);
|
|
|
+ }
|
|
|
+
|
|
|
+ private ReservationId submitAndVerifyReservation(String path, String media,
|
|
|
+ String reservationJson, int expectedId) throws Exception {
|
|
|
+
|
|
|
JSONJAXBContext jc =
|
|
|
new JSONJAXBContext(JSONConfiguration.mapped()
|
|
|
.build(), ReservationSubmissionRequestInfo.class);
|
|
@@ -421,7 +881,7 @@ public class TestRMWebServicesReservation extends JerseyTestBase {
|
|
|
ReservationId rid = null;
|
|
|
try {
|
|
|
rid = ReservationId.parseReservationId(json.getString("reservation-id"));
|
|
|
- assertEquals("incorrect return value", rid.getId(), 1);
|
|
|
+ assertEquals("incorrect return value", rid.getId(), expectedId);
|
|
|
} catch (JSONException j) {
|
|
|
// failure is possible and is checked outside
|
|
|
}
|
|
@@ -511,7 +971,45 @@ public class TestRMWebServicesReservation extends JerseyTestBase {
|
|
|
System.out.println("RESPONSE:" + response);
|
|
|
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
|
|
assertEquals(Status.OK, response.getClientResponseStatus());
|
|
|
+ }
|
|
|
+
|
|
|
+ private void testRDLHelper(JSONObject json) throws JSONException {
|
|
|
+ JSONObject requests = json.getJSONObject("reservation-definition")
|
|
|
+ .getJSONObject("reservation-requests");
|
|
|
+ String type = requests.getString
|
|
|
+ ("reservation-request-interpreter");
|
|
|
+
|
|
|
+ assertEquals("0", type);
|
|
|
+ assertEquals(60, requests.getJSONArray("reservation-request")
|
|
|
+ .getJSONObject(0).getInt("duration"));
|
|
|
+ }
|
|
|
|
|
|
+ private JSONObject testListReservationHelper(WebResource resource) throws
|
|
|
+ Exception {
|
|
|
+ return testListReservationHelper(resource, Status.OK);
|
|
|
}
|
|
|
|
|
|
+ private JSONObject testListReservationHelper(WebResource resource, Status
|
|
|
+ status) throws Exception {
|
|
|
+ Thread.sleep(1000);
|
|
|
+ ClientResponse response = resource.get(ClientResponse.class);
|
|
|
+
|
|
|
+ if (!this.isAuthenticationEnabled()) {
|
|
|
+ assertEquals(Status.UNAUTHORIZED, response.getClientResponseStatus());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
|
|
+ assertEquals(status, response.getClientResponseStatus());
|
|
|
+
|
|
|
+ return response.getEntity(JSONObject.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setupCluster(int nodes) throws Exception {
|
|
|
+ for (int i = 0; i < nodes; i++) {
|
|
|
+ MockNM amNodeManager =
|
|
|
+ rm.registerNode("127.0.0." + i + ":1234", 100 * 1024);
|
|
|
+ amNodeManager.nodeHeartbeat(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|