com.amazonaws.services.elasticbeanstalk.AWSElasticBeanstalkClient Java Examples

The following examples show how to use com.amazonaws.services.elasticbeanstalk.AWSElasticBeanstalkClient. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestSuccessfulBeanstalkDeploymentTask.java    From aws-ant-tasks with Apache License 2.0 6 votes vote down vote up
public void execute() {
    checkParams();
    AWSElasticBeanstalkClient bcClient = getOrCreateClient(AWSElasticBeanstalkClient.class);
    DescribeEnvironmentsRequest deRequest = new DescribeEnvironmentsRequest()
            .withEnvironmentNames(environmentName);
    DescribeEnvironmentsResult result = bcClient
            .describeEnvironments(deRequest);
    if (result.getEnvironments().size() < 1) {
        throw new BuildException(
                "No environments found with the specified name "
                        + environmentName);
    }
    try {
        AWSTestUtils.waitForEnvironmentToTransitionToStateAndHealth(
                environmentName, EnvironmentStatus.Ready, null, bcClient);
    } catch (InterruptedException e) {
        throw new BuildException(e.getMessage());
    }
}
 
Example #2
Source File: CreateBeanstalkApplicationTask.java    From aws-ant-tasks with Apache License 2.0 5 votes vote down vote up
public void execute() {
    checkParams();
    AWSElasticBeanstalkClient client = getOrCreateClient(AWSElasticBeanstalkClient.class);
    CreateApplicationRequest request = new CreateApplicationRequest(
            applicationName).withDescription(applicationDescription);
    System.out.println("Creating application " + applicationName + "...");
    try {
        client.createApplication(request);
    } catch (Exception e) {
        throw new BuildException(
                "Exception while attempting to create application: "
                        + e.getMessage(), e);
    }
    System.out.println("Application created successfully");
}
 
Example #3
Source File: TerminateBeanstalkEnvironmentTask.java    From aws-ant-tasks with Apache License 2.0 5 votes vote down vote up
public void execute() {
    System.out
            .println("Terminating environment " + environmentName + "...");
    checkParams();
    AWSElasticBeanstalkClient bcClient = getOrCreateClient(AWSElasticBeanstalkClient.class);
    try {
        bcClient.terminateEnvironment(new TerminateEnvironmentRequest()
                .withEnvironmentName(environmentName));
    } catch (Exception e) {
        throw new BuildException("Could not terminate environment "
                + e.getMessage(), e);
    }
    System.out
            .println("The request to terminate the environment has been submitted.");
}
 
Example #4
Source File: AWSTestUtils.java    From aws-ant-tasks with Apache License 2.0 5 votes vote down vote up
public static void waitForEnvironmentToTransitionToStateAndHealth(
        String environmentName, EnvironmentStatus state,
        EnvironmentHealth health, AWSElasticBeanstalkClient bcClient)
        throws InterruptedException {
    System.out.println("Waiting for instance " + environmentName
            + " to transition to " + state + "/" + health);

    int count = 0;
    while (true) {
        Thread.sleep(1000 * 30);
        if (count++ > 100) {
            throw new RuntimeException("Environment " + environmentName
                    + " never transitioned to " + state + "/" + health);
        }

        List<EnvironmentDescription> environments = bcClient
                .describeEnvironments(
                        new DescribeEnvironmentsRequest()
                                .withEnvironmentNames(environmentName))
                .getEnvironments();

        if (environments.size() == 0) {
            System.out
                    .println("No environments with that name were found.");
            return;
        }

        EnvironmentDescription environment = environments.get(0);
        System.out.println(" - " + environment.getStatus() + "/"
                + environment.getHealth());
        if (environment.getStatus().equalsIgnoreCase(state.toString()) == false)
            continue;
        if (health != null
                && environment.getHealth().equalsIgnoreCase(
                        health.toString()) == false)
            continue;
        return;
    }
}
 
Example #5
Source File: BeanstalkDeployer.java    From gradle-beanstalk-plugin with MIT License 4 votes vote down vote up
public BeanstalkDeployer(String s3Endpoint, String beanstalkEndpoint, AWSCredentialsProvider credentialsProvider) {
    s3 = new AmazonS3Client(credentialsProvider);
    elasticBeanstalk = new AWSElasticBeanstalkClient(credentialsProvider);
    s3.setEndpoint(s3Endpoint);
    elasticBeanstalk.setEndpoint(beanstalkEndpoint);
}
 
