discovery in progress

This commit is contained in:
insanity 2018-06-20 19:17:38 +09:00
parent c1fa8fdb05
commit 780d3b5b93
6 changed files with 179 additions and 82 deletions

View File

@ -93,7 +93,7 @@ export class DiscoveryComponent implements OnDestroy {
} }
case 'DiscoveryService.discoveredPort': { case 'DiscoveryService.discoveredPort': {
const port = discoveryNotify.params as Port; const port = discoveryNotify.params as Port;
this.discoveryResult.addPort(port); // this.discoveryResult.addPort(port);
break; break;
} }
case 'DiscoveryService.discoveredService': { case 'DiscoveryService.discoveredService': {

View File

@ -16,13 +16,13 @@
<ng-template let-node pTemplate="HOST"> <ng-template let-node pTemplate="HOST">
<div @discoveryResultAnim> <div @discoveryResultAnim>
<div *ngIf="checkHighlight(node.label, 0) else unhighlightHost"> <div *ngIf="checkHighlight(node.label, 0) else unhighlightHost">
<p-toggleButton onLabel="{{node.label}}" offLabel="{{node.label}}" onIcon="fa-check" offIcon="fa-square" [style]="{'width':'200px'}" <p-toggleButton [disabled]="checkExistTarget(node.data.target)" onLabel="{{node.label}}" offLabel="{{node.label}}" onIcon="fa-check"
(onChange)="onTargetSelect($event, node)"></p-toggleButton> offIcon="fa-square" [style]="{'width':'200px'}" (onChange)="onTargetSelect($event, node)"></p-toggleButton>
</div> </div>
<ng-template #unhighlightHost> <ng-template #unhighlightHost>
<p-toggleButton onLabel="{{node.label}}" offLabel="{{node.label}}" onIcon="fa-check" offIcon="fa-square" [style]="{'width':'200px', 'opacity': '0.2'}" <p-toggleButton [disabled]="checkExistTarget(node.data.target)" onLabel="{{node.label}}" offLabel="{{node.label}}" onIcon="fa-check"
(onChange)="onTargetSelect($event, node)"></p-toggleButton> offIcon="fa-square" [style]="{'width':'200px', 'opacity': '0.2'}" (onChange)="onTargetSelect($event, node)"></p-toggleButton>
</ng-template> </ng-template>
</div> </div>
</ng-template> </ng-template>
@ -31,12 +31,12 @@
<ng-template let-node pTemplate="SERVICE"> <ng-template let-node pTemplate="SERVICE">
<div @discoveryResultAnim> <div @discoveryResultAnim>
<div *ngIf="checkHighlight(node.data.name, 1) else unhighlightServ"> <div *ngIf="checkHighlight(node.data.name, 1) else unhighlightServ">
<p-toggleButton onLabel="{{node.label}} {{node.data.portType}}" offLabel="{{node.label}} {{node.data.portType}} {{node.data.portNumber}}" <p-toggleButton [disabled]="checkExistTarget(node.data.target)" onLabel="{{node.label}} {{node.data.portType}}" offLabel="{{node.label}} {{node.data.portType}} {{node.data.portNumber}}"
onIcon="fa-check" offIcon="fa-square" [style]="{'width':'300px'}" (onChange)="onTargetSelect($event, node)"></p-toggleButton> onIcon="fa-check" offIcon="fa-square" [style]="{'width':'300px'}" (onChange)="onTargetSelect($event, node)"></p-toggleButton>
</div> </div>
<ng-template #unhighlightServ> <ng-template #unhighlightServ>
<p-toggleButton onLabel="{{node.label}} {{node.data.portType}}" offLabel="{{node.label}} {{node.data.portType}} {{node.data.portNumber}}" <p-toggleButton [disabled]="checkExistTarget(node.data.target)" onLabel="{{node.label}} {{node.data.portType}}" offLabel="{{node.label}} {{node.data.portType}} {{node.data.portNumber}}"
onIcon="fa-check" offIcon="fa-square" [style]="{'width':'300px', 'opacity': '0.2'}" (onChange)="onTargetSelect($event, node)"></p-toggleButton> onIcon="fa-check" offIcon="fa-square" [style]="{'width':'300px', 'opacity': '0.2'}" (onChange)="onTargetSelect($event, node)"></p-toggleButton>
</ng-template> </ng-template>
@ -50,12 +50,12 @@
</p-panel> </p-panel>
<!-- <p-dialog header="Title" [(visible)]="displayTargetDone" [modal]="true" [responsive]="true" [width]="600" [minWidth]="200" [minY]="70" <p-dialog header="Title" [(visible)]="targetSaved" [modal]="true" [responsive]="true" [width]="600" [minWidth]="200" [minY]="70"
[closeOnEscape]="false"> [closeOnEscape]="false">
<span>Target 지정이 완료되었습니다. 이어서 Sensor를 등록하시면 좋겠다능</span> <span>Target 지정이 완료되었습니다. 이어서 Sensor를 등록하시면 좋겠다능</span>
<p-footer> <p-footer>
<button type="button" pButton label="메인으로"></button> <button type="button" pButton label="메인으로"></button>
<button type="button" pButton label="Target으로"></button> <button type="button" pButton label="Target으로"></button>
<button type="button" pButton label="InfraMap으로"></button> <button type="button" pButton label="InfraMap으로"></button>
</p-footer> </p-footer>
</p-dialog> --> </p-dialog>

View File

@ -9,10 +9,10 @@ import { TreeNode, Message, Tree } from 'primeng/primeng';
import { ProbeHost } from '@overflow/commons-typescript/model/probe'; import { ProbeHost } from '@overflow/commons-typescript/model/probe';
import { Anim } from './animation'; import { Anim } from './animation';
import { TargetService } from '@overflow/target/service/target.service'; import { TargetService } from '@overflow/target/service/target.service';
import { InfraService, InfraHost, MetaTargetHostTypeEnum, toMetaTargetHostType, Infra } from '@overflow/commons-typescript'; import { InfraService, InfraHost, MetaTargetHostTypeEnum, toMetaTargetHostType, Infra, MetaInfraTypeEnum, toMetaInfraTypeEnum, toMetaInfraType, InfraZone, Target, Page, PageParams } from '@overflow/commons-typescript';
import { InfraService as InfraRegistService } from '../../infra/service/infra.service'; import { InfraService as InfraRegistService } from '../../infra/service/infra.service';
import { Observable, of, Subscription } from 'rxjs'; import { Observable, of, Subscription } from 'rxjs';
import { catchError, exhaustMap, map, tap, take } from 'rxjs/operators'; import { catchError, map, tap, take } from 'rxjs/operators';
@Component({ @Component({
selector: 'of-discovery-result', selector: 'of-discovery-result',
@ -30,6 +30,9 @@ export class SearchResultComponent implements OnInit, OnChanges {
@Input() filterServices: Map<string, boolean>; @Input() filterServices: Map<string, boolean>;
@Input() finished: boolean; @Input() finished: boolean;
infras: Infra[];
existTargets: Target[];
discoverySubscription: Subscription; discoverySubscription: Subscription;
zoneNode: TreeNode[] = []; zoneNode: TreeNode[] = [];
hostNode: TreeNode[] = []; hostNode: TreeNode[] = [];
@ -37,20 +40,17 @@ export class SearchResultComponent implements OnInit, OnChanges {
msgs: Message[]; msgs: Message[];
error$: Observable<any>; error$: Observable<any>;
targetSaveSucceed: boolean;
displayTargetDone: boolean;
discoveredHosts: Host[] = []; discoveredHosts: Host[] = [];
discoveredServices: Service[] = []; discoveredServices: Service[] = [];
infraSaved: boolean;
targetSaved: boolean;
pending$: Observable<boolean>; pending$: Observable<boolean>;
constructor( constructor(
private targetService: TargetService, private infraRegistService: InfraRegistService,
private infraRegistService: InfraRegistService private targetService: TargetService
) { ) {
this.targetSaveSucceed = false;
this.displayTargetDone = false;
} }
ngOnInit(): void { ngOnInit(): void {
@ -62,17 +62,65 @@ export class SearchResultComponent implements OnInit, OnChanges {
children: this.hostNode, children: this.hostNode,
expanded: true expanded: true
}); });
this.getExistTarget();
}
getExistTarget() {
const pageParams: PageParams = {
pageNo: 0,
countPerPage: 99999,
sortCol: 'id',
sortDirection: 'descending'
};
this.targetService.readAllByProbeID(this.probeHost.probe.id, pageParams)
.pipe(
tap(() => {
}),
map((targetPage: Page<Target>) => {
this.existTargets = targetPage.content;
}),
catchError(error => {
this.error$ = of(error);
return of();
}),
tap(() => {
}),
take(1),
).subscribe();
} }
ngOnChanges(changes: SimpleChanges): void { ngOnChanges(changes: SimpleChanges): void {
if (changes['finished'] && changes['finished'].currentValue === true) { if (changes['finished'] && changes['finished'].currentValue === true) {
this.msgs = [];
this.msgs.push({
severity: 'success',
summary: 'Discovery가 완료되었습니다. 모니터링 대상(들)을 선택 후 저장하세요.',
});
this.saveDiscoveredInfras(); this.saveDiscoveredInfras();
}
}
displayInform() {
this.msgs = [];
this.msgs.push({
severity: 'success',
summary: 'Discovery가 완료되었습니다. 모니터링 대상(들)을 선택 후 저장하세요.',
});
}
rerenderInfras() {
this.hostNode = [];
for (const infra of this.infras) {
switch (infra.metaInfraType) {
case toMetaInfraType(MetaInfraTypeEnum.ZONE):
const infraZone: InfraZone = infra;
break;
case toMetaInfraType(MetaInfraTypeEnum.HOST):
const infraHost: InfraHost = infra;
this.addInfraHost(infraHost);
break;
case toMetaInfraType(MetaInfraTypeEnum.SERVICE):
const infraService: InfraService = infra;
this.addInfraService(infraService)
break;
default:
break;
}
} }
} }
@ -83,33 +131,36 @@ export class SearchResultComponent implements OnInit, OnChanges {
this.discoveredServices) this.discoveredServices)
.pipe( .pipe(
tap(() => { tap(() => {
this.infraSaved = false;
this.pending$ = of(true); this.pending$ = of(true);
}), }),
map((infras: Infra[]) => { map((infras: Infra[]) => {
console.log(infras); if (infras) {
this.infras = infras;
this.rerenderInfras();
this.displayInform();
}
}), }),
catchError(error => { catchError(error => {
this.error$ = of(error); this.error$ = of(error);
return of(); return of();
}), }),
tap(() => { tap(() => {
this.infraSaved = true;
this.pending$ = of(false); this.pending$ = of(false);
}), }),
take(1), take(1),
).subscribe(); ).subscribe();
} }
addHost(host: Host) { addHost(host: Host) {
const idx = this.findHostIndex(host); const idx = this.findHostIndex(host);
this.hostNode.splice(idx, 0, { this.hostNode.splice(idx, 0, {
type: 'HOST', type: 'HOST',
label: host.address, label: host.address,
data: { data: {
exist: false,
ip: this.convertIPtoNumber(host.address), ip: this.convertIPtoNumber(host.address),
mac: host.mac, mac: host.mac,
openPorts: [],
target: host target: host
}, },
expanded: true, expanded: true,
@ -120,8 +171,8 @@ export class SearchResultComponent implements OnInit, OnChanges {
} }
addService(service: Service) { addService(service: Service) {
const targetHostNode = this.findHostNodeByService(service); const targetHostNode = this.findHostNodeByService(service.port.host.address);
const idx = this.findServiceIndex(targetHostNode.children, service); const idx = this.findServiceIndex(targetHostNode.children, service.name);
targetHostNode.children.splice(idx, 0, { targetHostNode.children.splice(idx, 0, {
type: 'SERVICE', type: 'SERVICE',
label: service.name + ' (' + service.port.portNumber + ')', label: service.name + ' (' + service.port.portNumber + ')',
@ -135,15 +186,39 @@ export class SearchResultComponent implements OnInit, OnChanges {
this.discoveredServices.push(service); this.discoveredServices.push(service);
} }
addPort(port: Port) { addInfraHost(infraHost: InfraHost) {
// this.hostNode.forEach(node => { const host: Host = {
// if (node.data.id === port.host.id) { address: infraHost.infraHostIPs[0].address,
// node.data.openPorts.push(port); }
// return; const idx = this.findHostIndex(host);
// } this.hostNode.splice(idx, 0, {
// }); type: 'HOST',
label: host.address,
data: {
ip: this.convertIPtoNumber(host.address),
target: infraHost
},
expanded: true,
children: []
});
} }
addInfraService(infraService: InfraService) {
const targetHostNode = this.findHostNodeByService(infraService.infraHostPort.infraHostIP.address);
const idx = this.findServiceIndex(targetHostNode.children, infraService.metaTargetServiceType.name);
targetHostNode.children.splice(idx, 0, {
type: 'SERVICE',
label: infraService.metaTargetServiceType.name + ' (' + infraService.infraHostPort.port + ')',
data: {
name: infraService.metaTargetServiceType.name,
portType: infraService.infraHostPort.metaPortType.name,
portNumber: infraService.infraHostPort.port,
target: infraService
},
});
}
onTargetSelect(e, node: TreeNode) { onTargetSelect(e, node: TreeNode) {
const data = node.data.target; const data = node.data.target;
if (e.checked) { if (e.checked) {
@ -165,23 +240,23 @@ export class SearchResultComponent implements OnInit, OnChanges {
return index; return index;
} }
findServiceIndex(serviceNodes: TreeNode[], service: Service) { findServiceIndex(serviceNodes: TreeNode[], serviceName: string) {
let index = 0; let index = 0;
serviceNodes.forEach(node => { serviceNodes.forEach(node => {
// if (node.data.portNumber < service.port.portNumber) { // if (node.data.portNumber < service.port.portNumber) {
// index++; // index++;
// } // }
if (node.data.name.toUpperCase().localeCompare(service.name.toUpperCase()) === -1) { if (node.data.name.toUpperCase().localeCompare(serviceName.toUpperCase()) === -1) {
index++; index++;
} }
}); });
return index; return index;
} }
findHostNodeByService(service: Service) { findHostNodeByService(serviceAddress: string) {
let targetHost = null; let targetHost = null;
this.hostNode.forEach((value, i) => { this.hostNode.forEach((value, i) => {
if (value.data.ip === this.convertIPtoNumber(service.port.host.address)) { if (value.data.ip === this.convertIPtoNumber(serviceAddress)) {
targetHost = value; targetHost = value;
return; return;
} }
@ -191,7 +266,6 @@ export class SearchResultComponent implements OnInit, OnChanges {
convertIPtoNumber(ip: string) { convertIPtoNumber(ip: string) {
return ip.split('.').map((octet, index, array) => { return ip.split('.').map((octet, index, array) => {
// tslint:disable-next-line:radix
return parseInt(octet) * Math.pow(256, (array.length - index - 1)); return parseInt(octet) * Math.pow(256, (array.length - index - 1));
}).reduce((prev, curr) => { }).reduce((prev, curr) => {
return prev + curr; return prev + curr;
@ -209,36 +283,60 @@ export class SearchResultComponent implements OnInit, OnChanges {
return highlight; return highlight;
} }
checkExistTarget(infra: Infra): boolean {
if (!this.infraSaved) {
return false;
}
for (const target of this.existTargets) {
if (target.infra.id === infra.id) {
return true;
}
}
return false;
}
saveTargets() { saveTargets() {
// const hosts: Host[] = []; const targets: Target[] = [];
// const services: Service[] = []; this.selectedItems.forEach(value => {
// this.selectedItems.forEach(value => { const infra: Infra = value;
// if (!value.port) { let name: string;
// hosts.push(value); if (value.metaInfraType === toMetaInfraType(MetaInfraTypeEnum.ZONE)) {
// } else { const infraZone: InfraZone = value;
// services.push(value); name = infraZone.network;
// } } else if (value.metaInfraType === toMetaInfraType(MetaInfraTypeEnum.HOST)) {
// }); const infraHost: InfraHost = value;
// this.targetService.registDiscoveredTargets(this.probeHost.probe.id, hosts, services) name = infraHost.infraHostIPs[0].address;
// .pipe( } else if (value.metaInfraType === toMetaInfraType(MetaInfraTypeEnum.SERVICE)) {
// tap(() => { const infraService: InfraService = value;
// this.targetSaveSucceed = false; name = infraService.metaInfraType.name;
// }), }
// map((targets: Target[]) => {
// if (targets) { const target: Target = {
// this.displayTargetDone = true; infra: {
// } id: infra.id
// }), },
// catchError(error => { name: name,
// this.error$ = of(error); sensorCount: 0,
// return of(); };
// }), targets.push(target);
// tap(() => { });
// this.targetSaveSucceed = true; this.targetService.registAll(targets, this.probeHost.probe.id)
// }), .pipe(
// take(1), tap(() => {
// ).subscribe(); }),
map((targets: Target[]) => {
if (targets) {
this.targetSaved = true;
}
}),
catchError(error => {
this.error$ = of(error);
return of();
}),
tap(() => {
}),
take(1),
).subscribe();
} }
} }

View File

@ -7,7 +7,7 @@ import { catchError, exhaustMap, map, tap, take } from 'rxjs/operators';
import { TreeNode, MenuItem, ContextMenu } from 'primeng/primeng'; import { TreeNode, MenuItem, ContextMenu } from 'primeng/primeng';
import { PageParams, Page } from '@overflow/commons-typescript/core/model'; import { PageParams, Page } from '@overflow/commons-typescript/core/model';
import { ProbeHost, MetaInfraTypeEnum } from '@overflow/commons-typescript'; import { ProbeHost, MetaInfraTypeEnum } from '@overflow/commons-typescript';
import { InfraService as InfraCRUDService } from '../service/infra.service'; import { InfraService as InfraManageService } from '../service/infra.service';
@Component({ @Component({
selector: 'of-infra-tree', selector: 'of-infra-tree',
@ -34,7 +34,7 @@ export class InfraTreeComponent implements OnInit, OnChanges {
@ViewChild('cmService') cmService: ContextMenu; @ViewChild('cmService') cmService: ContextMenu;
constructor( constructor(
private infraService: InfraCRUDService, private infraService: InfraManageService,
) { ) {
} }

View File

@ -32,17 +32,15 @@
"strictPropertyInitialization": true /* Enable strict checking of property initialization in classes. */, "strictPropertyInitialization": true /* Enable strict checking of property initialization in classes. */,
// "noImplicitThis": true /* Raise error on 'this' expressions with an implied 'any' type. */, // "noImplicitThis": true /* Raise error on 'this' expressions with an implied 'any' type. */,
// "alwaysStrict": true /* Parse in strict mode and emit "use strict" for each source file. */, // "alwaysStrict": true /* Parse in strict mode and emit "use strict" for each source file. */,
/* Additional Checks */ /* Additional Checks */
// "noUnusedLocals": true /* Report errors on unused locals. */, // "noUnusedLocals": true /* Report errors on unused locals. */,
// "noUnusedParameters": true /* Report errors on unused parameters. */, // "noUnusedParameters": true /* Report errors on unused parameters. */,
"noImplicitReturns": true /* Report error when not all code paths in function return a value. */, "noImplicitReturns": true /* Report error when not all code paths in function return a value. */,
"noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */, "noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */,
/* Debugging Options */ /* Debugging Options */
"traceResolution": false /* Report module resolution log messages. */, "traceResolution": false /* Report module resolution log messages. */,
"listEmittedFiles": false /* Print names of generated files part of the compilation. */, "listEmittedFiles": false /* Print names of generated files part of the compilation. */,
"listFiles": false /* Print names of files part of the compilation. */, "listFiles": false /* Print names of files part of the compilation. */,
"pretty": true /* Stylize errors and messages using color and context. */, "pretty": true /* Stylize errors and messages using color and context. */,
} }
} }

View File

@ -125,6 +125,7 @@
"use-life-cycle-interface": true, "use-life-cycle-interface": true,
"use-pipe-transform-interface": true, "use-pipe-transform-interface": true,
"component-class-suffix": true, "component-class-suffix": true,
"directive-class-suffix": true "directive-class-suffix": true,
"no-unused-variable": true
} }
} }