/** * forceRollingUpdateUndeploy is used to undeploy jobs from hosts that have been removed from the * deployment group. It disables the 'skipRedundantUndeploys' flag, which disables the * redundantDeployment() check. */ private RollingUpdateOp forceRollingUpdateUndeploy(final ZooKeeperClient client, final RollingUpdateOpFactory opFactory, final DeploymentGroup deploymentGroup, final String host) { return rollingUpdateUndeploy(client, opFactory, deploymentGroup, host, false); }
private RollingUpdateOp rollingUpdateUndeploy(final ZooKeeperClient client, final RollingUpdateOpFactory opFactory, final DeploymentGroup deploymentGroup, final String host, final boolean skipRedundantUndeploys) { final List<ZooKeeperOperation> operations = Lists.newArrayList(); for (final Deployment deployment : getTasks(client, host).values()) { if (!ownedByDeploymentGroup(deployment, deploymentGroup) && !isMigration(deployment, deploymentGroup)) { continue; } if (skipRedundantUndeploys && redundantUndeployment(deployment, deploymentGroup)) { continue; } try { final String token = MoreObjects.firstNonNull( deploymentGroup.getRolloutOptions().getToken(), Job.EMPTY_TOKEN); operations.addAll(getUndeployOperations(client, host, deployment.getJobId(), token)); log.debug("planned undeploy operations for job={}", deployment.getJobId()); } catch (TokenVerificationException e) { return opFactory.error(e, host, RollingUpdateError.TOKEN_VERIFICATION_ERROR); } catch (HostNotFoundException e) { return opFactory.error(e, host, RollingUpdateError.HOST_NOT_FOUND); } catch (JobNotDeployedException e) { // probably somebody beat us to the punch of undeploying. that's fine. } } return opFactory.nextTask(operations); }
private RollingUpdateOp processRollingUpdateTask(final ZooKeeperClient client, final RollingUpdateOpFactory opFactory, final RolloutTask task, final DeploymentGroup deploymentGroup) { final RolloutTask.Action action = task.getAction(); final String host = task.getTarget(); switch (action) { case UNDEPLOY_OLD_JOBS: // add undeploy ops for jobs previously deployed by this deployment group return rollingUpdateUndeploy(client, opFactory, deploymentGroup, host); case DEPLOY_NEW_JOB: // add deploy ops for the new job return rollingUpdateDeploy(client, opFactory, deploymentGroup, host); case AWAIT_RUNNING: return rollingUpdateAwaitRunning(client, opFactory, deploymentGroup, host); case FORCE_UNDEPLOY_JOBS: return forceRollingUpdateUndeploy(client, opFactory, deploymentGroup, host); case AWAIT_UNDEPLOYED: return rollingUpdateAwaitUndeployed(client, opFactory, deploymentGroup, host); case MARK_UNDEPLOYED: return rollingUpdateMarkUndeployed(client, opFactory, deploymentGroup, host); default: throw new HeliosRuntimeException(String.format( "unknown rollout task type %s for deployment group %s.", action, deploymentGroup.getName())); } }
private RollingUpdateTaskResult getRollingUpdateTaskResult(final RolloutTask task, final DeploymentGroup group) { final RollingUpdateTaskResult result; if (task == null) { // if there is no rollout task, then we're done by definition. this can happen // when (for example) there are no hosts in the deployment group result = RollingUpdateTaskResult.TASK_COMPLETE; } else { final String host = task.getTarget(); final RolloutTask.Action action = task.getAction(); switch (action) { case UNDEPLOY_OLD_JOBS: // add undeploy ops for jobs previously deployed by this deployment group result = rollingUpdateUndeploy(group, host); break; case DEPLOY_NEW_JOB: // add deploy ops for the new job result = rollingUpdateDeploy(group, host); break; case AWAIT_RUNNING: result = rollingUpdateAwaitRunning(group, host); break; default: throw new HeliosRuntimeException(String.format( "unknown rollout task type %s for deployment group %s.", action, group.getName())); } } return result; }