Search in sources :

Example 1 with Fn

use of com.scaleset.cfbuilder.core.Fn in project TOSCAna by StuPro-TOSCAna.

the class PrepareModelNodeVisitor method visit.

@Override
public void visit(MysqlDatabase node) {
    // if certain values aren't given, fill them
    if (node.getPassword().isPresent()) {
        // password needs to be at least 8 characters long
        String password = node.getPassword().get();
        if (password.length() < minPWLength) {
            logger.warn("Database password too short, creating new random password");
            node.setPassword(randomString(minPWLength));
        }
    } else {
        logger.warn("No database password given, creating new random password");
        node.setPassword(randomString(minPWLength));
    }
    if (!node.getUser().isPresent()) {
        logger.warn("User not set, setting to default");
        node.setUser(DEFAULT_DB_USER);
    }
    if (!node.getPort().isPresent()) {
        logger.warn("Database port not set, setting to default");
        node.setPort(DEFAULT_DB_PORT);
    }
    // check if Mysql is the only node hosted on his compute node
    Compute compute = getCompute(node);
    if (topology.incomingEdgesOf(compute).stream().filter(relation -> relation instanceof HostedOn).collect(Collectors.toSet()).size() == 1) {
        // means our dbms is the only one hosted on this compute
        // means we can set the private address as reference the database endpoint
        Fn databaseEndpointFn = Fn.fnGetAtt(toAlphanumerical(node.getEntityName()), AWS_ENDPOINT_REFERENCE);
        String databaseEndpoint = databaseEndpointFn.toString(true);
        cfnModule.putFn(databaseEndpoint, databaseEndpointFn);
        compute.setPrivateAddress(databaseEndpoint);
        compute.setPublicAddress(databaseEndpoint);
        logger.debug("Set private address and public address of '{}' to reference MysqlDatabase '{}'", compute.getEntityName(), node.getEntityName());
        // also the underlying compute should not get mapped to an ec2
        cfnModule.removeComputeToEc2(compute);
        logger.debug("Removing Compute '{}' to be transformed", compute.getEntityName());
    }
}
Also used : Compute(org.opentosca.toscana.model.node.Compute) HostedOn(org.opentosca.toscana.model.relation.HostedOn) NodeVisitor(org.opentosca.toscana.model.visitor.NodeVisitor) Collectors(java.util.stream.Collectors) SecureRandom(java.security.SecureRandom) Port(org.opentosca.toscana.model.datatype.Port) Fn(com.scaleset.cfbuilder.core.Fn) MysqlDatabase(org.opentosca.toscana.model.node.MysqlDatabase) CloudFormationLifecycle.toAlphanumerical(org.opentosca.toscana.plugins.cloudformation.CloudFormationLifecycle.toAlphanumerical) TransformationContext(org.opentosca.toscana.core.transformation.TransformationContext) WebApplication(org.opentosca.toscana.model.node.WebApplication) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) CloudFormationModule(org.opentosca.toscana.plugins.cloudformation.CloudFormationModule) HostedOn(org.opentosca.toscana.model.relation.HostedOn) Compute(org.opentosca.toscana.model.node.Compute) Fn(com.scaleset.cfbuilder.core.Fn)

Example 2 with Fn

use of com.scaleset.cfbuilder.core.Fn in project TOSCAna by StuPro-TOSCAna.

the class PrepareModelNodeVisitor method visit.

@Override
public void visit(Compute node) {
    // compute nodes only get transformed if they are present in this map
    cfnModule.addComputeToEc2(node);
    // Set private and public address of this EC2 instance
    String computeName = toAlphanumerical(node.getEntityName());
    Fn privateIpFn = Fn.fnGetAtt(computeName, AWS_INSTANCE_PRIVATE_IP);
    Fn publicIpFn = Fn.fnGetAtt(computeName, AWS_INSTANCE_PUBLIC_IP);
    String privateIpFnString = privateIpFn.toString(true);
    String publicIpFnString = publicIpFn.toString(true);
    cfnModule.putFn(privateIpFnString, privateIpFn);
    cfnModule.putFn(publicIpFnString, publicIpFn);
    node.setPrivateAddress(privateIpFnString);
    node.setPublicAddress(publicIpFnString);
}
Also used : Fn(com.scaleset.cfbuilder.core.Fn)

Example 3 with Fn

use of com.scaleset.cfbuilder.core.Fn in project TOSCAna by StuPro-TOSCAna.

the class PrepareModelRelationshipVisitor method visit.

@Override
public void visit(ConnectsTo relation) {
    RootNode source = topology.getEdgeSource(relation);
    RootNode target = topology.getEdgeTarget(relation);
    if (source instanceof WebApplication && target instanceof MysqlDatabase) {
        MysqlDatabase mysqlDatabase = (MysqlDatabase) target;
        WebApplication webApplication = (WebApplication) source;
        // if they are hosted on the same compute --> we can set the compute private address to
        Compute computeMysqlDatabase = getCompute(mysqlDatabase);
        Compute computeWebApplication = getCompute(webApplication);
        if (computeMysqlDatabase.equals(computeWebApplication)) {
            // means we can set the private address as reference to the database endpoint
            Fn databaseEndpointFn = Fn.fnGetAtt(toAlphanumerical(mysqlDatabase.getEntityName()), AWS_ENDPOINT_REFERENCE);
            String databaseEndpoint = databaseEndpointFn.toString(true);
            cfnModule.putFn(databaseEndpoint, databaseEndpointFn);
            computeMysqlDatabase.setPrivateAddress(databaseEndpoint);
            computeMysqlDatabase.setPublicAddress(databaseEndpoint);
            logger.debug("Set private address and public address of '{}' to reference MysqlDatabase '{}'", computeMysqlDatabase.getEntityName(), mysqlDatabase.getEntityName());
        } else {
            logger.debug("Cannot safely set private/public address of '{}'", computeMysqlDatabase.getEntityName());
        }
    } else {
        logger.debug("Drop relationship, because it is not supported");
    }
}
Also used : RootNode(org.opentosca.toscana.model.node.RootNode) MysqlDatabase(org.opentosca.toscana.model.node.MysqlDatabase) Compute(org.opentosca.toscana.model.node.Compute) Fn(com.scaleset.cfbuilder.core.Fn) WebApplication(org.opentosca.toscana.model.node.WebApplication)

Aggregations

Fn (com.scaleset.cfbuilder.core.Fn)3 Compute (org.opentosca.toscana.model.node.Compute)2 MysqlDatabase (org.opentosca.toscana.model.node.MysqlDatabase)2 WebApplication (org.opentosca.toscana.model.node.WebApplication)2 SecureRandom (java.security.SecureRandom)1 Collectors (java.util.stream.Collectors)1 RandomStringUtils (org.apache.commons.lang3.RandomStringUtils)1 TransformationContext (org.opentosca.toscana.core.transformation.TransformationContext)1 Port (org.opentosca.toscana.model.datatype.Port)1 RootNode (org.opentosca.toscana.model.node.RootNode)1 HostedOn (org.opentosca.toscana.model.relation.HostedOn)1 NodeVisitor (org.opentosca.toscana.model.visitor.NodeVisitor)1 CloudFormationLifecycle.toAlphanumerical (org.opentosca.toscana.plugins.cloudformation.CloudFormationLifecycle.toAlphanumerical)1 CloudFormationModule (org.opentosca.toscana.plugins.cloudformation.CloudFormationModule)1