Search in sources :

Example 46 with ByteAmount

use of com.twitter.heron.common.basics.ByteAmount 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)

Example 47 with ByteAmount

use of com.twitter.heron.common.basics.ByteAmount in project heron by twitter.

the class TopologyUtilsTest method testGetComponentRamMapAllRamSpecified.

@Test
public void testGetComponentRamMapAllRamSpecified() {
    int componentParallelism = 2;
    Config topologyConfig = new Config();
    Map<String, Integer> spouts = new HashMap<>();
    spouts.put("spout", componentParallelism);
    Map<String, Integer> bolts = new HashMap<>();
    bolts.put("bolt", componentParallelism);
    ByteAmount boltRam = ByteAmount.fromGigabytes(1);
    ByteAmount spoutRam = ByteAmount.fromGigabytes(2);
    topologyConfig.setComponentRam("spout", spoutRam);
    topologyConfig.setComponentRam("bolt", boltRam);
    // sort the component ram map
    Map<String, ByteAmount> ramMap = new TreeMap<>(TopologyUtils.getComponentRamMapConfig(TopologyTests.createTopology("test", topologyConfig, spouts, bolts)));
    Assert.assertArrayEquals(new String[] { "bolt", "spout" }, ramMap.keySet().toArray());
    Assert.assertArrayEquals(new ByteAmount[] { boltRam, spoutRam }, ramMap.values().toArray());
}
Also used : ByteAmount(com.twitter.heron.common.basics.ByteAmount) HashMap(java.util.HashMap) Config(com.twitter.heron.api.Config) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 48 with ByteAmount

use of com.twitter.heron.common.basics.ByteAmount in project heron by twitter.

the class PackingPlan method getMaxContainerResources.

/**
   * Computes the maximum of all the resources required by the containers in the packing plan. If
   * the PackingPlan has already been scheduled, the scheduled resources will be used over the
   * required resources.
   *
   * @return maximum Resources found in all containers.
   */
public Resource getMaxContainerResources() {
    double maxCpu = 0;
    ByteAmount maxRam = ByteAmount.ZERO;
    ByteAmount maxDisk = ByteAmount.ZERO;
    for (ContainerPlan containerPlan : getContainers()) {
        Resource containerResource = containerPlan.getScheduledResource().or(containerPlan.getRequiredResource());
        maxCpu = Math.max(maxCpu, containerResource.getCpu());
        maxRam = maxRam.max(containerResource.getRam());
        maxDisk = maxDisk.max(containerResource.getDisk());
    }
    return new Resource(maxCpu, maxRam, maxDisk);
}
Also used : ByteAmount(com.twitter.heron.common.basics.ByteAmount)

Example 49 with ByteAmount

use of com.twitter.heron.common.basics.ByteAmount in project heron by twitter.

the class Resource method plus.

/**
   * Adds a given resource from the current resource.
   */
public Resource plus(Resource other) {
    double totalCpu = this.getCpu() + other.getCpu();
    ByteAmount totalRam = this.getRam().plus(other.getRam());
    ByteAmount totalDisk = this.getDisk().plus(other.getDisk());
    return new Resource(totalCpu, totalRam, totalDisk);
}
Also used : ByteAmount(com.twitter.heron.common.basics.ByteAmount)

Example 50 with ByteAmount

use of com.twitter.heron.common.basics.ByteAmount in project heron by twitter.

the class Resource method subtractAbsolute.

/**
   * Subtracts a given resource from the current resource. The results is never negative.
   */
public Resource subtractAbsolute(Resource other) {
    double cpuDifference = this.getCpu() - other.getCpu();
    double extraCpu = Math.max(0, cpuDifference);
    ByteAmount ramDifference = this.getRam().minus(other.getRam());
    ByteAmount extraRam = ByteAmount.ZERO.max(ramDifference);
    ByteAmount diskDifference = this.getDisk().minus(other.getDisk());
    ByteAmount extraDisk = ByteAmount.ZERO.max(diskDifference);
    return new Resource(extraCpu, extraRam, extraDisk);
}
Also used : ByteAmount(com.twitter.heron.common.basics.ByteAmount)

Aggregations

ByteAmount (com.twitter.heron.common.basics.ByteAmount)50 PackingPlan (com.twitter.heron.spi.packing.PackingPlan)30 Test (org.junit.Test)30 TopologyAPI (com.twitter.heron.api.generated.TopologyAPI)27 Resource (com.twitter.heron.spi.packing.Resource)14 HashMap (java.util.HashMap)13 HashSet (java.util.HashSet)7 Config (com.twitter.heron.spi.common.Config)4 Config (com.twitter.heron.api.Config)3 InstanceId (com.twitter.heron.spi.packing.InstanceId)3 ArrayList (java.util.ArrayList)3 TreeMap (java.util.TreeMap)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Map (java.util.Map)2 EvaluatorRequest (org.apache.reef.driver.evaluator.EvaluatorRequest)2 RamRequirement (com.twitter.heron.packing.RamRequirement)1 ResourceExceededException (com.twitter.heron.packing.ResourceExceededException)1 PackingPlanBuilder (com.twitter.heron.packing.builder.PackingPlanBuilder)1 BaseContainer (com.twitter.heron.scheduler.mesos.framework.BaseContainer)1 PackingException (com.twitter.heron.spi.packing.PackingException)1