Search in sources :

Example 11 with Compute

use of org.opentosca.toscana.model.node.Compute 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)

Example 12 with Compute

use of org.opentosca.toscana.model.node.Compute 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 13 with Compute

use of org.opentosca.toscana.model.node.Compute 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 14 with Compute

use of org.opentosca.toscana.model.node.Compute 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 15 with Compute

use of org.opentosca.toscana.model.node.Compute in project TOSCAna by StuPro-TOSCAna.

the class CloudFoundryLifecycle method prepare.

@Override
public void prepare() {
    logger.info("Begin preparation for transformation to Cloud Foundry");
    PrepareVisitor prepareVisitor = new PrepareVisitor(logger);
    for (RootNode node : context.getModel().getNodes()) {
        node.accept(prepareVisitor);
    }
    logger.debug("Collecting Compute Nodes in topology");
    ComputeNodeFindingVisitor computeFinder = new ComputeNodeFindingVisitor();
    model.getNodes().forEach(e -> {
        e.accept(computeFinder);
        KubernetesNodeContainer container = new KubernetesNodeContainer(e);
        nodes.put(e.getEntityName(), container);
    });
    computeFinder.getComputeNodes().forEach(e -> computeNodes.add(nodes.get(e.getEntityName())));
    logger.debug("Finding top Level Nodes");
    graph = model.getTopology();
    Set<RootNode> topLevelNodes = determineTopLevelNodes(context.getModel(), computeFinder.getComputeNodes().stream().map(Compute.class::cast).collect(Collectors.toList()), e -> nodes.get(e.getEntityName()).activateParentComputeNode());
    logger.debug("Building complete Topology stacks");
    this.stacks.addAll(buildTopologyStacks(model, topLevelNodes, nodes));
    // TODO: check how many different applications there are and fill list with them
    // probably there must be a combination of application and set of nodes
    applications = new ArrayList<>();
    int i = 1;
    for (NodeStack stack : stacks) {
        Application myApp = new Application(i, context);
        i++;
        myApp.setProvider(provider);
        myApp.setConnection(connection);
        myApp.setName(stack.getStackName());
        myApp.addStack(stack);
        applications.add(myApp);
    }
}
Also used : RootNode(org.opentosca.toscana.model.node.RootNode) Compute(org.opentosca.toscana.model.node.Compute) KubernetesNodeContainer(org.opentosca.toscana.plugins.kubernetes.util.KubernetesNodeContainer) NodeStack(org.opentosca.toscana.plugins.kubernetes.util.NodeStack) ComputeNodeFindingVisitor(org.opentosca.toscana.plugins.kubernetes.visitor.util.ComputeNodeFindingVisitor) PrepareVisitor(org.opentosca.toscana.plugins.cloudfoundry.visitor.PrepareVisitor) Application(org.opentosca.toscana.plugins.cloudfoundry.application.Application)

Aggregations

Compute (org.opentosca.toscana.model.node.Compute)15 SdkClientException (com.amazonaws.SdkClientException)8 TransformationFailureException (org.opentosca.toscana.plugins.util.TransformationFailureException)8 SecurityGroup (com.scaleset.cfbuilder.ec2.SecurityGroup)6 RootNode (org.opentosca.toscana.model.node.RootNode)4 WebApplication (org.opentosca.toscana.model.node.WebApplication)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 BaseUnitTest (org.opentosca.toscana.core.BaseUnitTest)3 MysqlDatabase (org.opentosca.toscana.model.node.MysqlDatabase)3 Fn (com.scaleset.cfbuilder.core.Fn)2 CFNCommand (com.scaleset.cfbuilder.ec2.metadata.CFNCommand)2 CFNPackage (com.scaleset.cfbuilder.ec2.metadata.CFNPackage)2 List (java.util.List)2 TransformationContext (org.opentosca.toscana.core.transformation.TransformationContext)2 EffectiveModel (org.opentosca.toscana.model.EffectiveModel)2 EffectiveModelFactory (org.opentosca.toscana.model.EffectiveModelFactory)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