From c3ac713f9985ba28183c474703b2c9064568138e Mon Sep 17 00:00:00 2001 From: snoop Date: Mon, 23 Apr 2018 21:31:16 +0900 Subject: [PATCH] fixed discovery --- .../component/setting/setting.component.ts | 71 ++++++++++++++++--- .../store/discover/discover.reducer.ts | 25 +++++-- .../store/discover/discover.state.ts | 6 ++ 3 files changed, 85 insertions(+), 17 deletions(-) diff --git a/src/packages/discovery/component/setting/setting.component.ts b/src/packages/discovery/component/setting/setting.component.ts index fa96db3..1d8cb16 100644 --- a/src/packages/discovery/component/setting/setting.component.ts +++ b/src/packages/discovery/component/setting/setting.component.ts @@ -42,6 +42,11 @@ export class SettingComponent implements OnInit, AfterContentInit { settingSucceed$: any; discoveryResult$: any; + + discoveryReq$: any; + discoveryStart$: any; + discoveryEnd$: any; + probe: Probe = null; started = false; @@ -92,11 +97,14 @@ export class SettingComponent implements OnInit, AfterContentInit { ) { this.settingSucceed$ = discoverdstore.pipe(select(SettingSelector.select('isStart'))); this.discoveryResult$ = this.discoverstore.pipe(select(DiscoverSelector.select('zones'))); + this.discoveryReq$ = this.discoverstore.pipe(select(DiscoverSelector.select('isReq'))); + this.discoveryStart$ = this.discoverstore.pipe(select(DiscoverSelector.select('isStart'))); + this.discoveryEnd$ = this.discoverstore.pipe(select(DiscoverSelector.select('isEnd'))); } ngOnInit() { - this.treeNodes = this.convertViewHost(this.testObj); + // this.treeNodes = this.convertViewHost(this.testObj); this.settingSucceed$.subscribe( (succeed: boolean) => { @@ -122,10 +130,53 @@ export class SettingComponent implements OnInit, AfterContentInit { this.discoveryResult$.subscribe( (zones: Map) => { - console.log('ZoneZoneZoneZoneZoneZoneZone'); - // console.log(JSON.stringify(zones)); - this.treeNodes = this.convertTreeViewZone(zones); - this.zones = zones; + + if (zones !== undefined && zones !== null) { + console.log('ZoneZoneZoneZoneZoneZoneZone'); + // console.log(JSON.stringify(zones)); + this.treeNodes = this.convertTreeViewZone(zones); + this.zones = zones; + } + + }, + (error: RPCClientError) => { + console.log(error.response.message); + } + ); + + this.discoveryReq$.subscribe( + (isReq: boolean) => { + + if (isReq !== undefined && isReq !== null) { + console.log('isReqisReqisReqisReq'); + } + + }, + (error: RPCClientError) => { + console.log(error.response.message); + } + ); + + this.discoveryReq$.subscribe( + (isStart: boolean) => { + + if (isStart !== undefined && isStart !== null) { + console.log('isStartisStartisStart'); + } + + }, + (error: RPCClientError) => { + console.log(error.response.message); + } + ); + + this.discoveryEnd$.subscribe( + (isEnd: boolean) => { + + if (isEnd !== undefined && isEnd !== null) { + console.log('isEndisEndisEndisEnd'); + } + }, (error: RPCClientError) => { console.log(error.response.message); @@ -140,11 +191,11 @@ export class SettingComponent implements OnInit, AfterContentInit { isZone(zone: Zone): boolean { - for (let i = 0; i < this.treeNodes.length; ++i) { - if (zone.iface === this.treeNodes[i].iface) { - return true; - } - } + // for (let i = 0; i < this.treeNodes.length; ++i) { + // if (zone.iface === this.treeNodes[i].iface) { + // return true; + // } + // } return false; } diff --git a/src/packages/discovery/store/discover/discover.reducer.ts b/src/packages/discovery/store/discover/discover.reducer.ts index 35b78b2..ad5bd21 100644 --- a/src/packages/discovery/store/discover/discover.reducer.ts +++ b/src/packages/discovery/store/discover/discover.reducer.ts @@ -20,10 +20,17 @@ import { export function reducer(state = initialState, action: Actions): State { switch (action.type) { case ActionType.DiscoveryStart: { - return state; + + return { + ...state, + isStart: true + }; } case ActionType.DiscoveryStop: { - return state; + return { + ...state, + isEnd: true + }; } case ActionType.DiscoveredZone: { const zone: Zone = action.payload; @@ -160,24 +167,28 @@ export function reducer(state = initialState, action: Actions): State { zone.hosts = new Map(); } - zone.hosts.set(service.port.host.ip, service.port.host); - // if (undefined === zone) { // console.error(`Discovery.DiscoveredService: Zone[${service.port.host.zone.network}] is not exist`); // } // if (null === zone.hosts || undefined === zone.hosts.get(service.port.host.ip)) { // console.error(`Discovery.DiscoveredPort: Host[${service.port.host.ip}] is not exist`); // } - const host: Host = zone.hosts.get(service.port.host.ip); + let host: Host = null; + host = zone.hosts.get(service.port.host.ip); - if (null === host.ports || undefined === host.ports) { + if (host === undefined || host === null) { + zone.hosts.set(service.port.host.ip, service.port.host); + host = service.port.host; + } + + if (undefined === host.ports || null === host.ports) { host.ports = new Map(); host.ports.set(service.port.portNumber, service.port); } const port: Port = host.ports.get(service.port.portNumber); - if (null === port.services || undefined === port.services) { + if ( undefined === port.services || null === port.services) { port.services = new Map(); } port.services.set(service.serviceName, service); diff --git a/src/packages/discovery/store/discover/discover.state.ts b/src/packages/discovery/store/discover/discover.state.ts index f563036..2793f69 100644 --- a/src/packages/discovery/store/discover/discover.state.ts +++ b/src/packages/discovery/store/discover/discover.state.ts @@ -6,11 +6,17 @@ export interface State { error: RPCClientError | null; processing: boolean; zones: Map | null; + isReq: boolean; + isStart: boolean; + isEnd: boolean; } export const initialState: State = { error: null, processing: false, zones: null, + isReq: false, + isStart: false, + isEnd: false };