Search in sources :

Example 41 with ReservationDefinition

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

the class PlanningAlgorithm method allocateUser.

/**
   * Performs the actual allocation for a ReservationDefinition within a Plan.
   *
   * @param reservationId the identifier of the reservation
   * @param user the user who owns the reservation
   * @param plan the Plan to which the reservation must be fitted
   * @param contract encapsulates the resources required by the user for his
   *          session
   * @param oldReservation the existing reservation (null if none)
   * @return whether the allocateUser function was successful or not
   *
   * @throws PlanningException if the session cannot be fitted into the plan
   * @throws ContractValidationException
   */
protected boolean allocateUser(ReservationId reservationId, String user, Plan plan, ReservationDefinition contract, ReservationAllocation oldReservation) throws PlanningException, ContractValidationException {
    // Adjust the ResourceDefinition to account for system "imperfections"
    // (e.g., scheduling delays for large containers).
    ReservationDefinition adjustedContract = adjustContract(plan, contract);
    // Compute the job allocation
    RLESparseResourceAllocation allocation = computeJobAllocation(plan, reservationId, adjustedContract, user);
    // If no job allocation was found, fail
    if (allocation == null) {
        throw new PlanningException("The planning algorithm could not find a valid allocation" + " for your request");
    }
    // Translate the allocation to a map (with zero paddings)
    long step = plan.getStep();
    long jobArrival = stepRoundUp(adjustedContract.getArrival(), step);
    long jobDeadline = stepRoundUp(adjustedContract.getDeadline(), step);
    Map<ReservationInterval, Resource> mapAllocations = allocationsToPaddedMap(allocation, jobArrival, jobDeadline);
    // Create the reservation
    ReservationAllocation capReservation = new // ID
    InMemoryReservationAllocation(// ID
    reservationId, // Contract
    adjustedContract, // User name
    user, // Queue name
    plan.getQueueName(), // Earliest start time
    findEarliestTime(mapAllocations), // Latest end time
    findLatestTime(mapAllocations), // Allocations
    mapAllocations, // Resource calculator
    plan.getResourceCalculator(), // Minimum allocation
    plan.getMinimumAllocation());
    // Add (or update) the reservation allocation
    if (oldReservation != null) {
        return plan.updateReservation(capReservation);
    } else {
        return plan.addReservation(capReservation, false);
    }
}
Also used : RLESparseResourceAllocation(org.apache.hadoop.yarn.server.resourcemanager.reservation.RLESparseResourceAllocation) InMemoryReservationAllocation(org.apache.hadoop.yarn.server.resourcemanager.reservation.InMemoryReservationAllocation) ReservationDefinition(org.apache.hadoop.yarn.api.records.ReservationDefinition) Resource(org.apache.hadoop.yarn.api.records.Resource) PlanningException(org.apache.hadoop.yarn.server.resourcemanager.reservation.exceptions.PlanningException) ReservationInterval(org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationInterval) InMemoryReservationAllocation(org.apache.hadoop.yarn.server.resourcemanager.reservation.InMemoryReservationAllocation) ReservationAllocation(org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationAllocation)

Example 42 with ReservationDefinition

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

the class TestGreedyReservationAgent method testAllImpossible.

