use of com.twitter.heron.spi.packing.Resource in project heron by twitter.
the class CommonPackingTests method setUp.
@Before
public void setUp() {
this.spoutParallelism = 4;
this.boltParallelism = 3;
this.totalInstances = this.spoutParallelism + this.boltParallelism;
// Set up the topology and its config. Tests can safely modify the config by reference after the
// topology is created, but those changes will not be reflected in the underlying protobuf
// object Config and Topology objects. This is typically fine for packing tests since they don't
// access the protobuf values.
this.topologyConfig = new com.twitter.heron.api.Config();
this.topology = getTopology(spoutParallelism, boltParallelism, topologyConfig);
Config config = PackingTestUtils.newTestConfig(this.topology);
this.instanceDefaultResources = new Resource(Context.instanceCpu(config), Context.instanceRam(config), Context.instanceDisk(config));
}
use of com.twitter.heron.spi.packing.Resource in project heron by twitter.
the class FirstFitDecreasingPacking method getSortedRAMInstances.
/**
* Sort the components in decreasing order based on their RAM requirements
*
* @return The sorted list of components and their RAM requirements
*/
private ArrayList<RamRequirement> getSortedRAMInstances(Set<String> componentNames) {
ArrayList<RamRequirement> ramRequirements = new ArrayList<>();
Map<String, ByteAmount> ramMap = TopologyUtils.getComponentRamMapConfig(topology);
for (String componentName : componentNames) {
Resource requiredResource = PackingUtils.getResourceRequirement(componentName, ramMap, this.defaultInstanceResources, this.maxContainerResources, this.paddingPercentage);
ramRequirements.add(new RamRequirement(componentName, requiredResource.getRam()));
}
Collections.sort(ramRequirements, Collections.reverseOrder());
return ramRequirements;
}
use of com.twitter.heron.spi.packing.Resource in project heron by twitter.
the class PackingTestUtils method testContainerPlan.
@SafeVarargs
public static PackingPlan.ContainerPlan testContainerPlan(int containerId, Pair<String, Integer>... instanceInfo) {
double cpu = 1.5;
ByteAmount ram = ByteAmount.fromGigabytes(1);
Set<PackingPlan.InstancePlan> instancePlans = new HashSet<>();
for (Pair<String, Integer> info : instanceInfo) {
PackingPlan.InstancePlan instance = testInstancePlan(info.first, info.second);
instancePlans.add(instance);
cpu += instance.getResource().getCpu();
ram = ram.plus(instance.getResource().getRam());
}
Resource resource = new Resource(cpu, ram, ram);
return new PackingPlan.ContainerPlan(containerId, instancePlans, resource);
}
use of com.twitter.heron.spi.packing.Resource in project heron by twitter.
the class MesosSchedulerTest method testGetBaseContainer.
@Test
public void testGetBaseContainer() throws Exception {
final double CPU = 0.5;
final ByteAmount MEM = ByteAmount.fromMegabytes(100);
final ByteAmount DISK = ByteAmount.fromMegabytes(100);
Resource containerResources = new Resource(CPU, MEM, DISK);
PackingPlan.ContainerPlan containerPlan = new PackingPlan.ContainerPlan(0, new HashSet<PackingPlan.InstancePlan>(), containerResources);
Set<PackingPlan.ContainerPlan> containerPlans = new HashSet<>();
containerPlans.add(containerPlan);
PackingPlan packingPlan = new PackingPlan(TOPOLOGY_NAME, containerPlans);
BaseContainer container = scheduler.getBaseContainer(0, packingPlan);
// Assert we have constructed the correct BaseContainer structure
Assert.assertEquals(ROLE, container.runAsUser);
Assert.assertEquals(CPU, container.cpu, 0.01);
Assert.assertEquals(MEM, ByteAmount.fromMegabytes(((Double) container.memInMB).longValue()));
Assert.assertEquals(DISK, ByteAmount.fromMegabytes(((Double) container.diskInMB).longValue()));
Assert.assertEquals(SchedulerUtils.PORTS_REQUIRED_FOR_EXECUTOR, container.ports);
Assert.assertEquals(2, container.dependencies.size());
Assert.assertTrue(container.dependencies.contains(CORE_PACKAGE_URI));
Assert.assertTrue(container.dependencies.contains(TOPOLOGY_PACKAGE_URI));
Assert.assertTrue(container.environmentVariables.isEmpty());
Assert.assertTrue(container.name.startsWith("container_0"));
// Convert to JSON
String str = container.toString();
String json = BaseContainer.getJobDefinitionInJSON(container);
Assert.assertEquals(json, str);
// Convert the JSON back to BaseContainer
BaseContainer newContainer = BaseContainer.getJobFromJSONString(json);
Assert.assertEquals(json, BaseContainer.getJobDefinitionInJSON(newContainer));
}
Aggregations