use of org.apache.heron.spi.packing.InstanceId in project heron by twitter.
the class PackingTestHelper method toContainerIdComponentNames.
public static Pair<Integer, String>[] toContainerIdComponentNames(Pair<Integer, InstanceId>[] containerIdInstanceIds) {
@SuppressWarnings({ "unchecked", "rawtypes" }) Pair<Integer, String>[] containerIdComponentNames = new Pair[containerIdInstanceIds.length];
int i = 0;
for (Pair<Integer, InstanceId> containerIdInstanceId : containerIdInstanceIds) {
containerIdComponentNames[i++] = new Pair<>(containerIdInstanceId.first, containerIdInstanceId.second.getComponentName());
}
return containerIdComponentNames;
}
use of org.apache.heron.spi.packing.InstanceId 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 org.apache.heron.spi.packing.InstanceId in project heron by twitter.
the class PackingPlanBuilderTest method testGetContainers.
/**
* Tests the getContainers method.
*/
@Test
public void testGetContainers() {
Resource padding = new Resource(1.0, ByteAmount.fromGigabytes(1), ByteAmount.fromGigabytes(1));
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, packingPlan.getMaxContainerResources(), padding, new HashMap<String, TreeSet<Integer>>(), new TreeSet<Integer>());
assertEquals(packing.size(), containers.size());
for (Integer containerId : packing.keySet()) {
Container foundContainer = containers.get(containerId);
assertEquals(padding, foundContainer.getPadding());
assertEquals(packingPlan.getMaxContainerResources(), foundContainer.getCapacity());
assertEquals(2, foundContainer.getInstances().size());
}
}
use of org.apache.heron.spi.packing.InstanceId in project heron by twitter.
the class PackingPlanBuilderTest method testExceededCapacityAddingToPackingPlan.
@Test(expected = ResourceExceededException.class)
public void testExceededCapacityAddingToPackingPlan() throws ConstraintViolationException {
PackingPlan plan = doCreatePackingPlanTest(testContainerInstances);
@SuppressWarnings({ "unchecked", "rawtypes" }) Pair<Integer, InstanceId>[] added = new Pair[] { new Pair<>(3, new InstanceId("componentB", 4, 1)), new Pair<>(3, new InstanceId("componentB", 5, 2)) };
PackingTestHelper.addToTestPackingPlan(TOPOLOGY_ID, plan, PackingTestHelper.toContainerIdComponentNames(added), 0);
}
use of org.apache.heron.spi.packing.InstanceId in project heron by twitter.
the class ResourceCompliantRRPackingTest method testScaleDownHomogenousFirst.
@Test
public void testScaleDownHomogenousFirst() throws Exception {
@SuppressWarnings({ "unchecked", "rawtypes" }) Pair<Integer, InstanceId>[] initialComponentInstances = new Pair[] { new Pair<>(1, new InstanceId(SPOUT_NAME, 1, 0)), new Pair<>(1, new InstanceId(SPOUT_NAME, 2, 1)), new Pair<>(1, new InstanceId(BOLT_NAME, 3, 0)), new Pair<>(3, new InstanceId(BOLT_NAME, 4, 1)), new Pair<>(3, new InstanceId(BOLT_NAME, 5, 2)), new Pair<>(3, new InstanceId(BOLT_NAME, 6, 3)), new Pair<>(3, new InstanceId(BOLT_NAME, 7, 4)) };
Map<String, Integer> componentChanges = new HashMap<>();
componentChanges.put(BOLT_NAME, -4);
@SuppressWarnings({ "unchecked", "rawtypes" }) Pair<Integer, InstanceId>[] expectedComponentInstances = new Pair[] { new Pair<>(1, new InstanceId(SPOUT_NAME, 1, 0)), new Pair<>(1, new InstanceId(SPOUT_NAME, 2, 1)), new Pair<>(1, new InstanceId(BOLT_NAME, 3, 0)) };
doScaleDownTest(initialComponentInstances, componentChanges, expectedComponentInstances);
}
Aggregations