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