List of usage examples for com.amazonaws.services.elasticbeanstalk.model EnvironmentDescription getStatus
public String getStatus()
The current operational status of the environment:
Launching
: Environment is in the process of initial deployment.
From source file:br.com.ingenieux.mojo.beanstalk.cmd.env.waitfor.WaitForEnvironmentCommand.java
License:Apache License
protected List<Predicate<EnvironmentDescription>> getEnvironmentDescriptionPredicate( WaitForEnvironmentContext context) { // as well as those (which are used as predicate variables, thus being // final)/* w w w . jav a 2 s . co m*/ final String environmentRef = context.getEnvironmentRef(); final String statusToWaitFor = defaultString(context.getStatusToWaitFor(), "!Terminated"); final String healthToWaitFor = context.getHealth(); // Sanity Check Validate.isTrue(isNotBlank(environmentRef), "EnvironmentRef is blank or null", environmentRef); // some argument juggling final boolean negated = statusToWaitFor.startsWith("!"); // argument juggling List<Predicate<EnvironmentDescription>> result = new ArrayList<Predicate<EnvironmentDescription>>(); if (environmentRef.matches("e-\\p{Alnum}{10}")) { result.add(new Predicate<EnvironmentDescription>() { @Override public boolean apply(EnvironmentDescription t) { return t.getEnvironmentId().equals(environmentRef); } }); info("... with environmentId equal to '%s'", environmentRef); } else if (environmentRef.matches(".*\\Q.elasticbeanstalk.com\\E")) { result.add(new Predicate<EnvironmentDescription>() { @Override public boolean apply(EnvironmentDescription t) { return defaultString(t.getCNAME()).equals(environmentRef); } }); info("... with cname set to '%s'", environmentRef); } else { String tmpRE = Pattern.quote(environmentRef); if (environmentRef.endsWith("*")) { tmpRE = format("^\\Q%s\\E.*", environmentRef.substring(0, -1 + environmentRef.length())); } final String environmentRefNameRE = tmpRE; result.add(new Predicate<EnvironmentDescription>() { @Override public boolean apply(EnvironmentDescription t) { return t.getEnvironmentName().matches(environmentRefNameRE); } }); info("... with environmentName matching re '%s'", environmentRefNameRE); } { // start building predicates with the status one - "![status]" must // be equal to status or not status final int offset = negated ? 1 : 0; final String vStatusToWaitFor = statusToWaitFor.substring(offset); result.add(new Predicate<EnvironmentDescription>() { public boolean apply(EnvironmentDescription t) { boolean result = vStatusToWaitFor.equals(t.getStatus()); if (negated) { result = !result; } debug("testing status '%s' as equal as '%s' (negated? %s, offset: %d): %s", vStatusToWaitFor, t.getStatus(), negated, offset, result); return result; } }); info("... with status %s set to '%s'", (negated ? "*NOT*" : " "), vStatusToWaitFor); } { if (isNotBlank(healthToWaitFor)) { result.add(new Predicate<EnvironmentDescription>() { @Override public boolean apply(EnvironmentDescription t) { return t.getHealth().equals(healthToWaitFor); } }); info("... with health equal to '%s'", healthToWaitFor); } } return result; }
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 a v a2 s . c om 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:fr.xebia.cloud.amazon.aws.tools.AmazonAwsUtils.java
License:Apache License
public static void synchronousTerminateEnvironments(@Nonnull String applicationName, @Nonnull AWSElasticBeanstalk beanstalk) { Set<String> statusToTerminate = Sets.newHashSet("Launching", "Updating", "Ready"); Set<String> statusTerminating = Sets.newHashSet("Terminating"); List<EnvironmentDescription> environments = beanstalk .describeEnvironments(new DescribeEnvironmentsRequest().withApplicationName(applicationName)) .getEnvironments();//www. j ava2s. com List<EnvironmentDescription> environmentsToWaitFor = Collections.emptyList(); int counter = 0; while (counter < 1 * 60) { environmentsToWaitFor = Lists.newArrayList(); for (EnvironmentDescription environment : environments) { if (statusToTerminate.contains(environment.getStatus())) { TerminateEnvironmentResult terminateEnvironmentResult = beanstalk.terminateEnvironment( new TerminateEnvironmentRequest().withEnvironmentId(environment.getEnvironmentId())); logger.debug("Terminate environment {}, status:{} - ", new Object[] { environment.getEnvironmentName(), environment.getStatus(), terminateEnvironmentResult }); environmentsToWaitFor.add(environment); } else if (statusTerminating.contains(environment.getStatus())) { environmentsToWaitFor.add(environment); logger.debug("Skip termination of not running environment {}", environment); } else { logger.trace("skip terminated environment {}", environment); } } if (environmentsToWaitFor.isEmpty()) { break; } else { try { Thread.sleep(500); } catch (Exception e) { throw Throwables.propagate(e); } environments = beanstalk .describeEnvironments( new DescribeEnvironmentsRequest().withApplicationName(applicationName)) .getEnvironments(); } } if (!environmentsToWaitFor.isEmpty()) { logger.warn("Failure to terminate {}", environmentsToWaitFor); } }
From source file:jetbrains.buildServer.runner.elasticbeanstalk.AWSClient.java
License:Apache License
private void waitForDeployment(@NotNull String environmentId, String versionLabel, long startTime, int waitTimeoutSec, int waitIntervalSec) { myListener.deploymentWaitStarted(getEnvironment(environmentId).getEnvironmentName()); EnvironmentDescription environment; String status;//from www .j a va2 s . c o m List<EventDescription> newEvents; List<EventDescription> errorEvents; boolean hasError; Date startDate = new Date(startTime); while (true) { environment = getEnvironment(environmentId); myListener.deploymentInProgress(environment.getEnvironmentName()); status = getHumanReadableStatus(environment.getStatus()); newEvents = getNewEvents(environmentId, startDate); for (EventDescription event : newEvents) { myListener.deploymentUpdate(event.getMessage()); } if (System.currentTimeMillis() - startTime > waitTimeoutSec * 1000) { myListener.deploymentFailed(environment.getApplicationName(), environment.getEnvironmentName(), versionLabel, true, null); return; } errorEvents = getErrorEvents(environmentId, versionLabel); hasError = errorEvents.size() > 0; if (!status.equals("updating") || hasError) { break; } try { Thread.sleep(waitIntervalSec * 1000); } catch (InterruptedException e) { processFailure(e); return; } } if (isSuccess(environment, versionLabel)) { myListener.deploymentSucceeded(versionLabel); } else { Listener.ErrorInfo errorEvent = hasError ? getErrorInfo(errorEvents.get(0)) : null; myListener.deploymentFailed(environment.getApplicationName(), environment.getEnvironmentName(), versionLabel, false, errorEvent); } }
From source file:jp.classmethod.aws.gradle.elasticbeanstalk.AWSElasticBeanstalkWaitEnvironmentStatusTask.java
License:Apache License
@TaskAction public void waitEnvironmentForStatus() { // NOPMD // to enable conventionMappings feature String appName = getAppName(); String envName = getEnvName(); int loopTimeout = getLoopTimeout(); int loopWait = getLoopWait(); if (appName == null) { throw new GradleException("applicationName is not specified"); }//ww w. j a va 2s .c o m AwsBeanstalkPluginExtension ext = getProject().getExtensions().getByType(AwsBeanstalkPluginExtension.class); AWSElasticBeanstalk eb = ext.getClient(); long start = System.currentTimeMillis(); while (true) { if (System.currentTimeMillis() > start + (loopTimeout * 1000)) { throw new GradleException("Timeout"); } try { DescribeEnvironmentsResult der = eb.describeEnvironments(new DescribeEnvironmentsRequest() .withApplicationName(appName).withEnvironmentNames(envName)); if (der.getEnvironments() == null || der.getEnvironments().isEmpty()) { getLogger().info("environment " + envName + " @ " + appName + " not found"); return; } EnvironmentDescription ed = der.getEnvironments().get(0); if (successStatuses.contains(ed.getStatus())) { getLogger().info("Status of environment " + envName + " @ " + appName + " is now " + ed.getStatus() + "."); break; } else if (waitStatuses.contains(ed.getStatus())) { getLogger().info( "Status of environment " + envName + " @ " + appName + " is " + ed.getStatus() + "..."); try { Thread.sleep(loopWait * 1000); } catch (InterruptedException e) { throw new GradleException("interrupted", e); } } else { // fail if not contains in successStatus or waitStatus throw new GradleException("Status of environment " + envName + " @ " + appName + " is " + ed.getStatus() + ". It seems to be failed."); } } catch (AmazonServiceException e) { throw new GradleException(e.getMessage(), e); } } }
From source file:org.xmlsh.aws.gradle.elasticbeanstalk.AWSElasticBeanstalkWaitEnvironmentStatusTask.java
License:BSD License
@TaskAction public void waitEnvironmentForStatus() { // to enable conventionMappings feature String appName = getAppName(); String envName = getEnvName(); int loopTimeout = getLoopTimeout(); int loopWait = getLoopWait(); if (appName == null) throw new GradleException("applicationName is not specified"); AwsBeanstalkPluginExtension ext = getProject().getExtensions().getByType(AwsBeanstalkPluginExtension.class); AWSElasticBeanstalk eb = ext.getClient(); long start = System.currentTimeMillis(); while (true) { if (System.currentTimeMillis() > start + (loopTimeout * 1000)) { throw new GradleException("Timeout"); }//w w w . j av a 2 s . co m try { DescribeEnvironmentsResult der = eb.describeEnvironments(new DescribeEnvironmentsRequest() .withApplicationName(appName).withEnvironmentNames(envName)); if (der.getEnvironments() == null || der.getEnvironments().isEmpty()) { getLogger().info("environment " + envName + " @ " + appName + " not found"); return; } EnvironmentDescription ed = der.getEnvironments().get(0); if (successStatuses.contains(ed.getStatus())) { getLogger().info("Status of environment " + envName + " @ " + appName + " is now " + ed.getStatus() + "."); break; } else if (waitStatuses.contains(ed.getStatus())) { getLogger().info( "Status of environment " + envName + " @ " + appName + " is " + ed.getStatus() + "..."); try { Thread.sleep(loopWait * 1000); } catch (InterruptedException e) { throw new GradleException("interrupted"); } } else { // waitStatuses?successStatuses???fail?? throw new GradleException("Status of environment " + envName + " @ " + appName + " is " + ed.getStatus() + ". It seems to be failed."); } } catch (AmazonServiceException e) { throw new GradleException(e.getMessage()); } } }