Java 类org.apache.hadoop.yarn.api.records.ReservationDefinition 实例源码

项目:hadoop    文件:InMemoryReservationAllocation.java   
InMemoryReservationAllocation(ReservationId reservationID,
    ReservationDefinition contract, String user, String planName,
    long startTime, long endTime,
    Map<ReservationInterval, ReservationRequest> allocationRequests,
    ResourceCalculator calculator, Resource minAlloc) {
  this.contract = contract;
  this.startTime = startTime;
  this.endTime = endTime;
  this.reservationID = reservationID;
  this.user = user;
  this.allocationRequests = allocationRequests;
  this.planName = planName;
  resourcesOverTime = new RLESparseResourceAllocation(calculator, minAlloc);
  for (Map.Entry<ReservationInterval, ReservationRequest> r : allocationRequests
      .entrySet()) {
    resourcesOverTime.addInterval(r.getKey(), r.getValue());
    if (r.getValue().getConcurrency() > 1) {
      hasGang = true;
    }
  }
}
项目:hadoop    文件:TestInMemoryReservationAllocation.java   
@Test
public void testBlocks() {
  ReservationId reservationID =
      ReservationId.newInstance(rand.nextLong(), rand.nextLong());
  int[] alloc = { 10, 10, 10, 10, 10, 10 };
  int start = 100;
  ReservationDefinition rDef =
      createSimpleReservationDefinition(start, start + alloc.length + 1,
          alloc.length);
  Map<ReservationInterval, ReservationRequest> allocations =
      generateAllocation(start, alloc, false, false);
  ReservationAllocation rAllocation =
      new InMemoryReservationAllocation(reservationID, rDef, user, planName,
          start, start + alloc.length + 1, allocations, resCalc, minAlloc);
  doAssertions(rAllocation, reservationID, rDef, allocations, start, alloc);
  Assert.assertFalse(rAllocation.containsGangs());
  for (int i = 0; i < alloc.length; i++) {
    Assert.assertEquals(Resource.newInstance(1024 * (alloc[i]), (alloc[i]), (alloc[i])),
        rAllocation.getResourcesAtTime(start + i));
  }
}
项目:hadoop    文件:TestInMemoryReservationAllocation.java   
@Test
public void testSteps() {
  ReservationId reservationID =
      ReservationId.newInstance(rand.nextLong(), rand.nextLong());
  int[] alloc = { 10, 10, 10, 10, 10, 10 };
  int start = 100;
  ReservationDefinition rDef =
      createSimpleReservationDefinition(start, start + alloc.length + 1,
          alloc.length);
  Map<ReservationInterval, ReservationRequest> allocations =
      generateAllocation(start, alloc, true, false);
  ReservationAllocation rAllocation =
      new InMemoryReservationAllocation(reservationID, rDef, user, planName,
          start, start + alloc.length + 1, allocations, resCalc, minAlloc);
  doAssertions(rAllocation, reservationID, rDef, allocations, start, alloc);
  Assert.assertFalse(rAllocation.containsGangs());
  for (int i = 0; i < alloc.length; i++) {
    Assert.assertEquals(
        Resource.newInstance(1024 * (alloc[i] + i), (alloc[i] + i), (alloc[i] + i)),
        rAllocation.getResourcesAtTime(start + i));
  }
}
项目:hadoop    文件:TestInMemoryReservationAllocation.java   
@Test
public void testSkyline() {
  ReservationId reservationID =
      ReservationId.newInstance(rand.nextLong(), rand.nextLong());
  int[] alloc = { 0, 5, 10, 10, 5, 0 };
  int start = 100;
  ReservationDefinition rDef =
      createSimpleReservationDefinition(start, start + alloc.length + 1,
          alloc.length);
  Map<ReservationInterval, ReservationRequest> allocations =
      generateAllocation(start, alloc, true, false);
  ReservationAllocation rAllocation =
      new InMemoryReservationAllocation(reservationID, rDef, user, planName,
          start, start + alloc.length + 1, allocations, resCalc, minAlloc);
  doAssertions(rAllocation, reservationID, rDef, allocations, start, alloc);
  Assert.assertFalse(rAllocation.containsGangs());
  for (int i = 0; i < alloc.length; i++) {
    Assert.assertEquals(
        Resource.newInstance(1024 * (alloc[i] + i), (alloc[i] + i), (alloc[i] + i)),
        rAllocation.getResourcesAtTime(start + i));
  }
}
项目:hadoop    文件:TestInMemoryReservationAllocation.java   
@Test
public void testZeroAlloaction() {
  ReservationId reservationID =
      ReservationId.newInstance(rand.nextLong(), rand.nextLong());
  int[] alloc = {};
  long start = 0;
  ReservationDefinition rDef =
      createSimpleReservationDefinition(start, start + alloc.length + 1,
          alloc.length);
  Map<ReservationInterval, ReservationRequest> allocations =
      new HashMap<ReservationInterval, ReservationRequest>();
  ReservationAllocation rAllocation =
      new InMemoryReservationAllocation(reservationID, rDef, user, planName,
          start, start + alloc.length + 1, allocations, resCalc, minAlloc);
  doAssertions(rAllocation, reservationID, rDef, allocations, (int) start,
      alloc);
  Assert.assertFalse(rAllocation.containsGangs());
}
项目:hadoop    文件:TestInMemoryReservationAllocation.java   
@Test
public void testGangAlloaction() {
  ReservationId reservationID =
      ReservationId.newInstance(rand.nextLong(), rand.nextLong());
  int[] alloc = { 10, 10, 10, 10, 10, 10 };
  int start = 100;
  ReservationDefinition rDef =
      createSimpleReservationDefinition(start, start + alloc.length + 1,
          alloc.length);
  Map<ReservationInterval, ReservationRequest> allocations =
      generateAllocation(start, alloc, false, true);
  ReservationAllocation rAllocation =
      new InMemoryReservationAllocation(reservationID, rDef, user, planName,
          start, start + alloc.length + 1, allocations, resCalc, minAlloc);
  doAssertions(rAllocation, reservationID, rDef, allocations, start, alloc);
  Assert.assertTrue(rAllocation.containsGangs());
  for (int i = 0; i < alloc.length; i++) {
    Assert.assertEquals(Resource.newInstance(1024 * (alloc[i]), (alloc[i]), (alloc[i])),
        rAllocation.getResourcesAtTime(start + i));
  }
}
项目:hadoop    文件:TestInMemoryPlan.java   
@Test
public void testAddEmptyReservation() {
  Plan plan =
      new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L,
          resCalc, minAlloc, maxAlloc, planName, replanner, true);
  ReservationId reservationID =
      ReservationSystemTestUtil.getNewReservationId();
  int[] alloc = {};
  int start = 100;
  Map<ReservationInterval, ReservationRequest> allocations =
      new HashMap<ReservationInterval, ReservationRequest>();
  ReservationDefinition rDef =
      createSimpleReservationDefinition(start, start + alloc.length,
          alloc.length, allocations.values());
  ReservationAllocation rAllocation =
      new InMemoryReservationAllocation(reservationID, rDef, user, planName,
          start, start + alloc.length, allocations, resCalc, minAlloc);
  Assert.assertNull(plan.getReservationById(reservationID));
  try {
    plan.addReservation(rAllocation);
  } catch (PlanningException e) {
    Assert.fail(e.getMessage());
  }
}
项目:hadoop    文件:TestReservationInputValidator.java   
private ReservationSubmissionRequest createSimpleReservationSubmissionRequest(
    int numRequests, int numContainers, long arrival, long deadline,
    long duration) {
  // create a request with a single atomic ask
  ReservationSubmissionRequest request =
      new ReservationSubmissionRequestPBImpl();
  ReservationDefinition rDef = new ReservationDefinitionPBImpl();
  rDef.setArrival(arrival);
  rDef.setDeadline(deadline);
  if (numRequests > 0) {
    ReservationRequests reqs = new ReservationRequestsPBImpl();
    rDef.setReservationRequests(reqs);
    if (numContainers > 0) {
      ReservationRequest r =
          ReservationRequest.newInstance(Resource.newInstance(1024, 1, 1),
              numContainers, 1, duration);

      reqs.setReservationResources(Collections.singletonList(r));
      reqs.setInterpreter(ReservationRequestInterpreter.R_ALL);
    }
  }
  request.setQueue(PLAN_NAME);
  request.setReservationDefinition(rDef);
  return request;
}
项目:hadoop    文件:TestReservationInputValidator.java   
private ReservationUpdateRequest createSimpleReservationUpdateRequest(
    int numRequests, int numContainers, long arrival, long deadline,
    long duration) {
  // create a request with a single atomic ask
  ReservationUpdateRequest request = new ReservationUpdateRequestPBImpl();
  ReservationDefinition rDef = new ReservationDefinitionPBImpl();
  rDef.setArrival(arrival);
  rDef.setDeadline(deadline);
  if (numRequests > 0) {
    ReservationRequests reqs = new ReservationRequestsPBImpl();
    rDef.setReservationRequests(reqs);
    if (numContainers > 0) {
      ReservationRequest r =
          ReservationRequest.newInstance(Resource.newInstance(1024, 1, 1),
              numContainers, 1, duration);

      reqs.setReservationResources(Collections.singletonList(r));
      reqs.setInterpreter(ReservationRequestInterpreter.R_ALL);
    }
  }
  request.setReservationDefinition(rDef);
  request.setReservationId(ReservationSystemTestUtil.getNewReservationId());
  return request;
}
项目:hadoop    文件:TestClientRMService.java   
private ReservationSubmissionRequest createSimpleReservationRequest(
    int numContainers, long arrival, long deadline, long duration) {
  // create a request with a single atomic ask
  ReservationRequest r =
      ReservationRequest.newInstance(Resource.newInstance(1024, 1, 1),
          numContainers, 1, duration);
  ReservationRequests reqs =
      ReservationRequests.newInstance(Collections.singletonList(r),
          ReservationRequestInterpreter.R_ALL);
  ReservationDefinition rDef =
      ReservationDefinition.newInstance(arrival, deadline, reqs,
          "testClientRMService#reservation");
  ReservationSubmissionRequest request =
      ReservationSubmissionRequest.newInstance(rDef,
          ReservationSystemTestUtil.reservationQ);
  return request;
}
项目:hadoop    文件:TestYarnClient.java   
private ReservationSubmissionRequest createSimpleReservationRequest(
    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);
  return request;
}
项目:aliyun-oss-hadoop-fs    文件:AlignedPlannerWithGreedy.java   
@Override
public boolean createReservation(ReservationId reservationId, String user,
    Plan plan, ReservationDefinition contract) throws PlanningException {

  LOG.info("placing the following ReservationRequest: " + contract);

  try {
    boolean res =
        planner.createReservation(reservationId, user, plan, contract);

    if (res) {
      LOG.info("OUTCOME: SUCCESS, Reservation ID: "
          + reservationId.toString() + ", Contract: " + contract.toString());
    } else {
      LOG.info("OUTCOME: FAILURE, Reservation ID: "
          + reservationId.toString() + ", Contract: " + contract.toString());
    }
    return res;
  } catch (PlanningException e) {
    LOG.info("OUTCOME: FAILURE, Reservation ID: " + reservationId.toString()
        + ", Contract: " + contract.toString());
    throw e;
  }

}
项目:big-c    文件:TestInMemoryReservationAllocation.java   
@Test
public void testZeroAlloaction() {
  ReservationId reservationID =
      ReservationId.newInstance(rand.nextLong(), rand.nextLong());
  int[] alloc = {};
  long start = 0;
  ReservationDefinition rDef =
      createSimpleReservationDefinition(start, start + alloc.length + 1,
          alloc.length);
  Map<ReservationInterval, ReservationRequest> allocations =
      new HashMap<ReservationInterval, ReservationRequest>();
  ReservationAllocation rAllocation =
      new InMemoryReservationAllocation(reservationID, rDef, user, planName,
          start, start + alloc.length + 1, allocations, resCalc, minAlloc);
  doAssertions(rAllocation, reservationID, rDef, allocations, (int) start,
      alloc);
  Assert.assertFalse(rAllocation.containsGangs());
}
项目:big-c    文件:TestInMemoryPlan.java   
@Test
public void testAddEmptyReservation() {
  Plan plan =
      new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L,
          resCalc, minAlloc, maxAlloc, planName, replanner, true);
  ReservationId reservationID =
      ReservationSystemTestUtil.getNewReservationId();
  int[] alloc = {};
  int start = 100;
  Map<ReservationInterval, ReservationRequest> allocations =
      new HashMap<ReservationInterval, ReservationRequest>();
  ReservationDefinition rDef =
      createSimpleReservationDefinition(start, start + alloc.length,
          alloc.length, allocations.values());
  ReservationAllocation rAllocation =
      new InMemoryReservationAllocation(reservationID, rDef, user, planName,
          start, start + alloc.length, allocations, resCalc, minAlloc);
  Assert.assertNull(plan.getReservationById(reservationID));
  try {
    plan.addReservation(rAllocation);
  } catch (PlanningException e) {
    Assert.fail(e.getMessage());
  }
}
项目:aliyun-oss-hadoop-fs    文件:ReservationSystemUtil.java   
public static InMemoryReservationAllocation toInMemoryAllocation(
    String planName, ReservationId reservationId,
    ReservationAllocationStateProto allocationState, Resource minAlloc,
    ResourceCalculator planResourceCalculator) {
  ReservationDefinition definition =
      convertFromProtoFormat(
          allocationState.getReservationDefinition());
  Map<ReservationInterval, Resource> allocations = toAllocations(
          allocationState.getAllocationRequestsList());
  InMemoryReservationAllocation allocation =
      new InMemoryReservationAllocation(reservationId, definition,
      allocationState.getUser(), planName, allocationState.getStartTime(),
      allocationState.getEndTime(), allocations, planResourceCalculator,
      minAlloc, allocationState.getContainsGangs());
  return allocation;
}
项目:aliyun-oss-hadoop-fs    文件:InMemoryReservationAllocation.java   
public InMemoryReservationAllocation(ReservationId reservationID,
    ReservationDefinition contract, String user, String planName,
    long startTime, long endTime,
    Map<ReservationInterval, Resource> allocations,
    ResourceCalculator calculator, Resource minAlloc, boolean hasGang) {
  this.contract = contract;
  this.startTime = startTime;
  this.endTime = endTime;
  this.reservationID = reservationID;
  this.user = user;
  this.allocationRequests = allocations;
  this.planName = planName;
  this.hasGang = hasGang;
  resourcesOverTime = new RLESparseResourceAllocation(calculator);
  for (Map.Entry<ReservationInterval, Resource> r : allocations
      .entrySet()) {
    resourcesOverTime.addInterval(r.getKey(), r.getValue());
  }
}
项目:big-c    文件:TestYarnClient.java   
private ReservationSubmissionRequest createSimpleReservationRequest(
    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);
  return request;
}
项目:aliyun-oss-hadoop-fs    文件:TestInMemoryReservationAllocation.java   
@Test
public void testBlocks() {
  ReservationId reservationID =
      ReservationId.newInstance(rand.nextLong(), rand.nextLong());
  int[] alloc = { 10, 10, 10, 10, 10, 10 };
  int start = 100;
  ReservationDefinition rDef =
      ReservationSystemTestUtil.createSimpleReservationDefinition(
          start, start + alloc.length + 1,
          alloc.length);
  Map<ReservationInterval, Resource> allocations =
      generateAllocation(start, alloc, false, false);
  ReservationAllocation rAllocation =
      new InMemoryReservationAllocation(reservationID, rDef, user, planName,
          start, start + alloc.length + 1, allocations, resCalc, minAlloc);
  doAssertions(rAllocation, reservationID, rDef, allocations, start, alloc);
  Assert.assertFalse(rAllocation.containsGangs());
  for (int i = 0; i < alloc.length; i++) {
    Assert.assertEquals(Resource.newInstance(1024 * (alloc[i]), (alloc[i])),
        rAllocation.getResourcesAtTime(start + i));
  }
}
项目:aliyun-oss-hadoop-fs    文件:TestInMemoryReservationAllocation.java   
@Test
public void testSteps() {
  ReservationId reservationID =
      ReservationId.newInstance(rand.nextLong(), rand.nextLong());
  int[] alloc = { 10, 10, 10, 10, 10, 10 };
  int start = 100;
  ReservationDefinition rDef =
      ReservationSystemTestUtil.createSimpleReservationDefinition(
          start, start + alloc.length + 1,
          alloc.length);
  Map<ReservationInterval, Resource> allocations =
      generateAllocation(start, alloc, true, false);
  ReservationAllocation rAllocation =
      new InMemoryReservationAllocation(reservationID, rDef, user, planName,
          start, start + alloc.length + 1, allocations, resCalc, minAlloc);
  doAssertions(rAllocation, reservationID, rDef, allocations, start, alloc);
  Assert.assertFalse(rAllocation.containsGangs());
  for (int i = 0; i < alloc.length; i++) {
    Assert.assertEquals(
        Resource.newInstance(1024 * (alloc[i] + i), (alloc[i] + i)),
        rAllocation.getResourcesAtTime(start + i));
  }
}
项目:aliyun-oss-hadoop-fs    文件:TestInMemoryReservationAllocation.java   
@Test
public void testZeroAlloaction() {
  ReservationId reservationID =
      ReservationId.newInstance(rand.nextLong(), rand.nextLong());
  int[] alloc = {};
  long start = 0;
  ReservationDefinition rDef =
      ReservationSystemTestUtil.createSimpleReservationDefinition(
          start, start + alloc.length + 1,
          alloc.length);
  Map<ReservationInterval, Resource> allocations =
      new HashMap<ReservationInterval, Resource>();
  ReservationAllocation rAllocation =
      new InMemoryReservationAllocation(reservationID, rDef, user, planName,
          start, start + alloc.length + 1, allocations, resCalc, minAlloc);
  doAssertions(rAllocation, reservationID, rDef, allocations, (int) start,
      alloc);
  Assert.assertFalse(rAllocation.containsGangs());
}
项目:aliyun-oss-hadoop-fs    文件:TestInMemoryReservationAllocation.java   
@Test
public void testGangAlloaction() {
  ReservationId reservationID =
      ReservationId.newInstance(rand.nextLong(), rand.nextLong());
  int[] alloc = { 10, 10, 10, 10, 10, 10 };
  int start = 100;
  ReservationDefinition rDef =
      ReservationSystemTestUtil.createSimpleReservationDefinition(
          start, start + alloc.length + 1,
          alloc.length);
  boolean isGang = true;
  Map<ReservationInterval, Resource> allocations =
      generateAllocation(start, alloc, false, isGang);
  ReservationAllocation rAllocation =
      new InMemoryReservationAllocation(reservationID, rDef, user, planName,
          start, start + alloc.length + 1, allocations, resCalc, minAlloc,
          isGang);
  doAssertions(rAllocation, reservationID, rDef, allocations, start, alloc);
  Assert.assertTrue(rAllocation.containsGangs());
  for (int i = 0; i < alloc.length; i++) {
    Assert.assertEquals(Resource.newInstance(1024 * (alloc[i]), (alloc[i])),
        rAllocation.getResourcesAtTime(start + i));
  }
}
项目:big-c    文件:TestInMemoryReservationAllocation.java   
@Test
public void testBlocks() {
  ReservationId reservationID =
      ReservationId.newInstance(rand.nextLong(), rand.nextLong());
  int[] alloc = { 10, 10, 10, 10, 10, 10 };
  int start = 100;
  ReservationDefinition rDef =
      createSimpleReservationDefinition(start, start + alloc.length + 1,
          alloc.length);
  Map<ReservationInterval, ReservationRequest> allocations =
      generateAllocation(start, alloc, false, false);
  ReservationAllocation rAllocation =
      new InMemoryReservationAllocation(reservationID, rDef, user, planName,
          start, start + alloc.length + 1, allocations, resCalc, minAlloc);
  doAssertions(rAllocation, reservationID, rDef, allocations, start, alloc);
  Assert.assertFalse(rAllocation.containsGangs());
  for (int i = 0; i < alloc.length; i++) {
    Assert.assertEquals(Resource.newInstance(1024 * (alloc[i]), (alloc[i])),
        rAllocation.getResourcesAtTime(start + i));
  }
}
项目:aliyun-oss-hadoop-fs    文件:TestInMemoryPlan.java   
@Test
public void testAddEmptyReservation() {
  Plan plan =
      new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L,
          resCalc, minAlloc, maxAlloc, planName, replanner, true, context);
  ReservationId reservationID =
      ReservationSystemTestUtil.getNewReservationId();
  int[] alloc = {};
  int start = 100;
  Map<ReservationInterval, ReservationRequest> allocations =
      new HashMap<ReservationInterval, ReservationRequest>();
  ReservationDefinition rDef =
      createSimpleReservationDefinition(start, start + alloc.length,
          alloc.length, allocations.values());
  Map<ReservationInterval, Resource> allocs = ReservationSystemUtil.toResources
      (allocations);
  ReservationAllocation rAllocation =
      new InMemoryReservationAllocation(reservationID, rDef, user, planName,
          start, start + alloc.length, allocs, resCalc, minAlloc);
  Assert.assertNull(plan.getReservationById(reservationID));
  try {
    plan.addReservation(rAllocation, false);
  } catch (PlanningException e) {
    Assert.fail(e.getMessage());
  }
}
项目:aliyun-oss-hadoop-fs    文件:TestCapacityOverTimePolicy.java   
@Test
public void testSimplePass2() throws IOException, PlanningException {
  // generate allocation from single tenant that exceed avg momentarily but
  // fit within
  // max instantanesou
  int[] f = generateData(3600, (int) Math.ceil(0.69 * totCont));
  ReservationDefinition rDef =
      ReservationSystemTestUtil.createSimpleReservationDefinition(
          initTime, initTime + f.length + 1, f.length);
  assertTrue(plan.toString(),
      plan.addReservation(new InMemoryReservationAllocation(
          ReservationSystemTestUtil.getNewReservationId(), rDef, "u1",
          "dedicated", initTime, initTime + f.length,
          ReservationSystemTestUtil.generateAllocation(initTime, step, f),
          res, minAlloc), false));
}
项目:aliyun-oss-hadoop-fs    文件:TestCapacityOverTimePolicy.java   
@Test(expected = ResourceOverCommitException.class)
public void testMultiTenantFail() throws IOException, PlanningException {
  // generate allocation from multiple tenants that exceed tot capacity
  int[] f = generateData(3600, (int) Math.ceil(0.25 * totCont));
  ReservationDefinition rDef =
      ReservationSystemTestUtil.createSimpleReservationDefinition(
          initTime, initTime + f.length + 1, f.length);
  for (int i = 0; i < 5; i++) {
    assertTrue(plan.toString(),
        plan.addReservation(new InMemoryReservationAllocation(
            ReservationSystemTestUtil.getNewReservationId(), rDef, "u" + i,
            "dedicated", initTime, initTime + f.length,
            ReservationSystemTestUtil.generateAllocation(initTime, step, f),
            res, minAlloc), false));
  }
}
项目:aliyun-oss-hadoop-fs    文件:TestCapacityOverTimePolicy.java   
@Test(expected = PlanningQuotaException.class)
public void testFailAvg() throws IOException, PlanningException {
  // generate an allocation which violates the 25% average single-shot
  Map<ReservationInterval, Resource> req =
      new TreeMap<ReservationInterval, Resource>();
  long win = timeWindow / 2 + 100;
  int cont = (int) Math.ceil(0.5 * totCont);
  req.put(new ReservationInterval(initTime, initTime + win),
      ReservationSystemUtil.toResource(
          ReservationRequest.newInstance(Resource.newInstance(1024, 1),
              cont)));
  ReservationDefinition rDef =
      ReservationSystemTestUtil.createSimpleReservationDefinition(
          initTime, initTime + win, win);
  assertTrue(plan.toString(),
      plan.addReservation(new InMemoryReservationAllocation(
          ReservationSystemTestUtil.getNewReservationId(), rDef, "u1",
          "dedicated", initTime, initTime + win, req, res, minAlloc), false));
}
项目:big-c    文件:TestInMemoryReservationAllocation.java   
@Test
public void testSteps() {
  ReservationId reservationID =
      ReservationId.newInstance(rand.nextLong(), rand.nextLong());
  int[] alloc = { 10, 10, 10, 10, 10, 10 };
  int start = 100;
  ReservationDefinition rDef =
      createSimpleReservationDefinition(start, start + alloc.length + 1,
          alloc.length);
  Map<ReservationInterval, ReservationRequest> allocations =
      generateAllocation(start, alloc, true, false);
  ReservationAllocation rAllocation =
      new InMemoryReservationAllocation(reservationID, rDef, user, planName,
          start, start + alloc.length + 1, allocations, resCalc, minAlloc);
  doAssertions(rAllocation, reservationID, rDef, allocations, start, alloc);
  Assert.assertFalse(rAllocation.containsGangs());
  for (int i = 0; i < alloc.length; i++) {
    Assert.assertEquals(
        Resource.newInstance(1024 * (alloc[i] + i), (alloc[i] + i)),
        rAllocation.getResourcesAtTime(start + i));
  }
}
项目:aliyun-oss-hadoop-fs    文件:TestNoOverCommitPolicy.java   
@Test(expected = MismatchedUserException.class)
public void testUserMismatch() throws IOException, PlanningException {
  // generate allocation from single tenant that exceed capacity
  int[] f = generateData(3600, (int) (0.5 * totCont));
  ReservationDefinition rDef =
      ReservationSystemTestUtil.createSimpleReservationDefinition(
          initTime, initTime + f.length + 1, f.length);
  ReservationId rid = ReservationSystemTestUtil.getNewReservationId();

  plan.addReservation(new InMemoryReservationAllocation(rid, rDef, "u1",
      "dedicated", initTime, initTime + f.length, ReservationSystemTestUtil
          .generateAllocation(initTime, step, f), res, minAlloc), false);

  // trying to update a reservation with a mismatching user
  plan.updateReservation(new InMemoryReservationAllocation(rid, rDef, "u2",
      "dedicated", initTime, initTime + f.length, ReservationSystemTestUtil
          .generateAllocation(initTime, step, f), res, minAlloc));
}
项目:aliyun-oss-hadoop-fs    文件:TestNoOverCommitPolicy.java   
@Test(expected = ResourceOverCommitException.class)
public void testMultiTenantFail() throws IOException, PlanningException {
  // generate allocation from multiple tenants that exceed tot capacity
  int[] f = generateData(3600, (int) Math.ceil(0.25 * totCont));
  ReservationDefinition rDef =
      ReservationSystemTestUtil.createSimpleReservationDefinition(
          initTime, initTime + f.length + 1, f.length);
  for (int i = 0; i < 5; i++) {
    assertTrue(plan.toString(),
        plan.addReservation(new InMemoryReservationAllocation(
            ReservationSystemTestUtil.getNewReservationId(), rDef, "u" + i,
            "dedicated", initTime, initTime + f.length,
            ReservationSystemTestUtil.generateAllocation(initTime, step, f),
            res, minAlloc), false));
  }
}
项目:hadoop    文件:ReservationSubmissionRequestPBImpl.java   
@Override
public ReservationDefinition getReservationDefinition() {
  ReservationSubmissionRequestProtoOrBuilder p = viaProto ? proto : builder;
  if (reservationDefinition != null) {
    return reservationDefinition;
  }
  if (!p.hasReservationDefinition()) {
    return null;
  }
  reservationDefinition =
      convertFromProtoFormat(p.getReservationDefinition());
  return reservationDefinition;
}
项目:hadoop    文件:ReservationSubmissionRequestPBImpl.java   
@Override
public void setReservationDefinition(
    ReservationDefinition reservationDefinition) {
  maybeInitBuilder();
  if (reservationDefinition == null) {
    builder.clearReservationDefinition();
  }
  this.reservationDefinition = reservationDefinition;
}
项目:hadoop    文件:ReservationUpdateRequestPBImpl.java   
@Override
public ReservationDefinition getReservationDefinition() {
  ReservationUpdateRequestProtoOrBuilder p = viaProto ? proto : builder;
  if (reservationDefinition != null) {
    return reservationDefinition;
  }
  if (!p.hasReservationDefinition()) {
    return null;
  }
  reservationDefinition =
      convertFromProtoFormat(p.getReservationDefinition());
  return reservationDefinition;
}
项目:hadoop    文件:ReservationUpdateRequestPBImpl.java   
@Override
public void setReservationDefinition(
    ReservationDefinition reservationDefinition) {
  maybeInitBuilder();
  if (reservationDefinition == null) {
    builder.clearReservationDefinition();
  }
  this.reservationDefinition = reservationDefinition;
}
项目:hadoop    文件:ClientRMService.java   
private void refreshScheduler(String planName,
    ReservationDefinition contract, String reservationId) {
  if ((contract.getArrival() - clock.getTime()) < reservationSystem
      .getPlanFollowerTimeStep()) {
    LOG.debug(MessageFormat
        .format(
            "Reservation {0} is within threshold so attempting to create synchronously.",
            reservationId));
    reservationSystem.synchronizePlan(planName);
    LOG.info(MessageFormat.format("Created reservation {0} synchronously.",
        reservationId));
  }
}
项目:hadoop    文件:TestInMemoryReservationAllocation.java   
private void doAssertions(ReservationAllocation rAllocation,
    ReservationId reservationID, ReservationDefinition rDef,
    Map<ReservationInterval, ReservationRequest> allocations, int start,
    int[] alloc) {
  Assert.assertEquals(reservationID, rAllocation.getReservationId());
  Assert.assertEquals(rDef, rAllocation.getReservationDefinition());
  Assert.assertEquals(allocations, rAllocation.getAllocationRequests());
  Assert.assertEquals(user, rAllocation.getUser());
  Assert.assertEquals(planName, rAllocation.getPlanName());
  Assert.assertEquals(start, rAllocation.getStartTime());
  Assert.assertEquals(start + alloc.length + 1, rAllocation.getEndTime());
}
项目:hadoop    文件:TestInMemoryReservationAllocation.java   
private ReservationDefinition createSimpleReservationDefinition(long arrival,
    long deadline, long duration) {
  // create a request with a single atomic ask
  ReservationRequest r =
      ReservationRequest.newInstance(Resource.newInstance(1024, 1, 1), 1, 1,
          duration);
  ReservationDefinition rDef = new ReservationDefinitionPBImpl();
  ReservationRequests reqs = new ReservationRequestsPBImpl();
  reqs.setReservationResources(Collections.singletonList(r));
  reqs.setInterpreter(ReservationRequestInterpreter.R_ALL);
  rDef.setReservationRequests(reqs);
  rDef.setArrival(arrival);
  rDef.setDeadline(deadline);
  return rDef;
}
项目:hadoop    文件:TestGreedyReservationAgent.java   
@SuppressWarnings("javadoc")
@Test
public void testSimple() throws PlanningException {

  prepareBasicPlan();

  // create a request with a single atomic ask
  ReservationDefinition rr = new ReservationDefinitionPBImpl();
  rr.setArrival(5 * step);
  rr.setDeadline(20 * step);
  ReservationRequest r = ReservationRequest.newInstance(
      Resource.newInstance(2048, 2, 2), 10, 5, 10 * step);
  ReservationRequests reqs = new ReservationRequestsPBImpl();
  reqs.setReservationResources(Collections.singletonList(r));
  rr.setReservationRequests(reqs);

  ReservationId reservationID = ReservationSystemTestUtil
      .getNewReservationId();
  agent.createReservation(reservationID, "u1", plan, rr);

  assertTrue("Agent-based allocation failed", reservationID != null);
  assertTrue("Agent-based allocation failed", plan.getAllReservations()
      .size() == 3);

  ReservationAllocation cs = plan.getReservationById(reservationID);

  System.out.println("--------AFTER SIMPLE ALLOCATION (queue: "
      + reservationID + ")----------");
  System.out.println(plan.toString());
  System.out.println(plan.toCumulativeString());

  for (long i = 10 * step; i < 20 * step; i++) {
    assertTrue(
        "Agent-based allocation unexpected",
        Resources.equals(cs.getResourcesAtTime(i),
            Resource.newInstance(2048 * 10, 2 * 10, 2 * 10)));
  }

}
项目:hadoop    文件:TestGreedyReservationAgent.java   
@Test
public void testSingleSliding() throws PlanningException {
  prepareBasicPlan();

  // create a single request for which we need subsequent (tight) packing.
  ReservationDefinition rr = new ReservationDefinitionPBImpl();
  rr.setArrival(100 * step);
  rr.setDeadline(120 * step);
  ReservationRequests reqs = new ReservationRequestsPBImpl();
  reqs.setInterpreter(ReservationRequestInterpreter.R_ALL);
  ReservationRequest r = ReservationRequest.newInstance(
      Resource.newInstance(1024, 1, 1), 200, 10, 10 * step);

  List<ReservationRequest> list = new ArrayList<ReservationRequest>();
  list.add(r);
  reqs.setReservationResources(list);
  rr.setReservationRequests(reqs);

  // submit to agent
  ReservationId reservationID = ReservationSystemTestUtil
      .getNewReservationId();
  agent.createReservation(reservationID, "u1", plan, rr);

  // validate results, we expect the second one to be accepted
  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, 100 * step, 120 * step, 100, 1024, 1));

  System.out.println("--------AFTER packed ALLOCATION (queue: "
      + reservationID + ")----------");
  System.out.println(plan.toString());
  System.out.println(plan.toCumulativeString());

}
项目:hadoop    文件:ReservationSystemTestUtil.java   
public static ReservationDefinition generateRandomRR(Random rand, long i) {
  rand.setSeed(i);
  long now = System.currentTimeMillis();

  // start time at random in the next 12 hours
  long arrival = rand.nextInt(12 * 3600 * 1000);
  // deadline at random in the next day
  long deadline = arrival + rand.nextInt(24 * 3600 * 1000);

  // create a request with a single atomic ask
  ReservationDefinition rr = new ReservationDefinitionPBImpl();
  rr.setArrival(now + arrival);
  rr.setDeadline(now + deadline);

  int gang = 1 + rand.nextInt(9);
  int par = (rand.nextInt(1000) + 1) * gang;
  long dur = rand.nextInt(2 * 3600 * 1000); // random duration within 2h
  ReservationRequest r =
      ReservationRequest.newInstance(Resource.newInstance(1024, 1, 1), par,
          gang, dur);
  ReservationRequests reqs = new ReservationRequestsPBImpl();
  reqs.setReservationResources(Collections.singletonList(r));
  rand.nextInt(3);
  ReservationRequestInterpreter[] type =
      ReservationRequestInterpreter.values();
  reqs.setInterpreter(type[rand.nextInt(type.length)]);
  rr.setReservationRequests(reqs);

  return rr;

}
项目:hadoop    文件:ReservationSystemTestUtil.java   
public static ReservationDefinition generateBigRR(Random rand, long i) {
  rand.setSeed(i);
  long now = System.currentTimeMillis();

  // start time at random in the next 2 hours
  long arrival = rand.nextInt(2 * 3600 * 1000);
  // deadline at random in the next day
  long deadline = rand.nextInt(24 * 3600 * 1000);

  // create a request with a single atomic ask
  ReservationDefinition rr = new ReservationDefinitionPBImpl();
  rr.setArrival(now + arrival);
  rr.setDeadline(now + deadline);

  int gang = 1;
  int par = 100000; // 100k tasks
  long dur = rand.nextInt(60 * 1000); // 1min tasks
  ReservationRequest r =
      ReservationRequest.newInstance(Resource.newInstance(1024, 1, 1), par,
          gang, dur);
  ReservationRequests reqs = new ReservationRequestsPBImpl();
  reqs.setReservationResources(Collections.singletonList(r));
  rand.nextInt(3);
  ReservationRequestInterpreter[] type =
      ReservationRequestInterpreter.values();
  reqs.setInterpreter(type[rand.nextInt(type.length)]);
  rr.setReservationRequests(reqs);

  return rr;
}