Java 类com.amazonaws.services.elasticbeanstalk.AWSElasticBeanstalkClient 实例源码

项目:aws-ant-tasks    文件:TestSuccessfulBeanstalkDeploymentTask.java   
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());
    }
}
项目:awseb-deployment-plugin    文件:DeployerCommand.java   
@Override
public boolean perform() throws Exception {
    AWSClientFactory factory;

    if (null != getDeployerConfig().getCredentials()) {
        factory = AWSClientFactory
                .getClientFactory(getDeployerConfig().getCredentials(), getDeployerConfig().getAwsRegion());
    } else {
        factory = AWSClientFactory.getClientFactory("", getDeployerConfig().getAwsRegion());
    }

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

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

    return false;
}
项目:jcabi-beanstalk-maven-plugin    文件:EnvironmentTest.java   
/**
 * Environment can collect events from running environment.
 * @throws Exception If something is wrong
 */
@Test
public void collectsEventsFromLiveEnvironment() throws Exception {
    Assume.assumeThat(EnvironmentTest.AWS_KEY, Matchers.notNullValue());
    final AWSCredentials creds = new BasicAWSCredentials(
        EnvironmentTest.AWS_KEY,
        EnvironmentTest.AWS_SECRET
    );
    final AWSElasticBeanstalk ebt = new AWSElasticBeanstalkClient(creds);
    final Environment env = new Environment(ebt, "e-nxmcbf3pvk");
    Logger.info(
        this,
        "events: %[list]s",
        Arrays.asList(env.events())
    );
}
项目:awspush-maven-plugin    文件:AWSPush.java   
/**
 * Create a new Beanstalk application version using the file on S3 at s3BucketName/s3FileKey.
 * Deploy this application version to the Beanstalk environment.
 */
public void deployToEnvironment() {
    this.info("Connecting to ElasticBeanstalk");
    AWSElasticBeanstalkClient beanstalkClient = new AWSElasticBeanstalkClient(this.mvnArgs.getCredentials());

    // create new application version
    this.info("Creating new version " + this.mvnArgs.applicationName + "/" + this.mvnArgs.applicationVersion);
    S3Location s3Location = new S3Location()
            .withS3Bucket(this.mvnArgs.s3BucketName)
            .withS3Key(this.mvnArgs.s3FileKey);
    CreateApplicationVersionRequest versionRequest = new CreateApplicationVersionRequest()
            .withApplicationName(this.mvnArgs.applicationName)
            .withVersionLabel(this.mvnArgs.applicationVersion)
            .withSourceBundle(s3Location);
    CreateApplicationVersionResult versionResult = beanstalkClient.createApplicationVersion(versionRequest);
    Util.dump(versionResult, this.mvnArgs.getLog());

    // tell the environment to use the new application version
    this.info("Updating environment " + this.mvnArgs.environmentName + " with version " + this.mvnArgs.applicationVersion);
    UpdateEnvironmentRequest environmentRequest = new UpdateEnvironmentRequest()
            .withEnvironmentName(this.mvnArgs.environmentName)
            .withVersionLabel(this.mvnArgs.applicationVersion);
    UpdateEnvironmentResult envResult = beanstalkClient.updateEnvironment(environmentRequest);
    Util.dump(envResult, this.mvnArgs.getLog());
}
项目:aws-ant-tasks    文件:CreateBeanstalkApplicationTask.java   
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");
}
项目:aws-ant-tasks    文件:TerminateBeanstalkEnvironmentTask.java   
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.");
}
项目:aws-ant-tasks    文件:AWSTestUtils.java   
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;
    }
}
项目:jcabi-beanstalk-maven-plugin    文件:ApplicationTest.java   
/**
 * Environment can deploy and reverse with a broken WAR file. This test
 * has to be executed only if you have full access to AWS S3 bucket, and
 * AWS EBT for deployment. The test runs full cycle of deployment and then
 * destroying of a new environment. It won't hurt anything, but will
 * consume some EBT resources. Be careful.
 *
 * @throws Exception If something is wrong
 */