@Test
public void testAllImpossible() throws PlanningException {
    prepareBasicPlan();
    // create an ALL request, with an impossible combination, it should be
    // rejected, and allocation remain unchanged
    ReservationDefinition rr = new ReservationDefinitionPBImpl();
    rr.setArrival(100L);
    rr.setDeadline(120L);
    ReservationRequests reqs = new ReservationRequestsPBImpl();
    reqs.setInterpreter(ReservationRequestInterpreter.R_ALL);
    ReservationRequest r = ReservationRequest.newInstance(Resource.newInstance(1024, 1), 55, 5, 10);
    ReservationRequest r2 = ReservationRequest.newInstance(Resource.newInstance(2048, 2), 55, 5, 20);
    List<ReservationRequest> list = new ArrayList<ReservationRequest>();
    list.add(r);
    list.add(r2);
    reqs.setReservationResources(list);
    rr.setReservationRequests(reqs);
    ReservationId reservationID = ReservationSystemTestUtil.getNewReservationId();
    boolean result = false;
    try {
        // submit to agent
        result = agent.createReservation(reservationID, "u1", plan, rr);
        fail();
    } catch (PlanningException p) {
    // expected
    }
    // validate results, we expect the second one to be accepted
    assertFalse("Agent-based allocation failed", result);
    assertTrue("Agent-based allocation failed", plan.getAllReservations().size() == 2);
    System.out.println("--------AFTER ALL IMPOSSIBLE ALLOCATION (queue: " + reservationID + ")----------");
    System.out.println(plan.toString());
    System.out.println(plan.toCumulativeString());
}
Also used : ReservationRequestsPBImpl(org.apache.hadoop.yarn.api.records.impl.pb.ReservationRequestsPBImpl) ReservationId(org.apache.hadoop.yarn.api.records.ReservationId) ReservationDefinition(org.apache.hadoop.yarn.api.records.ReservationDefinition) ReservationRequest(org.apache.hadoop.yarn.api.records.ReservationRequest) ReservationDefinitionPBImpl(org.apache.hadoop.yarn.api.records.impl.pb.ReservationDefinitionPBImpl) ReservationRequests(org.apache.hadoop.yarn.api.records.ReservationRequests) ArrayList(java.util.ArrayList) PlanningException(org.apache.hadoop.yarn.server.resourcemanager.reservation.exceptions.PlanningException) Test(org.junit.Test)

Example 43 with ReservationDefinition

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

the class TestGreedyReservationAgent method testOrderNoGap.

@Test
public void testOrderNoGap() throws PlanningException {
    prepareBasicPlan();
    // create a chain of 4 RR, mixing gang and non-gang
    ReservationDefinition rr = new ReservationDefinitionPBImpl();
    rr.setArrival(0 * step);
    rr.setDeadline(60 * step);
    ReservationRequests reqs = new ReservationRequestsPBImpl();
    reqs.setInterpreter(ReservationRequestInterpreter.R_ORDER_NO_GAP);
    ReservationRequest r = ReservationRequest.newInstance(Resource.newInstance(2048, 2), 10, 1, 10 * step);
    ReservationRequest r2 = ReservationRequest.newInstance(Resource.newInstance(1024, 1), 10, 10, 20 * step);
    List<ReservationRequest> list = new ArrayList<ReservationRequest>();
    list.add(r);
    list.add(r2);
    list.add(r);
    list.add(r2);
    reqs.setReservationResources(list);
    rr.setReservationRequests(reqs);
    rr.setReservationRequests(reqs);
    // submit to agent
    ReservationId reservationID = ReservationSystemTestUtil.getNewReservationId();
    agent.createReservation(reservationID, "u1", plan, rr);
    System.out.println("--------AFTER ORDER ALLOCATION (queue: " + reservationID + ")----------");
    System.out.println(plan.toString());
    System.out.println(plan.toCumulativeString());
    // validate
    assertTrue("Agent-based allocation failed", reservationID != null);
    assertTrue("Agent-based allocation failed", plan.getAllReservations().size() == 3);
    ReservationAllocation cs = plan.getReservationById(reservationID);
    assertTrue(cs.toString(), check(cs, 0 * step, 10 * step, 20, 1024, 1));
    assertTrue(cs.toString(), check(cs, 10 * step, 30 * step, 10, 1024, 1));
    assertTrue(cs.toString(), check(cs, 30 * step, 40 * step, 20, 1024, 1));
    assertTrue(cs.toString(), check(cs, 40 * step, 60 * step, 10, 1024, 1));
}
Also used : ReservationRequestsPBImpl(org.apache.hadoop.yarn.api.records.impl.pb.ReservationRequestsPBImpl) ReservationId(org.apache.hadoop.yarn.api.records.ReservationId) ReservationDefinition(org.apache.hadoop.yarn.api.records.ReservationDefinition) ReservationRequest(org.apache.hadoop.yarn.api.records.ReservationRequest) ReservationDefinitionPBImpl(org.apache.hadoop.yarn.api.records.impl.pb.ReservationDefinitionPBImpl) ReservationRequests(org.apache.hadoop.yarn.api.records.ReservationRequests) ArrayList(java.util.ArrayList) InMemoryReservationAllocation(org.apache.hadoop.yarn.server.resourcemanager.reservation.InMemoryReservationAllocation) ReservationAllocation(org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationAllocation) Test(org.junit.Test)

