in console/react/src/topology/links.js [123:258]
initialize(nodeInfo, nodes, separateContainers, unknowns, height, localStorage) {
this.reset();
const connectionsPerContainer = {};
const nodeIds = Object.keys(nodeInfo);
const nodeNames = new Set(nodeIds.map(n => utils.nameFromId(n)));
// collect connection info for each router
for (let source = 0; source < nodeIds.length; source++) {
let onode = nodeInfo[nodeIds[source]];
// skip any routers without connections
if (
!onode.connection ||
!onode.connection.results ||
onode.connection.results.length === 0
) {
continue;
}
for (let c = 0; c < onode.connection.results.length; c++) {
let connection = utils.flatten(
onode.connection.attributeNames,
onode.connection.results[c]
);
// ignore internal only connections
if (connection.properties["qd.adaptor"]) {
continue;
}
// we need a unique connection.container
if (connection.container === "") {
connection.container = connection.name.replace("/", "").replace(":", "-");
//utils.uuidv4();
}
// this is a connection to another interior/edge router
if (
connection.role === "inter-router" ||
(connection.role === "edge" && separateContainers.has(connection.container)) ||
nodeNames.has(connection.container)
) {
const suid = nodes.get(source).uid();
const target = getContainerIndex(connection.container, nodeInfo);
if (target >= 0) {
const tuid = nodes.get(target).uid();
this.getLink(source, target, connection.dir, "", suid, tuid);
}
continue;
}
if (!connectionsPerContainer[connection.container])
connectionsPerContainer[connection.container] = [];
let linksDir = getLinkDir(connection, onode);
if (linksDir === "unknown") {
unknowns.push(nodeIds[source]);
}
connectionsPerContainer[connection.container].push({
source: source,
linksDir: linksDir,
connection: connection,
resultsIndex: c,
});
}
}
let unique = {};
// create map of type:id:dir to [containers]
for (let container in connectionsPerContainer) {
let key = getKey(connectionsPerContainer[container]);
if (!unique[key])
unique[key] = {
c: [],
nodes: [],
};
unique[key].c.push(container);
}
for (let key in unique) {
let containers = unique[key].c;
for (let i = 0; i < containers.length; i++) {
let containerId = containers[i];
let connections = connectionsPerContainer[containerId];
let container = connections[0];
let name =
utils.nameFromId(nodeIds[container.source]) +
"." +
container.connection.identity;
let position = this.getPosition(
name,
nodes,
container.source,
container.resultsIndex,
height,
localStorage
);
let node = nodes.getOrCreateNode({
id: nodeIds[container.source],
name,
nodeType: container.connection.role,
nodeIndex: nodes.getLength(),
x: position.x,
y: position.y,
connectionContainer: container.connection.container,
resultIndex: container.resultsIndex,
fixed: position.fixed,
properties: container.connection.properties,
});
node.host = container.connection.host;
node.cdir = container.linksDir;
node.user = container.connection.user;
node.isEncrypted = container.connection.isEncrypted;
node.connectionId = container.connection.identity;
node.uuid = `${containerId}-${node.routerId}-${node.nodeType}-${node.cdir}`;
// in case a created node (or group) is connected to multiple
// routers, we need to remember all the routers for traffic animations
for (let c = 1; c < connections.length; c++) {
if (!node.alsoConnectsTo) node.alsoConnectsTo = [];
node.alsoConnectsTo.push({
key: nodeIds[connections[c].source],
cdir: connections[c].linksDir,
connectionId: connections[c].connection.identity,
});
}
unique[key].nodes.push(node);
}
}
for (let key in unique) {
nodes.add(unique[key].nodes[0]);
let target = nodes.nodes.length - 1;
unique[key].nodes[0].normals = [unique[key].nodes[0]];
for (let n = 1; n < unique[key].nodes.length; n++) {
unique[key].nodes[0].normals.push(unique[key].nodes[n]);
}
let containerId = unique[key].c[0];
let links = connectionsPerContainer[containerId];
for (let l = 0; l < links.length; l++) {
let source = links[l].source;
const suid = nodes.get(source).uid();
const tuid = nodes.get(target).uid();
this.getLink(links[l].source, target, links[l].linksDir, "small", suid, tuid);
}
}
}