Search in sources :

Example 6 with SingularityTaskShellCommandRequest

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;
}
Also used : SingularityTaskShellCommandRequest(com.hubspot.singularity.SingularityTaskShellCommandRequest)

Example 7 with SingularityTaskShellCommandRequest

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()));
    }
}
Also used : SingularityTaskShellCommandRequest(com.hubspot.singularity.SingularityTaskShellCommandRequest) SingularityTaskCleanup(com.hubspot.singularity.SingularityTaskCleanup) SingularityTaskShellCommandRequestId(com.hubspot.singularity.SingularityTaskShellCommandRequestId) SingularityTaskId(com.hubspot.singularity.SingularityTaskId)

Example 8 with SingularityTaskShellCommandRequest

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));
}
Also used : ExecutorID(org.apache.mesos.v1.Protos.ExecutorID) SingularityTask(com.hubspot.singularity.SingularityTask) SingularityTaskShellCommandRequest(com.hubspot.singularity.SingularityTaskShellCommandRequest) AgentID(org.apache.mesos.v1.Protos.AgentID)

Aggregations

SingularityTaskShellCommandRequest (com.hubspot.singularity.SingularityTaskShellCommandRequest)8 SingularityTaskShellCommandRequestId (com.hubspot.singularity.SingularityTaskShellCommandRequestId)5 SingularityTaskCleanup (com.hubspot.singularity.SingularityTaskCleanup)4 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)4 SingularityTask (com.hubspot.singularity.SingularityTask)3 ArrayList (java.util.ArrayList)3 SingularityPendingRequest (com.hubspot.singularity.SingularityPendingRequest)2 TaskCleanupType (com.hubspot.singularity.TaskCleanupType)2 List (java.util.List)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 ImmutableList (com.google.common.collect.ImmutableList)1 ByteString (com.google.protobuf.ByteString)1 SingularityCreateResult (com.hubspot.singularity.SingularityCreateResult)1 SingularityShellCommand (com.hubspot.singularity.SingularityShellCommand)1 SingularityTaskShellCommandHistory (com.hubspot.singularity.SingularityTaskShellCommandHistory)1 SingularityTaskShellCommandUpdate (com.hubspot.singularity.SingularityTaskShellCommandUpdate)1 SingularityExpiringBounce (com.hubspot.singularity.expiring.SingularityExpiringBounce)1 AgentID (org.apache.mesos.v1.Protos.AgentID)1 ExecutorID (org.apache.mesos.v1.Protos.ExecutorID)1 Test (org.junit.Test)1