|
|
|
|
@@ -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<string, Zone> = null;
|
|
|
|
|
|
|
|
|
|
checkedSet = new Set();
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
private discoverdstore: Store<DiscoveredStore.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.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<string, Zone>) => {
|
|
|
|
|
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<string, Zone>) {
|
|
|
|
|
convertTreeViewZone(zones: Map<string, Zone>) {
|
|
|
|
|
|
|
|
|
|
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[] {
|
|
|
|
|
|