Search in sources :

Example 1 with BaseContainer

use of org.apache.heron.scheduler.mesos.framework.BaseContainer in project heron by twitter.

the class MesosScheduler method getBaseContainer.

/**
 * Get BaseContainer info.
 *
 * @param containerIndex container index to start
 * @param packing the PackingPlan
 * @return BaseContainer Info
 */
protected BaseContainer getBaseContainer(Integer containerIndex, PackingPlan packing) {
    BaseContainer container = new BaseContainer();
    container.name = TaskUtils.getTaskNameForContainerIndex(containerIndex);
    container.runAsUser = Context.role(config);
    container.description = String.format("Container %d for topology %s", containerIndex, Context.topologyName(config));
    // Fill in the resources requirement for this container
    fillResourcesRequirementForBaseContainer(container, containerIndex, packing);
    // Force running as shell
    container.shell = true;
    // Infinite retries
    container.retries = Integer.MAX_VALUE;
    // The dependencies for the container
    container.dependencies = new ArrayList<>();
    String topologyPath = Runtime.schedulerProperties(runtime).getProperty(Key.TOPOLOGY_PACKAGE_URI.value());
    String heronCoreReleasePath = Context.corePackageUri(config);
    container.dependencies.add(topologyPath);
    container.dependencies.add(heronCoreReleasePath);
    return container;
}
Also used : BaseContainer(org.apache.heron.scheduler.mesos.framework.BaseContainer)

Example 2 with BaseContainer

use of org.apache.heron.scheduler.mesos.framework.BaseContainer in project heron by twitter.

the class MesosSchedulerTest method before.

@Before
public void before() throws Exception {
    Config config = Mockito.mock(Config.class);
    Mockito.when(config.getStringValue(Key.TOPOLOGY_NAME)).thenReturn(TOPOLOGY_NAME);
    Mockito.when(config.getStringValue(Key.ROLE)).thenReturn(ROLE);
    Mockito.when(config.getStringValue(Key.CORE_PACKAGE_URI)).thenReturn(CORE_PACKAGE_URI);
    Config runtime = Mockito.mock(Config.class);
    Mockito.when(runtime.getLongValue(Key.NUM_CONTAINERS)).thenReturn(NUM_CONTAINER);
    Properties properties = new Properties();
    properties.put(Key.TOPOLOGY_PACKAGE_URI.value(), TOPOLOGY_PACKAGE_URI);
    Mockito.when(runtime.get(Key.SCHEDULER_PROPERTIES)).thenReturn(properties);
    mesosFramework = Mockito.mock(MesosFramework.class);
    SchedulerDriver driver = Mockito.mock(SchedulerDriver.class);
    baseContainer = Mockito.mock(BaseContainer.class);
    scheduler = Mockito.spy(MesosScheduler.class);
    Mockito.doReturn(mesosFramework).when(scheduler).getMesosFramework();
    Mockito.doReturn(driver).when(scheduler).getSchedulerDriver(Mockito.anyString(), Mockito.eq(mesosFramework));
    Mockito.doNothing().when(scheduler).startSchedulerDriver();
    scheduler.initialize(config, runtime);
}
Also used : BaseContainer(org.apache.heron.scheduler.mesos.framework.BaseContainer) MesosFramework(org.apache.heron.scheduler.mesos.framework.MesosFramework) Config(org.apache.heron.spi.common.Config) Properties(java.util.Properties) SchedulerDriver(org.apache.mesos.SchedulerDriver) Before(org.junit.Before)

Example 3 with BaseContainer

use of org.apache.heron.scheduler.mesos.framework.BaseContainer 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.ExecutorPort.getRequiredPorts().size(), 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(org.apache.heron.common.basics.ByteAmount) PackingPlan(org.apache.heron.spi.packing.PackingPlan) Resource(org.apache.heron.spi.packing.Resource) BaseContainer(org.apache.heron.scheduler.mesos.framework.BaseContainer) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

BaseContainer (org.apache.heron.scheduler.mesos.framework.BaseContainer)3 HashSet (java.util.HashSet)1 Properties (java.util.Properties)1 ByteAmount (org.apache.heron.common.basics.ByteAmount)1 MesosFramework (org.apache.heron.scheduler.mesos.framework.MesosFramework)1 Config (org.apache.heron.spi.common.Config)1 PackingPlan (org.apache.heron.spi.packing.PackingPlan)1 Resource (org.apache.heron.spi.packing.Resource)1 SchedulerDriver (org.apache.mesos.SchedulerDriver)1 Before (org.junit.Before)1 Test (org.junit.Test)1