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()); } }
@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; }
/** * 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()) ); }
/** * 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()); }
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"); }
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."); }
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; } }
/** * 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(); }
/** * 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()); }
public BeanstalkDeployer(String s3Endpoint, String beanstalkEndpoint, AWSCredentialsProvider credentialsProvider) { s3 = new AmazonS3Client(credentialsProvider); elasticBeanstalk = new AWSElasticBeanstalkClient(credentialsProvider); s3.setEndpoint(s3Endpoint); elasticBeanstalk.setEndpoint(beanstalkEndpoint); }
public static AWSElasticBeanstalk getElasticBeanstalk(AWSCredentialsProvider credentials, Region region) { AWSElasticBeanstalk awseb = region.createClient(AWSElasticBeanstalkClient.class, credentials, getClientConfig()); return awseb; }
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); } }
public void execute() { checkParams(); AWSElasticBeanstalkClient bcClient = getOrCreateClient(AWSElasticBeanstalkClient.class); bcClient.deleteApplication(new DeleteApplicationRequest(applicationName)); }
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"); } }