Search in sources :

Example 26 with Resource

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));
}
Also used : Config(com.twitter.heron.spi.common.Config) Resource(com.twitter.heron.spi.packing.Resource) Before(org.junit.Before)

Example 27 with Resource

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;
}
Also used : RamRequirement(com.twitter.heron.packing.RamRequirement) ByteAmount(com.twitter.heron.common.basics.ByteAmount) ArrayList(java.util.ArrayList) Resource(com.twitter.heron.spi.packing.Resource)

Example 28 with Resource

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);
}
Also used : ByteAmount(com.twitter.heron.common.basics.ByteAmount) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) Resource(com.twitter.heron.spi.packing.Resource) HashSet(java.util.HashSet)

Example 29 with 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));
}
Also used : ByteAmount(com.twitter.heron.common.basics.ByteAmount) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) Resource(com.twitter.heron.spi.packing.Resource) BaseContainer(com.twitter.heron.scheduler.mesos.framework.BaseContainer) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Resource (com.twitter.heron.spi.packing.Resource)29 ByteAmount (com.twitter.heron.common.basics.ByteAmount)14 PackingPlan (com.twitter.heron.spi.packing.PackingPlan)14 TopologyAPI (com.twitter.heron.api.generated.TopologyAPI)8 HashSet (java.util.HashSet)8 Test (org.junit.Test)7 Config (com.twitter.heron.spi.common.Config)5 ResourceExceededException (com.twitter.heron.packing.ResourceExceededException)4 InstanceId (com.twitter.heron.spi.packing.InstanceId)4 HashMap (java.util.HashMap)4 ArrayList (java.util.ArrayList)3 PackingPlanBuilder (com.twitter.heron.packing.builder.PackingPlanBuilder)2 Before (org.junit.Before)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 RamRequirement (com.twitter.heron.packing.RamRequirement)1 BaseContainer (com.twitter.heron.scheduler.mesos.framework.BaseContainer)1 PackingException (com.twitter.heron.spi.packing.PackingException)1