Search in sources :

Example 1 with ReservationUpdateResponseInfo

use of org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ReservationUpdateResponseInfo in project hadoop by apache.

the class RMWebServices method updateReservation.

/**
   * Function to update a Reservation to the RM.
   *
   * @param resContext provides information to construct the
   *          ReservationUpdateRequest
   * @param hsr the servlet request
   * @return Response containing the status code
   * @throws AuthorizationException
   * @throws IOException
   * @throws InterruptedException
   */
@POST
@Path("/reservation/update")
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response updateReservation(ReservationUpdateRequestInfo 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 ReservationUpdateRequest reservation = createReservationUpdateRequest(resContext);
    ReservationUpdateResponseInfo resRespInfo;
    try {
        resRespInfo = callerUGI.doAs(new PrivilegedExceptionAction<ReservationUpdateResponseInfo>() {

            @Override
            public ReservationUpdateResponseInfo run() throws IOException, YarnException {
                rm.getClientRMService().updateReservation(reservation);
                return new ReservationUpdateResponseInfo();
            }
        });
    } catch (UndeclaredThrowableException ue) {
        if (ue.getCause() instanceof YarnException) {
            throw new BadRequestException(ue.getCause().getMessage());
        }
        LOG.info("Update reservation request failed", ue);
        throw ue;
    }
    return Response.status(Status.OK).entity(resRespInfo).build();
}
Also used : ReservationUpdateRequest(org.apache.hadoop.yarn.api.protocolrecords.ReservationUpdateRequest) AuthorizationException(org.apache.hadoop.security.authorize.AuthorizationException) ReservationUpdateResponseInfo(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ReservationUpdateResponseInfo) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) BadRequestException(org.apache.hadoop.yarn.webapp.BadRequestException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) 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)

Aggregations

UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)1 AuthorizationException (org.apache.hadoop.security.authorize.AuthorizationException)1 ReservationUpdateRequest (org.apache.hadoop.yarn.api.protocolrecords.ReservationUpdateRequest)1 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)1 ReservationUpdateResponseInfo (org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ReservationUpdateResponseInfo)1 BadRequestException (org.apache.hadoop.yarn.webapp.BadRequestException)1