use of com.twitter.heron.spi.packing.PackingPlan in project heron by twitter.
the class PackingPlanBuilderTest method generatePacking.
private static PackingPlan generatePacking(Map<Integer, List<InstanceId>> basePacking) throws RuntimeException {
Resource resource = new Resource(2.0, ByteAmount.fromGigabytes(6), ByteAmount.fromGigabytes(25));
Set<PackingPlan.ContainerPlan> containerPlans = new HashSet<>();
for (int containerId : basePacking.keySet()) {
List<InstanceId> instanceList = basePacking.get(containerId);
Set<PackingPlan.InstancePlan> instancePlans = new HashSet<>();
for (InstanceId instanceId : instanceList) {
String componentName = instanceId.getComponentName();
Resource instanceResource;
switch(componentName) {
case "bolt":
instanceResource = new Resource(1.0, ByteAmount.fromGigabytes(2), ByteAmount.fromGigabytes(10));
break;
case "spout":
instanceResource = new Resource(1.0, ByteAmount.fromGigabytes(3), ByteAmount.fromGigabytes(10));
break;
default:
throw new RuntimeException(String.format("%s is not a valid component name", componentName));
}
instancePlans.add(new PackingPlan.InstancePlan(instanceId, instanceResource));
}
PackingPlan.ContainerPlan containerPlan = new PackingPlan.ContainerPlan(containerId, instancePlans, resource);
containerPlans.add(containerPlan);
}
return new PackingPlan("", containerPlans);
}
use of com.twitter.heron.spi.packing.PackingPlan in project heron by twitter.
the class PackingPlanBuilderTest method testRemoveFromPackingPlan.
@Test
public void testRemoveFromPackingPlan() throws ResourceExceededException {
PackingPlan plan = doCreatePackingPlanTest(testContainerInstances);
@SuppressWarnings({ "unchecked", "rawtypes" }) Pair<Integer, String>[] removed = new Pair[] { new Pair<>(1, "componentA"), new Pair<>(3, "componentA") };
PackingPlan updatedPlan = PackingTestHelper.removeFromTestPackingPlan(TOPOLOGY_ID, plan, removed, 0);
@SuppressWarnings({ "unchecked", "rawtypes" }) Pair<Integer, InstanceId>[] expected = new Pair[] { new Pair<>(3, new InstanceId("componentB", 3, 0)) };
AssertPacking.assertPackingPlan(TOPOLOGY_ID, expected, updatedPlan);
}
use of com.twitter.heron.spi.packing.PackingPlan in project heron by twitter.
the class PackingPlanBuilderTest method testGetContainers.
/**
* Tests the getContainers method.
*/
@Test
public void testGetContainers() throws ResourceExceededException {
int paddingPercentage = 10;
Map<Integer, List<InstanceId>> packing = new HashMap<>();
packing.put(7, Arrays.asList(new InstanceId("spout", 1, 0), new InstanceId("bolt", 2, 0)));
packing.put(3, Arrays.asList(new InstanceId("spout", 3, 0), new InstanceId("bolt", 4, 0)));
PackingPlan packingPlan = generatePacking(packing);
Map<Integer, Container> containers = PackingPlanBuilder.getContainers(packingPlan, paddingPercentage, new HashMap<String, TreeSet<Integer>>(), new TreeSet<Integer>());
assertEquals(packing.size(), containers.size());
for (Integer containerId : packing.keySet()) {
Container foundContainer = containers.get(containerId);
assertEquals(paddingPercentage, foundContainer.getPaddingPercentage());
assertEquals(packingPlan.getMaxContainerResources(), foundContainer.getCapacity());
assertEquals(2, foundContainer.getInstances().size());
}
}
use of com.twitter.heron.spi.packing.PackingPlan in project heron by twitter.
the class PackingPlanBuilderTest method testExceededCapacityAddingToPackingPlan.
@Test(expected = ResourceExceededException.class)
public void testExceededCapacityAddingToPackingPlan() throws ResourceExceededException {
PackingPlan plan = doCreatePackingPlanTest(testContainerInstances);
@SuppressWarnings({ "unchecked", "rawtypes" }) Pair<Integer, InstanceId>[] added = new Pair[] { new Pair<>(3, new InstanceId("componentB", 4, 1)) };
PackingTestHelper.addToTestPackingPlan(TOPOLOGY_ID, plan, PackingTestHelper.toContainerIdComponentNames(added), 0);
}
use of com.twitter.heron.spi.packing.PackingPlan in project heron by twitter.
the class PackingPlanBuilderTest method doCreatePackingPlanTest.
private static PackingPlan doCreatePackingPlanTest(Pair<Integer, InstanceId>[] instances) throws ResourceExceededException {
PackingPlan plan = PackingTestHelper.createTestPackingPlan(TOPOLOGY_ID, PackingTestHelper.toContainerIdComponentNames(instances), 0);
AssertPacking.assertPackingPlan(TOPOLOGY_ID, instances, plan);
return plan;
}
Aggregations