use of com.amazonaws.services.elasticbeanstalk.model.CreateEnvironmentRequest in project Synapse-Stack-Builder by Sage-Bionetworks.
the class ElasticBeanstalkSetup method createOrUpdateEnvironment.
/**
* Create a single environment
* @param version
* @return
*/
public Future<EnvironmentDescription> createOrUpdateEnvironment(final String servicePrefix, final String cfgTemplateName, final ApplicationVersionDescription version) {
final String environmentName = config.getEnvironmentName(servicePrefix);
final String environmentCNAME = config.getEnvironmentCNAMEPrefix(servicePrefix);
// This work is done on a separate thread.
Callable<EnvironmentDescription> worker = new Callable<EnvironmentDescription>() {
public EnvironmentDescription call() throws Exception {
EnvironmentDescription environment = describeEnvironment(environmentName);
if (environment == null) {
// Create it since it does not exist
logger.debug(String.format("Creating environment name: '%1$s' with CNAME: '%2$s' ", environmentName, environmentCNAME));
CreateEnvironmentRequest cer = new CreateEnvironmentRequest(resources.getRepoApplicationVersion().getApplicationName(), environmentName);
cer.setTemplateName(cfgTemplateName);
cer.setVersionLabel(version.getVersionLabel());
cer.setCNAMEPrefix(environmentCNAME);
// Query for it again
beanstalkClient.createEnvironment(cer);
environment = describeEnvironment(environmentName);
logger.debug(environment);
return environment;
} else {
// Note: No support for upgrading the environment, should deploy new stack instead
// Code deploys are OK
logger.debug("Environment already exists: " + environmentName + " updating it...");
// Should we update the version?
if (!environment.getVersionLabel().equals(version.getVersionLabel())) {
logger.debug("Environment version need to be updated for: " + environmentName + "... updating it...");
// Now update the version.
updateEnvironmentVersionOnly(environmentName, version, environment);
} else {
// Force a template change
// updateEnvironmentTemplateOnly(environmentName, version, environment);
}
// Return the new information.
environment = describeEnvironment(environmentName);
logger.debug(environment);
return environment;
}
}
};
// Start the worker.
return completionSvc.submit(worker);
}
Aggregations