ing test discovery result

This commit is contained in:
snoop 2018-03-29 17:13:33 +09:00
parent 969d1029b4
commit eb3ba33f95
4 changed files with 65 additions and 29 deletions

View File

@ -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 { MatCheckboxChange } from '@angular/material';
import { Store, select } from '@ngrx/store'; import { Store, select } from '@ngrx/store';
import { RPCClientError } from '@loafer/ng-rpc/protocol'; import { RPCClientError } from '@loafer/ng-rpc/protocol';
@ -14,6 +14,13 @@ import * as DiscoveredStore from '../../store/setting';
import { SettingSelector, DiscoverSelector } from '../../store'; import { SettingSelector, DiscoverSelector } from '../../store';
import * as DiscoverStore from '../../store/discover'; 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({ @Component({
selector: 'of-setting', selector: 'of-setting',
templateUrl: './setting.component.html', templateUrl: './setting.component.html',
@ -21,9 +28,12 @@ import * as DiscoverStore from '../../store/discover';
}) })
export class SettingComponent implements OnInit, AfterContentInit { export class SettingComponent implements OnInit, AfterContentInit {
probe$ = this.probeDetailStore.pipe(select(ProbeDetailSelector.select('probe')));
settingSucceed$: any; settingSucceed$: any;
discoveryResult$: any; discoveryResult$: any;
probe: Probe = null;
started = false; started = false;
cidr; cidr;
@ -43,13 +53,16 @@ export class SettingComponent implements OnInit, AfterContentInit {
{ name: 'Nginx' }, { name: 'Nginx' },
]; ];
hosts = []; treeNodes = [];
zones: Map<string, Zone> = null;
checkedSet = new Set(); checkedSet = new Set();
constructor( constructor(
private discoverdstore: Store<DiscoveredStore.State>, private discoverdstore: Store<DiscoveredStore.State>,
private discoverstore: Store<DiscoverStore.State>, private discoverstore: Store<DiscoverStore.State>,
private registStore: Store<RegistStore.State>,
private probeDetailStore: Store<ProbeDetailStore.State>
) { ) {
this.settingSucceed$ = discoverdstore.pipe(select(SettingSelector.select('isStart'))); this.settingSucceed$ = discoverdstore.pipe(select(SettingSelector.select('isStart')));
this.discoveryResult$ = this.discoverstore.pipe(select(DiscoverSelector.select('zones'))); 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( this.discoveryResult$.subscribe(
(zones: Map<string, Zone>) => { (zones: Map<string, Zone>) => {
console.log('ZoneZoneZoneZoneZoneZoneZone'); console.log('ZoneZoneZoneZoneZoneZoneZone');
// console.log(JSON.stringify(zones)); // console.log(JSON.stringify(zones));
this.convertTreeView2(zones); this.convertTreeViewZone(zones);
this.zones = zones;
}, },
(error: RPCClientError) => { (error: RPCClientError) => {
console.log(error.response.message); console.log(error.response.message);
@ -82,8 +107,8 @@ export class SettingComponent implements OnInit, AfterContentInit {
isZone(zone: Zone): boolean { isZone(zone: Zone): boolean {
for (let i = 0 ; i < this.hosts.length; ++i) { for (let i = 0 ; i < this.treeNodes.length; ++i) {
if (zone.iface === this.hosts[i].iface) { if (zone.iface === this.treeNodes[i].iface) {
return true; return true;
} }
} }
@ -91,35 +116,29 @@ export class SettingComponent implements OnInit, AfterContentInit {
return false; return false;
} }
convertTreeView2(zones: Map<string, Zone>) { convertTreeViewZone(zones: Map<string, Zone>) {
if (zones === undefined || zones === null) { if (zones === undefined || zones === null) {
return; return;
} }
console.log('convertTreeView2'); console.log('convertTreeViewZone');
const treeNodes: any[] = []; const treeNodes: any[] = [];
zones.forEach((value: Zone, key: string, map) => { zones.forEach((value: Zone, key: string, map) => {
if (this.isZone(value)) { if (this.isZone(value)) {
return; return;
} }
const jZone: any = { const jZone: any = {
title: 'Zone - ' + value.iface, title: 'Zone - ' + value.iface,
className : 'cn' + value.ip className : 'cn' + value.ip
}; };
jZone.obj = value; jZone.obj = value;
jZone.children = this.convertViewHost(value.hosts); jZone.children = this.convertViewHost(value.hosts);
treeNodes.push(jZone); treeNodes.push(jZone);
}); });
this.hosts = treeNodes; this.treeNodes = treeNodes;
} }
ngAfterContentInit() { 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( this.discoverstore.dispatch(new DiscoverStore.DiscoverZone(
{probeID: '52abd6fd57e511e7ac52080027658d13', discoveryZone: discoveryZone})); {probeID: this.probe.probeKey, discoveryZone: discoveryZone}));
this.started = true; this.started = true;
} }
@ -188,30 +210,41 @@ export class SettingComponent implements OnInit, AfterContentInit {
node.toggleActivated(true); node.toggleActivated(true);
if (node.isActive) { if (node.isActive) {
if (this.checkedSet.has(node.data) === false) { if (node.data.obj !== undefined) {
this.checkedSet.add(node.data); node.data.obj.isTarget = true;
} }
} else { } else {
if (this.checkedSet.has(node.data)) { if (node.data.obj !== undefined) {
this.checkedSet.delete(node.data); node.data.obj.isTarget = false;
} }
} }
console.log(this.zones);
} }
discoveryResultSave() { discoveryResultSave() {
console.log(this.checkedSet); // console.log(this.checkedSet);
}
convertTreeView(zone: Zone) { // send discovery save this.zones;
if (zone === undefined || zone === null) { // this.registStore.dispatch(new DiscoverStore.DiscoverZone(
return; // {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[] { convertViewHost(hosts): any[] {

View File

@ -8,6 +8,7 @@ export interface Host {
os: string; os: string;
discoveredDate?: Date; discoveredDate?: Date;
zone?: Zone; zone?: Zone;
isTarget?: boolean;
ports: Map<number, Port> | null; ports: Map<number, Port> | null;
} }

View File

@ -8,6 +8,7 @@ export interface Port {
portNumber: number; portNumber: number;
discoveredDate?: Date; discoveredDate?: Date;
host: Host; host: Host;
isTarget?: boolean;
services: Map<string, Service> | null; services: Map<string, Service> | null;
} }

View File

@ -6,4 +6,5 @@ export interface Service {
serviceName: string; serviceName: string;
discoveredDate?: Date; discoveredDate?: Date;
port: Port; port: Port;
isTarget?: boolean;
} }