Search in sources :

Example 1 with ConfigurationTemplate

use of com.scaleset.cfbuilder.beanstalk.ConfigurationTemplate 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);
    }
}
Also used : ApplicationVersion(com.scaleset.cfbuilder.beanstalk.ApplicationVersion) TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) SourceBundle(com.scaleset.cfbuilder.beanstalk.SourceBundle) ArrayList(java.util.ArrayList) ConfigurationTemplate(com.scaleset.cfbuilder.beanstalk.ConfigurationTemplate) SecurityGroup(com.scaleset.cfbuilder.ec2.SecurityGroup) TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) SdkClientException(com.amazonaws.SdkClientException) JavaRuntimeMapper(org.opentosca.toscana.plugins.cloudformation.mapper.JavaRuntimeMapper) OptionSetting(com.scaleset.cfbuilder.beanstalk.OptionSetting) Application(com.scaleset.cfbuilder.beanstalk.Application) WebApplication(org.opentosca.toscana.model.node.WebApplication) JavaApplication(org.opentosca.toscana.model.node.custom.JavaApplication)

Aggregations

SdkClientException (com.amazonaws.SdkClientException)1 Application (com.scaleset.cfbuilder.beanstalk.Application)1 ApplicationVersion (com.scaleset.cfbuilder.beanstalk.ApplicationVersion)1 ConfigurationTemplate (com.scaleset.cfbuilder.beanstalk.ConfigurationTemplate)1 OptionSetting (com.scaleset.cfbuilder.beanstalk.OptionSetting)1 SourceBundle (com.scaleset.cfbuilder.beanstalk.SourceBundle)1 SecurityGroup (com.scaleset.cfbuilder.ec2.SecurityGroup)1 ArrayList (java.util.ArrayList)1 WebApplication (org.opentosca.toscana.model.node.WebApplication)1 JavaApplication (org.opentosca.toscana.model.node.custom.JavaApplication)1 JavaRuntimeMapper (org.opentosca.toscana.plugins.cloudformation.mapper.JavaRuntimeMapper)1 TransformationFailureException (org.opentosca.toscana.plugins.util.TransformationFailureException)1