Search in sources :

Example 1 with ReservationId

use of org.apache.hadoop.yarn.api.records.ReservationId 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 ReservationId

use of org.apache.hadoop.yarn.api.records.ReservationId 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 ReservationId

use of org.apache.hadoop.yarn.api.records.ReservationId 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 ReservationId

use of org.apache.hadoop.yarn.api.records.ReservationId 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 5 with ReservationId

use of org.apache.hadoop.yarn.api.records.ReservationId in project hadoop by apache.

the class ClientRMService method updateReservation.

@Override
public ReservationUpdateResponse updateReservation(ReservationUpdateRequest request) throws YarnException, IOException {
    // Check if reservation system is enabled
    checkReservationSytem(AuditConstants.UPDATE_RESERVATION_REQUEST);
    ReservationUpdateResponse response = recordFactory.newRecordInstance(ReservationUpdateResponse.class);
    // Validate the input
    Plan plan = rValidator.validateReservationUpdateRequest(reservationSystem, request);
    ReservationId reservationId = request.getReservationId();
    String queueName = reservationSystem.getQueueForReservation(reservationId);
    // Check ACLs
    String user = checkReservationACLs(queueName, AuditConstants.UPDATE_RESERVATION_REQUEST, reservationId);
    // Try to update the reservation using default agent
    try {
        boolean result = plan.getReservationAgent().updateReservation(reservationId, user, plan, request.getReservationDefinition());
        if (!result) {
            String errMsg = "Unable to update reservation: " + reservationId;
            RMAuditLogger.logFailure(user, AuditConstants.UPDATE_RESERVATION_REQUEST, errMsg, "ClientRMService", errMsg);
            throw RPCUtil.getRemoteException(errMsg);
        }
    } catch (PlanningException e) {
        RMAuditLogger.logFailure(user, AuditConstants.UPDATE_RESERVATION_REQUEST, e.getMessage(), "ClientRMService", "Unable to update the reservation: " + reservationId);
        throw RPCUtil.getRemoteException(e);
    }
    RMAuditLogger.logSuccess(user, AuditConstants.UPDATE_RESERVATION_REQUEST, "ClientRMService: " + reservationId);
    return response;
}
Also used : ReservationId(org.apache.hadoop.yarn.api.records.ReservationId) ReservationUpdateResponse(org.apache.hadoop.yarn.api.protocolrecords.ReservationUpdateResponse) PlanningException(org.apache.hadoop.yarn.server.resourcemanager.reservation.exceptions.PlanningException) Plan(org.apache.hadoop.yarn.server.resourcemanager.reservation.Plan)

Aggregations

ReservationId (org.apache.hadoop.yarn.api.records.ReservationId)120 Test (org.junit.Test)85 ReservationDefinition (org.apache.hadoop.yarn.api.records.ReservationDefinition)40 PlanningException (org.apache.hadoop.yarn.server.resourcemanager.reservation.exceptions.PlanningException)27 ReservationSubmissionRequest (org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionRequest)19 ReservationAllocation (org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationAllocation)17 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)16 InMemoryReservationAllocation (org.apache.hadoop.yarn.server.resourcemanager.reservation.InMemoryReservationAllocation)16 WebResource (com.sun.jersey.api.client.WebResource)14 ReservationRequest (org.apache.hadoop.yarn.api.records.ReservationRequest)14 ReservationRequests (org.apache.hadoop.yarn.api.records.ReservationRequests)13 JSONObject (org.codehaus.jettison.json.JSONObject)13 ArrayList (java.util.ArrayList)11 ReservationSubmissionResponse (org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionResponse)11 IOException (java.io.IOException)10 Resource (org.apache.hadoop.yarn.api.records.Resource)10 ReservationDefinitionPBImpl (org.apache.hadoop.yarn.api.records.impl.pb.ReservationDefinitionPBImpl)10 ReservationRequestsPBImpl (org.apache.hadoop.yarn.api.records.impl.pb.ReservationRequestsPBImpl)10 ReservationListResponse (org.apache.hadoop.yarn.api.protocolrecords.ReservationListResponse)9 ReservationAllocationStateProto (org.apache.hadoop.yarn.proto.YarnProtos.ReservationAllocationStateProto)9