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