Search in sources :

Example 6 with DeployAcceptanceResult

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

the class SingularityDeployChecker method checkAcceptanceOfDeployStep.

private SingularityDeployResult checkAcceptanceOfDeployStep(SingularityRequest request, SingularityDeploy deploy, SingularityPendingDeploy pendingDeploy, Collection<SingularityTaskId> deployActiveTasks, Optional<SingularityUpdatePendingDeployRequest> updatePendingDeployRequest, Collection<SingularityTaskId> inactiveDeployMatchingTasks, Collection<SingularityTaskId> otherActiveTasks) {
    if (updatePendingDeployRequest.isPresent()) {
        maybeUpdatePendingRequest(pendingDeploy, deploy, request, updatePendingDeployRequest);
        return new SingularityDeployResult(DeployState.WAITING);
    }
    switch(deploy.getCanaryDeploySettings().getAcceptanceMode()) {
        case TIMED:
            if (System.currentTimeMillis() > pendingDeploy.getDeployProgress().getTimestamp() + deploy.getCanaryDeploySettings().getWaitMillisBetweenGroups()) {
                return checkCanaryMaybeFinished(request, deploy, pendingDeploy, deployActiveTasks, updatePendingDeployRequest, inactiveDeployMatchingTasks, otherActiveTasks);
            } else {
                LOG.info("Waiting for timed deploy step for {}", request.getId());
                return new SingularityDeployResult(DeployState.WAITING);
            }
        case CHECKS:
            Map<String, DeployAcceptanceResult> results = deployAcceptanceManager.getAcceptanceResults(request, deploy, pendingDeploy, deployActiveTasks, inactiveDeployMatchingTasks, otherActiveTasks);
            SingularityDeployProgress updatedProgress = pendingDeploy.getDeployProgress().withAcceptanceProgress(results);
            DeployState acceptanceHookDeployState = SingularityDeployAcceptanceManager.resultsToDeployState(updatedProgress.getStepAcceptanceResults());
            LOG.info("Acceptance checks had result {}", acceptanceHookDeployState);
            if (deploy.getCanaryDeploySettings().isEnableCanaryDeploy()) {
                if (acceptanceHookDeployState == DeployState.SUCCEEDED) {
                    if (deployActiveTasks.size() >= request.getInstancesSafe()) {
                        cleanupTasks(pendingDeploy, request, DeployState.SUCCEEDED, otherActiveTasks);
                        updatePendingDeploy(pendingDeploy, acceptanceHookDeployState, updatedProgress);
                        return new SingularityDeployResult(acceptanceHookDeployState, String.join(", ", updatedProgress.getAcceptanceResultMessageHistory()));
                    } else {
                        return advanceDeployStep(updatedProgress, request, deploy, pendingDeploy, deployActiveTasks, updatePendingDeployRequest, inactiveDeployMatchingTasks, otherActiveTasks);
                    }
                } else if (acceptanceHookDeployState == DeployState.FAILED) {
                    updatePendingDeploy(pendingDeploy, acceptanceHookDeployState, updatedProgress);
                    return new SingularityDeployResult(acceptanceHookDeployState, String.join(", ", updatedProgress.getAcceptanceResultMessageHistory()));
                }
                updatePendingDeploy(pendingDeploy, acceptanceHookDeployState, updatedProgress);
                return new SingularityDeployResult(acceptanceHookDeployState);
            } else {
                // Clean up all old tasks on acceptance
                switch(acceptanceHookDeployState) {
                    case WAITING:
                        updatePendingDeploy(pendingDeploy, acceptanceHookDeployState, updatedProgress);
                        return new SingularityDeployResult(DeployState.WAITING);
                    case SUCCEEDED:
                        cleanupTasks(pendingDeploy, request, DeployState.SUCCEEDED, otherActiveTasks);
                        updatePendingDeploy(pendingDeploy, acceptanceHookDeployState, updatedProgress);
                        return new SingularityDeployResult(DeployState.SUCCEEDED);
                    default:
                        LOG.info("Acceptance checks failed, cleaning up");
                        updatePendingDeploy(pendingDeploy, acceptanceHookDeployState, updatedProgress);
                        if (request.isLoadBalanced() && lbClient.isEnabled()) {
                            // Add previous tasks back to load balancer, since we previously took them out
                            if (updatedProgress.getPendingLbUpdate().isPresent()) {
                                return checkLbRevertToActiveTasks(request, deploy, pendingDeploy, updatedProgress, acceptanceHookDeployState, deployActiveTasks, otherActiveTasks);
                            } else {
                                return enqueueLbRevertToActiveTasks(request, pendingDeploy, updatedProgress, deployActiveTasks, otherActiveTasks);
                            }
                        } else {
                            return new SingularityDeployResult(acceptanceHookDeployState, String.join(", ", updatedProgress.getAcceptanceResultMessageHistory()));
                        }
                }
            }
        case NONE:
        default:
            return checkCanaryMaybeFinished(request, deploy, pendingDeploy, deployActiveTasks, updatePendingDeployRequest, inactiveDeployMatchingTasks, otherActiveTasks);
    }
}
Also used : DeployState(com.hubspot.singularity.DeployState) SingularityRequestDeployState(com.hubspot.singularity.SingularityRequestDeployState) SingularityDeployResult(com.hubspot.singularity.SingularityDeployResult) DeployAcceptanceResult(com.hubspot.singularity.DeployAcceptanceResult) SingularityDeployProgress(com.hubspot.singularity.SingularityDeployProgress)

Aggregations

DeployAcceptanceResult (com.hubspot.singularity.DeployAcceptanceResult)6 SingularityDeployProgress (com.hubspot.singularity.SingularityDeployProgress)4 SingularityDeployBuilder (com.hubspot.singularity.SingularityDeployBuilder)3 SingularityDeployResult (com.hubspot.singularity.SingularityDeployResult)3 SingularityTask (com.hubspot.singularity.SingularityTask)3 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)3 SingularityDeployRequest (com.hubspot.singularity.api.SingularityDeployRequest)3 Test (org.junit.jupiter.api.Test)3 SingularityRequest (com.hubspot.singularity.SingularityRequest)2 DeployAcceptanceState (com.hubspot.singularity.DeployAcceptanceState)1 DeployProgressLbUpdateHolder (com.hubspot.singularity.DeployProgressLbUpdateHolder)1 DeployState (com.hubspot.singularity.DeployState)1 SingularityPendingDeploy (com.hubspot.singularity.SingularityPendingDeploy)1 SingularityRequestDeployState (com.hubspot.singularity.SingularityRequestDeployState)1 DeployAcceptanceHook (com.hubspot.singularity.hooks.DeployAcceptanceHook)1 HashMap (java.util.HashMap)1 AfterEach (org.junit.jupiter.api.AfterEach)1