Example 44 with ReservationDefinition

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

the class TestGreedyReservationAgent method testAnyImpossible.

@Test
public void testAnyImpossible() throws PlanningException {
    prepareBasicPlan();
    // create an ANY request, with all impossible alternatives
    ReservationDefinition rr = new ReservationDefinitionPBImpl();
    rr.setArrival(100L);
    rr.setDeadline(120L);
    ReservationRequests reqs = new ReservationRequestsPBImpl();
    reqs.setInterpreter(ReservationRequestInterpreter.R_ANY);
    // longer than arrival-deadline
    ReservationRequest r1 = ReservationRequest.newInstance(Resource.newInstance(1024, 1), 35, 5, 30);
    // above max cluster size
    ReservationRequest r2 = ReservationRequest.newInstance(Resource.newInstance(1024, 1), 110, 110, 10);
    List<ReservationRequest> list = new ArrayList<ReservationRequest>();
    list.add(r1);
    list.add(r2);
    reqs.setReservationResources(list);
    rr.setReservationRequests(reqs);
    ReservationId reservationID = ReservationSystemTestUtil.getNewReservationId();
    boolean result = false;
    try {
        // submit to agent
        result = agent.createReservation(reservationID, "u1", plan, rr);
        fail();
    } catch (PlanningException p) {
    // expected
    }
    // validate results, we expect the second one to be accepted
    assertFalse("Agent-based allocation should have failed", result);
    assertTrue("Agent-based allocation should have failed", plan.getAllReservations().size() == 2);
    System.out.println("--------AFTER ANY IMPOSSIBLE ALLOCATION (queue: " + reservationID + ")----------");
    System.out.println(plan.toString());
    System.out.println(plan.toCumulativeString());
}
Also used : ReservationRequestsPBImpl(org.apache.hadoop.yarn.api.records.impl.pb.ReservationRequestsPBImpl) ReservationId(org.apache.hadoop.yarn.api.records.ReservationId) ReservationDefinition(org.apache.hadoop.yarn.api.records.ReservationDefinition) ReservationRequest(org.apache.hadoop.yarn.api.records.ReservationRequest) ReservationDefinitionPBImpl(org.apache.hadoop.yarn.api.records.impl.pb.ReservationDefinitionPBImpl) ReservationRequests(org.apache.hadoop.yarn.api.records.ReservationRequests) ArrayList(java.util.ArrayList) PlanningException(org.apache.hadoop.yarn.server.resourcemanager.reservation.exceptions.PlanningException) Test(org.junit.Test)

Example 45 with ReservationDefinition

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

the class TestSimpleCapacityReplanner method testReplanningPlanCapacityLoss.

