/** * Get capacity at time based on periodic repetition. * * @param tick UTC time for which the allocated {@link Resource} is queried. * @return {@link Resource} allocated at specified time */ public Resource getCapacityAtTime(long tick) { long convertedTime = (tick % timePeriod); return super.getCapacityAtTime(convertedTime); }
protected Resource getLoadAtTime(long t, RLESparseResourceAllocation planLoads, RLESparseResourceAllocation planModifications) { Resource planLoad = planLoads.getCapacityAtTime(t); return Resources.add(planLoad, planModifications.getCapacityAtTime(t)); }
@Override public Resource getTotalCommittedResources(long t) { readLock.lock(); try { return rleSparseVector.getCapacityAtTime(t); } finally { readLock.unlock(); } }
@Override public Resource getTotalCommittedResources(long t) { readLock.lock(); try { return rleSparseVector.getCapacityAtTime(t); } finally { readLock.unlock(); } }
@Override public Resource getConsumptionForUser(String user, long t) { readLock.lock(); try { RLESparseResourceAllocation userResAlloc = userResourceAlloc.get(user); if (userResAlloc != null) { return userResAlloc.getCapacityAtTime(t); } else { return Resources.clone(ZERO_RESOURCE); } } finally { readLock.unlock(); } }
@Override public Resource getConsumptionForUser(String user, long t) { readLock.lock(); try { RLESparseResourceAllocation userResAlloc = userResourceAlloc.get(user); if (userResAlloc != null) { return userResAlloc.getCapacityAtTime(t); } else { return Resources.clone(ZERO_RESOURCE); } } finally { readLock.unlock(); } }
/** * Get maximum capacity at periodic offsets from the specified time. * * @param tick UTC time base from which offsets are specified for finding the * maximum capacity. * @param period periodic offset at which capacities are evaluated. * @return the maximum {@link Resource} across the specified time instants. * @return true if removal is successful, false otherwise */ public Resource getMaximumPeriodicCapacity(long tick, long period) { Resource maxResource; if (period < timePeriod) { maxResource = super.getMaximumPeriodicCapacity(tick % timePeriod, period); } else { // if period is greater than the length of PeriodicRLESparseAllocation, // only a single value exists in this interval. maxResource = super.getCapacityAtTime(tick % timePeriod); } return maxResource; }
@Override public Resource getTotalCommittedResources(long t) { readLock.lock(); try { return Resources.add(rleSparseVector.getCapacityAtTime(t), periodicRle.getCapacityAtTime(t)); } finally { readLock.unlock(); } }
@Override public Resource getResourcesAtTime(long tick) { if (tick < startTime || tick >= endTime) { return Resource.newInstance(0, 0); } return Resources.clone(resourcesOverTime.getCapacityAtTime(tick)); }
@Override public Resource getResourcesAtTime(long tick) { if (tick < startTime || tick >= endTime) { return Resource.newInstance(0, 0); } return Resources.clone(resourcesOverTime.getCapacityAtTime(tick)); }
@Override public Resource getResourcesAtTime(long tick) { if (tick < startTime || tick >= endTime) { return Resource.newInstance(0, 0); } return Resources.clone(resourcesOverTime.getCapacityAtTime(tick)); }
merged.getCapacityAtTime(2L)); Assert.assertEquals(Resource.newInstance(0, 0), merged.getCapacityAtTime(3L)); Assert.assertEquals(Resource.newInstance(2, 2), merged.getCapacityAtTime(11L)); Assert.assertEquals(Resource.newInstance(15, 15), merged.getCapacityAtTime(12L)); Assert.assertEquals(Resource.newInstance(10, 10), merged.getCapacityAtTime(13L)); Assert.assertEquals(Resource.newInstance(0, 0), merged.getCapacityAtTime(14L)); Assert.assertEquals(Resource.newInstance(2, 2), merged.getCapacityAtTime(21L)); Assert.assertEquals(Resource.newInstance(5, 5), merged.getCapacityAtTime(22L)); Assert.assertEquals(Resource.newInstance(0, 0), merged.getCapacityAtTime(23L));
Assert.assertFalse(rleSparseVector.isEmpty()); Assert.assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(99)); Assert.assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(start + alloc.length + 1)); for (int i = 0; i < alloc.length; i++) { Assert.assertEquals( Resource.newInstance(1024 * (alloc[i] + i), (alloc[i] + i)), rleSparseVector.getCapacityAtTime(start + i)); rleSparseVector.getCapacityAtTime(start + alloc.length + 2)); for (Entry<ReservationInterval, Resource> ip : inputs) { rleSparseVector.removeInterval(ip.getKey(), ip.getValue()); for (int i = 0; i < alloc.length; i++) { Assert.assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(start + i));
Assert.assertFalse(rleSparseVector.isEmpty()); Assert.assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(99)); Assert.assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(start + alloc.length + 1)); for (int i = 0; i < alloc.length; i++) { Assert.assertEquals(Resource.newInstance(1024 * (alloc[i]), (alloc[i])), rleSparseVector.getCapacityAtTime(start + i)); rleSparseVector.getCapacityAtTime(start + alloc.length + 2)); for (Entry<ReservationInterval, Resource> ip : inputs) { rleSparseVector.removeInterval(ip.getKey(), ip.getValue()); for (int i = 0; i < alloc.length; i++) { Assert.assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(start + i));
Assert.assertFalse(rleSparseVector.isEmpty()); Assert.assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(99)); Assert.assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(start + alloc.length + 1)); for (int i = 0; i < alloc.length; i++) { Assert.assertEquals( Resource.newInstance(1024 * (alloc[i] + i), (alloc[i] + i)), rleSparseVector.getCapacityAtTime(start + i)); rleSparseVector.getCapacityAtTime(start + alloc.length + 2)); for (Entry<ReservationInterval, Resource> ip : inputs) { rleSparseVector.removeInterval(ip.getKey(), ip.getValue()); for (int i = 0; i < alloc.length; i++) { Assert.assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(start + i));
@Test public void testZeroAllocation() { ResourceCalculator resCalc = new DefaultResourceCalculator(); RLESparseResourceAllocation rleSparseVector = new RLESparseResourceAllocation(resCalc); rleSparseVector.addInterval(new ReservationInterval(0, Long.MAX_VALUE), Resource.newInstance(0, 0)); LOG.info(rleSparseVector.toString()); Assert.assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(new Random().nextLong())); Assert.assertTrue(rleSparseVector.isEmpty()); }
Assert.assertFalse(rleSparseVector.isEmpty()); Assert.assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(99)); Assert.assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(start + alloc.length + 1)); for (int i = 0; i < alloc.length; i++) { Assert.assertEquals(Resource.newInstance(1024 * (alloc[i]), (alloc[i])), rleSparseVector.getCapacityAtTime(start + i)); rleSparseVector.getCapacityAtTime(start + alloc.length + 2)); for (Entry<ReservationInterval, ReservationRequest> ip : inputs) { rleSparseVector.removeInterval(ip.getKey(), ip.getValue()); for (int i = 0; i < alloc.length; i++) { Assert.assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(start + i));
@Test public void testZeroAlloaction() { ResourceCalculator resCalc = new DefaultResourceCalculator(); Resource minAlloc = Resource.newInstance(1, 1); RLESparseResourceAllocation rleSparseVector = new RLESparseResourceAllocation(resCalc, minAlloc); rleSparseVector.addInterval(new ReservationInterval(0, Long.MAX_VALUE), ReservationRequest.newInstance(Resource.newInstance(0, 0), (0))); LOG.info(rleSparseVector.toString()); Assert.assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(new Random().nextLong())); Assert.assertTrue(rleSparseVector.isEmpty()); }
private void checkAllocation(Plan plan, int[] alloc, int start, long periodicity) { long end = start + alloc.length; if (periodicity > 0) { end = end + maxPeriodicity; } RLESparseResourceAllocation userCons = plan.getConsumptionForUserOverTime(user, start, end * 3); for (int i = 0; i < alloc.length; i++) { // only one instance for non-periodic reservation if (periodicity <= 0) { assertEquals(Resource.newInstance(1024 * (alloc[i]), (alloc[i])), plan.getTotalCommittedResources(start + i)); assertEquals(Resource.newInstance(1024 * (alloc[i]), (alloc[i])), userCons.getCapacityAtTime(start + i)); } else { // periodic reservations should repeat long y = 0; Resource res = Resource.newInstance(1024 * (alloc[i]), (alloc[i])); while (y <= end * 2) { assertEquals("At time: " + start + i + y, res, plan.getTotalCommittedResources(start + i + y)); assertEquals(" At time: " + (start + i + y), res, userCons.getCapacityAtTime(start + i + y)); y = y + periodicity; } } } }
assertEquals(92160, available.getCapacityAtTime(130).getMemorySize()); assertEquals(92160, available.getCapacityAtTime(140).getMemorySize()); assertEquals(92160, available.getCapacityAtTime(150).getMemorySize());