Search in sources :

Example 1 with PlanningException

use of org.apache.hadoop.yarn.server.resourcemanager.reservation.exceptions.PlanningException in project hadoop by apache.

the class TestInMemoryPlan method testDeleteNonExistingReservation.

@Test
public void testDeleteNonExistingReservation() {
    Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc, minAlloc, maxAlloc, planName, replanner, true, context);
    ReservationId reservationID = ReservationSystemTestUtil.getNewReservationId();
    // Try to delete a reservation without adding
    Assert.assertNull(plan.getReservationById(reservationID));
    try {
        plan.deleteReservation(reservationID);
        Assert.fail("Delete should fail as it does not exist in the plan");
    } catch (IllegalArgumentException e) {
        Assert.assertTrue(e.getMessage().endsWith("does not exist in the plan"));
    } catch (PlanningException e) {
        Assert.fail(e.getMessage());
    }
    Assert.assertNull(plan.getReservationById(reservationID));
}
Also used : ReservationId(org.apache.hadoop.yarn.api.records.ReservationId) PlanningException(org.apache.hadoop.yarn.server.resourcemanager.reservation.exceptions.PlanningException) Test(org.junit.Test)

Example 2 with PlanningException

use of org.apache.hadoop.yarn.server.resourcemanager.reservation.exceptions.PlanningException in project hadoop by apache.

the class TestInMemoryPlan method testGetReservationsByTimeInterval.

@Test
public void testGetReservationsByTimeInterval() {
    Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc, minAlloc, maxAlloc, planName, replanner, true, context);
    ReservationId reservationID = ReservationSystemTestUtil.getNewReservationId();
    int[] alloc = { 10, 10, 10, 10, 10, 10 };
    int start = 100;
    ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc);
    Assert.assertNull(plan.getReservationById(reservationID));
    try {
        plan.addReservation(rAllocation, false);
    } catch (PlanningException e) {
        Assert.fail(e.getMessage());
    }
    // Verify that get by time interval works if the selection interval
    // completely overlaps with the allocation.
    ReservationInterval interval = new ReservationInterval(rAllocation.getStartTime(), rAllocation.getEndTime());
    Set<ReservationAllocation> rAllocations = plan.getReservations(null, interval, "");
    Assert.assertTrue(rAllocations.size() == 1);
    Assert.assertTrue(rAllocation.compareTo((ReservationAllocation) rAllocations.toArray()[0]) == 0);
    // Verify that get by time interval works if the selection interval
    // falls within the allocation
    long duration = rAllocation.getEndTime() - rAllocation.getStartTime();
    interval = new ReservationInterval(rAllocation.getStartTime() + duration * (long) 0.3, rAllocation.getEndTime() - duration * (long) 0.3);
    rAllocations = plan.getReservations(null, interval, "");
    Assert.assertTrue(rAllocations.size() == 1);
    Assert.assertTrue(rAllocation.compareTo((ReservationAllocation) rAllocations.toArray()[0]) == 0);
    // Verify that get by time interval selects 1 allocation if the end
    // time of the selection interval falls right at the start of the
    // allocation.
    interval = new ReservationInterval(0, rAllocation.getStartTime());
    rAllocations = plan.getReservations(null, interval, "");
    Assert.assertTrue(rAllocations.size() == 1);
    Assert.assertTrue(rAllocation.compareTo((ReservationAllocation) rAllocations.toArray()[0]) == 0);
    // Verify that get by time interval selects no reservations if the start
    // time of the selection interval falls right at the end of the allocation.
    interval = new ReservationInterval(rAllocation.getEndTime(), Long.MAX_VALUE);
    rAllocations = plan.getReservations(null, interval, "");
    Assert.assertTrue(rAllocations.size() == 0);
    // Verify that get by time interval selects no reservations if the
    // selection interval and allocation interval do not overlap.
    interval = new ReservationInterval(0, rAllocation.getStartTime() / 2);
    rAllocations = plan.getReservations(null, interval, "");
    Assert.assertTrue(rAllocations.size() == 0);
}
Also used : ReservationId(org.apache.hadoop.yarn.api.records.ReservationId) PlanningException(org.apache.hadoop.yarn.server.resourcemanager.reservation.exceptions.PlanningException) Test(org.junit.Test)

Example 3 with PlanningException

use of org.apache.hadoop.yarn.server.resourcemanager.reservation.exceptions.PlanningException in project hadoop by apache.

the class TestInMemoryPlan method testGetReservationsAtTime.

