@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getEnvironmentName() == null) ? 0 : getEnvironmentName().hashCode()); hashCode = prime * hashCode + ((getEnvironmentId() == null) ? 0 : getEnvironmentId().hashCode()); hashCode = prime * hashCode + ((getApplicationName() == null) ? 0 : getApplicationName().hashCode()); hashCode = prime * hashCode + ((getVersionLabel() == null) ? 0 : getVersionLabel().hashCode()); hashCode = prime * hashCode + ((getSolutionStackName() == null) ? 0 : getSolutionStackName().hashCode()); hashCode = prime * hashCode + ((getPlatformArn() == null) ? 0 : getPlatformArn().hashCode()); hashCode = prime * hashCode + ((getTemplateName() == null) ? 0 : getTemplateName().hashCode()); hashCode = prime * hashCode + ((getDescription() == null) ? 0 : getDescription().hashCode()); hashCode = prime * hashCode + ((getEndpointURL() == null) ? 0 : getEndpointURL().hashCode()); hashCode = prime * hashCode + ((getCNAME() == null) ? 0 : getCNAME().hashCode()); hashCode = prime * hashCode + ((getDateCreated() == null) ? 0 : getDateCreated().hashCode()); hashCode = prime * hashCode + ((getDateUpdated() == null) ? 0 : getDateUpdated().hashCode()); hashCode = prime * hashCode + ((getStatus() == null) ? 0 : getStatus().hashCode()); hashCode = prime * hashCode + ((getAbortableOperationInProgress() == null) ? 0 : getAbortableOperationInProgress().hashCode()); hashCode = prime * hashCode + ((getHealth() == null) ? 0 : getHealth().hashCode()); hashCode = prime * hashCode + ((getHealthStatus() == null) ? 0 : getHealthStatus().hashCode()); hashCode = prime * hashCode + ((getResources() == null) ? 0 : getResources().hashCode()); hashCode = prime * hashCode + ((getTier() == null) ? 0 : getTier().hashCode()); hashCode = prime * hashCode + ((getEnvironmentLinks() == null) ? 0 : getEnvironmentLinks().hashCode()); hashCode = prime * hashCode + ((getEnvironmentArn() == null) ? 0 : getEnvironmentArn().hashCode()); return hashCode; }
@Override public String apply(EnvironmentDescription input) { return format("%s[%s]", input.getEnvironmentId(), input.getEnvironmentName()); } });
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; } return getService().updateEnvironment(request); } }
).getEnvironments(); String currentEnvironmentId = environments.get(i).getEnvironmentId(); environmentDescription.getVersionLabel(), getVersionLabel(), String.valueOf(bHasDifferentVersion)); final boolean bHealthyP = GREEN_HEALTH.equals(environmentDescription.getHealth()); final boolean bReadyP = STATUS_READY.equals(environmentDescription.getStatus());
if (curEnv.getVersionLabel().equals(versionLabel) && skipIfSameVersion) { getLog().warn(format("Environment is running version %s and skipIfSameVersion is true. Returning", versionLabel)); if (!solutionStack.equals(curEnv.getSolutionStackName()) && copySolutionStack) { if (getLog().isWarnEnabled()) { getLog() + "default ('%s'). If this is not the desired behavior please set the copySolutionStack property to" + " false.", curEnv.getSolutionStackName(), solutionStack)); solutionStack = curEnv.getSolutionStackName(); final boolean currentEnvironmentIsRed = "Red".equals(curEnv.getHealth()); String newEnvironmentName = getNewEnvironmentName(StringUtils.defaultString(this.environmentName, curEnv.getEnvironmentName())); getLog().info("And it will replace a '" + curEnv.getHealth() + "' enviroment"); for (int i = 1; i <= maxAttempts; i++) { try { swapEnvironmentCNames(newEnvDesc.getEnvironmentId(), curEnv.getEnvironmentId(), cnamePrefix, newEnvDesc); swapped = true; break; terminateEnvironment(newEnvDesc.getEnvironmentId()); terminateEnvironment(curEnv.getEnvironmentId());
EnvironmentDescription result = environmentDescriptionOpt.get(); if (newVersion.equals(result.getVersionLabel()) && AWS_ENVIRONMENT_STATUS_READY.equals(result.getStatus())) { log.info("Version reported is '" + result.getVersionLabel() + "'. Environment is '" + result.getStatus() + "' and " + "'" + result.getHealth()); break; } else { log.info("Version reported is '" + result.getVersionLabel() + "'. Environment is '" + result.getStatus() + "' and '" + result.getHealth() + "'.");
for (ListIterator<EnvironmentDescription> i = result.getEnvironments().listIterator(); i.hasNext(); ) { EnvironmentDescription element = i.next(); final String environmentLabel = element.getVersionLabel(); if (null != environmentLabel && environmentLabel.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."); csEnvironmentIds.append(element.getEnvironmentId()); if (i.hasNext()) { csEnvironmentIds.append(","); final String environmentId = element.getEnvironmentId();
boolean bActiveEnvironment = (d.getStatus().equals("Running") || d.getStatus().equals("Launching") || d.getStatus().equals("Ready")); boolean bMatchesVersion = appVersion.getVersionLabel().equals(d.getVersionLabel()); getLog().info("VersionLabel " + appVersion.getVersionLabel() + " is bound to environment " + d.getEnvironmentName() + " - Skipping it");
private void checkEnvironment(AWSElasticBeanstalk client, String environment) { // Environment needs to be ready to start an update // We query the environment in a loop to wait and report it status is ready // Unfortunately the elastic beanstalk sdk doesn't have waiters yet // https://aws.amazon.com/blogs/developer/waiters-in-the-aws-sdk-for-java/ for (int retries = 0; retries <= MAX_CHECK_ENVIRONMENT_RETRIES; retries++) { Optional<EnvironmentDescription> environmentDescriptionOpt = SimpleEnvironmentDescriber.describe(client, awsAppName, environment); if (!environmentDescriptionOpt.isPresent()) { log.info("Failed to describe environment"); } else { EnvironmentDescription result = environmentDescriptionOpt.get(); if (AWS_ENVIRONMENT_STATUS_READY.equals(result.getStatus()) && newVersion.equals(result.getVersionLabel())) { throw new GradleException("The application version to deploy and the currently used are the same."); } else if (AWS_ENVIRONMENT_STATUS_READY.equals(result.getStatus())) { log.fine("Status is '" + result.getStatus() + "'"); break; } else { log.fine("Status is '" + result.getStatus() + "'. Waiting for environment to get ready to update."); try { sleep(MILLIS_TO_WAIT); } catch (InterruptedException ie) { log.info("Application failed to sleep " + ie.getMessage()); } } } } throw new GradleException("Checking environment timed out."); }
String resultingStatus = result.getEnvironments().get(i).getStatus(); boolean abortableP = result.getEnvironments().get(i).getAbortableOperationInProgress(); String environmentId = result.getEnvironments().get(i).getEnvironmentId();
@Override public boolean apply(EnvironmentDescription t) { return t.getEnvironmentId().equals(environmentRef); } });
new WaitForEnvironmentContextBuilder().withApplicationName(applicationName).withEnvironmentRef(targetEnvironmentRef).build())); Validate.isTrue(isNotBlank(e0.getCNAME()), format("Environment '%s' must be non-worker (thus having a cname)", e1.getEnvironmentId())); Validate.isTrue(isNotBlank(e1.getCNAME()), format("Environment '%s' must be non-worker (thus having a cname)", e1.getEnvironmentId())); .withSourceEnvironmentId(e0.getEnvironmentId()) // .withDestinationEnvironmentId(e1.getEnvironmentId()) // .build(); } else if (nonBlank(sourceEnvironmentCNamePrefix, targetEnvironmentCNamePrefix)) { .withSourceEnvironmentId(sourceEnvironment.getEnvironmentId()) // .withDestinationEnvironmentId(targetEnvironment.getEnvironmentId()) // .build(); } else {
private Set<String> findDeployedLabels(String applicationName) { DescribeEnvironmentsRequest req = new DescribeEnvironmentsRequest(); req.setApplicationName(applicationName); Set<String> result = new TreeSet<String>(); for (EnvironmentDescription description : elasticBeanstalk.describeEnvironments(req).getEnvironments()) { if (description.getVersionLabel() != null) { // Ignore null value (for example when environment is launching) result.add(description.getVersionLabel()); } } return result; } }
@Override public boolean apply(EnvironmentDescription t) { return !t.getStatus().equals("Terminated"); } };
@Override protected Object executeInternal() throws AbstractMojoExecutionException { Set<String> configTemplates = new TreeSet<String>(super.getConfigurationTemplates(applicationName)); String today = DATE_FORMAT.format(new Date()); if (StringUtils.isBlank(templateName)) { int i = 1; do { templateName = String.format("%s-%s-%02d", curEnv.getEnvironmentName(), today, i++); } while (configTemplates.contains(templateName)); } CreateConfigurationTemplateResult result = getService() .createConfigurationTemplate( new CreateConfigurationTemplateRequest() .withEnvironmentId(curEnv.getEnvironmentId()) .withTemplateName(templateName) .withApplicationName(curEnv.getApplicationName())); getLog().info("Created config template " + templateName + " for environment " + curEnv.getEnvironmentId()); return result; } }
.withEnvironmentNames(TEST_ENVIRONMENTNAME)) .getEnvironments().get(0); assertEquals(TEST_ENVIRONMENTDESC, environment.getDescription()); assertTrue(environment.getCNAME().startsWith(TEST_CNAMEPREFIX)); assertEquals(TEST_SOLUTIONSTACKNAME, environment.getSolutionStackName());
protected boolean isSingleInstance(EnvironmentDescription env) { Validate.isTrue("WebServer".equals(env.getTier().getName()), "Not a Web Server environment!"); final DescribeConfigurationSettingsResult describeConfigurationSettingsResult = parentMojo .getService() .describeConfigurationSettings( new DescribeConfigurationSettingsRequest().withApplicationName(env.getApplicationName()).withEnvironmentName(env.getEnvironmentName())); Validate.isTrue(1 == describeConfigurationSettingsResult.getConfigurationSettings().size(), "There should be one environment"); final List<ConfigurationOptionSetting> optionSettings = describeConfigurationSettingsResult.getConfigurationSettings().get(0).getOptionSettings(); for (ConfigurationOptionSetting optionSetting : optionSettings) { if (ConfigUtil.optionSettingMatchesP(optionSetting, "aws:elasticbeanstalk:environment", "EnvironmentType")) { return "SingleInstance".equals(optionSetting.getValue()); } } throw new IllegalStateException("Unreachable code!"); }
if (!e.getEnvironmentId().equals(curEnv.getEnvironmentId()) && "WebServer".equals(e.getTier().getName())) { otherEnvId = e.getEnvironmentId(); break; getLog().info(format("(Green) Environment with environmentId['%s'] will be prepared once its ready to update", curEnv.getEnvironmentId())); .withStatusToWaitFor("Ready") .withApplicationName(applicationName) .withEnvironmentRef(curEnv.getEnvironmentId()) .build()); .swapEnvironmentCNAMEs(new SwapEnvironmentCNAMEsRequest().withDestinationEnvironmentId(curEnv.getEnvironmentId()).withSourceEnvironmentId(otherEnvId));
service.describeEvents( new DescribeEventsRequest() .withApplicationName(foundEnvironment.getApplicationName()) .withStartTime(new Date(1000 + lastMessageRecord.getTime())) .withEnvironmentId(foundEnvironment.getEnvironmentId()) .withSeverity("TRACE"));