fixed infra map

This commit is contained in:
snoop 2018-04-18 16:22:27 +09:00
parent f2dd38c7b2
commit 5adeb5e411

View File

@ -17,6 +17,12 @@ import { Infra, InfraHost, InfraOSApplication, InfraService } from '../../model'
import { Domain } from 'packages/domain/model'; import { Domain } from 'packages/domain/model';
import { AuthSelector } from 'packages/member/store'; import { AuthSelector } from 'packages/member/store';
import { sensorListSelector } from 'packages/sensor/store';
import * as SensorListStore from 'packages/sensor/store/list';
import { Sensor } from 'packages/sensor/model';
import * as _ from 'lodash';
interface HostData { interface HostData {
id: string; id: string;
@ -34,6 +40,7 @@ export class MapComponent implements OnInit, AfterContentInit {
infraTree: TreeNode[] = []; infraTree: TreeNode[] = [];
infras$ = this.listStore.pipe(select(ListSelector.select('page'))); infras$ = this.listStore.pipe(select(ListSelector.select('page')));
sensors$ = this.sensorListStore.pipe(select(sensorListSelector.select('page')));
display = false; display = false;
loading = false; loading = false;
@ -41,10 +48,15 @@ export class MapComponent implements OnInit, AfterContentInit {
totalList: Infra[]; totalList: Infra[];
hostDataList: HostData[] = new Array(); hostDataList: HostData[] = new Array();
sensorMap: Map<number, Array<Sensor>> = new Map();
targetTreeMap: Map<number, TreeNode> = new Map();
DEFAULT_EXPANDED: Boolean = true; DEFAULT_EXPANDED: Boolean = true;
constructor(private router: Router, constructor(private router: Router,
private listStore: Store<ListStore.State>, private listStore: Store<ListStore.State>,
private sensorListStore: Store<SensorListStore.State>
) {} ) {}
ngAfterContentInit() { ngAfterContentInit() {
@ -79,10 +91,88 @@ export class MapComponent implements OnInit, AfterContentInit {
(error: RPCClientError) => { (error: RPCClientError) => {
console.log(error.response.message); console.log(error.response.message);
}); });
this.sensors$.subscribe(
(page: Page) => {
if (page !== null) {
const sensorList = page.content;
console.log(sensorList);
this.addTreeForSensor(sensorList);
}
},
(error: RPCClientError) => {
console.log(error.response.message);
}
);
} }
ngOnInit() {} ngOnInit() {}
searchObj(treeList: any[], target: Target, searchList: any[]) {
if (treeList === undefined || treeList === null) {
return;
}
for (const t of treeList) {
if (t.obj !== undefined && t.obj == null) {
if (t.obj.target.id === target.id) {
searchList.push(t);
} else {
this.searchObj(t.children, target, searchList);
}
}
}
}
addTreeForSensor(sensorList: Array<Sensor>) {
if (sensorList === undefined || sensorList === null || sensorList.length <= 0) {
return;
}
// const tInfraTree = _.clone(this.infraTree);
// const it = tInfraTree[0];
// const it = this.infraTree[0];
// // for (const it of this.infraTree) {
// if (it.children === null || it.children === undefined) {
// it.children = [];
// }
// for (const itt of this.infraTree) {
// }
// }
for (const sensor of sensorList) {
const st = {
label: 'Sensors - ' + sensor.crawler.name,
expandedIcon: 'fa-folder-open',
collapsedIcon: 'fa-folder',
obj: sensor,
expanded: true
};
// FIXME:: target test id ....
const tt = this.targetTreeMap.get(3);
// const tt = this.targetTreeMap.get(sensor.target.id);
if (tt !== undefined && tt !== null) {
tt.children.push(st);
}
// it.children.push(st);
}
// this.infraTree = tInfraTree;
}
generateInfraHostData(filterStr?: string): TreeNode[] { generateInfraHostData(filterStr?: string): TreeNode[] {
@ -125,13 +215,7 @@ export class MapComponent implements OnInit, AfterContentInit {
const ihl: InfraHost[] = probeMap.get(infraHost.probe.id); const ihl: InfraHost[] = probeMap.get(infraHost.probe.id);
ihl.push(infraHost); ihl.push(infraHost);
probeMap.set(infraHost.probe.id, ihl); probeMap.set(infraHost.probe.id, ihl);
// const data: HostData = {
// id: String(infra.id),
// target: infra.target,
// host: infra,
// services: new Array(),
// };
// this.hostDataList.push(data);
} else if (infraType === 'OS_SERVICE') { } else if (infraType === 'OS_SERVICE') {
const infraService: InfraService = infra; const infraService: InfraService = infra;
if (filterStr && this.checkFilterString(infraService, filterStr)) { if (filterStr && this.checkFilterString(infraService, filterStr)) {
@ -145,70 +229,66 @@ export class MapComponent implements OnInit, AfterContentInit {
const isl = hostMap.get(infraService.host.ip); const isl = hostMap.get(infraService.host.ip);
isl.push(infraService); isl.push(infraService);
// const existHost = this.getExistHost(infraService.host); }
// if (existHost !== null) {
// existHost.services.push(infraService); }
// } else {
// const host: HostData = {
// id: String(infra.id), // const ProbeTree = {
// target: infra.target, // label: 'Probe',
// host: infraService.host, // expandedIcon: 'fa-folder-open',
// services: new Array() // collapsedIcon: 'fa-folder',
// expanded: true,
// children: [],
// }; // };
// host.services.push(infraService);
// this.hostDataList.push(host);
// }
}
}
const ProbeTree = {
label: 'Probe',
expandedIcon: 'fa-folder-open',
collapsedIcon: 'fa-folder',
expanded: true,
children: [],
};
// const probeTreeNodes: TreeNode[] = []; // const probeTreeNodes: TreeNode[] = [];
this.targetTreeMap.clear();
probeMap.forEach((ifhl: InfraHost[], key: number) => { probeMap.forEach((ifhl: InfraHost[], key: number) => {
const tp: TreeNode = { const tp = {
label: 'Probe - ' + key, label: 'Probe - ' + key,
expandedIcon: 'fa-folder-open', expandedIcon: 'fa-folder-open',
collapsedIcon: 'fa-folder', collapsedIcon: 'fa-folder',
expanded: this.DEFAULT_EXPANDED.valueOf(), expanded: this.DEFAULT_EXPANDED.valueOf(),
obj: ifhl,
children: [], children: [],
}; };
ifhl.map((ih: InfraHost, idx: number) => { ifhl.map((ih: InfraHost, idx: number) => {
const th: TreeNode = { const th = {
label: 'Host - ' + ih.ip, label: 'Host - ' + ih.ip,
expandedIcon: 'fa-folder-open', expandedIcon: 'fa-folder-open',
collapsedIcon: 'fa-folder', collapsedIcon: 'fa-folder',
expanded: this.DEFAULT_EXPANDED.valueOf(), expanded: this.DEFAULT_EXPANDED.valueOf(),
obj: ih,
children: [], children: [],
}; };
this.targetTreeMap.set(ih.target.id, th);
if (hostMap.has(ih.ip)) { if (hostMap.has(ih.ip)) {
const ifsl = hostMap.get(ih.ip); const ifsl = hostMap.get(ih.ip);
for (let i = 0 ; i < ifsl.length; ++i) { for (let i = 0 ; i < ifsl.length; ++i) {
const ts: TreeNode = { const ts = {
label: 'Service - ' + ifsl[i].vendor.name, label: 'Service - ' + ifsl[i].vendor.name,
expandedIcon: 'fa-folder-open', expandedIcon: 'fa-folder-open',
collapsedIcon: 'fa-folder', collapsedIcon: 'fa-folder',
expanded: this.DEFAULT_EXPANDED.valueOf(), expanded: this.DEFAULT_EXPANDED.valueOf(),
obj: ifsl[i],
children: [], children: [],
}; };
this.targetTreeMap.set(ifsl[i].target.id, ts);
th.children.push(ts); th.children.push(ts);
} }
@ -219,13 +299,13 @@ export class MapComponent implements OnInit, AfterContentInit {
}); });
ProbeTree.children.push(tp); // ProbeTree.children.push(tp);
infraTree.children.push(tp);
}); });
for (const infra of this.totalList) {
this.getSensorByInfra(infra);
infraTree.children.push(ProbeTree); }
this.loading = false; this.loading = false;
@ -236,6 +316,20 @@ export class MapComponent implements OnInit, AfterContentInit {
} }
getSensorByInfra(infra: Infra) {
const pageParams: PageParams = {
pageNo: '0',
countPerPage: '10',
sortCol: 'id',
sortDirection: 'descending'
};
this.sensorListStore.dispatch(new SensorListStore.ReadAllByInfra({id: String(infra.id), pageParams: pageParams}));
}
checkFilterString(infraService: InfraService, filterStr: string) { checkFilterString(infraService: InfraService, filterStr: string) {
const upperCased = filterStr.toUpperCase().toUpperCase(); const upperCased = filterStr.toUpperCase().toUpperCase();
if (infraService.vendor.name.toUpperCase().indexOf(upperCased) < 0 && if (infraService.vendor.name.toUpperCase().indexOf(upperCased) < 0 &&