use of com.hubspot.singularity.SingularityTaskShellCommandRequest in project Singularity by HubSpot.
the class TaskResource method startShellCommand.
private SingularityTaskShellCommandRequest startShellCommand(SingularityTaskId taskId, final SingularityShellCommand shellCommand, SingularityUser user) {
validator.checkValidShellCommand(shellCommand);
SingularityTaskShellCommandRequest shellRequest = new SingularityTaskShellCommandRequest(taskId, user.getEmail(), System.currentTimeMillis(), shellCommand);
taskManager.saveTaskShellCommandRequestToQueue(shellRequest);
return shellRequest;
}
use of com.hubspot.singularity.SingularityTaskShellCommandRequest in project Singularity by HubSpot.
the class SingularityCleaner method delete.
private void delete(SingularityRequestCleanup requestCleanup, Iterable<SingularityTaskId> activeTaskIds) {
final long start = System.currentTimeMillis();
for (SingularityTaskId taskId : activeTaskIds) {
LOG.debug("Adding task {} to cleanup (delete)", taskId.getId());
Optional<SingularityTaskShellCommandRequestId> runBeforeKillId = Optional.absent();
if (requestCleanup.getRunShellCommandBeforeKill().isPresent()) {
SingularityTaskShellCommandRequest shellRequest = new SingularityTaskShellCommandRequest(taskId, requestCleanup.getUser(), System.currentTimeMillis(), requestCleanup.getRunShellCommandBeforeKill().get());
taskManager.saveTaskShellCommandRequestToQueue(shellRequest);
runBeforeKillId = Optional.of(shellRequest.getId());
}
taskManager.createTaskCleanup(new SingularityTaskCleanup(requestCleanup.getUser(), TaskCleanupType.REQUEST_DELETING, start, taskId, requestCleanup.getMessage(), requestCleanup.getActionId(), runBeforeKillId, requestCleanup.getRemoveFromLoadBalancer()));
}
}
use of com.hubspot.singularity.SingularityTaskShellCommandRequest in project Singularity by HubSpot.
the class SingularityTaskShellCommandDispatchPoller method runActionOnPoll.
@Override
public void runActionOnPoll() {
final long start = System.currentTimeMillis();
final List<SingularityTaskShellCommandRequest> shellRequests = taskManager.getAllQueuedTaskShellCommandRequests();
if (!schedulerClient.isRunning()) {
LOG.warn("Unable to process shell requests because scheduler driver isn't present ({} tasks waiting)", shellRequests.size());
return;
}
if (shellRequests.isEmpty()) {
LOG.trace("No shell requests to send.");
return;
}
for (SingularityTaskShellCommandRequest shellRequest : shellRequests) {
Optional<SingularityTask> task = taskManager.getTask(shellRequest.getTaskId());
if (!task.isPresent() || !taskManager.isActiveTask(shellRequest.getTaskId().getId())) {
LOG.info("Skipping shell request {} because {} didn't exist or isn't active", shellRequest, shellRequest.getTaskId());
continue;
}
final ExecutorID executorId = MesosProtosUtils.toExecutorId(task.get().getMesosTask().getExecutor().getExecutorId());
final AgentID slaveId = MesosProtosUtils.toAgentId(task.get().getMesosTask().getAgentId());
final byte[] bytes = transcoder.toBytes(shellRequest);
schedulerClient.frameworkMessage(executorId, slaveId, bytes);
LOG.info("Sent {} ({} bytes) to {} on {}", shellRequest, bytes.length, executorId, slaveId);
taskManager.saveTaskShellCommandRequestToTask(shellRequest);
taskManager.deleteTaskShellCommandRequestFromQueue(shellRequest);
}
LOG.info("Sent {} shell requests to executors in {}", shellRequests.size(), JavaUtils.duration(start));
}
Aggregations