From f2a16ac753510358adb866b9ae8f36522e786d6e Mon Sep 17 00:00:00 2001 From: snoop Date: Wed, 18 Apr 2018 20:15:56 +0900 Subject: [PATCH] fixed infra and discovery --- .../component/setting/setting.component.ts | 6 +- .../infra/component/map/map.component.ts | 117 ++++++++---------- 2 files changed, 58 insertions(+), 65 deletions(-) diff --git a/src/packages/discovery/component/setting/setting.component.ts b/src/packages/discovery/component/setting/setting.component.ts index d533e6e..bc0842d 100644 --- a/src/packages/discovery/component/setting/setting.component.ts +++ b/src/packages/discovery/component/setting/setting.component.ts @@ -233,10 +233,10 @@ export class SettingComponent implements OnInit, AfterContentInit { console.log(discoveryZone); // console.log('start discovery - ' + this.probe.probeKey); - // this.discoverstore.dispatch(new DiscoverStore.DiscoverZone( - // { probeID: this.probe.probeKey, discoveryZone: discoveryZone })); + this.discoverstore.dispatch(new DiscoverStore.DiscoverZone( + { probeID: this.probe.probeKey, discoveryZone: discoveryZone })); - // this.started = true; + this.started = true; } checkDiscoveryResult(node) { diff --git a/src/packages/infra/component/map/map.component.ts b/src/packages/infra/component/map/map.component.ts index 68619c9..a01299a 100644 --- a/src/packages/infra/component/map/map.component.ts +++ b/src/packages/infra/component/map/map.component.ts @@ -178,20 +178,32 @@ export class MapComponent implements OnInit, AfterContentInit { const itl: TreeNode[] = []; - const root: TreeNode = { - label: 'Infra', - expandedIcon: 'fa-folder-open', - collapsedIcon: 'fa-folder', - expanded: true, - children: [], - }; - const probeMap: Map = new Map(); const hostMap: Map = new Map(); this.loading = true; + this.sortInfraToMap(probeMap, hostMap, filterStr); + + this.targetTreeMap.clear(); + + const infraTree: TreeNode = this.generateInfraTree(probeMap, hostMap); + + for (const infra of this.totalList) { + this.getSensorByInfra(infra); + } + + this.loading = false; + + itl.push(infraTree); + + return itl; + + } + + generateInfraTree(probeMap: Map, hostMap: Map): TreeNode { + const infraTree = { label: 'Infra', expandedIcon: 'fa-folder-open', @@ -200,52 +212,6 @@ export class MapComponent implements OnInit, AfterContentInit { children: [], }; - for (const infra of this.totalList) { - const infraType = infra.infraType.name; - if (infraType === 'HOST') { - const infraHost: InfraHost = infra; - if (filterStr && String(infraHost.ip).indexOf(filterStr) < 0) { - continue; - } - - if (probeMap.has(infraHost.probe.id) === false) { - probeMap.set(infraHost.probe.id, []); - } - - const ihl: InfraHost[] = probeMap.get(infraHost.probe.id); - ihl.push(infraHost); - probeMap.set(infraHost.probe.id, ihl); - - } else if (infraType === 'OS_SERVICE') { - const infraService: InfraService = infra; - if (filterStr && this.checkFilterString(infraService, filterStr)) { - continue; - } - - if (hostMap.has(infraService.host.ip) === false) { - hostMap.set(infraService.host.ip, []); - } - - const isl = hostMap.get(infraService.host.ip); - isl.push(infraService); - - } - - } - - - // const ProbeTree = { - // label: 'Probe', - // expandedIcon: 'fa-folder-open', - // collapsedIcon: 'fa-folder', - // expanded: true, - // children: [], - // }; - - // const probeTreeNodes: TreeNode[] = []; - - this.targetTreeMap.clear(); - probeMap.forEach((ifhl: InfraHost[], key: number) => { const tp = { @@ -303,17 +269,44 @@ export class MapComponent implements OnInit, AfterContentInit { infraTree.children.push(tp); }); + return infraTree; + } + + sortInfraToMap(probeMap: Map, hostMap: Map, filterStr: string) { + for (const infra of this.totalList) { - this.getSensorByInfra(infra); + const infraType = infra.infraType.name; + if (infraType === 'HOST') { + const infraHost: InfraHost = infra; + if (filterStr && String(infraHost.ip).indexOf(filterStr) < 0) { + continue; + } + + if (probeMap.has(infraHost.probe.id) === false) { + probeMap.set(infraHost.probe.id, []); + } + + const ihl: InfraHost[] = probeMap.get(infraHost.probe.id); + ihl.push(infraHost); + probeMap.set(infraHost.probe.id, ihl); + + } else if (infraType === 'OS_SERVICE') { + const infraService: InfraService = infra; + if (filterStr && this.checkFilterString(infraService, filterStr)) { + continue; + } + + if (hostMap.has(infraService.host.ip) === false) { + hostMap.set(infraService.host.ip, []); + } + + const isl = hostMap.get(infraService.host.ip); + isl.push(infraService); + + } + } - - this.loading = false; - - itl.push(infraTree); - - return itl; - } getSensorByInfra(infra: Infra) {