public SingularityTaskRequestHolder(SingularityTaskRequest taskRequest, Resources defaultResources, Resources defaultCustomExecutorResources) { this.taskRequest = taskRequest; this.executorResources = taskRequest.getDeploy().getCustomExecutorCmd().isPresent() ? taskRequest.getDeploy().getCustomExecutorResources().or(defaultCustomExecutorResources) : Resources.EMPTY_RESOURCES;; this.taskResources = taskRequest.getPendingTask().getResources().or(taskRequest.getDeploy().getResources()).or(defaultResources); this.totalResources = Resources.add(taskResources, executorResources); this.requestedPorts = new ArrayList<>(); if (taskRequest.getDeploy().getContainerInfo().isPresent() && taskRequest.getDeploy().getContainerInfo().get().getDocker().isPresent()) { requestedPorts.addAll(taskRequest.getDeploy().getContainerInfo().get().getDocker().get().getLiteralHostPorts()); } }
private void checkDocker(SingularityDeploy deploy) { if (deploy.getResources().isPresent() && deploy.getContainerInfo().get().getDocker().isPresent()) { final SingularityDockerInfo dockerInfo = deploy.getContainerInfo().get().getDocker().get(); final int numPorts = deploy.getResources().get().getNumPorts(); checkBadRequest(dockerInfo.getImage() != null, "docker image may not be null"); for (SingularityDockerPortMapping portMapping : dockerInfo.getPortMappings()) { if (portMapping.getContainerPortType() == SingularityPortMappingType.FROM_OFFER) { checkBadRequest(portMapping.getContainerPort() >= 0 && portMapping.getContainerPort() < numPorts, "Index of port resource for containerPort must be between 0 and %d (inclusive)", numPorts - 1); } if (portMapping.getHostPortType() == SingularityPortMappingType.FROM_OFFER) { checkBadRequest(portMapping.getHostPort() >= 0 && portMapping.getHostPort() < numPorts, "Index of port resource for hostPort must be between 0 and %d (inclusive)", numPorts - 1); } } } }
private TaskCleanupResult cleanTask(SingularityExecutorTaskDefinition taskDefinition, Optional<SingularityTaskHistory> taskHistory) { SingularityExecutorTaskLogManager logManager = new SingularityExecutorTaskLogManager(taskDefinition, templateManager, baseConfiguration, executorConfiguration, LOG, jsonObjectFileHelper, false); SingularityExecutorTaskCleanup taskCleanup = new SingularityExecutorTaskCleanup(logManager, executorConfiguration, taskDefinition, LOG, dockerUtils); boolean cleanupTaskAppDirectory = !taskDefinition.getExecutorData().getPreserveTaskSandboxAfterFinish().or(Boolean.FALSE); if (taskDefinition.shouldLogrotateLogFile()) { checkForUncompressedLogrotatedFile(taskDefinition); } if (taskHistory.isPresent()) { final Optional<SingularityTaskHistoryUpdate> lastUpdate = JavaUtils.getLast(taskHistory.get().getTaskUpdates()); if (lastUpdate.isPresent()) { if (lastUpdate.get().getTaskState().isDone() && System.currentTimeMillis() - lastUpdate.get().getTimestamp() > TimeUnit.MINUTES.toMillis(15)) { LOG.info("Task {} is done for > 15 minutes, removing logrotate files"); taskCleanup.cleanUpLogs(); } if (lastUpdate.get().getTaskState().isFailed()) { final long delta = System.currentTimeMillis() - lastUpdate.get().getTimestamp(); if (delta < cleanupConfiguration.getCleanupAppDirectoryOfFailedTasksAfterMillis()) { LOG.info("Not cleaning up task app directory of {} because only {} has elapsed since it failed (will cleanup after {})", taskDefinition.getTaskId(), JavaUtils.durationFromMillis(delta), JavaUtils.durationFromMillis(cleanupConfiguration.getCleanupAppDirectoryOfFailedTasksAfterMillis())); cleanupTaskAppDirectory = false; } } } } boolean isDocker = (taskHistory.isPresent() && taskHistory.get().getTask().getTaskRequest().getDeploy().getContainerInfo().isPresent() && taskHistory.get().getTask().getTaskRequest().getDeploy().getContainerInfo().get().getType() == SingularityContainerType.DOCKER); return taskCleanup.cleanup(cleanupTaskAppDirectory, isDocker); }
deploy.getContainerInfo().isPresent(), "If not using custom executor, specify a command or containerInfo. If using custom executor, specify executorData and customExecutorCmd and no command."); checkBadRequest(!deploy.getContainerInfo().isPresent() || deploy.getContainerInfo().get().getType() != null, "Container type must not be null"); if (deploy.getContainerInfo().isPresent()) { SingularityContainerInfo containerInfo = deploy.getContainerInfo().get(); checkBadRequest(containerInfo.getType() != null, "container type may not be null"); if (containerInfo.getVolumes().isPresent() && !containerInfo.getVolumes().get().isEmpty()) { if (deploy.getContainerInfo().get().getType() == SingularityContainerType.DOCKER) { checkDocker(deploy);
task.getDeploy().getContainerInfo().isPresent() || (task.getPendingTask().getCmdLineArgsList().isPresent() && !task.getPendingTask().getCmdLineArgsList().get().isEmpty())) { commandBldr.setShell(false);
Optional<Resource> portsResource = Optional.absent(); final Optional<SingularityContainerInfo> containerInfo = taskRequest.getDeploy().getContainerInfo(); if (desiredTaskResources.getNumPorts() > 0 || hasLiteralPortMapping(containerInfo)) { List<Long> requestedPorts = new ArrayList<>();
public SingularityTaskRequestHolder(SingularityTaskRequest taskRequest, Resources defaultResources, Resources defaultCustomExecutorResources) { this.taskRequest = taskRequest; this.executorResources = taskRequest.getDeploy().getCustomExecutorCmd().isPresent() ? taskRequest.getDeploy().getCustomExecutorResources().or(defaultCustomExecutorResources) : Resources.EMPTY_RESOURCES;; this.taskResources = taskRequest.getPendingTask().getResources().or(taskRequest.getDeploy().getResources()).or(defaultResources); this.totalResources = Resources.add(taskResources, executorResources); this.requestedPorts = new ArrayList<>(); if (taskRequest.getDeploy().getContainerInfo().isPresent() && taskRequest.getDeploy().getContainerInfo().get().getDocker().isPresent()) { requestedPorts.addAll(taskRequest.getDeploy().getContainerInfo().get().getDocker().get().getLiteralHostPorts()); } }
private void checkDocker(SingularityDeploy deploy) { if (deploy.getResources().isPresent() && deploy.getContainerInfo().get().getDocker().isPresent()) { final SingularityDockerInfo dockerInfo = deploy.getContainerInfo().get().getDocker().get(); final int numPorts = deploy.getResources().get().getNumPorts(); checkBadRequest(dockerInfo.getImage() != null, "docker image may not be null"); for (SingularityDockerPortMapping portMapping : dockerInfo.getPortMappings()) { if (portMapping.getContainerPortType() == SingularityPortMappingType.FROM_OFFER) { checkBadRequest(portMapping.getContainerPort() >= 0 && portMapping.getContainerPort() < numPorts, "Index of port resource for containerPort must be between 0 and %d (inclusive)", numPorts - 1); } if (portMapping.getHostPortType() == SingularityPortMappingType.FROM_OFFER) { checkBadRequest(portMapping.getHostPort() >= 0 && portMapping.getHostPort() < numPorts, "Index of port resource for hostPort must be between 0 and %d (inclusive)", numPorts - 1); } } } }
task.getDeploy().getContainerInfo().isPresent() || (task.getPendingTask().getCmdLineArgsList().isPresent() && !task.getPendingTask().getCmdLineArgsList().get().isEmpty())) { commandBldr.setShell(false);
deploy.getContainerInfo().isPresent(), "If not using custom executor, specify a command or containerInfo. If using custom executor, specify executorData and customExecutorCmd and no command."); checkBadRequest(!deploy.getContainerInfo().isPresent() || deploy.getContainerInfo().get().getType() != null, "Container type must not be null"); if (deploy.getContainerInfo().isPresent()) { SingularityContainerInfo containerInfo = deploy.getContainerInfo().get(); checkBadRequest(containerInfo.getType() != null, "container type may not be null"); if (containerInfo.getVolumes().isPresent() && !containerInfo.getVolumes().get().isEmpty()) { if (deploy.getContainerInfo().get().getType() == SingularityContainerType.DOCKER) { checkDocker(deploy);
Optional<Resource> portsResource = Optional.absent(); final Optional<SingularityContainerInfo> containerInfo = taskRequest.getDeploy().getContainerInfo(); if (desiredTaskResources.getNumPorts() > 0 || hasLiteralPortMapping(containerInfo)) { List<Long> requestedPorts = new ArrayList<>();