List of usage examples for com.amazonaws.services.elasticbeanstalk.model EnvironmentDescription getSolutionStackName
public String getSolutionStackName()
The name of the SolutionStack
deployed with this environment.
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 . j av a 2 s . c o m * 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; }