From eb3ba33f95bc8264ec97079d3b1aa022da61fdd0 Mon Sep 17 00:00:00 2001 From: snoop Date: Thu, 29 Mar 2018 17:13:33 +0900 Subject: [PATCH] ing test discovery result --- .../component/setting/setting.component.ts | 91 +++++++++++++------ src/packages/discovery/model/Host.ts | 1 + src/packages/discovery/model/Port.ts | 1 + src/packages/discovery/model/Service.ts | 1 + 4 files changed, 65 insertions(+), 29 deletions(-) diff --git a/src/packages/discovery/component/setting/setting.component.ts b/src/packages/discovery/component/setting/setting.component.ts index 7fc4ad4..49b7331 100644 --- a/src/packages/discovery/component/setting/setting.component.ts +++ b/src/packages/discovery/component/setting/setting.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, AfterContentInit, Host } from '@angular/core'; +import { Component, OnInit, AfterContentInit } from '@angular/core'; import { MatCheckboxChange } from '@angular/material'; import { Store, select } from '@ngrx/store'; import { RPCClientError } from '@loafer/ng-rpc/protocol'; @@ -14,6 +14,13 @@ import * as DiscoveredStore from '../../store/setting'; import { SettingSelector, DiscoverSelector } from '../../store'; import * as DiscoverStore from '../../store/discover'; +import * as RegistStore from '../../store/regist'; +import { Host } from 'packages/discovery/model/Host'; +import * as ProbeDetailStore from 'packages/probe/store'; +import { Probe } from 'packages/probe/model'; + +import { DetailSelector as ProbeDetailSelector} from 'packages/probe/store'; + @Component({ selector: 'of-setting', templateUrl: './setting.component.html', @@ -21,9 +28,12 @@ import * as DiscoverStore from '../../store/discover'; }) export class SettingComponent implements OnInit, AfterContentInit { + + probe$ = this.probeDetailStore.pipe(select(ProbeDetailSelector.select('probe'))); + settingSucceed$: any; discoveryResult$: any; - + probe: Probe = null; started = false; cidr; @@ -43,13 +53,16 @@ export class SettingComponent implements OnInit, AfterContentInit { { name: 'Nginx' }, ]; - hosts = []; + treeNodes = []; + zones: Map = null; checkedSet = new Set(); constructor( private discoverdstore: Store, private discoverstore: Store, + private registStore: Store, + private probeDetailStore: Store ) { this.settingSucceed$ = discoverdstore.pipe(select(SettingSelector.select('isStart'))); this.discoveryResult$ = this.discoverstore.pipe(select(DiscoverSelector.select('zones'))); @@ -67,11 +80,23 @@ export class SettingComponent implements OnInit, AfterContentInit { } ); + this.probe$.subscribe( + (probe: Probe) => { + if (probe != null) { + this.probe = probe; + } + }, + (error: RPCClientError) => { + console.log(error.response.message); + } + ); + this.discoveryResult$.subscribe( (zones: Map) => { console.log('ZoneZoneZoneZoneZoneZoneZone'); // console.log(JSON.stringify(zones)); - this.convertTreeView2(zones); + this.convertTreeViewZone(zones); + this.zones = zones; }, (error: RPCClientError) => { console.log(error.response.message); @@ -82,8 +107,8 @@ export class SettingComponent implements OnInit, AfterContentInit { isZone(zone: Zone): boolean { - for (let i = 0 ; i < this.hosts.length; ++i) { - if (zone.iface === this.hosts[i].iface) { + for (let i = 0 ; i < this.treeNodes.length; ++i) { + if (zone.iface === this.treeNodes[i].iface) { return true; } } @@ -91,35 +116,29 @@ export class SettingComponent implements OnInit, AfterContentInit { return false; } - convertTreeView2(zones: Map) { + convertTreeViewZone(zones: Map) { if (zones === undefined || zones === null) { return; } - console.log('convertTreeView2'); - + console.log('convertTreeViewZone'); const treeNodes: any[] = []; zones.forEach((value: Zone, key: string, map) => { - if (this.isZone(value)) { return; } - const jZone: any = { title: 'Zone - ' + value.iface, className : 'cn' + value.ip }; - jZone.obj = value; - jZone.children = this.convertViewHost(value.hosts); - treeNodes.push(jZone); }); - this.hosts = treeNodes; + this.treeNodes = treeNodes; } ngAfterContentInit() { @@ -177,9 +196,12 @@ export class SettingComponent implements OnInit, AfterContentInit { } }; - // this.store.dispatch(new DiscoverySettingStore.Setting(startInfo)); + + console.log('start discovery - ' + this.probe.probeKey); this.discoverstore.dispatch(new DiscoverStore.DiscoverZone( - {probeID: '52abd6fd57e511e7ac52080027658d13', discoveryZone: discoveryZone})); + {probeID: this.probe.probeKey, discoveryZone: discoveryZone})); + + this.started = true; } @@ -188,30 +210,41 @@ export class SettingComponent implements OnInit, AfterContentInit { node.toggleActivated(true); if (node.isActive) { - if (this.checkedSet.has(node.data) === false) { - this.checkedSet.add(node.data); + if (node.data.obj !== undefined) { + node.data.obj.isTarget = true; } } else { - if (this.checkedSet.has(node.data)) { - this.checkedSet.delete(node.data); + if (node.data.obj !== undefined) { + node.data.obj.isTarget = false; } } + console.log(this.zones); + } discoveryResultSave() { - console.log(this.checkedSet); - } + // console.log(this.checkedSet); - convertTreeView(zone: Zone) { + // send discovery save this.zones; - if (zone === undefined || zone === null) { - return; - } + // this.registStore.dispatch(new DiscoverStore.DiscoverZone( + // {probeID: '52abd6fd57e511e7ac52080027658d13', discoveryZone: discoveryZone})); - // const treeNodes = this.convertViewHost(zone.hosts); + this.zones.forEach((zone: Zone, key: string) => { + if (zone.hosts !== undefined && zone.hosts !== null && zone.hosts.size > 0) { + // FIXME: getHosts + const hosts: Host[] = []; + zone.hosts.forEach((h: Host, hKey: string) => { + hosts.push(h); + }); - console.log(JSON.stringify(zone)); + if (hosts.length > 0) { + this.registStore.dispatch(new RegistStore.DiscoverySaveAllTarget({hosts: hosts, probe: {id: 1}})); + } + + } + }); } convertViewHost(hosts): any[] { diff --git a/src/packages/discovery/model/Host.ts b/src/packages/discovery/model/Host.ts index 2d358ea..4b4f4ad 100644 --- a/src/packages/discovery/model/Host.ts +++ b/src/packages/discovery/model/Host.ts @@ -8,6 +8,7 @@ export interface Host { os: string; discoveredDate?: Date; zone?: Zone; + isTarget?: boolean; ports: Map | null; } diff --git a/src/packages/discovery/model/Port.ts b/src/packages/discovery/model/Port.ts index 6f6dbda..fef7e14 100644 --- a/src/packages/discovery/model/Port.ts +++ b/src/packages/discovery/model/Port.ts @@ -8,6 +8,7 @@ export interface Port { portNumber: number; discoveredDate?: Date; host: Host; + isTarget?: boolean; services: Map | null; } diff --git a/src/packages/discovery/model/Service.ts b/src/packages/discovery/model/Service.ts index 2549d06..c6bdff3 100644 --- a/src/packages/discovery/model/Service.ts +++ b/src/packages/discovery/model/Service.ts @@ -6,4 +6,5 @@ export interface Service { serviceName: string; discoveredDate?: Date; port: Port; + isTarget?: boolean; }