@Test
public void testReplanningPlanCapacityLoss() throws PlanningException {
    Resource clusterCapacity = Resource.newInstance(100 * 1024, 100);
    Resource minAlloc = Resource.newInstance(1024, 1);
    Resource maxAlloc = Resource.newInstance(1024 * 8, 8);
    ResourceCalculator res = new DefaultResourceCalculator();
    long step = 1L;
    Clock clock = mock(Clock.class);
    ReservationAgent agent = mock(ReservationAgent.class);
    SharingPolicy policy = new NoOverCommitPolicy();
    policy.init("root.dedicated", null);
    QueueMetrics queueMetrics = mock(QueueMetrics.class);
    when(clock.getTime()).thenReturn(0L);
    SimpleCapacityReplanner enf = new SimpleCapacityReplanner(clock);
    RMContext context = ReservationSystemTestUtil.createMockRMContext();
    ReservationSchedulerConfiguration conf = mock(ReservationSchedulerConfiguration.class);
    when(conf.getEnforcementWindow(any(String.class))).thenReturn(6L);
    enf.init("blah", conf);
    // Initialize the plan with more resources
    InMemoryPlan plan = new InMemoryPlan(queueMetrics, policy, agent, clusterCapacity, step, res, minAlloc, maxAlloc, "dedicated", enf, true, context, clock);
    // add reservation filling the plan (separating them 1ms, so we are sure
    // s2 follows s1 on acceptance
    long ts = System.currentTimeMillis();
    ReservationId r1 = ReservationId.newInstance(ts, 1);
    int[] f5 = { 20, 20, 20, 20, 20 };
    ReservationDefinition rDef = ReservationSystemTestUtil.createSimpleReservationDefinition(0, 0 + f5.length, f5.length);
    assertTrue(plan.toString(), plan.addReservation(new InMemoryReservationAllocation(r1, rDef, "u3", "dedicated", 0, 0 + f5.length, generateAllocation(0, f5), res, minAlloc), false));
    when(clock.getTime()).thenReturn(1L);
    ReservationId r2 = ReservationId.newInstance(ts, 2);
    assertTrue(plan.toString(), plan.addReservation(new InMemoryReservationAllocation(r2, rDef, "u4", "dedicated", 0, 0 + f5.length, generateAllocation(0, f5), res, minAlloc), false));
    when(clock.getTime()).thenReturn(2L);
    ReservationId r3 = ReservationId.newInstance(ts, 3);
    assertTrue(plan.toString(), plan.addReservation(new InMemoryReservationAllocation(r3, rDef, "u5", "dedicated", 0, 0 + f5.length, generateAllocation(0, f5), res, minAlloc), false));
    when(clock.getTime()).thenReturn(3L);
    ReservationId r4 = ReservationId.newInstance(ts, 4);
    assertTrue(plan.toString(), plan.addReservation(new InMemoryReservationAllocation(r4, rDef, "u6", "dedicated", 0, 0 + f5.length, generateAllocation(0, f5), res, minAlloc), false));
    when(clock.getTime()).thenReturn(4L);
    ReservationId r5 = ReservationId.newInstance(ts, 5);
    assertTrue(plan.toString(), plan.addReservation(new InMemoryReservationAllocation(r5, rDef, "u7", "dedicated", 0, 0 + f5.length, generateAllocation(0, f5), res, minAlloc), false));
    int[] f6 = { 50, 50, 50, 50, 50 };
    ReservationId r6 = ReservationId.newInstance(ts, 6);
    assertTrue(plan.toString(), plan.addReservation(new InMemoryReservationAllocation(r6, rDef, "u3", "dedicated", 10, 10 + f6.length, generateAllocation(10, f6), res, minAlloc), false));
    when(clock.getTime()).thenReturn(6L);
    ReservationId r7 = ReservationId.newInstance(ts, 7);
    assertTrue(plan.toString(), plan.addReservation(new InMemoryReservationAllocation(r7, rDef, "u4", "dedicated", 10, 10 + f6.length, generateAllocation(10, f6), res, minAlloc), false));
    // remove some of the resources (requires replanning)
    plan.setTotalCapacity(Resource.newInstance(70 * 1024, 70));
    when(clock.getTime()).thenReturn(0L);
    // run the replanner
    enf.plan(plan, null);
    // check which reservation are still present
    assertNotNull(plan.getReservationById(r1));
    assertNotNull(plan.getReservationById(r2));
    assertNotNull(plan.getReservationById(r3));
    assertNotNull(plan.getReservationById(r6));
    assertNotNull(plan.getReservationById(r7));
    // and which ones are removed
    assertNull(plan.getReservationById(r4));
    assertNull(plan.getReservationById(r5));
    // check resources at each moment in time no more exceed capacity
    for (int i = 0; i < 20; i++) {
        long tot = 0;
        for (ReservationAllocation r : plan.getReservationsAtTime(i)) {
            tot = r.getResourcesAtTime(i).getMemorySize();
        }
        assertTrue(tot <= 70 * 1024);
    }
}
Also used : InMemoryPlan(org.apache.hadoop.yarn.server.resourcemanager.reservation.InMemoryPlan) RMContext(org.apache.hadoop.yarn.server.resourcemanager.RMContext) SharingPolicy(org.apache.hadoop.yarn.server.resourcemanager.reservation.SharingPolicy) ReservationDefinition(org.apache.hadoop.yarn.api.records.ReservationDefinition) Resource(org.apache.hadoop.yarn.api.records.Resource) Clock(org.apache.hadoop.yarn.util.Clock) ReservationSchedulerConfiguration(org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationSchedulerConfiguration) DefaultResourceCalculator(org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator) ResourceCalculator(org.apache.hadoop.yarn.util.resource.ResourceCalculator) QueueMetrics(org.apache.hadoop.yarn.server.resourcemanager.scheduler.QueueMetrics) DefaultResourceCalculator(org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator) NoOverCommitPolicy(org.apache.hadoop.yarn.server.resourcemanager.reservation.NoOverCommitPolicy) ReservationId(org.apache.hadoop.yarn.api.records.ReservationId) InMemoryReservationAllocation(org.apache.hadoop.yarn.server.resourcemanager.reservation.InMemoryReservationAllocation) InMemoryReservationAllocation(org.apache.hadoop.yarn.server.resourcemanager.reservation.InMemoryReservationAllocation) ReservationAllocation(org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationAllocation) Test(org.junit.Test)

