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;
}
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;
}
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);
}
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;
}
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);
}
Aggregations