Search in sources :

Example 1 with OfferBuilder

use of org.apache.myriad.scheduler.offer.OfferBuilder in project incubator-myriad by apache.

the class TestResourceOfferContainer method testResourceOfferContainerForAuxServiceWithOutRole.

@Test
public void testResourceOfferContainerForAuxServiceWithOutRole() {
    Protos.Offer offer = new OfferBuilder("test.com").addScalarResource("cpus", 2.0).addScalarResource("mem", 8000).addRangeResource("ports", 3500, 3600).build();
    Map<String, Long> ports = new HashMap<>(4);
    ports.put("test1.address", 0L);
    ports.put("test2.address", 0L);
    ports.put("test3.address", 0L);
    ports.put("test4.port", 3501L);
    ServiceResourceProfile profile = new ServiceResourceProfile("jobhistory", 2.0, 8000.0, ports);
    ResourceOfferContainer roc = new ResourceOfferContainer(offer, profile, null);
    assertTrue(roc.getHostName().equals("test.com"));
    assertTrue("Should be satisfied if offer contains request", roc.satisfies(profile));
}
Also used : Protos(org.apache.mesos.Protos) HashMap(java.util.HashMap) OfferBuilder(org.apache.myriad.scheduler.offer.OfferBuilder) ServiceResourceProfile(org.apache.myriad.scheduler.ServiceResourceProfile) Test(org.junit.Test)

Example 2 with OfferBuilder

use of org.apache.myriad.scheduler.offer.OfferBuilder in project incubator-myriad by apache.

the class TestResourceOfferContainer method testResourceOfferContainerForAuxServiceWithRole.

@Test
public void testResourceOfferContainerForAuxServiceWithRole() {
    Protos.Offer offer = new OfferBuilder("test.com").addScalarResource("cpus", 2.0).addScalarResource("mem", 8000).addScalarResource("cpus", "test", 4.0).addScalarResource("mem", "test", 32000.0).addRangeResource("ports", 3500, 3600).addRangeResource("ports", "test", 1500, 1600).build();
    Map<String, Long> ports = new HashMap<>(4);
    ports.put("test1.address", 0L);
    ports.put("test2.address", 0L);
    ports.put("test3.address", 1500L);
    ports.put("test4.port", 3501L);
    ServiceResourceProfile profile = new ServiceResourceProfile("jobhistory", 2.0, 8000.0, ports);
    ResourceOfferContainer roc = new ResourceOfferContainer(offer, profile, null);
    assertTrue(roc.getHostName().equals("test.com"));
    assertTrue("Should be satisfied if offer contains request", roc.satisfies(profile));
}
Also used : Protos(org.apache.mesos.Protos) HashMap(java.util.HashMap) OfferBuilder(org.apache.myriad.scheduler.offer.OfferBuilder) ServiceResourceProfile(org.apache.myriad.scheduler.ServiceResourceProfile) Test(org.junit.Test)

Example 3 with OfferBuilder

use of org.apache.myriad.scheduler.offer.OfferBuilder in project incubator-myriad by apache.

the class TestNMTaskFactory method testNMTaskFactory.