Aggregations

ReservationDefinition (org.apache.hadoop.yarn.api.records.ReservationDefinition)70 Test (org.junit.Test)52 ReservationId (org.apache.hadoop.yarn.api.records.ReservationId)40 ReservationRequest (org.apache.hadoop.yarn.api.records.ReservationRequest)23 ReservationRequests (org.apache.hadoop.yarn.api.records.ReservationRequests)19 InMemoryReservationAllocation (org.apache.hadoop.yarn.server.resourcemanager.reservation.InMemoryReservationAllocation)19 Resource (org.apache.hadoop.yarn.api.records.Resource)17 ReservationAllocation (org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationAllocation)16 ReservationDefinitionPBImpl (org.apache.hadoop.yarn.api.records.impl.pb.ReservationDefinitionPBImpl)15 ReservationRequestsPBImpl (org.apache.hadoop.yarn.api.records.impl.pb.ReservationRequestsPBImpl)15 ReservationSubmissionRequest (org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionRequest)14 ArrayList (java.util.ArrayList)12 PlanningException (org.apache.hadoop.yarn.server.resourcemanager.reservation.exceptions.PlanningException)12 ReservationUpdateRequest (org.apache.hadoop.yarn.api.protocolrecords.ReservationUpdateRequest)7 ReservationSubmissionResponse (org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionResponse)6 Plan (org.apache.hadoop.yarn.server.resourcemanager.reservation.Plan)5 Clock (org.apache.hadoop.yarn.util.Clock)5 ReservationUpdateResponse (org.apache.hadoop.yarn.api.protocolrecords.ReservationUpdateResponse)4 IOException (java.io.IOException)3 GetNewReservationRequest (org.apache.hadoop.yarn.api.protocolrecords.GetNewReservationRequest)3