NMTaskFactory extends TaskFactory { @Inject NMTaskFactory(MyriadConfiguration cfg, TaskUtils taskUtils, ExecutorCommandLineGenerator clGenerator) { super(cfg, taskUtils, clGenerator); } @Inject  NMTaskFactory(MyriadConfiguration cfg, TaskUtils taskUtils, ExecutorCommandLineGenerator clGenerator); @Override Protos.TaskInfo createTask(ResourceOfferContainer resourceOfferContainer, Protos.FrameworkID frameworkId, Protos.TaskID taskId, NodeTask nodeTask); @Override Protos.ExecutorInfo getExecutorInfoForSlave(ResourceOfferContainer resourceOfferContainer, Protos.FrameworkID frameworkId, Protos.CommandInfo commandInfo);  }
@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()); }