Example usage for com.amazonaws.services.opsworks.model Deployment getStatus

List of usage examples for com.amazonaws.services.opsworks.model Deployment getStatus

Introduction

In this page you can find the example usage for com.amazonaws.services.opsworks.model Deployment getStatus.

Prototype


public String getStatus() 

Source Link

Document

The deployment status:

  • running

  • successful

  • failed

Usage

From source file:com.tispr.aws.OpsWorksClient.java

License:Apache License

protected Deployment deploy(App app, List<String> instanceIds, String comment, String revision, boolean noWait)
        throws ExecutionException, InterruptedException {
    DeploymentCommand command = new DeploymentCommand().withName(DeploymentCommandName.Deploy);

    CreateDeploymentRequest deployReq = new CreateDeploymentRequest().withAppId(app.getAppId())
            .withStackId(app.getStackId()).withCommand(command);

    if (instanceIds != null && !instanceIds.isEmpty()) {
        deployReq.withInstanceIds(instanceIds);
    }//from w  w w  .ja va 2  s.c  o  m

    if (comment != null && !comment.isEmpty()) {
        deployReq.withComment(comment);
    }

    if (revision != null && !revision.isEmpty()) {
        String customJson = String.format(
                "{\"deploy\":{\"%s\":{\"migrate\":false,\"scm\":{\"revision\":\"%s\"}}}}", app.getShortname(),
                revision);
        deployReq.withCustomJson(customJson);
    }

    CreateDeploymentResult deployRes = opsWorksClient.createDeployment(deployReq);

    String deploymentId = deployRes.getDeploymentId();
    Deployment deployment;
    int timeSpent = 0;

    while (timeSpent < DEPLOYMENT_TIMEOUT) {
        deployment = getDeployment(app.getAppId(), app.getStackId(), deploymentId);
        if (!deployment.getStatus().equals("running") || noWait) {
            return deployment;
        }

        Thread.sleep(DEPLOYMENT_CHECK_INTERVAL * 1000);
        timeSpent += DEPLOYMENT_CHECK_INTERVAL;
    }

    throw new IllegalStateException(
            String.format("Deployment [appId=%s], [stackId=%s], [deploymentId=%s] timed out.", app.getAppId(),
                    app.getStackId(), deploymentId));
}

From source file:com.tispr.gocd.OpsWorksGoPlugin.java

License:Apache License

@Override
protected GoPluginApiResponse handleTaskExecution(GoPluginApiRequest request) {
    Map<String, Object> response = new HashMap<String, Object>();
    try {//from w ww.j a va 2  s.c o  m
        Map<String, Object> map = (Map<String, Object>) new GsonBuilder().create()
                .fromJson(request.requestBody(), Object.class);

        Map<String, Object> configVars = (Map<String, Object>) map.get("config");
        Map<String, Object> context = (Map<String, Object>) map.get("context");
        Map<String, String> envVars = (Map<String, String>) context.get("environmentVariables");

        String appId = getValue(configVars, "appId");
        String layerId = getValue(configVars, "layerId");
        String noWait = getValue(configVars, "noWaitTrue");

        boolean noWaitValue = (noWait != null && noWait.equals("true"));

        String comment = String.format("Deploy build %s via go.cd", envVars.get("GO_PIPELINE_COUNTER"));
        String revision = envVars.get("GO_REVISION");

        log(String.format("[opsworks] Deployment of [appId=%s] started.", appId));

        OpsWorksClient opsWorksClient = new OpsWorksClient(envVars.get(AWS_ACCESS_KEY_ID),
                envVars.get(AWS_SECRET_ACCESS_KEY));
        Deployment d = opsWorksClient.deploy(appId, layerId, comment, revision, noWaitValue);

        if (d.getStatus().equals("successful") || noWaitValue) {
            response.put("success", true);
            response.put("message",
                    String.format("[opsworks] Deployment of [appId=%s] completed successfully.", appId));
        } else {
            response.put("success", false);
            response.put("message", String.format("[opsworks] Deployment of [appId=%s] failed.", appId));
        }
    } catch (Exception e) {
        response.put("success", false);
        response.put("message", "[opsworks] Deployment interrupted. Reason: " + e.getMessage());
    }
    return renderJSON(SUCCESS_RESPONSE_CODE, response);
}