Search in sources :

Example 1 with SingularityCreateResult

use of com.hubspot.singularity.SingularityCreateResult in project Singularity by HubSpot.

the class TaskManager method createTaskCleanup.

public SingularityCreateResult createTaskCleanup(SingularityTaskCleanup cleanup) {
    leaderCache.createTaskCleanupIfNotExists(cleanup);
    final SingularityCreateResult result = create(getCleanupPath(cleanup.getTaskId().getId()), cleanup, taskCleanupTranscoder);
    if (result == SingularityCreateResult.CREATED) {
        saveTaskHistoryUpdate(cleanup);
    }
    return result;
}
Also used : SingularityCreateResult(com.hubspot.singularity.SingularityCreateResult)

Example 2 with SingularityCreateResult

use of com.hubspot.singularity.SingularityCreateResult in project Singularity by HubSpot.

the class SingularityCmdLineArgsMigration method checkPendingTasks.

private void checkPendingTasks() {
    try {
        if (curator.checkExists().forPath(TASK_PENDING_PATH) == null) {
            return;
        }
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
    try {
        for (SingularityPendingTaskId pendingTaskId : taskManager.getPendingTaskIds()) {
            Optional<String> cmdLineArgs = getCmdLineArgs(pendingTaskId);
            SingularityCreateResult result = taskManager.savePendingTask(new SingularityPendingTaskBuilder().setPendingTaskId(pendingTaskId).setCmdLineArgsList(getCmdLineArgs(cmdLineArgs)).build());
            LOG.info("Saving {} ({}) {}", pendingTaskId, cmdLineArgs, result);
        }
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) SingularityCreateResult(com.hubspot.singularity.SingularityCreateResult) SingularityPendingTaskBuilder(com.hubspot.singularity.SingularityPendingTaskBuilder)

Example 3 with SingularityCreateResult

use of com.hubspot.singularity.SingularityCreateResult in project Singularity by HubSpot.

the class RequestHelper method checkReschedule.

private void checkReschedule(SingularityRequest newRequest, Optional<SingularityRequest> maybeOldRequest, Optional<String> user, long timestamp, Optional<Boolean> skipHealthchecks, Optional<String> message, Optional<SingularityBounceRequest> maybeBounceRequest) {
    if (!maybeOldRequest.isPresent()) {
        return;
    }
    if (shouldReschedule(newRequest, maybeOldRequest.get())) {
        Optional<String> maybeDeployId = deployManager.getInUseDeployId(newRequest.getId());
        if (maybeDeployId.isPresent()) {
            if (maybeBounceRequest.isPresent()) {
                Optional<String> actionId = maybeBounceRequest.get().getActionId().or(Optional.of(UUID.randomUUID().toString()));
                Optional<Boolean> removeFromLoadBalancer = Optional.absent();
                SingularityCreateResult createResult = requestManager.createCleanupRequest(new SingularityRequestCleanup(user, maybeBounceRequest.get().getIncremental().or(true) ? RequestCleanupType.INCREMENTAL_BOUNCE : RequestCleanupType.BOUNCE, System.currentTimeMillis(), Optional.<Boolean>absent(), removeFromLoadBalancer, newRequest.getId(), Optional.of(maybeDeployId.get()), skipHealthchecks, message, actionId, maybeBounceRequest.get().getRunShellCommandBeforeKill()));
                if (createResult != SingularityCreateResult.EXISTED) {
                    requestManager.bounce(newRequest, System.currentTimeMillis(), user, Optional.of("Bouncing due to bounce after scale"));
                    final SingularityBounceRequest validatedBounceRequest = validator.checkBounceRequest(maybeBounceRequest.get());
                    requestManager.saveExpiringObject(new SingularityExpiringBounce(newRequest.getId(), maybeDeployId.get(), user, System.currentTimeMillis(), validatedBounceRequest, actionId.get()));
                } else {
                    requestManager.addToPendingQueue(new SingularityPendingRequest(newRequest.getId(), maybeDeployId.get(), timestamp, user, PendingType.UPDATED_REQUEST, skipHealthchecks, message));
                }
            } else {
                requestManager.addToPendingQueue(new SingularityPendingRequest(newRequest.getId(), maybeDeployId.get(), timestamp, user, PendingType.UPDATED_REQUEST, skipHealthchecks, message));
            }
        }
    }
}
Also used : SingularityRequestCleanup(com.hubspot.singularity.SingularityRequestCleanup) SingularityPendingRequest(com.hubspot.singularity.SingularityPendingRequest) SingularityExpiringBounce(com.hubspot.singularity.expiring.SingularityExpiringBounce) SingularityCreateResult(com.hubspot.singularity.SingularityCreateResult) SingularityBounceRequest(com.hubspot.singularity.api.SingularityBounceRequest)

Example 4 with SingularityCreateResult

use of com.hubspot.singularity.SingularityCreateResult in project Singularity by HubSpot.

the class DeployManager method saveDeploy.

public SingularityCreateResult saveDeploy(SingularityRequest request, SingularityDeployMarker deployMarker, SingularityDeploy deploy) {
    final SingularityCreateResult deploySaveResult = create(getDeployDataPath(deploy.getRequestId(), deploy.getId()), deploy, deployTranscoder);
    if (deploySaveResult == SingularityCreateResult.EXISTED) {
        LOG.info("Deploy object for {} already existed (new marker: {})", deploy, deployMarker);
    }
    singularityEventListener.deployHistoryEvent(new SingularityDeployUpdate(deployMarker, Optional.of(deploy), DeployEventType.STARTING, Optional.<SingularityDeployResult>absent()));
    create(getDeployMarkerPath(deploy.getRequestId(), deploy.getId()), deployMarker, deployMarkerTranscoder);
    final Optional<SingularityRequestDeployState> currentState = getRequestDeployState(deploy.getRequestId());
    Optional<SingularityDeployMarker> activeDeploy = Optional.absent();
    Optional<SingularityDeployMarker> pendingDeploy = Optional.absent();
    if (request.isDeployable()) {
        if (currentState.isPresent()) {
            activeDeploy = currentState.get().getActiveDeploy();
        }
        pendingDeploy = Optional.of(deployMarker);
    } else {
        activeDeploy = Optional.of(deployMarker);
    }
    final SingularityRequestDeployState newState = new SingularityRequestDeployState(deploy.getRequestId(), activeDeploy, pendingDeploy);
    return saveNewRequestDeployState(newState);
}
Also used : SingularityDeployResult(com.hubspot.singularity.SingularityDeployResult) SingularityDeployMarker(com.hubspot.singularity.SingularityDeployMarker) SingularityDeployUpdate(com.hubspot.singularity.SingularityDeployUpdate) SingularityCreateResult(com.hubspot.singularity.SingularityCreateResult) SingularityRequestDeployState(com.hubspot.singularity.SingularityRequestDeployState)

Example 5 with SingularityCreateResult

use of com.hubspot.singularity.SingularityCreateResult in project Singularity by HubSpot.

the class SingularityMesosStatusUpdateHandler method unsafeProcessStatusUpdate.

private void unsafeProcessStatusUpdate(Protos.TaskStatus status, SingularityTaskId taskIdObj) {
    final String taskId = status.getTaskId().getValue();
    long timestamp = System.currentTimeMillis();
    if (status.hasTimestamp()) {
        timestamp = (long) (status.getTimestamp() * 1000);
    }
    long now = System.currentTimeMillis();
    long delta = now - timestamp;
    LOG.debug("Update: task {} is now {} ({}) at {} (delta: {})", taskId, status.getState(), status.getMessage(), timestamp, JavaUtils.durationFromMillis(delta));
    statusUpdateDeltas.put(now, delta);
    final SingularityTaskStatusHolder newTaskStatusHolder = new SingularityTaskStatusHolder(taskIdObj, Optional.of(mesosProtosUtils.taskStatusFromProtos(status)), System.currentTimeMillis(), serverId, Optional.<String>absent());
    final Optional<SingularityTaskStatusHolder> previousTaskStatusHolder = taskManager.getLastActiveTaskStatus(taskIdObj);
    final ExtendedTaskState taskState = MesosUtils.fromTaskState(status.getState());
    if (isDuplicateOrIgnorableStatusUpdate(previousTaskStatusHolder, newTaskStatusHolder)) {
        LOG.trace("Ignoring status update {} to {}", taskState, taskIdObj);
        saveNewTaskStatusHolder(taskIdObj, newTaskStatusHolder, taskState);
        return;
    }
    if (status.getState() == TaskState.TASK_LOST) {
        lostTasksMeter.mark();
        if (configuration.getDisasterDetection().isEnabled()) {
            taskLostReasons.add(status.getReason());
        }
    }
    final Optional<SingularityTask> task = taskManager.getTask(taskIdObj);
    final boolean isActiveTask = taskManager.isActiveTask(taskId);
    if (isActiveTask && !taskState.isDone()) {
        if (task.isPresent()) {
            final Optional<SingularityPendingDeploy> pendingDeploy = deployManager.getPendingDeploy(taskIdObj.getRequestId());
            Optional<SingularityRequestWithState> requestWithState = Optional.absent();
            if (taskState == ExtendedTaskState.TASK_RUNNING) {
                requestWithState = requestManager.getRequest(taskIdObj.getRequestId());
                healthchecker.enqueueHealthcheck(task.get(), pendingDeploy, requestWithState);
            }
            if (!pendingDeploy.isPresent() || !pendingDeploy.get().getDeployMarker().getDeployId().equals(taskIdObj.getDeployId())) {
                if (!requestWithState.isPresent()) {
                    requestWithState = requestManager.getRequest(taskIdObj.getRequestId());
                }
                newTaskChecker.enqueueNewTaskCheck(task.get(), requestWithState, healthchecker);
            }
        } else {
            final String message = String.format("Task %s is active but is missing task data", taskId);
            exceptionNotifier.notify(message);
            LOG.error(message);
        }
    }
    final Optional<String> statusMessage = getStatusMessage(status, task);
    final SingularityTaskHistoryUpdate taskUpdate = new SingularityTaskHistoryUpdate(taskIdObj, timestamp, taskState, statusMessage, status.hasReason() ? Optional.of(status.getReason().name()) : Optional.<String>absent());
    final SingularityCreateResult taskHistoryUpdateCreateResult = taskManager.saveTaskHistoryUpdate(taskUpdate);
    logSupport.checkDirectoryAndContainerId(taskIdObj);
    if (taskState.isDone()) {
        healthchecker.cancelHealthcheck(taskId);
        newTaskChecker.cancelNewTaskCheck(taskId);
        taskManager.deleteKilledRecord(taskIdObj);
        slaveAndRackManager.checkStateAfterFinishedTask(taskIdObj, status.getAgentId().getValue(), leaderCache);
        scheduler.handleCompletedTask(task, taskIdObj, isActiveTask, timestamp, taskState, taskHistoryUpdateCreateResult, status);
    }
    saveNewTaskStatusHolder(taskIdObj, newTaskStatusHolder, taskState);
}
Also used : SingularityCreateResult(com.hubspot.singularity.SingularityCreateResult) ExtendedTaskState(com.hubspot.singularity.ExtendedTaskState) SingularityTask(com.hubspot.singularity.SingularityTask) SingularityTaskHistoryUpdate(com.hubspot.singularity.SingularityTaskHistoryUpdate) SingularityPendingDeploy(com.hubspot.singularity.SingularityPendingDeploy) SingularityRequestWithState(com.hubspot.singularity.SingularityRequestWithState) SingularityTaskStatusHolder(com.hubspot.singularity.SingularityTaskStatusHolder)

Aggregations

SingularityCreateResult (com.hubspot.singularity.SingularityCreateResult)11 SingularityPendingRequest (com.hubspot.singularity.SingularityPendingRequest)3 SingularityRequestWithState (com.hubspot.singularity.SingularityRequestWithState)3 SingularityRequestCleanup (com.hubspot.singularity.SingularityRequestCleanup)2 SingularityTask (com.hubspot.singularity.SingularityTask)2 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)2 ApiResponses (com.wordnik.swagger.annotations.ApiResponses)2 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 ImmutableList (com.google.common.collect.ImmutableList)1 ExtendedTaskState (com.hubspot.singularity.ExtendedTaskState)1 SingularityDeployMarker (com.hubspot.singularity.SingularityDeployMarker)1 SingularityDeployResult (com.hubspot.singularity.SingularityDeployResult)1 SingularityDeployUpdate (com.hubspot.singularity.SingularityDeployUpdate)1 SingularityPendingDeploy (com.hubspot.singularity.SingularityPendingDeploy)1 SingularityPendingTaskBuilder (com.hubspot.singularity.SingularityPendingTaskBuilder)1 SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)1 SingularityRequestDeployState (com.hubspot.singularity.SingularityRequestDeployState)1 SingularityShellCommand (com.hubspot.singularity.SingularityShellCommand)1