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));
}
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));
}
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());
}
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);
}
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);
}
Aggregations