Search in sources :

Example 16 with TransformationFailureException

use of org.opentosca.toscana.plugins.util.TransformationFailureException in project TOSCAna by StuPro-TOSCAna.

the class CloudFormationLifecycle method transform.

@Override
public void transform() {
    logger.info("Begin transformation to CloudFormation.");
    Set<RootNode> nodes = model.getNodes();
    // Visit Compute nodes first, then all others
    try {
        TransformModelNodeVisitor cfnNodeVisitor = new TransformModelNodeVisitor(context, cfnModule);
        logger.info("Transform nodes");
        visitComputeNodesFirst(nodes, cfnNodeVisitor);
        logger.info("Handling environment variables.");
        EnvironmentHandler environmentHandler = new EnvironmentHandler(cfnModule, logger);
        environmentHandler.handleEnvironment();
        logger.info("Creating CloudFormation template.");
        fileAccess.access(OUTPUT_DIR + CloudFormationFileCreator.TEMPLATE_YAML).appendln(cfnModule.toString()).close();
        CloudFormationFileCreator fileCreator = new CloudFormationFileCreator(context, cfnModule);
        logger.info("Creating CloudFormation scripts.");
        fileCreator.copyUtilScripts();
        fileCreator.copyUtilDependencies();
        fileCreator.writeScripts();
        fileCreator.copyFiles();
        fileCreator.writeReadme(context);
    } catch (IOException ie) {
        logger.error("File access error");
        throw new TransformationFailureException("Could not write template with fileAccess", ie);
    } catch (TransformationFailureException tfe) {
        logger.error("Transformation to CloudFormation unsuccessful. Please check the StackTrace for more Info.");
        throw tfe;
    } catch (Exception e) {
        logger.error("Transformation to CloudFormation unsuccessful. Unexpected exception should not appear here.");
        throw new TransformationFailureException("Unexpected exception", e);
    }
    logger.info("Transformation to CloudFormation successful.");
}
Also used : RootNode(org.opentosca.toscana.model.node.RootNode) TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) EnvironmentHandler(org.opentosca.toscana.plugins.cloudformation.handler.EnvironmentHandler) TransformModelNodeVisitor(org.opentosca.toscana.plugins.cloudformation.visitor.TransformModelNodeVisitor) IOException(java.io.IOException) TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) UnsupportedTypeException(org.opentosca.toscana.model.visitor.UnsupportedTypeException) IOException(java.io.IOException)

Example 17 with TransformationFailureException

use of org.opentosca.toscana.plugins.util.TransformationFailureException in project TOSCAna by StuPro-TOSCAna.

the class TransformModelNodeVisitor method visit.

@Override
public void visit(Dbms node) {
    try {
        // get the compute where the dbms this node is hosted on, is hosted on
        Compute computeHost = getCompute(node);
        String computeHostName = toAlphanumerical(computeHost.getEntityName());
        operationHandler.handleGenericHostedNode(node, computeHost);
        // Open Dbms port
        String SecurityGroupName = computeHostName + SECURITY_GROUP;
        SecurityGroup securityGroup = (SecurityGroup) cfnModule.getResource(SecurityGroupName);
        if (node.getPort().isPresent()) {
            Integer dbmsPort = node.getPort().orElseThrow(() -> new IllegalArgumentException("Database " + "port not set"));
            securityGroup.ingress(ingress -> ingress.cidrIp(IP_OPEN), PROTOCOL_TCP, dbmsPort);
        }
    } catch (Exception e) {
        logger.error("Error while creating Dbms resource.");
        throw new TransformationFailureException("Failed at Dbms node " + node.getEntityName(), e);
    }
}
Also used : TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) Compute(org.opentosca.toscana.model.node.Compute) SecurityGroup(com.scaleset.cfbuilder.ec2.SecurityGroup) TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) SdkClientException(com.amazonaws.SdkClientException)

Example 18 with TransformationFailureException

use of org.opentosca.toscana.plugins.util.TransformationFailureException in project TOSCAna by StuPro-TOSCAna.

the class TransformModelNodeVisitor method visit.

@Override
public void visit(WebApplication node) {
    try {
        // get the compute where the apache this node is hosted on, is hosted on
        Compute compute = getCompute(node);
        String computeName = toAlphanumerical(compute.getEntityName());
        node.getAppEndpoint().getPort().ifPresent(port -> {
            SecurityGroup computeSecurityGroup = (SecurityGroup) cfnModule.getResource(computeName + SECURITY_GROUP);
            computeSecurityGroup.ingress(ingress -> ingress.cidrIp(IP_OPEN), PROTOCOL_TCP, port.port);
        });
        // handle create
        operationHandler.handleCreate(node, computeName);
        // handle configure
        operationHandler.handleConfigure(node, computeName);
        // handle start
        operationHandler.handleStart(node, computeName);
    } catch (Exception e) {
        logger.error("Error while creating WebApplication");
        throw new TransformationFailureException("Failed at WebApplication node " + node.getEntityName(), e);
    }
}
Also used : TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) Compute(org.opentosca.toscana.model.node.Compute) SecurityGroup(com.scaleset.cfbuilder.ec2.SecurityGroup) TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) SdkClientException(com.amazonaws.SdkClientException)

Example 19 with TransformationFailureException

use of org.opentosca.toscana.plugins.util.TransformationFailureException in project TOSCAna by StuPro-TOSCAna.

the class TransformModelNodeVisitor method visit.

