@Test public void testShellCommand() { final SingularityRequest request = new SingularityRequestBuilder("test", RequestType.WORKER).build(); final SingularityDeploy deploy = new SingularityDeployBuilder("test", "1") .setCommand(Optional.of("/bin/echo hi")) .build(); final SingularityTaskRequest taskRequest = new SingularityTaskRequest(request, deploy, pendingTask); final SingularityTask task = builder.buildTask(offer, null, taskRequest, taskResources, executorResources); assertEquals("/bin/echo hi", task.getMesosTask().getCommand().getValue()); assertEquals(0, task.getMesosTask().getCommand().getArgumentsCount()); assertTrue(task.getMesosTask().getCommand().getShell()); }
public SingularityTask buildTask(Protos.Offer offer, List<Resource> availableResources, SingularityTaskRequest taskRequest, Resources desiredTaskResources, Resources desiredExecutorResources) { final String sanitizedRackId = JavaUtils.getReplaceHyphensWithUnderscores(slaveAndRackHelper.getRackIdOrDefault(offer)); final String sanitizedHost = JavaUtils.getReplaceHyphensWithUnderscores(slaveAndRackHelper.getMaybeTruncatedHost(offer)); final SingularityTaskId taskId = new SingularityTaskId(taskRequest.getPendingTask().getPendingTaskId().getRequestId(), taskRequest.getDeploy().getId(), System.currentTimeMillis(), taskRequest.getPendingTask().getPendingTaskId().getInstanceNo(), sanitizedHost, sanitizedRackId); final TaskInfo.Builder bldr = TaskInfo.newBuilder() .setTaskId(TaskID.newBuilder().setValue(taskId.toString())); Optional<long[]> ports = Optional.absent(); Optional<Resource> portsResource = Optional.absent(); final Optional<SingularityContainerInfo> containerInfo = taskRequest.getDeploy().getContainerInfo(); if (desiredTaskResources.getNumPorts() > 0 || hasLiteralPortMapping(containerInfo)) { List<Long> requestedPorts = new ArrayList<>(); if (hasLiteralPortMapping(containerInfo)) { requestedPorts.addAll(containerInfo.get().getDocker().get().getLiteralHostPorts()); } portsResource = Optional.of(MesosUtils.getPortsResource(desiredTaskResources.getNumPorts(), availableResources, requestedPorts)); ports = Optional.of(MesosUtils.getPorts(portsResource.get(), desiredTaskResources.getNumPorts())); } if (containerInfo.isPresent()) { prepareContainerInfo(offer, taskId, bldr, containerInfo.get(), ports); } if (taskRequest.getDeploy().getCustomExecutorCmd().isPresent()) { prepareCustomExecutor(bldr, taskId, taskRequest, offer, ports, desiredExecutorResources); } else { prepareCommand(bldr, taskId, taskRequest, offer, ports); } if (portsResource.isPresent()) { bldr.addResources(portsResource.get()); } bldr.addResources(MesosUtils.getCpuResource(desiredTaskResources.getCpus())); bldr.addResources(MesosUtils.getMemoryResource(desiredTaskResources.getMemoryMb())); bldr.setSlaveId(offer.getSlaveId()); bldr.setName(taskRequest.getRequest().getId()); if (taskRequest.getDeploy().getLabels().isPresent() && !taskRequest.getDeploy().getLabels().get().isEmpty()) { Builder labelsBuilder = Labels.newBuilder(); for (Map.Entry<String, String> label : taskRequest.getDeploy().getLabels().get().entrySet()) { labelsBuilder.addLabels(Label.newBuilder().setKey(label.getKey()).setValue(label.getValue()).build()); } bldr.setLabels(labelsBuilder); } TaskInfo task = bldr.build(); return new SingularityTask(taskRequest, taskId, offer, task, slaveAndRackHelper.getRackId(offer)); }
SingularityMesosTaskBuilder { public SingularityTask buildTask(Protos.Offer offer, List<Resource> availableResources, SingularityTaskRequest taskRequest, Resources desiredTaskResources, Resources desiredExecutorResources) { final String sanitizedRackId = JavaUtils.getReplaceHyphensWithUnderscores(slaveAndRackHelper.getRackIdOrDefault(offer)); final String sanitizedHost = JavaUtils.getReplaceHyphensWithUnderscores(slaveAndRackHelper.getMaybeTruncatedHost(offer)); final SingularityTaskId taskId = new SingularityTaskId(taskRequest.getPendingTask().getPendingTaskId().getRequestId(), taskRequest.getDeploy().getId(), System.currentTimeMillis(), taskRequest.getPendingTask().getPendingTaskId().getInstanceNo(), sanitizedHost, sanitizedRackId); final TaskInfo.Builder bldr = TaskInfo.newBuilder() .setTaskId(TaskID.newBuilder().setValue(taskId.toString())); Optional<long[]> ports = Optional.absent(); Optional<Resource> portsResource = Optional.absent(); final Optional<SingularityContainerInfo> containerInfo = taskRequest.getDeploy().getContainerInfo(); if (desiredTaskResources.getNumPorts() > 0 || hasLiteralPortMapping(containerInfo)) { List<Long> requestedPorts = new ArrayList<>(); if (hasLiteralPortMapping(containerInfo)) { requestedPorts.addAll(containerInfo.get().getDocker().get().getLiteralHostPorts()); } portsResource = Optional.of(MesosUtils.getPortsResource(desiredTaskResources.getNumPorts(), availableResources, requestedPorts)); ports = Optional.of(MesosUtils.getPorts(portsResource.get(), desiredTaskResources.getNumPorts())); } if (containerInfo.isPresent()) { prepareContainerInfo(offer, taskId, bldr, containerInfo.get(), ports); } if (taskRequest.getDeploy().getCustomExecutorCmd().isPresent()) { prepareCustomExecutor(bldr, taskId, taskRequest, offer, ports, desiredExecutorResources); } else { prepareCommand(bldr, taskId, taskRequest, offer, ports); } if (portsResource.isPresent()) { bldr.addResources(portsResource.get()); } bldr.addResources(MesosUtils.getCpuResource(desiredTaskResources.getCpus())); bldr.addResources(MesosUtils.getMemoryResource(desiredTaskResources.getMemoryMb())); bldr.setSlaveId(offer.getSlaveId()); bldr.setName(taskRequest.getRequest().getId()); if (taskRequest.getDeploy().getLabels().isPresent() && !taskRequest.getDeploy().getLabels().get().isEmpty()) { Builder labelsBuilder = Labels.newBuilder(); for (Map.Entry<String, String> label : taskRequest.getDeploy().getLabels().get().entrySet()) { labelsBuilder.addLabels(Label.newBuilder().setKey(label.getKey()).setValue(label.getValue()).build()); } bldr.setLabels(labelsBuilder); } TaskInfo task = bldr.build(); return new SingularityTask(taskRequest, taskId, offer, task, slaveAndRackHelper.getRackId(offer)); } }
SingularityMesosTaskBuilder { public SingularityTask buildTask(Protos.Offer offer, List<Resource> availableResources, SingularityTaskRequest taskRequest, Resources desiredTaskResources, Resources desiredExecutorResources) { final String sanitizedRackId = JavaUtils.getReplaceHyphensWithUnderscores(slaveAndRackHelper.getRackIdOrDefault(offer)); final String sanitizedHost = JavaUtils.getReplaceHyphensWithUnderscores(slaveAndRackHelper.getMaybeTruncatedHost(offer)); final SingularityTaskId taskId = new SingularityTaskId(taskRequest.getPendingTask().getPendingTaskId().getRequestId(), taskRequest.getDeploy().getId(), System.currentTimeMillis(), taskRequest.getPendingTask().getPendingTaskId().getInstanceNo(), sanitizedHost, sanitizedRackId); final TaskInfo.Builder bldr = TaskInfo.newBuilder() .setTaskId(TaskID.newBuilder().setValue(taskId.toString())); Optional<long[]> ports = Optional.absent(); Optional<Resource> portsResource = Optional.absent(); final Optional<SingularityContainerInfo> containerInfo = taskRequest.getDeploy().getContainerInfo(); if (desiredTaskResources.getNumPorts() > 0 || hasLiteralPortMapping(containerInfo)) { List<Long> requestedPorts = new ArrayList<>(); if (hasLiteralPortMapping(containerInfo)) { requestedPorts.addAll(containerInfo.get().getDocker().get().getLiteralHostPorts()); } portsResource = Optional.of(MesosUtils.getPortsResource(desiredTaskResources.getNumPorts(), availableResources, requestedPorts)); ports = Optional.of(MesosUtils.getPorts(portsResource.get(), desiredTaskResources.getNumPorts())); } if (containerInfo.isPresent()) { prepareContainerInfo(offer, taskId, bldr, containerInfo.get(), ports); } if (taskRequest.getDeploy().getCustomExecutorCmd().isPresent()) { prepareCustomExecutor(bldr, taskId, taskRequest, offer, ports, desiredExecutorResources); } else { prepareCommand(bldr, taskId, taskRequest, offer, ports); } if (portsResource.isPresent()) { bldr.addResources(portsResource.get()); } bldr.addResources(MesosUtils.getCpuResource(desiredTaskResources.getCpus())); bldr.addResources(MesosUtils.getMemoryResource(desiredTaskResources.getMemoryMb())); bldr.setSlaveId(offer.getSlaveId()); bldr.setName(taskRequest.getRequest().getId()); if (taskRequest.getDeploy().getLabels().isPresent() && !taskRequest.getDeploy().getLabels().get().isEmpty()) { Builder labelsBuilder = Labels.newBuilder(); for (Map.Entry<String, String> label : taskRequest.getDeploy().getLabels().get().entrySet()) { labelsBuilder.addLabels(Label.newBuilder().setKey(label.getKey()).setValue(label.getValue()).build()); } bldr.setLabels(labelsBuilder); } TaskInfo task = bldr.build(); return new SingularityTask(taskRequest, taskId, offer, task, slaveAndRackHelper.getRackId(offer)); } @Inject  SingularityMesosTaskBuilder(ObjectMapper objectMapper, SingularitySlaveAndRackHelper slaveAndRackHelper, ExecutorIdGenerator idGenerator, SingularityConfiguration configuration); }
SingularityMesosTaskBuilder { public SingularityTask buildTask(Protos.Offer offer, List<Resource> availableResources, SingularityTaskRequest taskRequest, Resources desiredTaskResources, Resources desiredExecutorResources) { final String sanitizedRackId = JavaUtils.getReplaceHyphensWithUnderscores(slaveAndRackHelper.getRackIdOrDefault(offer)); final String sanitizedHost = JavaUtils.getReplaceHyphensWithUnderscores(slaveAndRackHelper.getMaybeTruncatedHost(offer)); final SingularityTaskId taskId = new SingularityTaskId(taskRequest.getPendingTask().getPendingTaskId().getRequestId(), taskRequest.getDeploy().getId(), System.currentTimeMillis(), taskRequest.getPendingTask().getPendingTaskId().getInstanceNo(), sanitizedHost, sanitizedRackId); final TaskInfo.Builder bldr = TaskInfo.newBuilder() .setTaskId(TaskID.newBuilder().setValue(taskId.toString())); Optional<long[]> ports = Optional.absent(); Optional<Resource> portsResource = Optional.absent(); final Optional<SingularityContainerInfo> containerInfo = taskRequest.getDeploy().getContainerInfo(); if (desiredTaskResources.getNumPorts() > 0 || hasLiteralPortMapping(containerInfo)) { List<Long> requestedPorts = new ArrayList<>(); if (hasLiteralPortMapping(containerInfo)) { requestedPorts.addAll(containerInfo.get().getDocker().get().getLiteralHostPorts()); } portsResource = Optional.of(MesosUtils.getPortsResource(desiredTaskResources.getNumPorts(), availableResources, requestedPorts)); ports = Optional.of(MesosUtils.getPorts(portsResource.get(), desiredTaskResources.getNumPorts())); } if (containerInfo.isPresent()) { prepareContainerInfo(offer, taskId, bldr, containerInfo.get(), ports); } if (taskRequest.getDeploy().getCustomExecutorCmd().isPresent()) { prepareCustomExecutor(bldr, taskId, taskRequest, offer, ports, desiredExecutorResources); } else { prepareCommand(bldr, taskId, taskRequest, offer, ports); } if (portsResource.isPresent()) { bldr.addResources(portsResource.get()); } bldr.addResources(MesosUtils.getCpuResource(desiredTaskResources.getCpus())); bldr.addResources(MesosUtils.getMemoryResource(desiredTaskResources.getMemoryMb())); bldr.setSlaveId(offer.getSlaveId()); bldr.setName(taskRequest.getRequest().getId()); if (taskRequest.getDeploy().getLabels().isPresent() && !taskRequest.getDeploy().getLabels().get().isEmpty()) { Builder labelsBuilder = Labels.newBuilder(); for (Map.Entry<String, String> label : taskRequest.getDeploy().getLabels().get().entrySet()) { labelsBuilder.addLabels(Label.newBuilder().setKey(label.getKey()).setValue(label.getValue()).build()); } bldr.setLabels(labelsBuilder); } TaskInfo task = bldr.build(); return new SingularityTask(taskRequest, taskId, offer, task, slaveAndRackHelper.getRackId(offer)); } @Inject  SingularityMesosTaskBuilder(ObjectMapper objectMapper, SingularitySlaveAndRackHelper slaveAndRackHelper, ExecutorIdGenerator idGenerator, SingularityConfiguration configuration); SingularityTask buildTask(Protos.Offer offer, List<Resource> availableResources, SingularityTaskRequest taskRequest, Resources desiredTaskResources, Resources desiredExecutorResources); }
SingularityMesosTaskBuilder { public SingularityTask buildTask(Protos.Offer offer, List<Resource> availableResources, SingularityTaskRequest taskRequest, Resources desiredTaskResources, Resources desiredExecutorResources) { final String sanitizedRackId = JavaUtils.getReplaceHyphensWithUnderscores(slaveAndRackHelper.getRackIdOrDefault(offer)); final String sanitizedHost = JavaUtils.getReplaceHyphensWithUnderscores(slaveAndRackHelper.getMaybeTruncatedHost(offer)); final SingularityTaskId taskId = new SingularityTaskId(taskRequest.getPendingTask().getPendingTaskId().getRequestId(), taskRequest.getDeploy().getId(), System.currentTimeMillis(), taskRequest.getPendingTask().getPendingTaskId().getInstanceNo(), sanitizedHost, sanitizedRackId); final TaskInfo.Builder bldr = TaskInfo.newBuilder() .setTaskId(TaskID.newBuilder().setValue(taskId.toString())); Optional<long[]> ports = Optional.absent(); Optional<Resource> portsResource = Optional.absent(); final Optional<SingularityContainerInfo> containerInfo = taskRequest.getDeploy().getContainerInfo(); if (desiredTaskResources.getNumPorts() > 0 || hasLiteralPortMapping(containerInfo)) { List<Long> requestedPorts = new ArrayList<>(); if (hasLiteralPortMapping(containerInfo)) { requestedPorts.addAll(containerInfo.get().getDocker().get().getLiteralHostPorts()); } portsResource = Optional.of(MesosUtils.getPortsResource(desiredTaskResources.getNumPorts(), availableResources, requestedPorts)); ports = Optional.of(MesosUtils.getPorts(portsResource.get(), desiredTaskResources.getNumPorts())); } if (containerInfo.isPresent()) { prepareContainerInfo(offer, taskId, bldr, containerInfo.get(), ports); } if (taskRequest.getDeploy().getCustomExecutorCmd().isPresent()) { prepareCustomExecutor(bldr, taskId, taskRequest, offer, ports, desiredExecutorResources); } else { prepareCommand(bldr, taskId, taskRequest, offer, ports); } if (portsResource.isPresent()) { bldr.addResources(portsResource.get()); } bldr.addResources(MesosUtils.getCpuResource(desiredTaskResources.getCpus())); bldr.addResources(MesosUtils.getMemoryResource(desiredTaskResources.getMemoryMb())); bldr.setSlaveId(offer.getSlaveId()); bldr.setName(taskRequest.getRequest().getId()); if (taskRequest.getDeploy().getLabels().isPresent() && !taskRequest.getDeploy().getLabels().get().isEmpty()) { Builder labelsBuilder = Labels.newBuilder(); for (Map.Entry<String, String> label : taskRequest.getDeploy().getLabels().get().entrySet()) { labelsBuilder.addLabels(Label.newBuilder().setKey(label.getKey()).setValue(label.getValue()).build()); } bldr.setLabels(labelsBuilder); } TaskInfo task = bldr.build(); return new SingularityTask(taskRequest, taskId, offer, task, slaveAndRackHelper.getRackId(offer)); } @Inject  SingularityMesosTaskBuilder(ObjectMapper objectMapper, SingularitySlaveAndRackHelper slaveAndRackHelper, ExecutorIdGenerator idGenerator, SingularityConfiguration configuration); SingularityTask buildTask(Protos.Offer offer, List<Resource> availableResources, SingularityTaskRequest taskRequest, Resources desiredTaskResources, Resources desiredExecutorResources);  }