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);
}
}
Aggregations