Search in sources :

Example 6 with RootNode

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

the class TypeWrapper method wrapNodes.

public static Map<String, RootNode> wrapNodes(ServiceGraph graph) {
    Map<String, RootNode> nodes = new HashMap<>();
    Iterator<Entity> it = graph.iterator(ToscaStructure.NODE_TEMPLATES);
    while (it.hasNext()) {
        RootNode node = wrapTypedElement((MappingEntity) it.next());
        nodes.put(node.getEntityName(), node);
    }
    return nodes;
}
Also used : RootNode(org.opentosca.toscana.model.node.RootNode) Entity(org.opentosca.toscana.core.parse.model.Entity) MappingEntity(org.opentosca.toscana.core.parse.model.MappingEntity) HashMap(java.util.HashMap)

Example 7 with RootNode

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

the class PrepareHandler method prepare.

public void prepare() {
    ComputeNodeFindingVisitor computeFinder = findComputeNodes();
    Set<RootNode> topLevelNodes = findTopLevelNodes(computeFinder);
    groupStacks(topLevelNodes);
    updateAddresses();
}
Also used : RootNode(org.opentosca.toscana.model.node.RootNode) ComputeNodeFindingVisitor(org.opentosca.toscana.plugins.kubernetes.visitor.util.ComputeNodeFindingVisitor)

Example 8 with RootNode

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

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

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

the class DockerfileBuildingVisitor method handleDefault.

/**
 *     This method implements the default node transformation behaviour. This means, the
 *     exectuion of scripts implements the functionality thats expected from the node.
 */
private void handleDefault(RootNode node, String[] ignoredLifecycles) {
    try {
        Map<NodeStack, String> address = new HashMap<>();
        // Add the ports exposed by the node to the ports list
        node.getCapabilities().forEach(e -> {
            try {
                if (e instanceof EndpointCapability) {
                    if (((EndpointCapability) e).getPort().isPresent()) {
                        ports.add(((EndpointCapability) e).getPort().get().port);
                    }
                }
            } catch (Exception ex) {
                logger.warn("Failed reading Port from node {}", node.getEntityName(), ex);
            }
        });
        // name. We therefore have to set this to 127.0.0.1 ('localhost' causes issues too)
        for (Requirement e : node.getRequirements()) {
            if (e.getRelationship().isPresent() && e.getRelationship().get() instanceof ConnectsTo) {
                for (Object o : e.getFulfillers()) {
                    if (o instanceof RootNode) {
                        NodeStack targetStack = this.connectionGraph.vertexSet().stream().filter(ek -> ek.hasNode((RootNode) o)).findFirst().orElse(null);
                        if (targetStack != null && targetStack.getComputeNode() == this.stack.getComputeNode()) {
                            address.put(this.stack, this.stack.getComputeNode().getPrivateAddress().orElse(null));
                            this.stack.getComputeNode().setPrivateAddress(IPV4_LOCAL_ADDRESS);
                        }
                    }
                }
            }
        }
        // Add the scripts from the lifecycle to the Dockerfile
        addLifecycleOperationsToDockerfile(node.getEntityName(), node.getStandardLifecycle(), ignoredLifecycles);
        // Reset to original address
        address.forEach((k, v) -> {
            k.getComputeNode().setPrivateAddress(v);
        });
    } catch (IOException e) {
        throw new UnsupportedOperationException("Transformation failed while copying artifacts", e);
    }
}
Also used : Requirement(org.opentosca.toscana.model.requirement.Requirement) RootNode(org.opentosca.toscana.model.node.RootNode) ConnectsTo(org.opentosca.toscana.model.relation.ConnectsTo) HashMap(java.util.HashMap) NodeStack(org.opentosca.toscana.plugins.kubernetes.util.NodeStack) IOException(java.io.IOException) TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) IOException(java.io.IOException) EndpointCapability(org.opentosca.toscana.model.capability.EndpointCapability)

Aggregations

RootNode (org.opentosca.toscana.model.node.RootNode)20 RootRelationship (org.opentosca.toscana.model.relation.RootRelationship)7 WebApplication (org.opentosca.toscana.model.node.WebApplication)6 Compute (org.opentosca.toscana.model.node.Compute)4 TransformationFailureException (org.opentosca.toscana.plugins.util.TransformationFailureException)4 LinkedList (java.util.LinkedList)3 Test (org.junit.Test)3 BaseUnitTest (org.opentosca.toscana.core.BaseUnitTest)3 EffectiveModelFactory (org.opentosca.toscana.model.EffectiveModelFactory)3 Artifact (org.opentosca.toscana.model.artifact.Artifact)3 UnsupportedTypeException (org.opentosca.toscana.model.visitor.UnsupportedTypeException)3 Application (org.opentosca.toscana.plugins.cloudfoundry.application.Application)3 NodeStack (org.opentosca.toscana.plugins.kubernetes.util.NodeStack)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Entity (org.opentosca.toscana.core.parse.model.Entity)2 MappingEntity (org.opentosca.toscana.core.parse.model.MappingEntity)2 EffectiveModel (org.opentosca.toscana.model.EffectiveModel)2 EndpointCapability (org.opentosca.toscana.model.capability.EndpointCapability)2