YARN-6687. Validate that the duration of the periodic reservation is less than the periodicity. (subru via curino)

(cherry picked from commit 28d97b79b6)
This commit is contained in:
Carlo Curino 2017-08-11 16:58:04 -07:00 committed by Subru Krishnan
parent 630ada1b4e
commit 394573780b
2 changed files with 106 additions and 5 deletions

View File

@ -129,11 +129,12 @@ public class ReservationInputValidator {
Resources.multiply(rr.getCapability(), rr.getConcurrency())); Resources.multiply(rr.getCapability(), rr.getConcurrency()));
} }
// verify the allocation is possible (skip for ANY) // verify the allocation is possible (skip for ANY)
if (contract.getDeadline() - contract.getArrival() < minDuration long duration = contract.getDeadline() - contract.getArrival();
if (duration < minDuration
&& type != ReservationRequestInterpreter.R_ANY) { && type != ReservationRequestInterpreter.R_ANY) {
message = message =
"The time difference (" "The time difference ("
+ (contract.getDeadline() - contract.getArrival()) + (duration)
+ ") between arrival (" + contract.getArrival() + ") " + ") between arrival (" + contract.getArrival() + ") "
+ "and deadline (" + contract.getDeadline() + ") must " + "and deadline (" + contract.getDeadline() + ") must "
+ " be greater or equal to the minimum resource duration (" + " be greater or equal to the minimum resource duration ("
@ -158,15 +159,22 @@ public class ReservationInputValidator {
// check that the recurrence is a positive long value. // check that the recurrence is a positive long value.
String recurrenceExpression = contract.getRecurrenceExpression(); String recurrenceExpression = contract.getRecurrenceExpression();
try { try {
Long recurrence = Long.parseLong(recurrenceExpression); long recurrence = Long.parseLong(recurrenceExpression);
if (recurrence < 0) { if (recurrence < 0) {
message = "Negative Period : " + recurrenceExpression + ". Please try" message = "Negative Period : " + recurrenceExpression + ". Please try"
+ " again with a non-negative long value as period"; + " again with a non-negative long value as period.";
throw RPCUtil.getRemoteException(message);
}
// verify duration is less than recurrence for periodic reservations
if (recurrence > 0 && duration > recurrence) {
message = "Duration of the requested reservation: " + duration
+ " is greater than the recurrence: " + recurrence
+ ". Please try again with a smaller duration.";
throw RPCUtil.getRemoteException(message); throw RPCUtil.getRemoteException(message);
} }
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
message = "Invalid period " + recurrenceExpression + ". Please try" message = "Invalid period " + recurrenceExpression + ". Please try"
+ " again with a non-negative long value as period"; + " again with a non-negative long value as period.";
throw RPCUtil.getRemoteException(message); throw RPCUtil.getRemoteException(message);
} }
} }

View File

@ -303,6 +303,7 @@ public class TestReservationInputValidator {
@Test @Test
public void testSubmitReservationInvalidRecurrenceExpression() { public void testSubmitReservationInvalidRecurrenceExpression() {
// first check recurrence expression
ReservationSubmissionRequest request = ReservationSubmissionRequest request =
createSimpleReservationSubmissionRequest(1, 1, 1, 5, 3, "123abc"); createSimpleReservationSubmissionRequest(1, 1, 1, 5, 3, "123abc");
plan = null; plan = null;
@ -318,6 +319,23 @@ public class TestReservationInputValidator {
.startsWith("Invalid period ")); .startsWith("Invalid period "));
LOG.info(message); LOG.info(message);
} }
// now check duration
request =
createSimpleReservationSubmissionRequest(1, 1, 1, 50, 3, "10");
plan = null;
try {
plan =
rrValidator.validateReservationSubmissionRequest(rSystem, request,
ReservationSystemTestUtil.getNewReservationId());
Assert.fail();
} catch (YarnException e) {
Assert.assertNull(plan);
String message = e.getMessage();
Assert.assertTrue(message
.startsWith("Duration of the requested reservation:"));
LOG.info(message);
}
} }
@Test @Test
@ -499,6 +517,73 @@ public class TestReservationInputValidator {
} }
} }
@Test
public void testUpdateReservationValidRecurrenceExpression() {
ReservationUpdateRequest request =
createSimpleReservationUpdateRequest(1, 1, 1, 5, 3, "600000");
plan = null;
try {
plan =
rrValidator.validateReservationUpdateRequest(rSystem, request);
} catch (YarnException e) {
Assert.fail(e.getMessage());
}
Assert.assertNotNull(plan);
}
@Test
public void testUpdateReservationNegativeRecurrenceExpression() {
ReservationUpdateRequest request =
createSimpleReservationUpdateRequest(1, 1, 1, 5, 3, "-1234");
plan = null;
try {
plan =
rrValidator.validateReservationUpdateRequest(rSystem, request);
Assert.fail();
} catch (YarnException e) {
Assert.assertNull(plan);
String message = e.getMessage();
Assert.assertTrue(message
.startsWith("Negative Period : "));
LOG.info(message);
}
}
@Test
public void testUpdateReservationInvalidRecurrenceExpression() {
// first check recurrence expression
ReservationUpdateRequest request =
createSimpleReservationUpdateRequest(1, 1, 1, 5, 3, "123abc");
plan = null;
try {
plan =
rrValidator.validateReservationUpdateRequest(rSystem, request);
Assert.fail();
} catch (YarnException e) {
Assert.assertNull(plan);
String message = e.getMessage();
Assert.assertTrue(message
.startsWith("Invalid period "));
LOG.info(message);
}
// now check duration
request =
createSimpleReservationUpdateRequest(1, 1, 1, 50, 3, "10");
plan = null;
try {
plan =
rrValidator.validateReservationUpdateRequest(rSystem, request);
Assert.fail();
} catch (YarnException e) {
Assert.assertNull(plan);
String message = e.getMessage();
Assert.assertTrue(message
.startsWith("Duration of the requested reservation:"));
LOG.info(message);
}
}
@Test @Test
public void testDeleteReservationNormal() { public void testDeleteReservationNormal() {
ReservationDeleteRequest request = new ReservationDeleteRequestPBImpl(); ReservationDeleteRequest request = new ReservationDeleteRequestPBImpl();
@ -710,11 +795,19 @@ public class TestReservationInputValidator {
private ReservationUpdateRequest createSimpleReservationUpdateRequest( private ReservationUpdateRequest createSimpleReservationUpdateRequest(
int numRequests, int numContainers, long arrival, long deadline, int numRequests, int numContainers, long arrival, long deadline,
long duration) { long duration) {
return createSimpleReservationUpdateRequest(numRequests, numContainers,
arrival, deadline, duration, "0");
}
private ReservationUpdateRequest createSimpleReservationUpdateRequest(
int numRequests, int numContainers, long arrival, long deadline,
long duration, String recurrence) {
// create a request with a single atomic ask // create a request with a single atomic ask
ReservationUpdateRequest request = new ReservationUpdateRequestPBImpl(); ReservationUpdateRequest request = new ReservationUpdateRequestPBImpl();
ReservationDefinition rDef = new ReservationDefinitionPBImpl(); ReservationDefinition rDef = new ReservationDefinitionPBImpl();
rDef.setArrival(arrival); rDef.setArrival(arrival);
rDef.setDeadline(deadline); rDef.setDeadline(deadline);
rDef.setRecurrenceExpression(recurrence);
if (numRequests > 0) { if (numRequests > 0) {
ReservationRequests reqs = new ReservationRequestsPBImpl(); ReservationRequests reqs = new ReservationRequestsPBImpl();
rDef.setReservationRequests(reqs); rDef.setReservationRequests(reqs);