Example #6
Source File: CreateBeanstalkEnvironmentTask.java    From aws-ant-tasks with Apache License 2.0 4 votes vote down vote up
public void execute() {
    checkParams();
    AWSElasticBeanstalkClient client = getOrCreateClient(AWSElasticBeanstalkClient.class);
    CreateEnvironmentRequest eRequest = new CreateEnvironmentRequest(
            applicationName, environmentName)
            .withDescription(environmentDescription)
            .withVersionLabel(versionLabel)
            .withSolutionStackName(solutionStackName);
    if (!(tierName == null || tierType == null || tierVersion == null)) {
        eRequest.setTier(new EnvironmentTier().withName(tierName)
                .withType(tierType).withVersion(tierVersion));
    }

    if (cnamePrefix != null) {
        CheckDNSAvailabilityResult dnsResult = client
                .checkDNSAvailability(new CheckDNSAvailabilityRequest(
                        cnamePrefix));
        if (!dnsResult.isAvailable()) {
            throw new BuildException("The specified CNAME " + cnamePrefix
                    + " was not available");
        }
        eRequest.setCNAMEPrefix(cnamePrefix);
    }
    List<ConfigurationOptionSetting> optionSettings = new LinkedList<ConfigurationOptionSetting>();
    for (Setting setting : settings) {
        optionSettings.add(new ConfigurationOptionSetting(setting
                .getNamespace(), setting.getOptionName(), setting
                .getValue()));
    }
    if (optionSettings.size() > 0) {
        eRequest.setOptionSettings(optionSettings);
    }
    System.out.println("Creating environment " + environmentName + "...");
    String cNAME = "";
    try {
        CreateEnvironmentResult result = client.createEnvironment(eRequest);
        if ((cNAME = result.getCNAME()) == null) {
            System.out
                    .println("Create environment request submitted. The environment configuration does not support a CNAME.");
        } else {
            System.out
                    .println("Create environment request submitted. When the environment is finished launching, your deployment will be available at "
                            + cNAME);
        }
    } catch (Exception e) {
        throw new BuildException(
                "Exception while attempting to create environment: "
                        + e.getMessage(), e);
    }

}
 
Example #7
Source File: DeleteBeanstalkApplicationTask.java    From aws-ant-tasks with Apache License 2.0 4 votes vote down vote up
public void execute() {
    checkParams();
    AWSElasticBeanstalkClient bcClient = getOrCreateClient(AWSElasticBeanstalkClient.class);
    bcClient.deleteApplication(new DeleteApplicationRequest(applicationName));
}
 
Example #8
Source File: AWSEBDeploymentBuilder.java    From awseb-deployment-plugin with Apache License 2.0 4 votes vote down vote up
public FormValidation doValidateCredentials(
        @QueryParameter("credentialId") final String credentialId,
        @QueryParameter final String awsRegion) {
    for (String value : Arrays.asList(credentialId, awsRegion)) {
        if (value.contains("$")) {
            return FormValidation.warning("Validation skipped due to parameter usage ('$')");
        }
    }

    StringWriter stringWriter = new StringWriter();
    PrintWriter w = new PrintWriter(stringWriter, true);

    try {
        w.printf("<ul>%n");

        w.printf("<li>Building Client (credentialId: '%s', region: '%s')</li>%n", Util.escape(credentialId),
                Util.escape(awsRegion));

        AWSClientFactory factory = AWSClientFactory.getClientFactory(credentialId, awsRegion);

        AmazonS3Client amazonS3 = factory.getService(AmazonS3Client.class);

        String s3Endpoint = factory.getEndpointFor(amazonS3);

        w.printf("<li>Testing Amazon S3 Service (endpoint: %s)</li>%n", Util.escape(s3Endpoint));

        w.printf("<li>Buckets Found: %d</li>%n", amazonS3.listBuckets().size());

        AWSElasticBeanstalkClient
                awsElasticBeanstalk =
                factory.getService(AWSElasticBeanstalkClient.class);

        String
                awsEBEndpoint =
                factory.getEndpointFor(awsElasticBeanstalk);

        w.printf("<li>Testing AWS Elastic Beanstalk Service (endpoint: %s)</li>%n",
                Util.escape(awsEBEndpoint));

        List<String>
                applicationList =
                Lists.transform(awsElasticBeanstalk.describeApplications().getApplications(),
                        new Function<ApplicationDescription, String>() {
                            @Override
                            public String apply(ApplicationDescription input) {
                                return input.getApplicationName();
                            }
                        });

        w.printf("<li>Applications Found: %d (%s)</li>%n", applicationList.size(),
                Util.escape(StringUtils.join(applicationList, ", ")));

        w.printf("</ul>%n");

        return FormValidation.okWithMarkup(stringWriter.toString());
    } catch (Exception exc) {
        return FormValidation.error(exc, "Failure");
    }
}
 
Example #9
Source File: DeployerCommand.java    From awseb-deployment-plugin with Apache License 2.0 3 votes vote down vote up
@Override
public boolean perform() throws Exception {
    AWSClientFactory factory;

    factory = AWSClientFactory.getClientFactory(getConfig().getCredentialId(), getConfig().getAwsRegion());

    log("Using region: '%s'", getConfig().getAwsRegion());

    setS3(factory.getService(AmazonS3Client.class));
    setAwseb(factory.getService(AWSElasticBeanstalkClient.class));

    return false;
}