@Test
public void deploysAndReversesWithLiveAccount() throws Exception {
    Assume.assumeThat(ApplicationTest.AWS_KEY, Matchers.notNullValue());
    final AWSCredentials creds = new BasicAWSCredentials(
        ApplicationTest.AWS_KEY,
        ApplicationTest.AWS_SECRET
    );
    final AWSElasticBeanstalk ebt = new AWSElasticBeanstalkClient(creds);
    final String name = "netbout";
    final Application app = new Application(ebt, name);
    final File war = this.temp.newFile("temp.war");
    FileUtils.writeStringToFile(war, "broken JAR file content");
    final Environment candidate = app.candidate(
        new OverridingVersion(
            ebt,
            name,
            new OverridingBundle(
                new AmazonS3Client(creds),
                "webapps.netbout.com",
                war.getName(),
                war
            )
        ),
        name
    );
    MatcherAssert.assertThat(candidate.green(), Matchers.equalTo(false));
    Logger.info(this, "tail report:\n%s", candidate.tail());
    candidate.terminate();
}
项目:jcabi-beanstalk-maven-plugin    文件:EnvironmentTest.java   
/**
 * Environment can fetch TAIL report from live environment.
 * @throws Exception If something is wrong
 */
@Test
public void fetchesTailReportFromLiveEnvironment() throws Exception {
    Assume.assumeThat(EnvironmentTest.AWS_KEY, Matchers.notNullValue());
    final AWSCredentials creds = new BasicAWSCredentials(
        EnvironmentTest.AWS_KEY,
        EnvironmentTest.AWS_SECRET
    );
    final AWSElasticBeanstalk ebt = new AWSElasticBeanstalkClient(creds);
    final Environment env = new Environment(ebt, "e-2n2mqauqae");
    Logger.info(this, "tail report:\n%s", env.tail());
}
项目:gradle-beanstalk-plugin    文件:BeanstalkDeployer.java   
public BeanstalkDeployer(String s3Endpoint, String beanstalkEndpoint, AWSCredentialsProvider credentialsProvider) {
    s3 = new AmazonS3Client(credentialsProvider);
    elasticBeanstalk = new AWSElasticBeanstalkClient(credentialsProvider);
    s3.setEndpoint(s3Endpoint);
    elasticBeanstalk.setEndpoint(beanstalkEndpoint);
}
项目:aws-beanstalk-publisher    文件:AWSEBUtils.java   
public static AWSElasticBeanstalk getElasticBeanstalk(AWSCredentialsProvider credentials, Region region) {
    AWSElasticBeanstalk awseb = region.createClient(AWSElasticBeanstalkClient.class, credentials, getClientConfig());
    return awseb;
}
项目:aws-ant-tasks    文件:CreateBeanstalkEnvironmentTask.java   
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);
    }

}
项目:aws-ant-tasks    文件:DeleteBeanstalkApplicationTask.java   
public void execute() {
    checkParams();
    AWSElasticBeanstalkClient bcClient = getOrCreateClient(AWSElasticBeanstalkClient.class);
    bcClient.deleteApplication(new DeleteApplicationRequest(applicationName));
}
项目:awseb-deployment-plugin    文件:AWSEBDeploymentBuilder.java   
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", credentialId,
                awsRegion);

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

        AmazonS3 amazonS3 = factory.getService(AmazonS3Client.class);
        String s3Endpoint = factory.getEndpointFor((AmazonS3Client) amazonS3);

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

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

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

        String
                awsEBEndpoint =
                factory.getEndpointFor((AWSElasticBeanstalkClient) awsElasticBeanstalk);

        w.printf("<li>Testing AWS Elastic Beanstalk Service (endpoint: %s)</li>%n",
                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(),
                StringUtils.join(applicationList, ", "));

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

        return FormValidation.okWithMarkup(stringWriter.toString());
    } catch (Exception exc) {
        return FormValidation.error(exc, "Failure");
    }
}