Search in sources :

Example 21 with ReservationRequests

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

the class ReservationInputValidator method validateReservationDefinition.

private void validateReservationDefinition(ReservationId reservationId, ReservationDefinition contract, Plan plan, String auditConstant) throws YarnException {
    String message = "";
    // check if deadline is in the past
    if (contract == null) {
        message = "Missing reservation definition." + " Please try again by specifying a reservation definition.";
        RMAuditLogger.logFailure("UNKNOWN", auditConstant, "validate reservation input definition", "ClientRMService", message);
        throw RPCUtil.getRemoteException(message);
    }
    if (contract.getDeadline() <= clock.getTime()) {
        message = "The specified deadline: " + contract.getDeadline() + " is the past. Please try again with deadline in the future.";
        RMAuditLogger.logFailure("UNKNOWN", auditConstant, "validate reservation input definition", "ClientRMService", message);
        throw RPCUtil.getRemoteException(message);
    }
    // Check if at least one RR has been specified
    ReservationRequests resReqs = contract.getReservationRequests();
    if (resReqs == null) {
        message = "No resources have been specified to reserve." + "Please try again by specifying the resources to reserve.";
        RMAuditLogger.logFailure("UNKNOWN", auditConstant, "validate reservation input definition", "ClientRMService", message);
        throw RPCUtil.getRemoteException(message);
    }
    List<ReservationRequest> resReq = resReqs.getReservationResources();
    if (resReq == null || resReq.isEmpty()) {
        message = "No resources have been specified to reserve." + " Please try again by specifying the resources to reserve.";
        RMAuditLogger.logFailure("UNKNOWN", auditConstant, "validate reservation input definition", "ClientRMService", message);
        throw RPCUtil.getRemoteException(message);
    }
    // compute minimum duration and max gang size
    long minDuration = 0;
    Resource maxGangSize = Resource.newInstance(0, 0);
    ReservationRequestInterpreter type = contract.getReservationRequests().getInterpreter();
    for (ReservationRequest rr : resReq) {
        if (type == ReservationRequestInterpreter.R_ALL || type == ReservationRequestInterpreter.R_ANY) {
            minDuration = Math.max(minDuration, rr.getDuration());
        } else {
            minDuration += rr.getDuration();
        }
        maxGangSize = Resources.max(plan.getResourceCalculator(), plan.getTotalCapacity(), maxGangSize, Resources.multiply(rr.getCapability(), rr.getConcurrency()));
    }
    // verify the allocation is possible (skip for ANY)
    if (contract.getDeadline() - contract.getArrival() < minDuration && type != ReservationRequestInterpreter.R_ANY) {
        message = "The time difference (" + (contract.getDeadline() - contract.getArrival()) + ") between arrival (" + contract.getArrival() + ") " + "and deadline (" + contract.getDeadline() + ") must " + " be greater or equal to the minimum resource duration (" + minDuration + ")";
        RMAuditLogger.logFailure("UNKNOWN", auditConstant, "validate reservation input definition", "ClientRMService", message);
        throw RPCUtil.getRemoteException(message);
    }
    // capacity (skip for ANY)
    if (Resources.greaterThan(plan.getResourceCalculator(), plan.getTotalCapacity(), maxGangSize, plan.getTotalCapacity()) && type != ReservationRequestInterpreter.R_ANY) {
        message = "The size of the largest gang in the reservation definition (" + maxGangSize + ") exceed the capacity available (" + plan.getTotalCapacity() + " )";
        RMAuditLogger.logFailure("UNKNOWN", auditConstant, "validate reservation input definition", "ClientRMService", message);
        throw RPCUtil.getRemoteException(message);
    }
    // check that the recurrence is a positive long value.
    String recurrenceExpression = contract.getRecurrenceExpression();
    try {
        Long recurrence = Long.parseLong(recurrenceExpression);
        if (recurrence < 0) {
            message = "Negative Period : " + recurrenceExpression + ". Please try" + " again with a non-negative long value as period";
            throw RPCUtil.getRemoteException(message);
        }
    } catch (NumberFormatException e) {
        message = "Invalid period " + recurrenceExpression + ". Please try" + " again with a non-negative long value as period";
        throw RPCUtil.getRemoteException(message);
    }
}
Also used : ReservationRequestInterpreter(org.apache.hadoop.yarn.api.records.ReservationRequestInterpreter) ReservationRequest(org.apache.hadoop.yarn.api.records.ReservationRequest) ReservationRequests(org.apache.hadoop.yarn.api.records.ReservationRequests) Resource(org.apache.hadoop.yarn.api.records.Resource)

Example 22 with ReservationRequests

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

the class TestYarnClient method createSimpleReservationRequest.

private ReservationSubmissionRequest createSimpleReservationRequest(ReservationId reservationId, int numContainers, long arrival, long deadline, long duration) {
    // create a request with a single atomic ask
    ReservationRequest r = ReservationRequest.newInstance(Resource.newInstance(1024, 1), numContainers, 1, duration);
    ReservationRequests reqs = ReservationRequests.newInstance(Collections.singletonList(r), ReservationRequestInterpreter.R_ALL);
    ReservationDefinition rDef = ReservationDefinition.newInstance(arrival, deadline, reqs, "testYarnClient#reservation");
    ReservationSubmissionRequest request = ReservationSubmissionRequest.newInstance(rDef, ReservationSystemTestUtil.reservationQ, reservationId);
    return request;
}
Also used : ReservationRequest(org.apache.hadoop.yarn.api.records.ReservationRequest) ReservationDefinition(org.apache.hadoop.yarn.api.records.ReservationDefinition) ReservationRequests(org.apache.hadoop.yarn.api.records.ReservationRequests) ReservationSubmissionRequest(org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionRequest)

Aggregations

ReservationRequests (org.apache.hadoop.yarn.api.records.ReservationRequests)22 ReservationRequest (org.apache.hadoop.yarn.api.records.ReservationRequest)20 ReservationDefinition (org.apache.hadoop.yarn.api.records.ReservationDefinition)19 ReservationDefinitionPBImpl (org.apache.hadoop.yarn.api.records.impl.pb.ReservationDefinitionPBImpl)15 ReservationRequestsPBImpl (org.apache.hadoop.yarn.api.records.impl.pb.ReservationRequestsPBImpl)15 ReservationId (org.apache.hadoop.yarn.api.records.ReservationId)13 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)10 InMemoryReservationAllocation (org.apache.hadoop.yarn.server.resourcemanager.reservation.InMemoryReservationAllocation)8 ReservationAllocation (org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationAllocation)7 ReservationSubmissionRequest (org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionRequest)6 ReservationRequestInterpreter (org.apache.hadoop.yarn.api.records.ReservationRequestInterpreter)4 PlanningException (org.apache.hadoop.yarn.server.resourcemanager.reservation.exceptions.PlanningException)4 Resource (org.apache.hadoop.yarn.api.records.Resource)3 GetNewReservationRequest (org.apache.hadoop.yarn.api.protocolrecords.GetNewReservationRequest)2 ReservationListRequest (org.apache.hadoop.yarn.api.protocolrecords.ReservationListRequest)2 ReservationListResponse (org.apache.hadoop.yarn.api.protocolrecords.ReservationListResponse)2 ReservationUpdateRequest (org.apache.hadoop.yarn.api.protocolrecords.ReservationUpdateRequest)2 LocalResource (org.apache.hadoop.yarn.api.records.LocalResource)2 LocalResourceInfo (org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.LocalResourceInfo)2