Skip to content

Instantly share code, notes, and snippets.

@karanmalhi
Created May 21, 2012 22:15

Revisions

  1. @kmalhi kmalhi created this gist May 21, 2012.
    35 changes: 35 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    private DeploymentStatus getDeploymentStatus(DeploymentAction latest) {
    DeploymentStatus status;
    if (Action.DELETE.equals(latest.getAction())) {
    status = DeploymentStatus.DELETING;
    } else {
    boolean inProcess = false;
    int failCount = 0;
    // if size is 0, that means we do not have any status yes, a typical indication that the deployment on servers has not started yet.
    if (latest.getStatuses().size() == 0) {
    // the deployment is still in progress, i.e. about to start
    status = DeploymentStatus.IN_PROGRESS;
    return status;
    }
    for (ServerDeploy s : latest.getStatuses()) {
    switch (s.getState()) {
    case IN_PROCESS:
    inProcess = true;
    break;
    case FAILED:
    failCount++;
    break;
    }
    }
    // the order of check is critical here. Even if we get a failure, we still need to make sure that deployments on other servers complete
    // i.e. you want to let the deployment finish on as many servers as possible , hence we want to keep it in progress till then
    if (inProcess) {
    status = DeploymentStatus.IN_PROGRESS;
    } else if (failCount == 0) {
    status = DeploymentStatus.SUCCESSFUL;
    } else {
    status = DeploymentStatus.FAILED;
    }
    }
    return status;
    }