@Override
public void visit(MysqlDatabase node) {
    try {
        String nodeName = toAlphanumerical(node.getEntityName());
        // get the compute where the dbms this node is hosted on, is hosted on
        Compute compute = getCompute(node);
        String serverName = toAlphanumerical(compute.getEntityName());
        String dbName = node.getDatabaseName();
        String masterUser = node.getUser().orElseThrow(() -> new IllegalArgumentException("Database user not set"));
        String masterPassword = node.getPassword().orElseThrow(() -> new IllegalArgumentException("Database " + "password not set"));
        Integer port = node.getPort().orElseThrow(() -> new IllegalArgumentException("Database port not set"));
        // check what values should be taken
        ComputeCapability hostedOnComputeCapability = compute.getHost();
        CapabilityMapper capabilityMapper = createCapabilityMapper();
        String dBInstanceClass = capabilityMapper.mapComputeCapabilityToInstanceType(hostedOnComputeCapability, CapabilityMapper.RDS_DISTINCTION);
        Integer allocatedStorage = capabilityMapper.mapComputeCapabilityToRDSAllocatedStorage(hostedOnComputeCapability);
        // SSD
        String storageType = "gp2";
        String securityGroupName = nodeName + SECURITY_GROUP;
        SecurityGroup securityGroup = cfnModule.resource(SecurityGroup.class, securityGroupName).groupDescription("Open database " + dbName + " for access to group " + serverName + SECURITY_GROUP);
        Set<Compute> hostsOfConnectedTo = getHostsOfConnectedTo(node);
        for (Compute hostOfConnectedTo : hostsOfConnectedTo) {
            securityGroup.ingress(ingress -> ingress.sourceSecurityGroupName(cfnModule.ref(toAlphanumerical(hostOfConnectedTo.getEntityName()) + SECURITY_GROUP)), PROTOCOL_TCP, port);
        }
        cfnModule.resource(DBInstance.class, nodeName).engine("MySQL").dBName(dbName).masterUsername(masterUser).masterUserPassword(masterPassword).dBInstanceClass(dBInstanceClass).allocatedStorage(allocatedStorage).storageType(storageType).vPCSecurityGroups(cfnModule.fnGetAtt(securityGroupName, "GroupId"));
        // handle sql artifact
        for (Artifact artifact : node.getArtifacts()) {
            String relPath = artifact.getFilePath();
            if (relPath.endsWith(".sql")) {
                String sql = cfnModule.getFileAccess().read(artifact.getFilePath());
                String computeName = createSqlCompute(node, sql);
                securityGroup.ingress(ingress -> ingress.sourceSecurityGroupName(cfnModule.ref(toAlphanumerical(computeName) + SECURITY_GROUP)), PROTOCOL_TCP, port);
            }
        }
    } catch (Exception e) {
        logger.error("Error while creating MysqlDatabase resource.");
        throw new TransformationFailureException("Failed at MysqlDatabase node " + node.getEntityName(), e);
    }
}
Also used : TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) Compute(org.opentosca.toscana.model.node.Compute) SecurityGroup(com.scaleset.cfbuilder.ec2.SecurityGroup) CapabilityMapper(org.opentosca.toscana.plugins.cloudformation.mapper.CapabilityMapper) Artifact(org.opentosca.toscana.model.artifact.Artifact) TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) SdkClientException(com.amazonaws.SdkClientException) ComputeCapability(org.opentosca.toscana.model.capability.ComputeCapability)

Example 20 with TransformationFailureException

use of org.opentosca.toscana.plugins.util.TransformationFailureException in project TOSCAna by StuPro-TOSCAna.

the class CloudFoundryLifecycle method transform.

@Override
public void transform() {
    logger.info("Begin transformation to Cloud Foundry.");
    PluginFileAccess fileAccess = context.getPluginFileAccess();
    fillApplications();
    try {
        FileCreator fileCreator = new FileCreator(fileAccess, filledApplications, context);
        fileCreator.createFiles();
    } catch (FileNotFoundException f) {
        throw new TransformationFailureException("A file which is declared in the template could not be found", f);
    } catch (IOException | JSONException e) {
        e.printStackTrace();
    }
}
Also used : PluginFileAccess(org.opentosca.toscana.core.plugin.PluginFileAccess) FileCreator(org.opentosca.toscana.plugins.cloudfoundry.filecreator.FileCreator) TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) FileNotFoundException(java.io.FileNotFoundException) JSONException(org.json.JSONException) IOException(java.io.IOException)

Aggregations

TransformationFailureException (org.opentosca.toscana.plugins.util.TransformationFailureException)22 IOException (java.io.IOException)10 SdkClientException (com.amazonaws.SdkClientException)8 Compute (org.opentosca.toscana.model.node.Compute)8 SecurityGroup (com.scaleset.cfbuilder.ec2.SecurityGroup)6 Artifact (org.opentosca.toscana.model.artifact.Artifact)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 ArrayList (java.util.ArrayList)3 JSONException (org.json.JSONException)3 RootNode (org.opentosca.toscana.model.node.RootNode)3 CFNCommand (com.scaleset.cfbuilder.ec2.metadata.CFNCommand)2 CFNPackage (com.scaleset.cfbuilder.ec2.metadata.CFNPackage)2 ComputeCapability (org.opentosca.toscana.model.capability.ComputeCapability)2 EndpointCapability (org.opentosca.toscana.model.capability.EndpointCapability)2 WebApplication (org.opentosca.toscana.model.node.WebApplication)2 Operation (org.opentosca.toscana.model.operation.Operation)2 Instance (com.scaleset.cfbuilder.ec2.Instance)1 CFNInit (com.scaleset.cfbuilder.ec2.metadata.CFNInit)1 DBInstance (com.scaleset.cfbuilder.rds.DBInstance)1 FileNotFoundException (java.io.FileNotFoundException)1