use of com.amazonaws.services.elasticbeanstalk.model.ConfigurationOptionSetting in project Synapse-Stack-Builder by Sage-Bionetworks.
the class ElasticBeanstalkSetup method getAllElasticBeanstalkOptions.
/**
* Get all options
* @return
* @throws IOException
*/
public List<ConfigurationOptionSetting> getAllElasticBeanstalkOptions(StackEnvironmentType env) {
List<ConfigurationOptionSetting> list = new LinkedList<ConfigurationOptionSetting>();
// Load the properties
Properties rawConfig = InputConfiguration.loadPropertyFile(Constants.ELASTIC_BEANSTALK_CONFIG_PROP_FILE_NAME);
rawConfig = config.createFilteredProperties(rawConfig);
// Process the keys
logger.debug("Building the following ConfigurationOptionSetting list...");
for (String key : rawConfig.stringPropertyNames()) {
String value = rawConfig.getProperty(key);
// Process the key
// The last '.' is the start of the name, everything before the last '.' is the namespaces.
String[] split = key.split("\\.");
StringBuilder builder = new StringBuilder();
for (int i = 0; i < split.length - 1; i++) {
if (i != 0) {
builder.append(":");
}
builder.append(split[i]);
}
String nameSpace = builder.toString();
// Name can contain spaces and colons both of which where replaced in the property file.
// Replace all '-' with space and all '?" with colons.
String nameRaw = split[split.length - 1];
nameRaw = nameRaw.replaceAll("-", " ");
// What is left is the name
String name = nameRaw.replaceAll("\\?", ":");
// We override some of the auto-scaling values for production.
if (config.isProductionStack()) {
if ("aws:autoscaling:asg".equals(nameSpace)) {
// We need a minimum of two instances for production.
if ("MinSize".equals(name)) {
if (Long.parseLong(value) < 8) {
logger.debug("Overriding aws.autoscaling.asg.MinSize for production to be at least 4");
value = "4";
if ((env.equals(StackEnvironmentType.REPO)) || (env.equals(StackEnvironmentType.WORKERS))) {
value = "8";
}
}
}
if ("MaxSize".equals(name)) {
if (Long.parseLong(value) < 12) {
logger.debug("Overriding aws.autoscaling.asg.MaxSize for production to be at least 8");
value = "8";
if ((env.equals(StackEnvironmentType.REPO)) || (env.equals(StackEnvironmentType.WORKERS))) {
value = "12";
}
}
}
// We want our two instances to be in any two zones. See PLFM-1560
if ("Availability Zones".equals(name)) {
if (!"Any 2".equals(value)) {
logger.debug("Overriding aws.autoscaling.asg.Availability-Zones for production to be at least 'Any 2'");
value = "Any 2";
}
}
}
}
// Override health check URL for plfm
if ("aws.elasticbeanstalk.application.Application-Healthcheck-URL".equals(key)) {
if (env.equals(StackEnvironmentType.REPO)) {
logger.debug("Overriding aws.elasticbeanstalk.application.Application Healthcheck URL to '/repo/v1/version'");
value = "/repo/v1/version";
}
}
// The SNS topic now dependendent on the environment
if ("aws.elasticbeanstalk.sns.topics.Notification-Topic-Name".equals(key)) {
value = config.getEnvironmentInstanceNotificationTopicName(env);
}
ConfigurationOptionSetting config = new ConfigurationOptionSetting(nameSpace, name, value);
list.add(config);
logger.debug(config);
}
// For production we need one more configuration added. See PLFM-1571
if (config.isProductionStack()) {
ConfigurationOptionSetting cfg;
cfg = new ConfigurationOptionSetting("aws:autoscaling:asg", "Custom Availability Zones", "us-east-1c, us-east-1e");
list.add(cfg);
}
// Add ACM cert ARNs based on templateSuffix
String arn = resources.getACMCertificateArn(env);
list.add(new ConfigurationOptionSetting("aws:elb:loadbalancer", "SSLCertificateId", arn));
return list;
}
use of com.amazonaws.services.elasticbeanstalk.model.ConfigurationOptionSetting in project Synapse-Stack-Builder by Sage-Bionetworks.
the class ElasticBeanstalkSetup method createAllEnvironments.
/**
* Create the environments
*/
public void createAllEnvironments() {
// setup the role, policy, and profile needed for rolling logs to S3.
configureInstanceProfileForLogRolingToS3();
// Create a profile that will used to enable logging.
String plfmElbTemplateName = config.getElasticBeanstalkTemplateName() + "-plfm";
String workerElbTemplateName = config.getElasticBeanstalkTemplateName() + "-worker";
String portalElbTemplateName = config.getElasticBeanstalkTemplateName() + "-portal";
// First create or update the templates using the current data.
List<ConfigurationOptionSetting> cfgOptSettings = getAllElasticBeanstalkOptions(StackEnvironmentType.REPO);
resources.setElasticBeanstalkConfigurationTemplate("plfm", createOrUpdateConfigurationTemplate(plfmElbTemplateName, cfgOptSettings));
cfgOptSettings = getAllElasticBeanstalkOptions(StackEnvironmentType.WORKERS);
resources.setElasticBeanstalkConfigurationTemplate("worker", createOrUpdateConfigurationTemplate(workerElbTemplateName, cfgOptSettings));
cfgOptSettings = getAllElasticBeanstalkOptions(StackEnvironmentType.PORTAL);
resources.setElasticBeanstalkConfigurationTemplate("portal", createOrUpdateConfigurationTemplate(portalElbTemplateName, cfgOptSettings));
// Create the environments
// portal
createOrUpdateEnvironment(PREFIX_PORTAL, portalElbTemplateName, resources.getPortalApplicationVersion());
// repo
createOrUpdateEnvironment(PREFIX_REPO, plfmElbTemplateName, resources.getRepoApplicationVersion());
// workers svc
createOrUpdateEnvironment(PREFIX_WORKERS, workerElbTemplateName, resources.getWorkersApplicationVersion());
// Fetch all of the results
for (int numEnvironments = 0; numEnvironments < Constants.SVC_PREFIXES.size(); numEnvironments++) {
try {
Future<EnvironmentDescription> futureEnvDesc = completionSvc.take();
EnvironmentDescription envDesc = futureEnvDesc.get();
addCreatedEnvironmentDescriptionToResources(envDesc);
logger.info("Environment created for : %s\n".format(envDesc.getApplicationName()));
} catch (InterruptedException e) {
// Exception in task
logger.error("Error: InterruptedException");
e.printStackTrace();
} catch (ExecutionException e) {
// Exception getting result
logger.error("Error: ExecutionException");
e.printStackTrace();
}
}
}
use of com.amazonaws.services.elasticbeanstalk.model.ConfigurationOptionSetting in project Synapse-Stack-Builder by Sage-Bionetworks.
the class ElasticBeanstalkSetupTest method testAutoScaleMultiZoneProduction.
/**
* This is a test for PLFM-1560.
*
* @throws IOException
*/
@Test
public void testAutoScaleMultiZoneProduction() throws IOException {
List<ConfigurationOptionSetting> expected = new LinkedList<ConfigurationOptionSetting>();
// For prod the min should be 2
config = TestHelper.createTestConfig("prod");
resources = TestHelper.createTestResources(config);
setup = new ElasticBeanstalkSetup(factory, config, resources);
// From the server tab
expected.add(new ConfigurationOptionSetting().withNamespace("aws:autoscaling:asg").withOptionName("Availability Zones").withValue("Any 2"));
List<ConfigurationOptionSetting> result = setup.getAllElasticBeanstalkOptions(StackEnvironmentType.REPO);
// Make sure we can find all of the expected values
for (ConfigurationOptionSetting expectedCon : expected) {
ConfigurationOptionSetting found = find(expectedCon.getNamespace(), expectedCon.getOptionName(), result);
assertNotNull("Failed to find expected configuration: " + expectedCon, found);
assertEquals("Values did not match for namespace: " + expectedCon.getNamespace() + " and option name: " + expectedCon.getOptionName(), expectedCon.getValue(), found.getValue());
}
}
use of com.amazonaws.services.elasticbeanstalk.model.ConfigurationOptionSetting in project Synapse-Stack-Builder by Sage-Bionetworks.
the class ElasticBeanstalkSetupTest method testCustomAvailabilityZonesProduction.
/**
* This is a test for PLFM-1571.
*
* @throws IOException
*/
@Test
public void testCustomAvailabilityZonesProduction() throws IOException {
List<ConfigurationOptionSetting> expected = new LinkedList<ConfigurationOptionSetting>();
// For prod the min should be 2
config = TestHelper.createTestConfig("prod");
resources = TestHelper.createTestResources(config);
setup = new ElasticBeanstalkSetup(factory, config, resources);
// From the server tab
expected.add(new ConfigurationOptionSetting().withNamespace("aws:autoscaling:asg").withOptionName("Custom Availability Zones").withValue("us-east-1c, us-east-1e"));
List<ConfigurationOptionSetting> result = setup.getAllElasticBeanstalkOptions(StackEnvironmentType.REPO);
// Make sure we can find all of the expected values
for (ConfigurationOptionSetting expectedCon : expected) {
ConfigurationOptionSetting found = find(expectedCon.getNamespace(), expectedCon.getOptionName(), result);
assertNotNull("Failed to find expected configuration: " + expectedCon, found);
assertEquals("Values did not match for namespace: " + expectedCon.getNamespace() + " and option name: " + expectedCon.getOptionName(), expectedCon.getValue(), found.getValue());
}
}
use of com.amazonaws.services.elasticbeanstalk.model.ConfigurationOptionSetting in project Synapse-Stack-Builder by Sage-Bionetworks.
the class ElasticBeanstalkSetupTest method testCreateConfigurationTemplate.
@Test
public void testCreateConfigurationTemplate() {
List<ConfigurationOptionSetting> cfgOptSettings = new ArrayList<ConfigurationOptionSetting>();
String templateName = "newTemplate";
DescribeConfigurationOptionsRequest dcoReq = new DescribeConfigurationOptionsRequest().withApplicationName(config.getElasticBeanstalkApplicationName()).withTemplateName(templateName);
AmazonServiceException expectedAmznException = new AmazonServiceException("Invalid template name");
expectedAmznException.setErrorCode("InvalidParameterValue");
when(mockClient.describeConfigurationOptions(dcoReq)).thenThrow(expectedAmznException);
CreateConfigurationTemplateRequest expectedCctReq = new CreateConfigurationTemplateRequest();
expectedCctReq.setApplicationName(config.getElasticBeanstalkApplicationName());
expectedCctReq.setOptionSettings(cfgOptSettings);
expectedCctReq.setSolutionStackName(Constants.SOLUTION_STACK_NAME_64BIT_TOMCAT8_JAVA8_2017_03_AMI);
expectedCctReq.setTemplateName(templateName);
setup.createOrUpdateConfigurationTemplate(templateName, cfgOptSettings);
verify(mockClient).createConfigurationTemplate(expectedCctReq);
}
Aggregations