use of org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionRequest in project hadoop by apache.
the class TestYarnClient method testListReservationsByTimeInterval.
@Test
public void testListReservationsByTimeInterval() throws Exception {
MiniYARNCluster cluster = setupMiniYARNCluster();
YarnClient client = setupYarnClient(cluster);
try {
Clock clock = new UTCClock();
long arrival = clock.getTime();
long duration = 60000;
long deadline = (long) (arrival + 1.05 * duration);
ReservationSubmissionRequest sRequest = submitReservationTestHelper(client, arrival, deadline, duration);
// List reservations, search by a point in time within the reservation
// range.
arrival = clock.getTime();
ReservationId reservationID = sRequest.getReservationId();
ReservationListRequest request = ReservationListRequest.newInstance(ReservationSystemTestUtil.reservationQ, "", arrival + duration / 2, arrival + duration / 2, true);
ReservationListResponse response = client.listReservations(request);
Assert.assertNotNull(response);
Assert.assertEquals(1, response.getReservationAllocationState().size());
Assert.assertEquals(response.getReservationAllocationState().get(0).getReservationId().getId(), reservationID.getId());
// List reservations, search by time within reservation interval.
request = ReservationListRequest.newInstance(ReservationSystemTestUtil.reservationQ, "", 1, Long.MAX_VALUE, true);
response = client.listReservations(request);
Assert.assertNotNull(response);
Assert.assertEquals(1, response.getReservationAllocationState().size());
Assert.assertEquals(response.getReservationAllocationState().get(0).getReservationId().getId(), reservationID.getId());
// Verify that the full resource allocations exist.
Assert.assertTrue(response.getReservationAllocationState().get(0).getResourceAllocationRequests().size() > 0);
// Verify that the full RDL is returned.
ReservationRequests reservationRequests = response.getReservationAllocationState().get(0).getReservationDefinition().getReservationRequests();
Assert.assertTrue(reservationRequests.getInterpreter().toString().equals("R_ALL"));
Assert.assertTrue(reservationRequests.getReservationResources().get(0).getDuration() == duration);
} finally {
// clean-up
if (client != null) {
client.stop();
}
cluster.stop();
}
}
use of org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionRequest in project hadoop by apache.
the class RMWebServices method createReservationSubmissionRequest.
private ReservationSubmissionRequest createReservationSubmissionRequest(ReservationSubmissionRequestInfo resContext) throws IOException {
// defending against a couple of common submission format problems
if (resContext == null) {
throw new BadRequestException("Input ReservationSubmissionContext should not be null");
}
ReservationDefinitionInfo resInfo = resContext.getReservationDefinition();
if (resInfo == null) {
throw new BadRequestException("Input ReservationDefinition should not be null");
}
ReservationRequestsInfo resReqsInfo = resInfo.getReservationRequests();
if (resReqsInfo == null || resReqsInfo.getReservationRequest() == null || resReqsInfo.getReservationRequest().size() == 0) {
throw new BadRequestException("The ReservationDefinition should" + " contain at least one ReservationRequest");
}
ReservationRequestInterpreter[] values = ReservationRequestInterpreter.values();
ReservationRequestInterpreter resInt = values[resReqsInfo.getReservationRequestsInterpreter()];
List<ReservationRequest> list = new ArrayList<ReservationRequest>();
for (ReservationRequestInfo resReqInfo : resReqsInfo.getReservationRequest()) {
ResourceInfo rInfo = resReqInfo.getCapability();
Resource capability = Resource.newInstance(rInfo.getMemorySize(), rInfo.getvCores());
int numContainers = resReqInfo.getNumContainers();
int minConcurrency = resReqInfo.getMinConcurrency();
long duration = resReqInfo.getDuration();
ReservationRequest rr = ReservationRequest.newInstance(capability, numContainers, minConcurrency, duration);
list.add(rr);
}
ReservationRequests reqs = ReservationRequests.newInstance(list, resInt);
ReservationDefinition rDef = ReservationDefinition.newInstance(resInfo.getArrival(), resInfo.getDeadline(), reqs, resInfo.getReservationName());
ReservationId reservationId = ReservationId.parseReservationId(resContext.getReservationId());
ReservationSubmissionRequest request = ReservationSubmissionRequest.newInstance(rDef, resContext.getQueue(), reservationId);
return request;
}
use of org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionRequest in project hadoop by apache.
the class RMWebServices method submitReservation.
/**
* Function to submit a Reservation to the RM.
*
* @param resContext provides information to construct the
* ReservationSubmissionRequest
* @param hsr the servlet request
* @return Response containing the status code
* @throws AuthorizationException
* @throws IOException
* @throws InterruptedException
*/
@POST
@Path("/reservation/submit")
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response submitReservation(ReservationSubmissionRequestInfo resContext, @Context HttpServletRequest hsr) throws AuthorizationException, IOException, InterruptedException {
init();
UserGroupInformation callerUGI = getCallerUserGroupInformation(hsr, true);
if (callerUGI == null) {
throw new AuthorizationException("Unable to obtain user name, " + "user not authenticated");
}
if (UserGroupInformation.isSecurityEnabled() && isStaticUser(callerUGI)) {
String msg = "The default static user cannot carry out this operation.";
return Response.status(Status.FORBIDDEN).entity(msg).build();
}
final ReservationSubmissionRequest reservation = createReservationSubmissionRequest(resContext);
try {
callerUGI.doAs(new PrivilegedExceptionAction<ReservationSubmissionResponse>() {
@Override
public ReservationSubmissionResponse run() throws IOException, YarnException {
return rm.getClientRMService().submitReservation(reservation);
}
});
} catch (UndeclaredThrowableException ue) {
if (ue.getCause() instanceof YarnException) {
throw new BadRequestException(ue.getCause().getMessage());
}
LOG.info("Submit reservation request failed", ue);
throw ue;
}
return Response.status(Status.ACCEPTED).build();
}
use of org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionRequest in project hadoop by apache.
the class TestYarnClient method testListReservationsByInvalidTimeInterval.
@Test
public void testListReservationsByInvalidTimeInterval() throws Exception {
MiniYARNCluster cluster = setupMiniYARNCluster();
YarnClient client = setupYarnClient(cluster);
try {
Clock clock = new UTCClock();
long arrival = clock.getTime();
long duration = 60000;
long deadline = (long) (arrival + 1.05 * duration);
ReservationSubmissionRequest sRequest = submitReservationTestHelper(client, arrival, deadline, duration);
// List reservations, search by invalid end time == -1.
ReservationListRequest request = ReservationListRequest.newInstance(ReservationSystemTestUtil.reservationQ, "", 1, -1, true);
ReservationListResponse response = client.listReservations(request);
Assert.assertNotNull(response);
Assert.assertEquals(1, response.getReservationAllocationState().size());
Assert.assertEquals(response.getReservationAllocationState().get(0).getReservationId().getId(), sRequest.getReservationId().getId());
// List reservations, search by invalid end time < -1.
request = ReservationListRequest.newInstance(ReservationSystemTestUtil.reservationQ, "", 1, -10, true);
response = client.listReservations(request);
Assert.assertNotNull(response);
Assert.assertEquals(1, response.getReservationAllocationState().size());
Assert.assertEquals(response.getReservationAllocationState().get(0).getReservationId().getId(), sRequest.getReservationId().getId());
} finally {
// clean-up
if (client != null) {
client.stop();
}
cluster.stop();
}
}
use of org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionRequest in project hadoop by apache.
the class TestReservationSystemWithRMHA method testReservationResizeAfterFailover.
@Test
public void testReservationResizeAfterFailover() throws Exception {
startRMs();
addNodeCapacityToPlan(rm1, 102400, 100);
ClientRMService clientService = rm1.getClientRMService();
ReservationId resID1 = getNewReservation(clientService).getReservationId();
// create a reservation
ReservationSubmissionRequest request = createReservationSubmissionRequest(resID1);
ReservationDefinition reservationDefinition = request.getReservationDefinition();
ReservationSubmissionResponse response = null;
try {
response = clientService.submitReservation(request);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
Assert.assertNotNull(response);
Assert.assertNotNull(resID1);
LOG.info("Submit reservation response: " + resID1);
ReservationId resID2 = getNewReservation(clientService).getReservationId();
request.setReservationId(resID2);
try {
response = clientService.submitReservation(request);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
Assert.assertNotNull(response);
Assert.assertNotNull(resID2);
LOG.info("Submit reservation response: " + resID2);
ReservationId resID3 = getNewReservation(clientService).getReservationId();
request.setReservationId(resID3);
try {
response = clientService.submitReservation(request);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
Assert.assertNotNull(response);
Assert.assertNotNull(resID3);
LOG.info("Submit reservation response: " + resID3);
// allow the reservations to become active
waitForReservationActivation(rm1, resID1, ReservationSystemTestUtil.reservationQ);
// validate reservations before failover
Plan plan = rm1.getRMContext().getReservationSystem().getPlan(ReservationSystemTestUtil.reservationQ);
validateReservation(plan, resID1, reservationDefinition);
validateReservation(plan, resID2, reservationDefinition);
validateReservation(plan, resID3, reservationDefinition);
ResourceScheduler scheduler = rm1.getResourceScheduler();
QueueInfo resQ1 = scheduler.getQueueInfo(resID1.toString(), false, false);
Assert.assertEquals(0.05, resQ1.getCapacity(), 0.001f);
QueueInfo resQ2 = scheduler.getQueueInfo(resID2.toString(), false, false);
Assert.assertEquals(0.05, resQ2.getCapacity(), 0.001f);
QueueInfo resQ3 = scheduler.getQueueInfo(resID3.toString(), false, false);
Assert.assertEquals(0.05, resQ3.getCapacity(), 0.001f);
// Do the failover
explicitFailover();
addNodeCapacityToPlan(rm2, 5120, 5);
// check if reservations exists after failover
plan = rm2.getRMContext().getReservationSystem().getPlan(ReservationSystemTestUtil.reservationQ);
validateReservation(plan, resID1, reservationDefinition);
validateReservation(plan, resID3, reservationDefinition);
// verify if the reservations have been resized
scheduler = rm2.getResourceScheduler();
resQ1 = scheduler.getQueueInfo(resID1.toString(), false, false);
Assert.assertEquals(1f / 3f, resQ1.getCapacity(), 0.001f);
resQ2 = scheduler.getQueueInfo(resID2.toString(), false, false);
Assert.assertEquals(1f / 3f, resQ2.getCapacity(), 0.001f);
resQ3 = scheduler.getQueueInfo(resID3.toString(), false, false);
Assert.assertEquals(1f / 3f, resQ3.getCapacity(), 0.001f);
}
Aggregations