@riil-frontend/component-topology 9.0.0-a.20 → 9.0.0-a.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.js +9 -9
- package/es/core/editor/components/settings/core/updateElementProperty.js +6 -1
- package/es/core/editor/components/settings/propertyViews/node/data/BindIpInput.js +104 -0
- package/es/core/editor/components/settings/propertyViews/node/data/Data.js +47 -14
- package/es/core/hooks/useCanvasTheme.js +4 -4
- package/es/core/hooks/useTopoEdit.js +144 -16
- package/es/core/models/TopoApp.js +1 -1
- package/es/core/models/utils/linkUtils.js +18 -0
- package/es/core/store/models/topoConfig.js +36 -7
- package/es/core/test/Test.js +3 -3
- package/es/networkTopo/services/link.js +1 -1
- package/es/networkTopo/services/topo/basic.js +26 -16
- package/es/networkTopo/services/topo/networkLink.js +45 -3
- package/es/networkTopo/utils/exitLinkUtil.js +224 -0
- package/es/utils/htElementUtils.js +21 -21
- package/lib/core/editor/components/settings/core/updateElementProperty.js +6 -1
- package/lib/core/editor/components/settings/propertyViews/node/data/BindIpInput.js +120 -0
- package/lib/core/editor/components/settings/propertyViews/node/data/Data.js +49 -14
- package/lib/core/hooks/useCanvasTheme.js +4 -4
- package/lib/core/hooks/useTopoEdit.js +146 -15
- package/lib/core/models/TopoApp.js +1 -1
- package/lib/core/models/utils/linkUtils.js +21 -1
- package/lib/core/store/models/topoConfig.js +37 -7
- package/lib/core/test/Test.js +3 -3
- package/lib/networkTopo/services/topo/basic.js +27 -16
- package/lib/networkTopo/services/topo/networkLink.js +45 -3
- package/lib/networkTopo/utils/exitLinkUtil.js +235 -0
- package/lib/utils/htElementUtils.js +21 -21
- package/package.json +2 -2
@@ -27,6 +27,8 @@ var _topoData = require("../../../utils/topoData");
|
|
27
27
|
|
28
28
|
var _topoData2 = require("../../../core/models/topoData");
|
29
29
|
|
30
|
+
var _networkLink = _interopRequireDefault(require("../../../networkTopo/services/topo/networkLink"));
|
31
|
+
|
30
32
|
var _getTopoData = require("../../../networkTopo/getTopoData");
|
31
33
|
|
32
34
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
@@ -264,19 +266,20 @@ function _default(topoApp) {
|
|
264
266
|
var _this2 = this;
|
265
267
|
|
266
268
|
return (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
|
267
|
-
var editState, resources, _editState$groups, groups, _editState$exportLink, exportLinkIdList, query, data;
|
269
|
+
var editState, resources, _editState$groups, groups, _editState$exportLink, exportLinkIdList, _editState$ipNodes, ipNodes, query, data;
|
268
270
|
|
269
271
|
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
270
272
|
while (1) {
|
271
273
|
switch (_context2.prev = _context2.next) {
|
272
274
|
case 0:
|
273
275
|
editState = rootState.topoConfig;
|
274
|
-
resources = editState.resources, _editState$groups = editState.groups, groups = _editState$groups === void 0 ? [] : _editState$groups, _editState$exportLink = editState.exportLinkIdList, exportLinkIdList = _editState$exportLink === void 0 ? [] : _editState$exportLink;
|
276
|
+
resources = editState.resources, _editState$groups = editState.groups, groups = _editState$groups === void 0 ? [] : _editState$groups, _editState$exportLink = editState.exportLinkIdList, exportLinkIdList = _editState$exportLink === void 0 ? [] : _editState$exportLink, _editState$ipNodes = editState.ipNodes, ipNodes = _editState$ipNodes === void 0 ? [] : _editState$ipNodes;
|
275
277
|
query = {
|
276
278
|
id: rootState.topoMod.topoId,
|
277
279
|
resources: resources,
|
278
280
|
groups: groups,
|
279
|
-
exportLinkIdList: exportLinkIdList
|
281
|
+
exportLinkIdList: exportLinkIdList,
|
282
|
+
ipNodes: ipNodes
|
280
283
|
};
|
281
284
|
_context2.next = 5;
|
282
285
|
return _this2.getTopoByConditions(query);
|
@@ -330,14 +333,14 @@ function _default(topoApp) {
|
|
330
333
|
var _this4 = this;
|
331
334
|
|
332
335
|
return (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4() {
|
333
|
-
var topoId, resources, groups, exportLinkIdList, viewConditions, groupInfo, data, _yield$Promise$all, dataWithLinkDetail, _combTopoData, topoData, resAndMetrics, topoDataTrans;
|
336
|
+
var topoId, resources, groups, exportLinkIdList, ipNodes, viewConditions, groupInfo, data, _yield$Promise$all, dataWithLinkDetail, _combTopoData, topoData, resAndMetrics, topoDataTrans;
|
334
337
|
|
335
338
|
return _regenerator["default"].wrap(function _callee4$(_context4) {
|
336
339
|
while (1) {
|
337
340
|
switch (_context4.prev = _context4.next) {
|
338
341
|
case 0:
|
339
342
|
// rlog.debug("getTopoByConditions--------", params);
|
340
|
-
topoId = params.id, resources = params.resources, groups = params.groups, exportLinkIdList = params.exportLinkIdList;
|
343
|
+
topoId = params.id, resources = params.resources, groups = params.groups, exportLinkIdList = params.exportLinkIdList, ipNodes = params.ipNodes;
|
341
344
|
viewConditions = (0, _topoData2.resToConditions)(resources);
|
342
345
|
groupInfo = (0, _utils.isAvailableArray)(groups) && groups.map(function (group) {
|
343
346
|
return (0, _extends2["default"])({}, group, {
|
@@ -347,7 +350,7 @@ function _default(topoApp) {
|
|
347
350
|
}); // rlog.debug("getTopoByConditions--------", viewConditions, groupInfo);
|
348
351
|
|
349
352
|
_context4.next = 5;
|
350
|
-
return topoApp.serverApi.getTopoDataByResource(topoId, viewConditions, groupInfo, exportLinkIdList);
|
353
|
+
return topoApp.serverApi.getTopoDataByResource(topoId, viewConditions, groupInfo, exportLinkIdList, ipNodes);
|
351
354
|
|
352
355
|
case 5:
|
353
356
|
data = _context4.sent;
|
@@ -416,7 +419,7 @@ function _default(topoApp) {
|
|
416
419
|
}))
|
417
420
|
};
|
418
421
|
|
419
|
-
_rlog["default"].debug(
|
422
|
+
_rlog["default"].debug("saveGlobalConfig", config);
|
420
423
|
|
421
424
|
_context5.next = 5;
|
422
425
|
return topoApp.serverApi.saveTopoSettings(topoApp.id, config);
|
@@ -485,6 +488,33 @@ function _default(topoApp) {
|
|
485
488
|
switchToViewMode: function switchToViewMode() {
|
486
489
|
this.reset();
|
487
490
|
dispatch.topoMod.switchToViewMode();
|
491
|
+
},
|
492
|
+
queryAllLinkByIp: function queryAllLinkByIp(data) {
|
493
|
+
return (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee8() {
|
494
|
+
var _result$data;
|
495
|
+
|
496
|
+
var ids, ip, result;
|
497
|
+
return _regenerator["default"].wrap(function _callee8$(_context8) {
|
498
|
+
while (1) {
|
499
|
+
switch (_context8.prev = _context8.next) {
|
500
|
+
case 0:
|
501
|
+
ids = data.ids, ip = data.ip;
|
502
|
+
console.log("queryAllLinkByIp", ids, ip);
|
503
|
+
_context8.next = 4;
|
504
|
+
return _networkLink["default"].queryLinksByIp(ids, ip);
|
505
|
+
|
506
|
+
case 4:
|
507
|
+
result = _context8.sent;
|
508
|
+
console.log("queryAllLinkByIp-result", result);
|
509
|
+
return _context8.abrupt("return", (_result$data = result === null || result === void 0 ? void 0 : result.data) !== null && _result$data !== void 0 ? _result$data : []);
|
510
|
+
|
511
|
+
case 7:
|
512
|
+
case "end":
|
513
|
+
return _context8.stop();
|
514
|
+
}
|
515
|
+
}
|
516
|
+
}, _callee8);
|
517
|
+
}))();
|
488
518
|
}
|
489
519
|
};
|
490
520
|
}
|
package/lib/core/test/Test.js
CHANGED
@@ -39,7 +39,7 @@ var Test = /*#__PURE__*/function () {
|
|
39
39
|
|
40
40
|
var nodeElement = htTopo.getGraphView().sm().fd();
|
41
41
|
var ip = {
|
42
|
-
'id': '
|
42
|
+
'id': 'ip:1.1.1.1',
|
43
43
|
'name': '1.1.1.1',
|
44
44
|
customName: null,
|
45
45
|
// 'groupId': null,
|
@@ -51,12 +51,12 @@ var Test = /*#__PURE__*/function () {
|
|
51
51
|
|
52
52
|
};
|
53
53
|
nodeElement.a(ip);
|
54
|
-
nodeElement.setTag('
|
54
|
+
nodeElement.setTag('ip:1.1.1.1');
|
55
55
|
var link = {
|
56
56
|
'id': '0000000019b462d1',
|
57
57
|
'name': '172.17.160.116(Gi2/2/0/1) - 172.27.130.13(Gi 0/9)',
|
58
58
|
'source': '00000000029f9411',
|
59
|
-
'target': '
|
59
|
+
'target': 'ip:1.1.1.1',
|
60
60
|
'operation': 'delete',
|
61
61
|
'interfaceSource': '0000000018080aee',
|
62
62
|
'interfaceTarget': '000000000341b015',
|
@@ -25,7 +25,9 @@ var _cmdb = require("../cmdb");
|
|
25
25
|
|
26
26
|
var _model = require("../model");
|
27
27
|
|
28
|
-
var
|
28
|
+
var _exitLinkUtil = require("../../utils/exitLinkUtil");
|
29
|
+
|
30
|
+
var _excluded = ["groups", "resources", "exportLinkIdList"];
|
29
31
|
var API_ROOT = _constants.TOPO_API_ROOT;
|
30
32
|
/**
|
31
33
|
* 拓扑图(看做一个容器)的“父容器”ID
|
@@ -72,10 +74,16 @@ function prepareResourceParams(conditions, query) {
|
|
72
74
|
dynamicCondition.sort = query.sortBy + " " + query.sortOrder;
|
73
75
|
}
|
74
76
|
|
75
|
-
var fixedConditionIdList = staticRes || undefined;
|
76
77
|
return {
|
77
78
|
dynamicCondition: dynamicCondition,
|
78
|
-
fixedConditionIdList:
|
79
|
+
fixedConditionIdList: (staticRes || []).filter(function (ciId) {
|
80
|
+
return !ciId.startsWith('ip:');
|
81
|
+
}),
|
82
|
+
linkIps: (staticRes || []).filter(function (ciId) {
|
83
|
+
return ciId.startsWith('ip:');
|
84
|
+
}).map(function (ciId) {
|
85
|
+
return ciId.replace('ip:', '');
|
86
|
+
})
|
79
87
|
};
|
80
88
|
}
|
81
89
|
|
@@ -420,7 +428,7 @@ var _default = (0, _extends2["default"])({
|
|
420
428
|
*/
|
421
429
|
getTopoData: function getTopoData(id) {
|
422
430
|
return (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee12() {
|
423
|
-
var _result$links, result;
|
431
|
+
var _result$nodes, _result$links, result;
|
424
432
|
|
425
433
|
return _regenerator["default"].wrap(function _callee12$(_context12) {
|
426
434
|
while (1) {
|
@@ -432,13 +440,14 @@ var _default = (0, _extends2["default"])({
|
|
432
440
|
|
433
441
|
case 3:
|
434
442
|
result = _context12.sent;
|
435
|
-
return _context12.abrupt("return", (0, _extends2["default"])({}, result, {
|
443
|
+
return _context12.abrupt("return", (0, _exitLinkUtil.processExitLink)((0, _extends2["default"])({}, result, {
|
444
|
+
nodes: (_result$nodes = result.nodes) !== null && _result$nodes !== void 0 ? _result$nodes : [],
|
436
445
|
links: ((_result$links = result.links) !== null && _result$links !== void 0 ? _result$links : []).map(function (item) {
|
437
446
|
return (0, _extends2["default"])({}, item, {
|
438
447
|
ciType: 'network_link'
|
439
448
|
});
|
440
449
|
})
|
441
|
-
}));
|
450
|
+
})));
|
442
451
|
|
443
452
|
case 7:
|
444
453
|
_context12.prev = 7;
|
@@ -464,9 +473,9 @@ var _default = (0, _extends2["default"])({
|
|
464
473
|
* @param {Array} groups
|
465
474
|
* @returns
|
466
475
|
*/
|
467
|
-
getTopoDataByResource: function getTopoDataByResource(id, resources, groups
|
476
|
+
getTopoDataByResource: function getTopoDataByResource(id, resources, groups) {
|
468
477
|
return (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee13() {
|
469
|
-
var _result$links2;
|
478
|
+
var _result$nodes2, _result$links2;
|
470
479
|
|
471
480
|
var data, obj, result;
|
472
481
|
return _regenerator["default"].wrap(function _callee13$(_context13) {
|
@@ -485,19 +494,18 @@ var _default = (0, _extends2["default"])({
|
|
485
494
|
|
486
495
|
obj = prepareGroupParams(data);
|
487
496
|
_context13.next = 5;
|
488
|
-
return _componentTopologyUtils.request.post(API_ROOT + "/structure/byCondition/" + id, (0, _extends2["default"])({}, obj
|
489
|
-
exportLinkIdList: exportLinkIdList
|
490
|
-
}));
|
497
|
+
return _componentTopologyUtils.request.post(API_ROOT + "/structure/byCondition/" + id, (0, _extends2["default"])({}, obj));
|
491
498
|
|
492
499
|
case 5:
|
493
500
|
result = _context13.sent;
|
494
|
-
return _context13.abrupt("return", (0, _extends2["default"])({}, result, {
|
501
|
+
return _context13.abrupt("return", (0, _exitLinkUtil.processByConditionResult)((0, _extends2["default"])({}, result, {
|
502
|
+
nodes: (_result$nodes2 = result.nodes) !== null && _result$nodes2 !== void 0 ? _result$nodes2 : [],
|
495
503
|
links: ((_result$links2 = result.links) !== null && _result$links2 !== void 0 ? _result$links2 : []).map(function (item) {
|
496
504
|
return (0, _extends2["default"])({}, item, {
|
497
505
|
ciType: 'network_link'
|
498
506
|
});
|
499
507
|
})
|
500
|
-
}));
|
508
|
+
})));
|
501
509
|
|
502
510
|
case 7:
|
503
511
|
case "end":
|
@@ -517,12 +525,12 @@ var _default = (0, _extends2["default"])({
|
|
517
525
|
*/
|
518
526
|
bindResourceToTopo: function bindResourceToTopo(id, config) {
|
519
527
|
return (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee14() {
|
520
|
-
var groups, resources, otherConfig, newGroups, obj;
|
528
|
+
var groups, resources, exportLinkIdList, otherConfig, newGroups, obj;
|
521
529
|
return _regenerator["default"].wrap(function _callee14$(_context14) {
|
522
530
|
while (1) {
|
523
531
|
switch (_context14.prev = _context14.next) {
|
524
532
|
case 0:
|
525
|
-
groups = config.groups, resources = config.resources, otherConfig = (0, _objectWithoutPropertiesLoose2["default"])(config, _excluded);
|
533
|
+
groups = config.groups, resources = config.resources, exportLinkIdList = config.exportLinkIdList, otherConfig = (0, _objectWithoutPropertiesLoose2["default"])(config, _excluded);
|
526
534
|
newGroups = isAvailableArray(groups) ? groups : [];
|
527
535
|
|
528
536
|
if (resources) {
|
@@ -536,7 +544,10 @@ var _default = (0, _extends2["default"])({
|
|
536
544
|
|
537
545
|
obj = prepareGroupParams(newGroups);
|
538
546
|
_context14.next = 6;
|
539
|
-
return _componentTopologyUtils.request.post(API_ROOT + "/resource/" + id, (0, _extends2["default"])({}, otherConfig, obj
|
547
|
+
return _componentTopologyUtils.request.post(API_ROOT + "/resource/" + id, (0, _extends2["default"])({}, otherConfig, obj, {
|
548
|
+
exportLinkIdList: [] // 传空数组清空
|
549
|
+
|
550
|
+
}));
|
540
551
|
|
541
552
|
case 6:
|
542
553
|
return _context14.abrupt("return", _context14.sent);
|
@@ -17,9 +17,9 @@ var API_ROOT = _constants.TOPO_API_ROOT;
|
|
17
17
|
var _default = {
|
18
18
|
/**
|
19
19
|
* 批量查询ci类型是否可创建链路
|
20
|
-
*
|
21
|
-
* @param {*} typeCodes
|
22
|
-
* @returns
|
20
|
+
*
|
21
|
+
* @param {*} typeCodes
|
22
|
+
* @returns
|
23
23
|
*/
|
24
24
|
getCiTypesConnectable: function getCiTypesConnectable(typeCodes) {
|
25
25
|
return (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
|
@@ -40,6 +40,48 @@ var _default = {
|
|
40
40
|
}
|
41
41
|
}, _callee);
|
42
42
|
}))();
|
43
|
+
},
|
44
|
+
|
45
|
+
/**
|
46
|
+
* 通过ip查询关联链路
|
47
|
+
*
|
48
|
+
* @param {array} ciIds
|
49
|
+
*/
|
50
|
+
queryLinksByIp: function queryLinksByIp(ids, ip) {
|
51
|
+
return (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
|
52
|
+
var stag, condition, parm, result;
|
53
|
+
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
54
|
+
while (1) {
|
55
|
+
switch (_context2.prev = _context2.next) {
|
56
|
+
case 0:
|
57
|
+
stag = "'" + ids.join("','") + "'";
|
58
|
+
condition = "type('network_link') && network_link.destination_ipv4 = '" + ip + "' && network_link.source_device_id in [" + stag + "]";
|
59
|
+
parm = {
|
60
|
+
condition: condition,
|
61
|
+
sort: "name asc",
|
62
|
+
currentPage: 1,
|
63
|
+
pageSize: 999
|
64
|
+
};
|
65
|
+
_context2.prev = 3;
|
66
|
+
_context2.next = 6;
|
67
|
+
return _componentTopologyUtils.request.post("/mdc/v1/api/cmdb/commonQueryCiData", parm);
|
68
|
+
|
69
|
+
case 6:
|
70
|
+
result = _context2.sent;
|
71
|
+
return _context2.abrupt("return", result);
|
72
|
+
|
73
|
+
case 10:
|
74
|
+
_context2.prev = 10;
|
75
|
+
_context2.t0 = _context2["catch"](3);
|
76
|
+
rlog.error("通过ip查询关联链路", _context2.t0);
|
77
|
+
|
78
|
+
case 13:
|
79
|
+
case "end":
|
80
|
+
return _context2.stop();
|
81
|
+
}
|
82
|
+
}
|
83
|
+
}, _callee2, null, [[3, 10]]);
|
84
|
+
}))();
|
43
85
|
}
|
44
86
|
};
|
45
87
|
exports["default"] = _default;
|
@@ -0,0 +1,235 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
exports.__esModule = true;
|
6
|
+
exports.isUniqueIp = isUniqueIp;
|
7
|
+
exports.processByConditionResult = processByConditionResult;
|
8
|
+
exports.processExitLink = processExitLink;
|
9
|
+
|
10
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
11
|
+
|
12
|
+
var _htElementUtils = require("../../utils/htElementUtils");
|
13
|
+
|
14
|
+
function findPingNodeFromHt(nodes, ip) {
|
15
|
+
return nodes.find(function (node) {
|
16
|
+
return node.a('ciType') === "ping" && node.a('ipAddress') === ip;
|
17
|
+
});
|
18
|
+
}
|
19
|
+
|
20
|
+
function isPingHtNode(node, ip) {
|
21
|
+
return node.a('ciType') === "ping" && node.a('ipAddress') === ip;
|
22
|
+
}
|
23
|
+
|
24
|
+
function isIpHtNode(node, ip) {
|
25
|
+
return node.a('bindType') === ip && node.a('ipAddress') === ip;
|
26
|
+
}
|
27
|
+
|
28
|
+
function buildIpNode(ip) {
|
29
|
+
return {
|
30
|
+
'id': "ip:" + ip,
|
31
|
+
'name': ip,
|
32
|
+
bindType: 'ip',
|
33
|
+
// 绑定资源类型。关联资源 值为空,关联IP ip
|
34
|
+
bindIp: ip,
|
35
|
+
// TODO 所属区域,从序列化拿
|
36
|
+
// 'groupId': null,
|
37
|
+
// 'groupTag': null,
|
38
|
+
ipAddress: ip,
|
39
|
+
// 'attributes': [],
|
40
|
+
// 'metrics': [],
|
41
|
+
type: "node",
|
42
|
+
// 'dtype': 'device'
|
43
|
+
operation: "delete"
|
44
|
+
};
|
45
|
+
}
|
46
|
+
|
47
|
+
function getHtSerialize(serialize) {
|
48
|
+
if (serialize) {
|
49
|
+
return JSON.parse(serialize);
|
50
|
+
}
|
51
|
+
|
52
|
+
return null;
|
53
|
+
}
|
54
|
+
|
55
|
+
function isExitLink(link) {
|
56
|
+
return link.attributes.destination_type === "ip";
|
57
|
+
} // 判断拓扑图上ip是否唯一
|
58
|
+
|
59
|
+
|
60
|
+
function isUniqueIp(dataModel, ip, nodeElement) {
|
61
|
+
var nodes = (0, _htElementUtils.getNodes)(dataModel);
|
62
|
+
var isUnique = !!nodes.filter(function (node) {
|
63
|
+
return node.getId() !== nodeElement.getId();
|
64
|
+
}).filter(function (node) {
|
65
|
+
return isPingHtNode(node, ip) || isIpHtNode(node, ip);
|
66
|
+
});
|
67
|
+
return isUnique;
|
68
|
+
}
|
69
|
+
/**
|
70
|
+
* 打开拓扑出口链路处理
|
71
|
+
* @param {*} topoData
|
72
|
+
* @returns
|
73
|
+
*/
|
74
|
+
|
75
|
+
|
76
|
+
function processExitLink(topoData) {
|
77
|
+
var nodes = topoData.nodes,
|
78
|
+
links = topoData.links;
|
79
|
+
var serialize = (0, _extends2["default"])({}, getHtSerialize(topoData.serialize));
|
80
|
+
|
81
|
+
if (!serialize) {
|
82
|
+
return topoData;
|
83
|
+
} // 历史数据升级
|
84
|
+
|
85
|
+
|
86
|
+
links.filter(isExitLink) // 升级V1.4前配置的出口链路目的端节点为IP节点
|
87
|
+
.forEach(function (link) {
|
88
|
+
return upgradeExitLinkTarget(link);
|
89
|
+
}); // 出口链路目的端设置为IP节点或者ping资源节点id
|
90
|
+
|
91
|
+
var newLinks = links.map(function (link) {
|
92
|
+
if (!isExitLink(link) || link.target && nodes.find(function (node) {
|
93
|
+
return node.id === link.target;
|
94
|
+
})) {
|
95
|
+
return link;
|
96
|
+
}
|
97
|
+
|
98
|
+
var destinationIp = link.attributes['network_link.destination_ipv4'];
|
99
|
+
var pingNode = findPingNode(nodes, destinationIp); // 出口链路目的端设置为IP节点或者ping资源节点id
|
100
|
+
|
101
|
+
var target = pingNode ? pingNode.id : "ip:" + destinationIp; // 历史数据适配:同IP节点关联多个不同IP的链路、分级拓扑。target匹配不到元素时,根据序列化匹配
|
102
|
+
|
103
|
+
var targetSerialize = findElementSerializeById(serialize, target);
|
104
|
+
|
105
|
+
if (!targetSerialize) {
|
106
|
+
var linkSerialize = findElementSerializeById(serialize, link.id);
|
107
|
+
|
108
|
+
if (linkSerialize) {
|
109
|
+
// 根据链路序列化数据找目的端节点
|
110
|
+
// eslint-disable-next-line no-underscore-dangle
|
111
|
+
var targetNodeSerialize = serialize.d.find(function (item) {
|
112
|
+
return item.i === linkSerialize.p.target.__i;
|
113
|
+
});
|
114
|
+
|
115
|
+
if (targetNodeSerialize) {
|
116
|
+
target = targetNodeSerialize.p.tag;
|
117
|
+
}
|
118
|
+
}
|
119
|
+
}
|
120
|
+
|
121
|
+
return (0, _extends2["default"])({}, link, {
|
122
|
+
target: target
|
123
|
+
});
|
124
|
+
}); // IP节点构造为node。如果有相同ip的ping资源和图片节点,图片节点消失(不构造)
|
125
|
+
|
126
|
+
var ipNodes = getIpNodes();
|
127
|
+
|
128
|
+
function getIpNodes() {
|
129
|
+
// 从序列化获取关联的IP
|
130
|
+
var ips = serialize.d.filter(function (item) {
|
131
|
+
return item.a.bindType === 'ip';
|
132
|
+
}).map(function (item) {
|
133
|
+
return item.a.bindIp;
|
134
|
+
}).filter(function (item) {
|
135
|
+
return !!item;
|
136
|
+
}).filter(function (ip) {
|
137
|
+
return !findPingNode(nodes, ip);
|
138
|
+
}); // TODO 过滤ping资源对应的ip
|
139
|
+
|
140
|
+
return ips.map(buildIpNode);
|
141
|
+
}
|
142
|
+
|
143
|
+
function findIpNodeSerialize(serialize, ip) {
|
144
|
+
return serialize.d.find(function (item) {
|
145
|
+
return item.p.tag === "ip:" + ip;
|
146
|
+
});
|
147
|
+
}
|
148
|
+
|
149
|
+
function findElementSerializeById(serialize, id) {
|
150
|
+
return serialize.d.find(function (item) {
|
151
|
+
return item.a.id === id;
|
152
|
+
});
|
153
|
+
}
|
154
|
+
/**
|
155
|
+
* 链路在序列化存在且目的端不是ping资源、IP节点时,升级链路目的端序列化数据为IP节点
|
156
|
+
* @param {*} link
|
157
|
+
*/
|
158
|
+
|
159
|
+
|
160
|
+
function upgradeExitLinkTarget(link) {
|
161
|
+
var destinationIp = link.attributes['network_link.destination_ipv4'];
|
162
|
+
var linkSerialize = findElementSerializeById(serialize, link.id);
|
163
|
+
|
164
|
+
if (linkSerialize) {
|
165
|
+
// 根据链路序列化数据找目的端节点
|
166
|
+
// eslint-disable-next-line no-underscore-dangle
|
167
|
+
var targetNodeSerialize = serialize.d.find(function (item) {
|
168
|
+
return item.i === linkSerialize.p.target.__i;
|
169
|
+
});
|
170
|
+
|
171
|
+
if (!targetNodeSerialize.p.tag) {
|
172
|
+
targetNodeSerialize.a = (0, _extends2["default"])({}, targetNodeSerialize.a, buildIpNode(destinationIp), {
|
173
|
+
isbinding: true
|
174
|
+
});
|
175
|
+
targetNodeSerialize.p.tag = "ip:" + destinationIp;
|
176
|
+
}
|
177
|
+
}
|
178
|
+
}
|
179
|
+
|
180
|
+
return (0, _extends2["default"])({}, topoData, {
|
181
|
+
nodes: [].concat(nodes, ipNodes),
|
182
|
+
links: newLinks,
|
183
|
+
serialize: serialize
|
184
|
+
});
|
185
|
+
} // 从拓扑数据查找
|
186
|
+
|
187
|
+
|
188
|
+
function findPingNode(nodes, ip) {
|
189
|
+
return nodes.find(function (node) {
|
190
|
+
return node.ciType === "ping" && (node.ipAddress || node.attributes.ipv4_address) === ip;
|
191
|
+
});
|
192
|
+
}
|
193
|
+
/**
|
194
|
+
* 编辑模式按资源查询拓扑数据处理出口链路target
|
195
|
+
* FIXME 移到frontend 网络拓扑编辑
|
196
|
+
* @param {*} topoData
|
197
|
+
* @returns
|
198
|
+
*/
|
199
|
+
|
200
|
+
|
201
|
+
function processByConditionResult(topoData) {
|
202
|
+
var nodes = topoData.nodes,
|
203
|
+
links = topoData.links;
|
204
|
+
var ipNodes = getIpNodes();
|
205
|
+
|
206
|
+
function getIpNodes() {
|
207
|
+
// 从序列化获取关联的IP
|
208
|
+
var ips = [].filter(function (ip) {
|
209
|
+
return !findPingNode(nodes, ip);
|
210
|
+
}); // TODO 过滤ping资源对应的ip
|
211
|
+
|
212
|
+
return ips.map(buildIpNode);
|
213
|
+
} // 出口链路目的端设置为IP节点或者ping资源节点id
|
214
|
+
|
215
|
+
|
216
|
+
var newLinks = links.map(function (link) {
|
217
|
+
if (!isExitLink(link) || link.target && nodes.find(function (node) {
|
218
|
+
return node.id === link.target;
|
219
|
+
})) {
|
220
|
+
return link;
|
221
|
+
}
|
222
|
+
|
223
|
+
var destinationIp = link.attributes['network_link.destination_ipv4'];
|
224
|
+
var pingNode = findPingNode(nodes, destinationIp); // 出口链路目的端设置为IP节点或者ping资源节点id
|
225
|
+
|
226
|
+
var target = pingNode ? pingNode.id : "ip:" + destinationIp;
|
227
|
+
return (0, _extends2["default"])({}, link, {
|
228
|
+
target: target
|
229
|
+
});
|
230
|
+
});
|
231
|
+
return (0, _extends2["default"])({}, topoData, {
|
232
|
+
nodes: [].concat(nodes, ipNodes),
|
233
|
+
links: newLinks
|
234
|
+
});
|
235
|
+
}
|