List of usage examples for com.amazonaws.services.elasticbeanstalk.model EnvironmentDescription getVersionLabel
public String getVersionLabel()
The application version deployed in this environment.
From source file:br.com.ingenieux.jenkins.plugins.awsebdeployment.cmd.ZeroDowntime.java
License:Apache License
@Override public boolean perform() throws Exception { environmentNames = generateEnvironmentNames(); EnvironmentDescription environmentDescription = null; try {/*from ww w . ja va2s. c o m*/ environmentDescription = lookupEnvironmentIds(environmentNames); environmentId = environmentDescription.getEnvironmentId(); } catch (InvalidDeploymentTypeException exc) { log("Zero Downtime isn't valid for Worker Environments."); return true; } catch (InvalidEnvironmentsSizeException exc) { log("Unable to find any suitable environment. Aborting."); return true; } if (environmentDescription.getVersionLabel().equals(getVersionLabel())) { log("The version to deploy and currently used are the same. Even if you overwrite, AWSEB won't allow you to update." + "Skipping."); return true; } templateName = createConfigurationTemplate(environmentId); String clonedEnvironmentId = createEnvironment(getVersionLabel(), templateName, environmentNames); setEnvironmentId(clonedEnvironmentId); log("From now on, we'll use '%s' as the environmentId, but once finished, we'll swap and replace with '%s'", getEnvironmentId(), environmentId); return false; }
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 . jav a 2s . 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; }
From source file:br.com.ingenieux.mojo.beanstalk.version.CleanPreviousVersionsMojo.java
License:Apache License
@Override protected Object executeInternal() throws MojoExecutionException, MojoFailureException { boolean bVersionsToKeepDefined = (null != versionsToKeep); boolean bDaysToKeepDefined = (null != daysToKeep); if (!(bVersionsToKeepDefined ^ bDaysToKeepDefined)) { throw new MojoFailureException("Declare either versionsToKeep or daysToKeep, but not both nor none!"); }/* www. j ava 2 s . c o m*/ DescribeApplicationVersionsRequest describeApplicationVersionsRequest = new DescribeApplicationVersionsRequest() .withApplicationName(applicationName); DescribeApplicationVersionsResult appVersions = getService() .describeApplicationVersions(describeApplicationVersionsRequest); DescribeEnvironmentsResult environments = getService().describeEnvironments(); List<ApplicationVersionDescription> appVersionList = new ArrayList<ApplicationVersionDescription>( appVersions.getApplicationVersions()); deletedVersionsCount = 0; for (EnvironmentDescription d : environments.getEnvironments()) { boolean bActiveEnvironment = (d.getStatus().equals("Running") || d.getStatus().equals("Launching") || d.getStatus().equals("Ready")); for (ListIterator<ApplicationVersionDescription> appVersionIterator = appVersionList .listIterator(); appVersionIterator.hasNext();) { ApplicationVersionDescription appVersion = appVersionIterator.next(); boolean bMatchesVersion = appVersion.getVersionLabel().equals(d.getVersionLabel()); if (bActiveEnvironment && bMatchesVersion) { getLog().info("VersionLabel " + appVersion.getVersionLabel() + " is bound to environment " + d.getEnvironmentName() + " - Skipping it"); appVersionIterator.remove(); } } } filterAppVersionListByVersionLabelPattern(appVersionList, cleanFilter); Collections.sort(appVersionList, new Comparator<ApplicationVersionDescription>() { @Override public int compare(ApplicationVersionDescription o1, ApplicationVersionDescription o2) { return new CompareToBuilder().append(o1.getDateUpdated(), o2.getDateUpdated()).toComparison(); } }); if (bDaysToKeepDefined) { Date now = new Date(); for (ApplicationVersionDescription d : appVersionList) { long delta = now.getTime() - d.getDateUpdated().getTime(); delta /= 1000; delta /= 86400; boolean shouldDeleteP = (delta > daysToKeep); if (getLog().isDebugEnabled()) { getLog().debug("Version " + d.getVersionLabel() + " was from " + delta + " days ago. Should we delete? " + shouldDeleteP); } if (shouldDeleteP) { deleteVersion(d); } } } else { while (appVersionList.size() > versionsToKeep) { deleteVersion(appVersionList.remove(0)); } } getLog().info("Deleted " + deletedVersionsCount + " versions."); return null; }
From source file:br.com.ingenieux.mojo.beanstalk.version.RollbackVersionMojo.java
License:Apache License
@Override protected Object executeInternal() throws MojoExecutionException, MojoFailureException { // TODO: Deal with withVersionLabels DescribeApplicationVersionsRequest describeApplicationVersionsRequest = new DescribeApplicationVersionsRequest() .withApplicationName(applicationName); DescribeApplicationVersionsResult appVersions = getService() .describeApplicationVersions(describeApplicationVersionsRequest); DescribeEnvironmentsRequest describeEnvironmentsRequest = new DescribeEnvironmentsRequest() .withApplicationName(applicationName).withEnvironmentIds(curEnv.getEnvironmentId()) .withEnvironmentNames(curEnv.getEnvironmentName()).withIncludeDeleted(false); DescribeEnvironmentsResult environments = getService().describeEnvironments(describeEnvironmentsRequest); List<ApplicationVersionDescription> appVersionList = new ArrayList<ApplicationVersionDescription>( appVersions.getApplicationVersions()); List<EnvironmentDescription> environmentList = environments.getEnvironments(); if (environmentList.isEmpty()) { throw new MojoFailureException("No environments were found"); }/*from www .j av a 2 s . com*/ EnvironmentDescription d = environmentList.get(0); Collections.sort(appVersionList, new Comparator<ApplicationVersionDescription>() { @Override public int compare(ApplicationVersionDescription o1, ApplicationVersionDescription o2) { return new CompareToBuilder().append(o1.getDateUpdated(), o2.getDateUpdated()).toComparison(); } }); Collections.reverse(appVersionList); if (latestVersionInstead) { ApplicationVersionDescription latestVersionDescription = appVersionList.get(0); return changeToVersion(d, latestVersionDescription); } ListIterator<ApplicationVersionDescription> versionIterator = appVersionList.listIterator(); String curVersionLabel = d.getVersionLabel(); while (versionIterator.hasNext()) { ApplicationVersionDescription versionDescription = versionIterator.next(); String versionLabel = versionDescription.getVersionLabel(); if (curVersionLabel.equals(versionLabel) && versionIterator.hasNext()) { return changeToVersion(d, versionIterator.next()); } } throw new MojoFailureException("No previous version was found (current version: " + curVersionLabel); }
From source file:br.com.ingenieux.mojo.beanstalk.version.RollbackVersionMojo.java
License:Apache License
Object changeToVersion(EnvironmentDescription d, ApplicationVersionDescription latestVersionDescription) { String curVersionLabel = d.getVersionLabel(); String versionLabel = latestVersionDescription.getVersionLabel(); UpdateEnvironmentRequest request = new UpdateEnvironmentRequest().withEnvironmentId(d.getEnvironmentId()) .withVersionLabel(versionLabel); getLog().info("Changing versionLabel for Environment[name=" + curEnv.getEnvironmentName() + "; environmentId=" + curEnv.getEnvironmentId() + "] from version " + curVersionLabel + " to version " + latestVersionDescription.getVersionLabel()); if (dryRun) { return null; }//from w w w. j a v a 2 s .co m return getService().updateEnvironment(request); }
From source file:jetbrains.buildServer.runner.elasticbeanstalk.AWSClient.java
License:Apache License
private boolean isSuccess(@NotNull EnvironmentDescription environment, @NotNull String versionLabel) { return environment.getVersionLabel().equals(versionLabel); }