@Test
public void testGetReservationsAtTime() {
    Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc, minAlloc, maxAlloc, planName, replanner, true, context);
    ReservationId reservationID = ReservationSystemTestUtil.getNewReservationId();
    int[] alloc = { 10, 10, 10, 10, 10, 10 };
    int start = 100;
    ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc);
    Assert.assertNull(plan.getReservationById(reservationID));
    try {
        plan.addReservation(rAllocation, false);
    } catch (PlanningException e) {
        Assert.fail(e.getMessage());
    }
    Set<ReservationAllocation> rAllocations = plan.getReservationsAtTime(rAllocation.getStartTime());
    Assert.assertTrue(rAllocations.size() == 1);
    Assert.assertTrue(rAllocation.compareTo((ReservationAllocation) rAllocations.toArray()[0]) == 0);
}
Also used : ReservationId(org.apache.hadoop.yarn.api.records.ReservationId) PlanningException(org.apache.hadoop.yarn.server.resourcemanager.reservation.exceptions.PlanningException) Test(org.junit.Test)

Example 4 with PlanningException

use of org.apache.hadoop.yarn.server.resourcemanager.reservation.exceptions.PlanningException in project hadoop by apache.

the class TestInMemoryPlan method testGetReservationsById.

@Test
public void testGetReservationsById() {
    Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc, minAlloc, maxAlloc, planName, replanner, true, context);
    ReservationId reservationID = ReservationSystemTestUtil.getNewReservationId();
    int[] alloc = { 10, 10, 10, 10, 10, 10 };
    int start = 100;
    ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc);
    Assert.assertNull(plan.getReservationById(reservationID));
    try {
        plan.addReservation(rAllocation, false);
    } catch (PlanningException e) {
        Assert.fail(e.getMessage());
    }
    // Verify that get by reservation id works.
    Set<ReservationAllocation> rAllocations = plan.getReservations(reservationID, null, "");
    Assert.assertTrue(rAllocations.size() == 1);
    Assert.assertTrue(rAllocation.compareTo((ReservationAllocation) rAllocations.toArray()[0]) == 0);
    // Verify that get by reservation id works even when time range
    // and user is invalid.
    ReservationInterval interval = new ReservationInterval(0, 0);
    rAllocations = plan.getReservations(reservationID, interval, "invalid");
    Assert.assertTrue(rAllocations.size() == 1);
    Assert.assertTrue(rAllocation.compareTo((ReservationAllocation) rAllocations.toArray()[0]) == 0);
}
Also used : ReservationId(org.apache.hadoop.yarn.api.records.ReservationId) PlanningException(org.apache.hadoop.yarn.server.resourcemanager.reservation.exceptions.PlanningException) Test(org.junit.Test)

Example 5 with PlanningException

use of org.apache.hadoop.yarn.server.resourcemanager.reservation.exceptions.PlanningException in project hadoop by apache.

the class TestInMemoryPlan method testAddReservation.

@Test
public void testAddReservation() {
    Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc, minAlloc, maxAlloc, planName, replanner, true, context);
    ReservationId reservationID = ReservationSystemTestUtil.getNewReservationId();
    int[] alloc = { 10, 10, 10, 10, 10, 10 };
    int start = 100;
    ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc);
    Assert.assertNull(plan.getReservationById(reservationID));
    try {
        plan.addReservation(rAllocation, false);
    } catch (PlanningException e) {
        Assert.fail(e.getMessage());
    }
    doAssertions(plan, rAllocation);
    checkAllocation(plan, alloc, start);
}
Also used : ReservationId(org.apache.hadoop.yarn.api.records.ReservationId) PlanningException(org.apache.hadoop.yarn.server.resourcemanager.reservation.exceptions.PlanningException) Test(org.junit.Test)

Aggregations

PlanningException (org.apache.hadoop.yarn.server.resourcemanager.reservation.exceptions.PlanningException)35 ReservationId (org.apache.hadoop.yarn.api.records.ReservationId)27 Test (org.junit.Test)24 ReservationDefinition (org.apache.hadoop.yarn.api.records.ReservationDefinition)12 Resource (org.apache.hadoop.yarn.api.records.Resource)8 ReservationRequest (org.apache.hadoop.yarn.api.records.ReservationRequest)5 ArrayList (java.util.ArrayList)4 ReservationRequests (org.apache.hadoop.yarn.api.records.ReservationRequests)4 ReservationDefinitionPBImpl (org.apache.hadoop.yarn.api.records.impl.pb.ReservationDefinitionPBImpl)4 ReservationRequestsPBImpl (org.apache.hadoop.yarn.api.records.impl.pb.ReservationRequestsPBImpl)4 TreeMap (java.util.TreeMap)3 InMemoryReservationAllocation (org.apache.hadoop.yarn.server.resourcemanager.reservation.InMemoryReservationAllocation)3 Plan (org.apache.hadoop.yarn.server.resourcemanager.reservation.Plan)3 ReservationAllocation (org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationAllocation)3 RLESparseResourceAllocation (org.apache.hadoop.yarn.server.resourcemanager.reservation.RLESparseResourceAllocation)2 ReservationInterval (org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationInterval)2 ReservationSchedulerConfiguration (org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationSchedulerConfiguration)2 HashSet (java.util.HashSet)1 Map (java.util.Map)1 NavigableMap (java.util.NavigableMap)1