@Test
public void testNMTaskFactory() {
    NMExecutorCommandLineGenerator clGenerator = new NMExecutorCommandLineGenerator(cfgWithDocker);
    TaskUtils taskUtils = new TaskUtils(cfgWithDocker);
    Protos.Offer offer = new OfferBuilder("test.com").addScalarResource("cpus", 10.0).addScalarResource("mem", 16000).addRangeResource("ports", 3500, 3505).build();
    ServiceResourceProfile profile = new ExtendedResourceProfile(new NMProfile("tooMuchCpu", 7L, 8000L), taskUtils.getNodeManagerCpus(), taskUtils.getNodeManagerMemory(), taskUtils.getNodeManagerPorts());
    NodeTask nodeTask = new NodeTask(profile, null);
    ResourceOfferContainer roc = new ResourceOfferContainer(offer, profile, null);
    NMTaskFactory taskFactory = new NMTaskFactory(cfgWithDocker, taskUtils, clGenerator);
    Protos.TaskInfo taskInfo = taskFactory.createTask(roc, frameworkId, makeTaskId("nm.zero"), nodeTask);
    assertFalse("taskInfo should not have a container", taskInfo.hasContainer());
    assertTrue("The container should have an executor", taskInfo.hasExecutor());
    Protos.ExecutorInfo executorInfo = taskInfo.getExecutor();
    assertTrue("executorInfo should have container", executorInfo.hasContainer());
    Protos.ContainerInfo containerInfo = executorInfo.getContainer();
    assertTrue("There should be two volumes", containerInfo.getVolumesCount() == 2);
    assertTrue("The first volume should be read only", containerInfo.getVolumes(0).getMode().equals(Protos.Volume.Mode.RO));
    assertTrue("The first volume should be read write", containerInfo.getVolumes(1).getMode().equals(Protos.Volume.Mode.RW));
    assertTrue("There should be a docker image", containerInfo.getDocker().hasImage());
    assertTrue("The docker image should be mesos/myraid", containerInfo.getDocker().getImage().equals("mesos/myriad"));
    assertTrue("Should be using host networking", containerInfo.getDocker().getNetwork().equals(Protos.ContainerInfo.DockerInfo.Network.HOST));
    assertTrue("There should be two parameters", containerInfo.getDocker().getParametersList().size() == 2);
    assertTrue("Privledged mode should be false", !containerInfo.getDocker().getPrivileged());
}
Also used : OfferBuilder(org.apache.myriad.scheduler.offer.OfferBuilder) NodeTask(org.apache.myriad.state.NodeTask) ResourceOfferContainer(org.apache.myriad.scheduler.resource.ResourceOfferContainer) Protos(org.apache.mesos.Protos) Test(org.junit.Test) BaseConfigurableTest(org.apache.myriad.BaseConfigurableTest)

Example 4 with OfferBuilder

use of org.apache.myriad.scheduler.offer.OfferBuilder in project incubator-myriad by apache.

the class TestServiceTaskFactory method testServiceTaskFactory.

@Test
public void testServiceTaskFactory() {
    ServiceCommandLineGenerator clGenerator = new ServiceCommandLineGenerator(cfgWithDocker);
    TaskUtils taskUtils = new TaskUtils(cfgWithDocker);
    Protos.Offer offer = new OfferBuilder("test.com").addScalarResource("cpus", 10.0).addScalarResource("mem", 16000).addRangeResource("ports", 3400, 3410).build();
    Map<String, ServiceConfiguration> stringServiceConfigurationMap = cfgWithDocker.getServiceConfigurations();
    System.out.print(stringServiceConfigurationMap);
    ServiceConfiguration serviceConfiguration = cfgWithDocker.getServiceConfigurations().get("jobhistory");
    ServiceResourceProfile profile = new ServiceResourceProfile("jobhistory", serviceConfiguration.getCpus(), serviceConfiguration.getJvmMaxMemoryMB(), serviceConfiguration.getPorts());
    NodeTask nodeTask = new NodeTask(profile, null);
    nodeTask.setTaskPrefix("jobhistory");
    ResourceOfferContainer roc = new ResourceOfferContainer(offer, profile, null);
    System.out.print(roc.getPorts());
    ServiceTaskFactory taskFactory = new ServiceTaskFactory(cfgWithDocker, taskUtils, clGenerator);
    Protos.TaskInfo taskInfo = taskFactory.createTask(roc, frameworkId, makeTaskId("jobhistory"), nodeTask);
    assertTrue("taskInfo should have a container", taskInfo.hasContainer());
    assertFalse("The container should not have an executor", taskInfo.hasExecutor());
    Protos.ContainerInfo containerInfo = taskInfo.getContainer();
    assertTrue("There should be two volumes", containerInfo.getVolumesCount() == 2);
    assertTrue("The first volume should be read only", containerInfo.getVolumes(0).getMode().equals(Protos.Volume.Mode.RO));
    assertTrue("The first volume should be read write", containerInfo.getVolumes(1).getMode().equals(Protos.Volume.Mode.RW));
    assertTrue("There should be a docker image", containerInfo.getDocker().hasImage());
    assertTrue("The docker image should be mesos/myraid", containerInfo.getDocker().getImage().equals("mesos/myriad"));
    assertTrue("Should be using host networking", containerInfo.getDocker().getNetwork().equals(Protos.ContainerInfo.DockerInfo.Network.HOST));
    assertTrue("There should be two parameters", containerInfo.getDocker().getParametersList().size() == 2);
    assertTrue("Privledged mode should be false", containerInfo.getDocker().getPrivileged() == false);
}
Also used : OfferBuilder(org.apache.myriad.scheduler.offer.OfferBuilder) NodeTask(org.apache.myriad.state.NodeTask) ResourceOfferContainer(org.apache.myriad.scheduler.resource.ResourceOfferContainer) ServiceConfiguration(org.apache.myriad.configuration.ServiceConfiguration) Protos(org.apache.mesos.Protos) Test(org.junit.Test) BaseConfigurableTest(org.apache.myriad.BaseConfigurableTest)

