List of usage examples for com.amazonaws.services.elasticbeanstalk.model CreateEnvironmentResult getEnvironmentId
public String getEnvironmentId()
The ID of this environment.
From source file:br.com.ingenieux.mojo.beanstalk.env.CreateEnvironmentMojo.java
License:Apache License
protected CreateEnvironmentResult createEnvironment(String cnameToCreate, String newEnvironmentName) throws AbstractMojoExecutionException { /*/*from www . j a v a 2s .co m*/ * Hey Aldrin, have you ever noticed we're getting pedantic on those validations? */ Validate.isTrue(isNotBlank(newEnvironmentName), "No New Environment Name Supplied"); if (null == optionSettings) { optionSettings = introspectOptionSettings(); } versionLabel = lookupVersionLabel(applicationName, versionLabel); CreateEnvironmentContextBuilder builder = CreateEnvironmentContextBuilder.createEnvironmentContext() // .withApplicationName(applicationName)// .withApplicationDescription(applicationDescription)// .withCnamePrefix(cnameToCreate)// .withSolutionStack(lookupSolutionStack(solutionStack))// .withTemplateName(templateName)// .withEnvironmentName(newEnvironmentName)// .withOptionSettings(optionSettings)// .withOptionsToRemove(optionsToRemove)// .withEnvironmentTierName(environmentTierName)// .withEnvironmentTierType(environmentTierType)// .withEnvironmentTierVersion(environmentTierVersion)// .withVersionLabel(versionLabel)// .withTags(tagsToUse);// CreateEnvironmentContext context = builder.build(); CreateEnvironmentCommand command = new CreateEnvironmentCommand(this); CreateEnvironmentResult result = command.execute(context); if (waitForReady) { WaitForEnvironmentContext ctx = new WaitForEnvironmentContextBuilder()// .withEnvironmentRef(result.getEnvironmentId())// .withApplicationName(result.getApplicationName())// .withHealth(mustBeHealthy ? "Green" : null)// .withStatusToWaitFor("Ready")// .build(); new WaitForEnvironmentCommand(this).execute(ctx); } return result; }
From source file:br.com.ingenieux.mojo.beanstalk.env.ReplaceEnvironmentMojo.java
License:Apache License
@Override protected Object executeInternal() throws Exception { solutionStack = lookupSolutionStack(solutionStack); /*//from w w w.ja va 2 s .c om * Is the desired cname not being used by other environments? If so, * just launch the environment */ if (!hasEnvironmentFor(applicationName, cnamePrefix)) { if (getLog().isInfoEnabled()) { getLog().info("Just launching a new environment."); } return super.executeInternal(); } /* * Gets the current environment using this cname */ EnvironmentDescription curEnv = getEnvironmentFor(applicationName, cnamePrefix); if (curEnv.getVersionLabel().equals(versionLabel) && skipIfSameVersion) { getLog().warn(format("Environment is running version %s and skipIfSameVersion is true. Returning", versionLabel)); return null; } /* * Decides on a environmentRef, and launches a new environment */ String cnamePrefixToCreate = getCNamePrefixToCreate(); if (getLog().isInfoEnabled()) { getLog().info("Creating a new environment on " + cnamePrefixToCreate + ".elasticbeanstalk.com"); } if (copyOptionSettings) { copyOptionSettings(curEnv); } if (!solutionStack.equals(curEnv.getSolutionStackName()) && copySolutionStack) { if (getLog().isWarnEnabled()) { getLog().warn(format( "(btw, we're launching with solutionStack/ set to '%s' based on the existing env instead of the " + "default ('%s'). If this is not the desired behavior please set the copySolutionStack property to" + " false.", curEnv.getSolutionStackName(), solutionStack)); } solutionStack = curEnv.getSolutionStackName(); } /** * TODO: Spend a comfy Saturday Afternoon in a Coffee Shop trying to figure out this nice boolean logic with Karnaugh Maps sponsored by Allogy */ boolean userWantsHealthyExitStatus = mustBeHealthy; final boolean currentEnvironmentIsRed = "Red".equals(curEnv.getHealth()); if (redToRedOkay) { //Side-effect: must be before createEnvironment() and waitForEnvironment() to effect superclass behavior. mustBeHealthy = !currentEnvironmentIsRed; } /** * // I really meant it. */ String newEnvironmentName = getNewEnvironmentName( StringUtils.defaultString(this.environmentName, curEnv.getEnvironmentName())); if (getLog().isInfoEnabled()) { getLog().info("And it'll be named " + newEnvironmentName); getLog().info("And it will replace a '" + curEnv.getHealth() + "' enviroment"); } CreateEnvironmentResult createEnvResult = createEnvironment(cnamePrefixToCreate, newEnvironmentName); /* * Waits for completion */ EnvironmentDescription newEnvDesc = null; try { newEnvDesc = waitForEnvironment(createEnvResult.getEnvironmentId()); } catch (Exception exc) { /* * Terminates the failed launched environment */ terminateEnvironment(createEnvResult.getEnvironmentId()); handleException(exc); return null; } /* * Swaps. Due to beanstalker-25, we're doing some extra logic we * actually woudln't want to. */ { boolean swapped = false; for (int i = 1; i <= maxAttempts; i++) { try { swapEnvironmentCNames(newEnvDesc.getEnvironmentId(), curEnv.getEnvironmentId(), cnamePrefix, newEnvDesc); swapped = true; break; } catch (Throwable exc) { if (exc instanceof MojoFailureException) { exc = Throwable.class.cast(MojoFailureException.class.cast(exc).getCause()); } getLog().warn(format("Attempt #%d/%d failed. Sleeping and retrying. Reason: %s (type: %s)", i, maxAttempts, exc.getMessage(), exc.getClass())); sleepInterval(attemptRetryInterval); } } if (!swapped) { getLog().info( "Failed to properly Replace Environment. Finishing the new one. And throwing you a failure"); terminateEnvironment(newEnvDesc.getEnvironmentId()); String message = "Unable to swap cnames. btw, see https://github.com/ingenieux/beanstalker/issues/25 and help us improve beanstalker"; getLog().warn(message); throw new MojoFailureException(message); } } /* * Terminates the previous environment */ terminateEnvironment(curEnv.getEnvironmentId()); /** * TODO: I really need a Saturday Afternoon in order to understand this ffs. */ if (currentEnvironmentIsRed && userWantsHealthyExitStatus) { final String newHealth = newEnvDesc.getHealth(); if (newHealth.equals("Green")) { getLog().info("Previous environment was 'Red', new environment is 'Green' (for the moment)"); } else { getLog().warn(format("Previous environment was 'Red', replacement environment is currently '%s'", newHealth)); //NB: we have already switched from one broken service to another, so this is more for the build status indicator... newEnvDesc = waitForGreenEnvironment(createEnvResult.getEnvironmentId()); } } return createEnvResult; }
From source file:jp.classmethod.aws.gradle.elasticbeanstalk.AWSElasticBeanstalkCreateEnvironmentTask.java
License:Apache License
@TaskAction public void createEnvironment() { // NOPMD // to enable conventionMappings feature String appName = getAppName(); String envName = getEnvName(); String envDesc = getEnvDesc(); String cnamePrefix = getCnamePrefix(); String templateName = getTemplateName(); String versionLabel = getVersionLabel(); Tier tier = getTier();//from w ww. j a va2 s .com Map<String, String> tags = getTags(); AwsBeanstalkPluginExtension ext = getProject().getExtensions().getByType(AwsBeanstalkPluginExtension.class); AWSElasticBeanstalk eb = ext.getClient(); DescribeEnvironmentsResult der = eb.describeEnvironments(new DescribeEnvironmentsRequest() .withApplicationName(appName).withEnvironmentNames(envName).withIncludeDeleted(false)); List<Tag> ebTags = tags.entrySet().stream().map(entry -> { Tag t = new Tag(); t.setKey(entry.getKey()); t.setValue(entry.getValue()); return t; }).collect(Collectors.toList()); if (der.getEnvironments() == null || der.getEnvironments().isEmpty()) { CreateEnvironmentRequest req = new CreateEnvironmentRequest().withApplicationName(appName) .withEnvironmentName(envName).withDescription(envDesc).withTemplateName(templateName) .withVersionLabel(versionLabel); if (tier != null) { req.withTier(tier.toEnvironmentTier()); if (tier == Tier.WebServer) { req.withCNAMEPrefix(cnamePrefix); } } if (ebTags != null && !ebTags.isEmpty()) { req.withTags(ebTags); } CreateEnvironmentResult result = eb.createEnvironment(req); getLogger().info("environment {} @ {} ({}) created", envName, appName, result.getEnvironmentId()); } else { String environmentId = der.getEnvironments().get(0).getEnvironmentId(); // Only these two values are required to deploy the a application UpdateEnvironmentRequest req = new UpdateEnvironmentRequest().withEnvironmentId(environmentId) .withVersionLabel(versionLabel); // All other variables are optional and refer to the environment if (isNotBlank(envName)) { req.withEnvironmentName(envName); } if (isNotBlank(envDesc)) { req.withDescription(envDesc); } if (isNotBlank(templateName)) { req.withTemplateName(templateName); } eb.updateEnvironment(req); getLogger().info("environment {} @ {} ({}) updated", envName, appName, environmentId); } }
From source file:org.xmlsh.aws.gradle.elasticbeanstalk.AWSElasticBeanstalkCreateEnvironmentTask.java
License:BSD License
@TaskAction public void createEnvironment() { // to enable conventionMappings feature String appName = getAppName(); String envName = getEnvName(); String envDesc = getEnvDesc(); String cnamePrefix = getCnamePrefix(); String templateName = getTemplateName(); String versionLabel = getVersionLabel(); Tier tier = getTier();//from w w w .j av a2 s.co m AwsBeanstalkPluginExtension ext = getProject().getExtensions().getByType(AwsBeanstalkPluginExtension.class); AWSElasticBeanstalk eb = ext.getClient(); DescribeEnvironmentsResult der = eb.describeEnvironments(new DescribeEnvironmentsRequest() .withApplicationName(appName).withEnvironmentNames(envName).withIncludeDeleted(false)); if (der.getEnvironments() == null || der.getEnvironments().isEmpty()) { CreateEnvironmentRequest req = new CreateEnvironmentRequest().withApplicationName(appName) .withEnvironmentName(envName).withDescription(envDesc).withTemplateName(templateName) .withVersionLabel(versionLabel).withTier(tier.toEnvironmentTier()); if (tier == Tier.WebServer) { req.withCNAMEPrefix(cnamePrefix); } CreateEnvironmentResult result = eb.createEnvironment(req); getLogger().info( "environment " + envName + " @ " + appName + " (" + result.getEnvironmentId() + ") created"); } else { String environmentId = der.getEnvironments().get(0).getEnvironmentId(); eb.updateEnvironment(new UpdateEnvironmentRequest().withEnvironmentId(environmentId) .withEnvironmentName(envName).withDescription(envDesc).withTemplateName(templateName) .withVersionLabel(versionLabel).withTier(tier.toEnvironmentTier())); getLogger().info("environment " + envName + " @ " + appName + " (" + environmentId + ") updated"); } }