Search in sources :

Example 1 with HostedOn

use of org.opentosca.toscana.model.relation.HostedOn in project TOSCAna by StuPro-TOSCAna.

the class GraphOperations method determineTopLevelNodes.

/**
 *     Finds the top level nodes in a given topology
 *
 *     @param model        The effective model containing the topology that should get analyzed
 *     @param computeNodes The list of Compute nodes for which the top level nodes should get determined
 *     @param onValidNode  Callback method that gets called if the node that currently processed by the iterator is valid.
 *     It does not only get called for every top level node
 *     @return the set of top level nodes for the given list of Compute nodes
 */
public static Set<RootNode> determineTopLevelNodes(EffectiveModel model, List<Compute> computeNodes, Consumer<RootNode> onValidNode) {
    Set<RootNode> topLevelNodes = new HashSet<>();
    Graph<RootNode, RootRelationship> graph = model.getTopology();
    // Determine Top level nodes (of complete stacks) and completely explore parts that are linked to a compute nodes
    computeNodes.forEach(computeNode -> {
        LinkedList<RootNode> nodeStack = new LinkedList<>();
        nodeStack.add(computeNode);
        while (!nodeStack.isEmpty()) {
            RootNode currentNode = nodeStack.pop();
            Set<RootRelationship> edges = graph.edgesOf(currentNode);
            int hostChildren = 0;
            for (RootRelationship edge : edges) {
                RootNode target = graph.getEdgeTarget(edge);
                RootNode source = graph.getEdgeSource(edge);
                if (target.equals(currentNode) && edge instanceof HostedOn) {
                    onValidNode.accept(source);
                    nodeStack.addLast(source);
                    hostChildren++;
                }
            }
            if (hostChildren == 0) {
                topLevelNodes.add(currentNode);
            }
        }
    });
    return topLevelNodes;
}
Also used : RootNode(org.opentosca.toscana.model.node.RootNode) HostedOn(org.opentosca.toscana.model.relation.HostedOn) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet) RootRelationship(org.opentosca.toscana.model.relation.RootRelationship)

Example 2 with HostedOn

use of org.opentosca.toscana.model.relation.HostedOn in project TOSCAna by StuPro-TOSCAna.

the class GraphOperations method buildTopologyStacks.

/**
 *     Converts a set of top level nodes into a list of NodeStacks
 *     @param model The model containing the topology to perform the operations with
 *     @param topLevelNodes The set of top level nodes for which the node stacks should be generated
 *     @param nodes a map containing all nodes in the topology (key is the node name),
 *     the nodes are wrapped in the {@link KubernetesNodeContainer} class
 *     @return the resulting list of node stacks
 */
public static List<NodeStack> buildTopologyStacks(EffectiveModel model, Set<RootNode> topLevelNodes, Map<String, KubernetesNodeContainer> nodes) {
    Graph<RootNode, RootRelationship> graph = model.getTopology();
    LinkedList<NodeStack> stacks = new LinkedList<>();
    topLevelNodes.forEach(node -> {
        LinkedList<KubernetesNodeContainer> stack = new LinkedList<>();
        LinkedList<RootNode> nodeStack = new LinkedList<>();
        nodeStack.add(node);
        while (!nodeStack.isEmpty()) {
            RootNode currentNode = nodeStack.pop();
            stack.add(nodes.get(currentNode.getEntityName()));
            Set<RootRelationship> edges = graph.edgesOf(currentNode);
            for (RootRelationship edge : edges) {
                RootNode target = graph.getEdgeTarget(edge);
                RootNode source = graph.getEdgeSource(edge);
                if (source.equals(currentNode) && edge instanceof HostedOn) {
                    nodeStack.addLast(target);
                }
            }
        }
        stacks.add(new NodeStack(stack));
    });
    return stacks;
}
Also used : RootNode(org.opentosca.toscana.model.node.RootNode) HostedOn(org.opentosca.toscana.model.relation.HostedOn) LinkedList(java.util.LinkedList) RootRelationship(org.opentosca.toscana.model.relation.RootRelationship)

Example 3 with HostedOn

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

Aggregations

HostedOn (org.opentosca.toscana.model.relation.HostedOn)3 LinkedList (java.util.LinkedList)2 RootNode (org.opentosca.toscana.model.node.RootNode)2 RootRelationship (org.opentosca.toscana.model.relation.RootRelationship)2 Fn (com.scaleset.cfbuilder.core.Fn)1 SecureRandom (java.security.SecureRandom)1 HashSet (java.util.HashSet)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 Compute (org.opentosca.toscana.model.node.Compute)1 MysqlDatabase (org.opentosca.toscana.model.node.MysqlDatabase)1 WebApplication (org.opentosca.toscana.model.node.WebApplication)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