Search in sources :

Example 1 with RootRelationship

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

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

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

the class DynamicRequirementTest method dynamicRequirementTest.

@Test
public void dynamicRequirementTest() {
    EffectiveModel model = new EffectiveModelFactory().create(TestTemplates.Requirements.DYNAMIC_REQUIREMENT, logMock());
    WebApplication app = (WebApplication) model.getNodes().iterator().next();
    Requirement<? extends Capability, ? extends RootNode, ? extends RootRelationship> dynamicRequirement = app.getRequirements().stream().filter(r -> "dynamic-requirement".equals(r.getEntityName())).findFirst().orElseThrow(() -> new IllegalStateException("dynamic requirement should exist"));
    RootRelationship relationship = dynamicRequirement.getRelationship().get();
    assertEquals(ConnectsTo.class, relationship.getClass());
    Capability capability = dynamicRequirement.get(dynamicRequirement.CAPABILITY);
    assertEquals(EndpointCapability.class, capability.getClass());
    RootNode fulfiller = dynamicRequirement.getFulfillers().iterator().next();
    assertEquals(app, fulfiller);
}
Also used : RootNode(org.opentosca.toscana.model.node.RootNode) EndpointCapability(org.opentosca.toscana.model.capability.EndpointCapability) Capability(org.opentosca.toscana.model.capability.Capability) WebApplication(org.opentosca.toscana.model.node.WebApplication) EffectiveModel(org.opentosca.toscana.model.EffectiveModel) EffectiveModelFactory(org.opentosca.toscana.model.EffectiveModelFactory) RootRelationship(org.opentosca.toscana.model.relation.RootRelationship) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Example 4 with RootRelationship

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

the class CloudFormationLifecycle method checkModel.

@Override
public boolean checkModel() {
    logger.info("Check model for compatibility to CloudFormation");
    Set<RootNode> nodes = model.getNodes();
    Set<RootRelationship> relationships = model.getTopology().edgeSet();
    try {
        CheckModelNodeVisitor checkModelNodeVisitor = new CheckModelNodeVisitor(context);
        logger.info("Check nodes");
        visitAllNodes(nodes, checkModelNodeVisitor);
        CheckModelRelationshipVisitor checkModelRelationshipVisitor = new CheckModelRelationshipVisitor(context);
        logger.info("Check relationships");
        visitAllRelationships(relationships, checkModelRelationshipVisitor);
    } catch (UnsupportedTypeException ute) {
        logger.error(ute.getMessage());
        return false;
    }
    return true;
}
Also used : RootNode(org.opentosca.toscana.model.node.RootNode) UnsupportedTypeException(org.opentosca.toscana.model.visitor.UnsupportedTypeException) CheckModelNodeVisitor(org.opentosca.toscana.plugins.cloudformation.visitor.CheckModelNodeVisitor) CheckModelRelationshipVisitor(org.opentosca.toscana.plugins.cloudformation.visitor.CheckModelRelationshipVisitor) RootRelationship(org.opentosca.toscana.model.relation.RootRelationship)

Example 5 with RootRelationship

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

the class CloudFormationLifecycle method prepare.

@Override
public void prepare() {
    logger.info("Prepare model for compatibility to CloudFormation");
    Set<RootNode> nodes = model.getNodes();
    Graph<RootNode, RootRelationship> topology = model.getTopology();
    PrepareModelNodeVisitor prepareModelNodeVisitor = new PrepareModelNodeVisitor(context, cfnModule);
    logger.info("Prepare nodes");
    visitComputeNodesFirst(nodes, prepareModelNodeVisitor);
    logger.info("Prepare relationships");
    PrepareModelRelationshipVisitor prepareModelRelationshipVisitor = new PrepareModelRelationshipVisitor(context, cfnModule);
    visitAllRelationships(topology.edgeSet(), prepareModelRelationshipVisitor);
}
Also used : PrepareModelNodeVisitor(org.opentosca.toscana.plugins.cloudformation.visitor.PrepareModelNodeVisitor) RootNode(org.opentosca.toscana.model.node.RootNode) PrepareModelRelationshipVisitor(org.opentosca.toscana.plugins.cloudformation.visitor.PrepareModelRelationshipVisitor) RootRelationship(org.opentosca.toscana.model.relation.RootRelationship)

Aggregations

RootNode (org.opentosca.toscana.model.node.RootNode)7 RootRelationship (org.opentosca.toscana.model.relation.RootRelationship)7 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 WebApplication (org.opentosca.toscana.model.node.WebApplication)2 HostedOn (org.opentosca.toscana.model.relation.HostedOn)2 Test (org.junit.Test)1 BaseUnitTest (org.opentosca.toscana.core.BaseUnitTest)1 EffectiveModel (org.opentosca.toscana.model.EffectiveModel)1 EffectiveModelFactory (org.opentosca.toscana.model.EffectiveModelFactory)1 Capability (org.opentosca.toscana.model.capability.Capability)1 EndpointCapability (org.opentosca.toscana.model.capability.EndpointCapability)1 Compute (org.opentosca.toscana.model.node.Compute)1 UnsupportedTypeException (org.opentosca.toscana.model.visitor.UnsupportedTypeException)1 CheckModelNodeVisitor (org.opentosca.toscana.plugins.cloudformation.visitor.CheckModelNodeVisitor)1 CheckModelRelationshipVisitor (org.opentosca.toscana.plugins.cloudformation.visitor.CheckModelRelationshipVisitor)1 PrepareModelNodeVisitor (org.opentosca.toscana.plugins.cloudformation.visitor.PrepareModelNodeVisitor)1 PrepareModelRelationshipVisitor (org.opentosca.toscana.plugins.cloudformation.visitor.PrepareModelRelationshipVisitor)1