use of com.scaleset.cfbuilder.beanstalk.SourceBundle in project TOSCAna by StuPro-TOSCAna.
the class TransformModelNodeVisitor method visit.
/**
* Transforms the {@link JavaApplication} node using AWS Beanstalk.
* <br>
* A Beanstalk Application, Configuration Template and Environment are created. A SecurityGroup is made and assigned
* to the OptionSettings as well as the environment variables that should be pushed. OptionSettings are settings that
* influence the Beanstalk Application.
*
* @param node the {@link JavaApplication} node to visit
*/
@Override
public void visit(JavaApplication node) {
try {
String nodeName = toAlphanumerical(node.getEntityName());
Application beanstalkApplication = cfnModule.resource(Application.class, nodeName).description("JavaApplication " + nodeName);
SourceBundle sourceBundle = operationHandler.handleJarArtifact(node.getJar());
ApplicationVersion beanstalkApplicationVersion = cfnModule.resource(ApplicationVersion.class, nodeName + "Version").applicationName(beanstalkApplication).description("JavaApplicationVersion " + nodeName).sourceBundle(sourceBundle);
JavaRuntimeMapper javaRuntimeMapper = new JavaRuntimeMapper(logger);
String stackConfig = javaRuntimeMapper.mapRuntimeToStackConfig(getJavaRuntime(node));
List<OptionSetting> optionSettings = new ArrayList<>();
ConfigurationTemplate beanstalkConfigurationTemplate = cfnModule.resource(ConfigurationTemplate.class, nodeName + "ConfigurationTemplate").applicationName(beanstalkApplication).description("JavaApplicationConfigurationTemplate " + nodeName).solutionStackName(stackConfig);
// add securitygroup
String hostComputeName = toAlphanumerical(getCompute(node).getEntityName());
SecurityGroup beanstalkSecurityGroup = cfnModule.resource(SecurityGroup.class, hostComputeName + SECURITY_GROUP).groupDescription("SecurityGroup for Beanstalk application " + nodeName + ".");
// get and open ports
List<Integer> portList = getPortsFromEnpointCapability(node);
beanstalkSecurityGroup.ingress(ingress -> ingress.cidrIp(IP_OPEN), PROTOCOL_TCP, portList.toArray());
// set securitygroup for beanstalk application
optionSettings.add(new OptionSetting("aws:autoscaling:launchconfiguration", "SecurityGroups").setValue(cfnModule.ref(hostComputeName + SECURITY_GROUP)));
// get environment variables as option settings
optionSettings.addAll(operationHandler.handleStartJava(node));
// add all option settings to beanstalk configuration
if (!optionSettings.isEmpty()) {
beanstalkConfigurationTemplate.optionSettings(optionSettings.toArray(new OptionSetting[0]));
}
cfnModule.resource(Environment.class, nodeName + "Environment").applicationName(beanstalkApplication).description("JavaApplicationEnvironment").templateName(beanstalkConfigurationTemplate).versionLabel(beanstalkApplicationVersion);
} catch (Exception e) {
logger.error("Error while creating JavaApplication");
throw new TransformationFailureException("Failed at JavaApplication node " + node.getEntityName(), e);
}
}
Aggregations