use of org.apache.heron.packing.constraints.ResourceConstraint in project heron by twitter.
the class PackingTestHelper method generateTestPackingPlan.
/**
* Returns a PackingPlan to use for testing scale up/down that has instances of specific
* components on specific containers.
*/
private static PackingPlan generateTestPackingPlan(String topologyName, PackingPlan previousPackingPlan, Pair<Integer, String>[] addInstances, Pair<Integer, String>[] removeInstances, int containerPadding) throws ConstraintViolationException {
PackingPlanBuilder builder = new PackingPlanBuilder(topologyName, previousPackingPlan);
int instanceCount = 0;
if (previousPackingPlan != null) {
instanceCount = previousPackingPlan.getInstanceCount();
} else if (addInstances != null) {
instanceCount = addInstances.length;
}
// use basic default resource to allow all instances to fit on a single container, if that's
// what the tester desired. We can extend this to permit passing custom resource requirements
// as needed.
Resource defaultInstanceResource = new Resource(1, ByteAmount.fromMegabytes(192), ByteAmount.fromMegabytes(1));
Map<String, Resource> componentResourceMap = PackingUtils.getComponentResourceMap(toParallelismMap(previousPackingPlan, addInstances, removeInstances).keySet(), new HashMap<>(), new HashMap<>(), new HashMap<>(), defaultInstanceResource);
builder.setDefaultInstanceResource(defaultInstanceResource);
builder.setRequestedComponentResource(componentResourceMap);
builder.setMaxContainerResource(new Resource(instanceCount, ByteAmount.fromMegabytes(192).multiply(instanceCount), ByteAmount.fromMegabytes(instanceCount)));
builder.setInstanceConstraints(Collections.singletonList(new MinRamConstraint()));
builder.setPackingConstraints(Collections.singletonList(new ResourceConstraint()));
if (addInstances != null) {
for (Pair<Integer, String> componentInstance : addInstances) {
builder.addInstance(componentInstance.first, componentInstance.second);
}
}
if (removeInstances != null) {
for (Pair<Integer, String> componentInstance : removeInstances) {
builder.removeInstance(componentInstance.first, componentInstance.second);
}
}
return builder.build();
}
Aggregations