Search in sources :

Example 1 with DeployState

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

the class SingularityDeployChecker method cancelLoadBalancer.

private SingularityDeployResult cancelLoadBalancer(SingularityPendingDeploy pendingDeploy, List<SingularityDeployFailure> deployFailures) {
    final SingularityLoadBalancerUpdate lbUpdate = sendCancelToLoadBalancer(pendingDeploy);
    final DeployState deployState = interpretLoadBalancerState(lbUpdate, DeployState.CANCELING);
    updatePendingDeploy(pendingDeploy, Optional.of(lbUpdate), deployState);
    return new SingularityDeployResult(deployState, lbUpdate, deployFailures);
}
Also used : SingularityLoadBalancerUpdate(com.hubspot.singularity.SingularityLoadBalancerUpdate) DeployState(com.hubspot.singularity.DeployState) SingularityRequestDeployState(com.hubspot.singularity.SingularityRequestDeployState) SingularityDeployResult(com.hubspot.singularity.SingularityDeployResult)

Example 2 with DeployState

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

the class SingularityDeployChecker method markStepFinished.

private SingularityDeployResult markStepFinished(SingularityPendingDeploy pendingDeploy, Optional<SingularityDeploy> deploy, Collection<SingularityTaskId> deployActiveTasks, Collection<SingularityTaskId> otherActiveTasks, SingularityRequest request, Optional<SingularityUpdatePendingDeployRequest> updatePendingDeployRequest) {
    SingularityDeployProgress deployProgress = pendingDeploy.getDeployProgress().get();
    if (updatePendingDeployRequest.isPresent() && getNewTargetInstances(deployProgress, request, updatePendingDeployRequest) != deployProgress.getTargetActiveInstances()) {
        maybeUpdatePendingRequest(pendingDeploy, deploy, request, updatePendingDeployRequest);
        return new SingularityDeployResult(DeployState.WAITING);
    }
    SingularityDeployProgress newProgress = deployProgress.withNewActiveInstances(deployActiveTasks.size()).withCompletedStep();
    DeployState deployState = isLastStepFinished(newProgress, request) ? DeployState.SUCCEEDED : DeployState.WAITING;
    String message = deployState == DeployState.SUCCEEDED ? "New deploy succeeded" : "New deploy is progressing, this task is being replaced";
    updatePendingDeploy(pendingDeploy, pendingDeploy.getLastLoadBalancerUpdate(), deployState, Optional.of(newProgress));
    for (SingularityTaskId taskId : tasksToShutDown(deployProgress, otherActiveTasks, request)) {
        taskManager.createTaskCleanup(new SingularityTaskCleanup(Optional.<String>absent(), TaskCleanupType.DEPLOY_STEP_FINISHED, System.currentTimeMillis(), taskId, Optional.of(message), Optional.<String>absent(), Optional.<SingularityTaskShellCommandRequestId>absent()));
    }
    return new SingularityDeployResult(deployState);
}
Also used : DeployState(com.hubspot.singularity.DeployState) SingularityRequestDeployState(com.hubspot.singularity.SingularityRequestDeployState) SingularityDeployResult(com.hubspot.singularity.SingularityDeployResult) SingularityTaskCleanup(com.hubspot.singularity.SingularityTaskCleanup) SingularityTaskShellCommandRequestId(com.hubspot.singularity.SingularityTaskShellCommandRequestId) SingularityDeployProgress(com.hubspot.singularity.SingularityDeployProgress) SingularityTaskId(com.hubspot.singularity.SingularityTaskId)

Example 3 with DeployState

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

the class SingularityDeployChecker method processLbState.

private SingularityDeployResult processLbState(SingularityRequest request, Optional<SingularityDeploy> deploy, SingularityPendingDeploy pendingDeploy, Optional<SingularityUpdatePendingDeployRequest> updatePendingDeployRequest, Collection<SingularityTaskId> deployActiveTasks, Collection<SingularityTaskId> otherActiveTasks, Collection<SingularityTaskId> tasksToShutDown, SingularityLoadBalancerUpdate lbUpdate) {
    List<SingularityTaskId> toRemoveFromLb = new ArrayList<>();
    for (SingularityTaskId taskId : tasksToShutDown) {
        Optional<SingularityLoadBalancerUpdate> maybeRemoveUpdate = taskManager.getLoadBalancerState(taskId, LoadBalancerRequestType.REMOVE);
        if (maybeRemoveUpdate.isPresent() && maybeRemoveUpdate.get().getLoadBalancerRequestId().getId().equals(lbUpdate.getLoadBalancerRequestId().getId())) {
            toRemoveFromLb.add(taskId);
        }
    }
    updateLoadBalancerStateForTasks(deployActiveTasks, LoadBalancerRequestType.ADD, lbUpdate);
    updateLoadBalancerStateForTasks(toRemoveFromLb, LoadBalancerRequestType.REMOVE, lbUpdate);
    DeployState deployState = interpretLoadBalancerState(lbUpdate, pendingDeploy.getCurrentDeployState());
    if (deployState == DeployState.SUCCEEDED) {
        // A step has completed, markStepFinished will determine SUCCEEDED/WAITING
        updatePendingDeploy(pendingDeploy, Optional.of(lbUpdate), DeployState.WAITING);
        return markStepFinished(pendingDeploy, deploy, deployActiveTasks, otherActiveTasks, request, updatePendingDeployRequest);
    } else if (deployState == DeployState.WAITING) {
        updatePendingDeploy(pendingDeploy, Optional.of(lbUpdate), deployState);
        maybeUpdatePendingRequest(pendingDeploy, deploy, request, updatePendingDeployRequest, Optional.of(lbUpdate));
        return new SingularityDeployResult(DeployState.WAITING);
    } else {
        updatePendingDeploy(pendingDeploy, Optional.of(lbUpdate), deployState);
        maybeUpdatePendingRequest(pendingDeploy, deploy, request, updatePendingDeployRequest, Optional.of(lbUpdate));
        return new SingularityDeployResult(deployState, lbUpdate, SingularityDeployFailure.lbUpdateFailed());
    }
}
Also used : SingularityLoadBalancerUpdate(com.hubspot.singularity.SingularityLoadBalancerUpdate) DeployState(com.hubspot.singularity.DeployState) SingularityRequestDeployState(com.hubspot.singularity.SingularityRequestDeployState) SingularityDeployResult(com.hubspot.singularity.SingularityDeployResult) ArrayList(java.util.ArrayList) SingularityTaskId(com.hubspot.singularity.SingularityTaskId)

Aggregations

DeployState (com.hubspot.singularity.DeployState)3 SingularityDeployResult (com.hubspot.singularity.SingularityDeployResult)3 SingularityRequestDeployState (com.hubspot.singularity.SingularityRequestDeployState)3 SingularityLoadBalancerUpdate (com.hubspot.singularity.SingularityLoadBalancerUpdate)2 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)2 SingularityDeployProgress (com.hubspot.singularity.SingularityDeployProgress)1 SingularityTaskCleanup (com.hubspot.singularity.SingularityTaskCleanup)1 SingularityTaskShellCommandRequestId (com.hubspot.singularity.SingularityTaskShellCommandRequestId)1 ArrayList (java.util.ArrayList)1