Search in sources :

Example 1 with ReservationListResponse

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

the class TestYarnClient method testListReservationsByReservationId.

@Test
public void testListReservationsByReservationId() 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);
        ReservationId reservationID = sRequest.getReservationId();
        ReservationListRequest request = ReservationListRequest.newInstance(ReservationSystemTestUtil.reservationQ, reservationID.toString(), -1, -1, false);
        ReservationListResponse response = client.listReservations(request);
        Assert.assertNotNull(response);
        Assert.assertEquals(1, response.getReservationAllocationState().size());
        Assert.assertEquals(response.getReservationAllocationState().get(0).getReservationId().getId(), reservationID.getId());
        Assert.assertEquals(response.getReservationAllocationState().get(0).getResourceAllocationRequests().size(), 0);
    } finally {
        // clean-up
        if (client != null) {
            client.stop();
        }
        cluster.stop();
    }
}
Also used : ReservationListResponse(org.apache.hadoop.yarn.api.protocolrecords.ReservationListResponse) ReservationId(org.apache.hadoop.yarn.api.records.ReservationId) ReservationListRequest(org.apache.hadoop.yarn.api.protocolrecords.ReservationListRequest) ReservationSubmissionRequest(org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionRequest) MiniYARNCluster(org.apache.hadoop.yarn.server.MiniYARNCluster) UTCClock(org.apache.hadoop.yarn.util.UTCClock) Clock(org.apache.hadoop.yarn.util.Clock) UTCClock(org.apache.hadoop.yarn.util.UTCClock) YarnClient(org.apache.hadoop.yarn.client.api.YarnClient) Test(org.junit.Test)

Example 2 with ReservationListResponse

use of org.apache.hadoop.yarn.api.protocolrecords.ReservationListResponse 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();
    }
}
Also used : ReservationListResponse(org.apache.hadoop.yarn.api.protocolrecords.ReservationListResponse) ReservationId(org.apache.hadoop.yarn.api.records.ReservationId) ReservationListRequest(org.apache.hadoop.yarn.api.protocolrecords.ReservationListRequest) ReservationRequests(org.apache.hadoop.yarn.api.records.ReservationRequests) ReservationSubmissionRequest(org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionRequest) MiniYARNCluster(org.apache.hadoop.yarn.server.MiniYARNCluster) UTCClock(org.apache.hadoop.yarn.util.UTCClock) Clock(org.apache.hadoop.yarn.util.Clock) UTCClock(org.apache.hadoop.yarn.util.UTCClock) YarnClient(org.apache.hadoop.yarn.client.api.YarnClient) Test(org.junit.Test)

Example 3 with ReservationListResponse

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

the class ClientRMService method listReservations.

@Override
public ReservationListResponse listReservations(ReservationListRequest requestInfo) throws YarnException, IOException {
    // Check if reservation system is enabled
    checkReservationSytem(AuditConstants.LIST_RESERVATION_REQUEST);
    ReservationListResponse response = recordFactory.newRecordInstance(ReservationListResponse.class);
    Plan plan = rValidator.validateReservationListRequest(reservationSystem, requestInfo);
    boolean includeResourceAllocations = requestInfo.getIncludeResourceAllocations();
    ReservationId reservationId = null;
    if (requestInfo.getReservationId() != null && !requestInfo.getReservationId().isEmpty()) {
        reservationId = ReservationId.parseReservationId(requestInfo.getReservationId());
    }
    checkReservationACLs(requestInfo.getQueue(), AuditConstants.LIST_RESERVATION_REQUEST, reservationId);
    long startTime = Math.max(requestInfo.getStartTime(), 0);
    long endTime = requestInfo.getEndTime() <= -1 ? Long.MAX_VALUE : requestInfo.getEndTime();
    Set<ReservationAllocation> reservations;
    reservations = plan.getReservations(reservationId, new ReservationInterval(startTime, endTime));
    List<ReservationAllocationState> info = ReservationSystemUtil.convertAllocationsToReservationInfo(reservations, includeResourceAllocations);
    response.setReservationAllocationState(info);
    return response;
}
Also used : ReservationListResponse(org.apache.hadoop.yarn.api.protocolrecords.ReservationListResponse) ReservationAllocationState(org.apache.hadoop.yarn.api.records.ReservationAllocationState) ReservationId(org.apache.hadoop.yarn.api.records.ReservationId) ReservationInterval(org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationInterval) Plan(org.apache.hadoop.yarn.server.resourcemanager.reservation.Plan) ReservationAllocation(org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationAllocation)

Example 4 with ReservationListResponse

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

the class RMWebServices method listReservation.

/**
   * Function to retrieve a list of all the reservations.
   */
