ServiceTaskFactory extends TaskFactory { @Inject ServiceTaskFactory(MyriadConfiguration cfg, TaskUtils taskUtils, ExecutorCommandLineGenerator clGenerator) { super(cfg, taskUtils, clGenerator); this.clGenerator = new ServiceCommandLineGenerator(cfg); } @Inject  ServiceTaskFactory(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 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); }