Example 5 with OfferBuilder

use of org.apache.myriad.scheduler.offer.OfferBuilder in project incubator-myriad by apache.

the class TestResourceOfferContainer method testResouceOfferContainerForNMWithOutRole.

@Test
public void testResouceOfferContainerForNMWithOutRole() {
    Protos.Offer offer = new OfferBuilder("test.com").addScalarResource("cpus", 4.0).addScalarResource("mem", 8000).addRangeResource("ports", 3500, 3600).build();
    Map<String, Long> ports = new HashMap<>(4);
    ports.put("test1.address", 0L);
    ports.put("test2.address", 0L);
    ports.put("test3.address", 0L);
    ports.put("test4.port", 3501L);
    ServiceResourceProfile profile1 = new ExtendedResourceProfile(new NMProfile("small", 2L, 6000L), .2, 1024.0, ports);
    ResourceOfferContainer roc = new ResourceOfferContainer(offer, profile1, "");
    System.out.print(roc.getCpus());
    System.out.print(roc.getMem());
    System.out.print(roc.getPorts());
    assertTrue(roc.getHostName().equals("test.com"));
    assertTrue("Should be satisfied if offer contains request", roc.satisfies(profile1));
    ServiceResourceProfile profile2 = new ExtendedResourceProfile(new NMProfile("tooMuchCpu", 7L, 8000L), .2, 1024.0, ports);
    roc = new ResourceOfferContainer(offer, profile2, "");
    assertFalse("Should be unsatisfied if too much cpu requested", roc.satisfies(profile2));
    ServiceResourceProfile profile3 = new ExtendedResourceProfile(new NMProfile("tooMuchMem", 3L, 50000L), .2, 1024.0, ports);
    roc = new ResourceOfferContainer(offer, profile3, "");
    assertFalse("Should be unsatisfied if too much memory requested", roc.satisfies(profile3));
    ports.put("test.bad.address", 1500L);
    ServiceResourceProfile profile4 = new ExtendedResourceProfile(new NMProfile("portOutOfRange", 3L, 50000L), .2, 1024.0, ports);
    roc = new ResourceOfferContainer(offer, profile4, "");
    assertFalse("Should be unsatisfied if port not in range", roc.satisfies(profile4));
    List<Protos.Resource> resourcesCpu = roc.consumeCpus(3.0);
    assertTrue("Should get a list of resources of size 1", resourcesCpu.size() == 1.0);
    assertTrue("Cpus should be decreased", roc.getCpus() == 1.0);
    List<Protos.Resource> resourcesMem = roc.consumeMem(7000.0);
    assertTrue("Should get a list of resources of size 1", resourcesMem.size() == 1);
    assertTrue("Mem should be decreased", roc.getMem() == 1000.0);
}
Also used : ExtendedResourceProfile(org.apache.myriad.scheduler.ExtendedResourceProfile) HashMap(java.util.HashMap) OfferBuilder(org.apache.myriad.scheduler.offer.OfferBuilder) NMProfile(org.apache.myriad.scheduler.NMProfile) Protos(org.apache.mesos.Protos) ServiceResourceProfile(org.apache.myriad.scheduler.ServiceResourceProfile) Test(org.junit.Test)

Aggregations

Protos (org.apache.mesos.Protos)6 OfferBuilder (org.apache.myriad.scheduler.offer.OfferBuilder)6 Test (org.junit.Test)6 HashMap (java.util.HashMap)4 ServiceResourceProfile (org.apache.myriad.scheduler.ServiceResourceProfile)4 BaseConfigurableTest (org.apache.myriad.BaseConfigurableTest)2 ExtendedResourceProfile (org.apache.myriad.scheduler.ExtendedResourceProfile)2 NMProfile (org.apache.myriad.scheduler.NMProfile)2 ResourceOfferContainer (org.apache.myriad.scheduler.resource.ResourceOfferContainer)2 NodeTask (org.apache.myriad.state.NodeTask)2 ServiceConfiguration (org.apache.myriad.configuration.ServiceConfiguration)1