Search in sources :

Example 6 with SecurityGroup

use of com.scaleset.cfbuilder.ec2.SecurityGroup 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 7 with SecurityGroup

use of com.scaleset.cfbuilder.ec2.SecurityGroup 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)

Aggregations

SecurityGroup (com.scaleset.cfbuilder.ec2.SecurityGroup)7 SdkClientException (com.amazonaws.SdkClientException)6 Compute (org.opentosca.toscana.model.node.Compute)6 TransformationFailureException (org.opentosca.toscana.plugins.util.TransformationFailureException)6 Instance (com.scaleset.cfbuilder.ec2.Instance)2 ArrayList (java.util.ArrayList)2 Artifact (org.opentosca.toscana.model.artifact.Artifact)2 ComputeCapability (org.opentosca.toscana.model.capability.ComputeCapability)2 EndpointCapability (org.opentosca.toscana.model.capability.EndpointCapability)2 CapabilityMapper (org.opentosca.toscana.plugins.cloudformation.mapper.CapabilityMapper)2 UserData (com.scaleset.cfbuilder.ec2.UserData)1 CFNCommand (com.scaleset.cfbuilder.ec2.metadata.CFNCommand)1 CFNInit (com.scaleset.cfbuilder.ec2.metadata.CFNInit)1 CFNPackage (com.scaleset.cfbuilder.ec2.metadata.CFNPackage)1 DBInstance (com.scaleset.cfbuilder.rds.DBInstance)1 List (java.util.List)1 Set (java.util.Set)1 TransformationContext (org.opentosca.toscana.core.transformation.TransformationContext)1 OsCapability (org.opentosca.toscana.model.capability.OsCapability)1 Apache (org.opentosca.toscana.model.node.Apache)1