Example usage for com.amazonaws.services.opsworks.model App getAppId

List of usage examples for com.amazonaws.services.opsworks.model App getAppId

Introduction

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

Prototype


public String getAppId() 

Source Link

Document

The app ID.

Usage

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

License:Apache License

protected App getApp(String appId) {
    DescribeAppsRequest req = new DescribeAppsRequest().withAppIds(appId);
    DescribeAppsResult res = opsWorksClient.describeApps(req);

    for (App app : res.getApps()) {
        if (app.getAppId().equals(appId)) {
            return app;
        }/*from  www  .  j a  va2s . c om*/
    }
    throw new IllegalArgumentException(String.format("Application [%s] not found.", appId));
}

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  .  j a  v a2 s  . c om

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