@GET
@Path("/reservation/list")
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
public Response listReservation(@QueryParam("queue") @DefaultValue("default") String queue, @QueryParam("reservation-id") @DefaultValue("") String reservationId, @QueryParam("start-time") @DefaultValue("0") long startTime, @QueryParam("end-time") @DefaultValue("-1") long endTime, @QueryParam("include-resource-allocations") @DefaultValue("false") boolean includeResourceAllocations, @Context HttpServletRequest hsr) throws Exception {
    init();
    final ReservationListRequest request = ReservationListRequest.newInstance(queue, reservationId, startTime, endTime, includeResourceAllocations);
    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();
    }
    ReservationListResponse resRespInfo;
    try {
        resRespInfo = callerUGI.doAs(new PrivilegedExceptionAction<ReservationListResponse>() {

            @Override
            public ReservationListResponse run() throws IOException, YarnException {
                return rm.getClientRMService().listReservations(request);
            }
        });
    } catch (UndeclaredThrowableException ue) {
        if (ue.getCause() instanceof YarnException) {
            throw new BadRequestException(ue.getCause().getMessage());
        }
        LOG.info("List reservation request failed", ue);
        throw ue;
    }
    ReservationListInfo resResponse = new ReservationListInfo(resRespInfo, includeResourceAllocations);
    return Response.status(Status.OK).entity(resResponse).build();
}
Also used : ReservationListInfo(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ReservationListInfo) ReservationListResponse(org.apache.hadoop.yarn.api.protocolrecords.ReservationListResponse) AuthorizationException(org.apache.hadoop.security.authorize.AuthorizationException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) ReservationListRequest(org.apache.hadoop.yarn.api.protocolrecords.ReservationListRequest) 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) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with ReservationListResponse

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

the class TestClientRMService method testListReservationsByTimeIntervalContainingNoReservations.

@Test
public void testListReservationsByTimeIntervalContainingNoReservations() {
    ResourceManager rm = setupResourceManager();
    ClientRMService clientService = rm.getClientRMService();
    Clock clock = new UTCClock();
    long arrival = clock.getTime();
    long duration = 60000;
    long deadline = (long) (arrival + 1.05 * duration);
    ReservationSubmissionRequest sRequest = submitReservationTestHelper(clientService, arrival, deadline, duration);
    // List reservations, search by very large start time.
    ReservationListRequest request = ReservationListRequest.newInstance(ReservationSystemTestUtil.reservationQ, "", Long.MAX_VALUE, -1, false);
    ReservationListResponse response = null;
    try {
        response = clientService.listReservations(request);
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
    // Ensure all reservations are filtered out.
    Assert.assertNotNull(response);
    Assert.assertEquals(response.getReservationAllocationState().size(), 0);
    duration = 30000;
    deadline = sRequest.getReservationDefinition().getDeadline();
    // List reservations, search by start time after the reservation
    // end time.
    request = ReservationListRequest.newInstance(ReservationSystemTestUtil.reservationQ, "", deadline + duration, deadline + 2 * duration, false);
    response = null;
    try {
        response = clientService.listReservations(request);
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
    // Ensure all reservations are filtered out.
    Assert.assertNotNull(response);
    Assert.assertEquals(response.getReservationAllocationState().size(), 0);
    arrival = clock.getTime();
    // List reservations, search by end time before the reservation start
    // time.
    request = ReservationListRequest.newInstance(ReservationSystemTestUtil.reservationQ, "", 0, arrival - duration, false);
    response = null;
    try {
        response = clientService.listReservations(request);
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
    // Ensure all reservations are filtered out.
    Assert.assertNotNull(response);
    Assert.assertEquals(response.getReservationAllocationState().size(), 0);
    // List reservations, search by very small end time.
    request = ReservationListRequest.newInstance(ReservationSystemTestUtil.reservationQ, "", 0, 1, false);
    response = null;
    try {
        response = clientService.listReservations(request);
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
    // Ensure all reservations are filtered out.
    Assert.assertNotNull(response);
    Assert.assertEquals(response.getReservationAllocationState().size(), 0);
    rm.stop();
}
Also used : ReservationListResponse(org.apache.hadoop.yarn.api.protocolrecords.ReservationListResponse) ReservationListRequest(org.apache.hadoop.yarn.api.protocolrecords.ReservationListRequest) ReservationSubmissionRequest(org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionRequest) UTCClock(org.apache.hadoop.yarn.util.UTCClock) Clock(org.apache.hadoop.yarn.util.Clock) UTCClock(org.apache.hadoop.yarn.util.UTCClock) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) IOException(java.io.IOException) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) AccessControlException(java.security.AccessControlException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) Test(org.junit.Test)

Aggregations

ReservationListResponse (org.apache.hadoop.yarn.api.protocolrecords.ReservationListResponse)14 ReservationListRequest (org.apache.hadoop.yarn.api.protocolrecords.ReservationListRequest)11 ReservationSubmissionRequest (org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionRequest)10 Clock (org.apache.hadoop.yarn.util.Clock)10 UTCClock (org.apache.hadoop.yarn.util.UTCClock)10 Test (org.junit.Test)10 ReservationId (org.apache.hadoop.yarn.api.records.ReservationId)9 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)6 IOException (java.io.IOException)5 AccessControlException (java.security.AccessControlException)5 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)5 YarnClient (org.apache.hadoop.yarn.client.api.YarnClient)5 ApplicationNotFoundException (org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException)5 MiniYARNCluster (org.apache.hadoop.yarn.server.MiniYARNCluster)5 ReservationDeleteRequest (org.apache.hadoop.yarn.api.protocolrecords.ReservationDeleteRequest)2 ReservationDeleteResponse (org.apache.hadoop.yarn.api.protocolrecords.ReservationDeleteResponse)2 ReservationRequests (org.apache.hadoop.yarn.api.records.ReservationRequests)2 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 GET (javax.ws.rs.GET)1