MCPcopy
hub / github.com/dockersamples/docker-swarm-visualizer / physicalStructProvider

Function physicalStructProvider

src/data-provider.js:61–239  ·  view source on GitHub ↗
([initialNodes, initialContainers])

Source from the content-addressed store, hash-verified

59
60
61let physicalStructProvider = ([initialNodes, initialContainers]) => {
62 let containers = _.map(initialContainers, _.cloneDeep);
63 let nodeClusters = [{ uuid: "clusterid", name: "" }];
64 let nodes = _.map(initialNodes, _.cloneDeep);
65 let root = [];
66
67 let addContainer = (container) => {
68 var cloned = Object.assign({}, container);
69 let NodeID = cloned.NodeID;
70 _.find(root, (cluster) => {
71 var node = _.find(cluster.children, { ID: NodeID });
72 if (!node) return;
73 var dt = new Date(cloned.UpdatedAt);
74 var color = stringToColor(cloned.ServiceID);
75 let serviceName = cloned.ServiceName;
76 let imageNameRegex = /([^/]+?)(\:([^/]+))?$/;
77 let imageNameMatches = imageNameRegex.exec(cloned.Spec.ContainerSpec.Image);
78 let tagName = imageNameMatches[3];
79 let dateStamp = dt.getDate() + "/" + (dt.getMonth() + 1) + " " + dt.getHours() + ":" + padStart(dt.getMinutes().toString(), 2, "0");
80 let startState = cloned.Status.State;
81
82
83
84
85 let imageTag = "<div style='height: 100%; padding: 5px 5px 5px 5px; border: 2px solid " + color + "'>" +
86 "<span class='contname' style='color: white; font-weight: bold;font-size: 12px'>" + serviceName + "</span>" +
87 "<br/> image : " + imageNameMatches[0] +
88 "<br/> tag : " + (tagName ? tagName : "latest") +
89 "<br/>" + (cloned.Spec.ContainerSpec.Args ? " cmd : " + cloned.Spec.ContainerSpec.Args + "<br/>" : "") +
90 " updated : " + dateStamp +
91 "<br/>" + (cloned.Status.ContainerStatus? cloned.Status.ContainerStatus.ContainerID : "null") +
92 "<br/> state : " + startState +
93 "</div>";
94
95 if (node.Spec.Role == 'manager') {
96 let containerlink = window.location.href + "apis/containers/" + cloned.Status.ContainerStatus.ContainerID + "/json";
97 cloned.link = containerlink;
98 }
99 cloned.tag = imageTag;
100 cloned.state = startState;
101
102 node.children.push(cloned);
103 return true;
104 });
105 },
106
107 updateContainer = (container, services) => {
108 let { uuid, node } = container;
109 let [nodeUuid] = uuidRegExp.exec(node);
110 _.find(root, (cluster) => {
111 let node = _.find(cluster.children, { uuid: nodeUuid });
112 if (!node) return;
113
114 let target = _.find(node.children, { uuid }) || {};
115 if (!target) return;
116
117 Object.assign(target, container);
118 return true;

Callers 2

startMethod · 0.85
reloadMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected