Search in sources :

Example 1 with ReservationSubmissionResponse

use of org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionResponse in project hadoop by apache.

the class ClientRMService method submitReservation.

@Override
public ReservationSubmissionResponse submitReservation(ReservationSubmissionRequest request) throws YarnException, IOException {
    // Check if reservation system is enabled
    checkReservationSytem(AuditConstants.SUBMIT_RESERVATION_REQUEST);
    ReservationSubmissionResponse response = recordFactory.newRecordInstance(ReservationSubmissionResponse.class);
    ReservationId reservationId = request.getReservationId();
    // Validate the input
    Plan plan = rValidator.validateReservationSubmissionRequest(reservationSystem, request, reservationId);
    ReservationAllocation allocation = plan.getReservationById(reservationId);
    if (allocation != null) {
        boolean isNewDefinition = !allocation.getReservationDefinition().equals(request.getReservationDefinition());
        if (isNewDefinition) {
            String message = "Reservation allocation already exists with the " + "reservation id " + reservationId.toString() + ", but a different" + " reservation definition was provided. Please try again with a " + "new reservation id, or consider updating the reservation instead.";
            throw RPCUtil.getRemoteException(message);
        } else {
            return response;
        }
    }
    // Check ACLs
    String queueName = request.getQueue();
    String user = checkReservationACLs(queueName, AuditConstants.SUBMIT_RESERVATION_REQUEST, null);
    try {
        // Try to place the reservation using the agent
        boolean result = plan.getReservationAgent().createReservation(reservationId, user, plan, request.getReservationDefinition());
        if (result) {
            // add the reservation id to valid ones maintained by reservation
            // system
            reservationSystem.setQueueForReservation(reservationId, queueName);
            // create the reservation synchronously if required
            refreshScheduler(queueName, request.getReservationDefinition(), reservationId.toString());
        // return the reservation id
        }
    } catch (PlanningException e) {
        RMAuditLogger.logFailure(user, AuditConstants.SUBMIT_RESERVATION_REQUEST, e.getMessage(), "ClientRMService", "Unable to create the reservation: " + reservationId);
        throw RPCUtil.getRemoteException(e);
    }
    RMAuditLogger.logSuccess(user, AuditConstants.SUBMIT_RESERVATION_REQUEST, "ClientRMService: " + reservationId);
    return response;
}
Also used : ReservationId(org.apache.hadoop.yarn.api.records.ReservationId) PlanningException(org.apache.hadoop.yarn.server.resourcemanager.reservation.exceptions.PlanningException) ReservationSubmissionResponse(org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionResponse) Plan(org.apache.hadoop.yarn.server.resourcemanager.reservation.Plan) ReservationAllocation(org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationAllocation)

Example 2 with ReservationSubmissionResponse

use of org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionResponse 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();
}
Also used : AuthorizationException(org.apache.hadoop.security.authorize.AuthorizationException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) ReservationSubmissionRequest(org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionRequest) BadRequestException(org.apache.hadoop.yarn.webapp.BadRequestException) IOException(java.io.IOException) ReservationSubmissionResponse(org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionResponse) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Example 3 with ReservationSubmissionResponse

use of org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionResponse in project hadoop by apache.

the class ReservationACLsTestBase method submitReservation.

private void submitReservation(String submitter, String queueName, ReservationId reservationId) throws Exception {
    ApplicationClientProtocol submitterClient = getRMClientForUser(submitter);
    ReservationSubmissionRequest reservationSubmissionRequest = ReservationSubmissionRequest.newInstance(makeSimpleReservationDefinition(), queueName, reservationId);
    ReservationSubmissionResponse response = submitterClient.submitReservation(reservationSubmissionRequest);
}
Also used : ReservationSubmissionRequest(org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionRequest) ReservationSubmissionResponse(org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionResponse) ApplicationClientProtocol(org.apache.hadoop.yarn.api.ApplicationClientProtocol)

Example 4 with ReservationSubmissionResponse

use of org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionResponse 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);
}
Also used : QueueInfo(org.apache.hadoop.yarn.api.records.QueueInfo) ReservationId(org.apache.hadoop.yarn.api.records.ReservationId) ReservationDefinition(org.apache.hadoop.yarn.api.records.ReservationDefinition) ReservationSubmissionRequest(org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionRequest) ResourceScheduler(org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler) ReservationSubmissionResponse(org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionResponse) Plan(org.apache.hadoop.yarn.server.resourcemanager.reservation.Plan) Test(org.junit.Test)

Example 5 with ReservationSubmissionResponse

use of org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionResponse in project hadoop by apache.

the class TestReservationSystemWithRMHA method testFailoverAndSubmitReservation.

@Test
public void testFailoverAndSubmitReservation() throws Exception {
    startRMs();
    addNodeCapacityToPlan(rm1, 102400, 100);
    // Do the failover
    explicitFailover();
    addNodeCapacityToPlan(rm2, 102400, 100);
    ClientRMService clientService = rm2.getClientRMService();
    ReservationId reservationID = getNewReservation(clientService).getReservationId();
    // create a reservation
    ReservationSubmissionRequest request = createReservationSubmissionRequest(reservationID);
    ReservationSubmissionResponse response = null;
    try {
        response = clientService.submitReservation(request);
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
    Assert.assertNotNull(response);
    Assert.assertNotNull(reservationID);
    LOG.info("Submit reservation response: " + reservationID);
    ReservationDefinition reservationDefinition = request.getReservationDefinition();
    // check if reservation is submitted successfully
    Plan plan = rm2.getRMContext().getReservationSystem().getPlan(ReservationSystemTestUtil.reservationQ);
    validateReservation(plan, reservationID, reservationDefinition);
}
Also used : ReservationId(org.apache.hadoop.yarn.api.records.ReservationId) ReservationDefinition(org.apache.hadoop.yarn.api.records.ReservationDefinition) ReservationSubmissionRequest(org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionRequest) ReservationSubmissionResponse(org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionResponse) Plan(org.apache.hadoop.yarn.server.resourcemanager.reservation.Plan) Test(org.junit.Test)

Aggregations

ReservationSubmissionResponse (org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionResponse)13 ReservationSubmissionRequest (org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionRequest)12 ReservationId (org.apache.hadoop.yarn.api.records.ReservationId)11 Test (org.junit.Test)8 ReservationDefinition (org.apache.hadoop.yarn.api.records.ReservationDefinition)6 Plan (org.apache.hadoop.yarn.server.resourcemanager.reservation.Plan)6 ReservationDeleteRequest (org.apache.hadoop.yarn.api.protocolrecords.ReservationDeleteRequest)3 ReservationUpdateRequest (org.apache.hadoop.yarn.api.protocolrecords.ReservationUpdateRequest)3 RMState (org.apache.hadoop.yarn.server.resourcemanager.recovery.RMStateStore.RMState)3 IOException (java.io.IOException)2 ReservationDeleteResponse (org.apache.hadoop.yarn.api.protocolrecords.ReservationDeleteResponse)2 ReservationUpdateResponse (org.apache.hadoop.yarn.api.protocolrecords.ReservationUpdateResponse)2 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)2 ReservationAllocationStateProto (org.apache.hadoop.yarn.proto.YarnProtos.ReservationAllocationStateProto)2 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 AccessControlException (java.security.AccessControlException)1 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1