discovery in progress
This commit is contained in:
parent
c1fa8fdb05
commit
780d3b5b93
|
@ -93,7 +93,7 @@ export class DiscoveryComponent implements OnDestroy {
|
|||
}
|
||||
case 'DiscoveryService.discoveredPort': {
|
||||
const port = discoveryNotify.params as Port;
|
||||
this.discoveryResult.addPort(port);
|
||||
// this.discoveryResult.addPort(port);
|
||||
break;
|
||||
}
|
||||
case 'DiscoveryService.discoveredService': {
|
||||
|
|
|
@ -16,13 +16,13 @@
|
|||
<ng-template let-node pTemplate="HOST">
|
||||
<div @discoveryResultAnim>
|
||||
<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'}"
|
||||
(onChange)="onTargetSelect($event, node)"></p-toggleButton>
|
||||
<p-toggleButton [disabled]="checkExistTarget(node.data.target)" onLabel="{{node.label}}" offLabel="{{node.label}}" onIcon="fa-check"
|
||||
offIcon="fa-square" [style]="{'width':'200px'}" (onChange)="onTargetSelect($event, node)"></p-toggleButton>
|
||||
</div>
|
||||
|
||||
<ng-template #unhighlightHost>
|
||||
<p-toggleButton onLabel="{{node.label}}" offLabel="{{node.label}}" onIcon="fa-check" offIcon="fa-square" [style]="{'width':'200px', 'opacity': '0.2'}"
|
||||
(onChange)="onTargetSelect($event, node)"></p-toggleButton>
|
||||
<p-toggleButton [disabled]="checkExistTarget(node.data.target)" onLabel="{{node.label}}" offLabel="{{node.label}}" onIcon="fa-check"
|
||||
offIcon="fa-square" [style]="{'width':'200px', 'opacity': '0.2'}" (onChange)="onTargetSelect($event, node)"></p-toggleButton>
|
||||
</ng-template>
|
||||
</div>
|
||||
</ng-template>
|
||||
|
@ -31,12 +31,12 @@
|
|||
<ng-template let-node pTemplate="SERVICE">
|
||||
<div @discoveryResultAnim>
|
||||
<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>
|
||||
</div>
|
||||
|
||||
<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>
|
||||
</ng-template>
|
||||
|
||||
|
@ -50,12 +50,12 @@
|
|||
</p-panel>
|
||||
|
||||
|
||||
<!-- <p-dialog header="Title" [(visible)]="displayTargetDone" [modal]="true" [responsive]="true" [width]="600" [minWidth]="200" [minY]="70"
|
||||
[closeOnEscape]="false">
|
||||
<p-dialog header="Title" [(visible)]="targetSaved" [modal]="true" [responsive]="true" [width]="600" [minWidth]="200" [minY]="70"
|
||||
[closeOnEscape]="false">
|
||||
<span>Target 지정이 완료되었습니다. 이어서 Sensor를 등록하시면 좋겠다능</span>
|
||||
<p-footer>
|
||||
<button type="button" pButton label="메인으로"></button>
|
||||
<button type="button" pButton label="Target으로"></button>
|
||||
<button type="button" pButton label="InfraMap으로"></button>
|
||||
</p-footer>
|
||||
</p-dialog> -->
|
||||
</p-dialog>
|
|
@ -9,10 +9,10 @@ import { TreeNode, Message, Tree } from 'primeng/primeng';
|
|||
import { ProbeHost } from '@overflow/commons-typescript/model/probe';
|
||||
import { Anim } from './animation';
|
||||
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 { Observable, of, Subscription } from 'rxjs';
|
||||
import { catchError, exhaustMap, map, tap, take } from 'rxjs/operators';
|
||||
import { catchError, map, tap, take } from 'rxjs/operators';
|
||||
|
||||
@Component({
|
||||
selector: 'of-discovery-result',
|
||||
|
@ -30,6 +30,9 @@ export class SearchResultComponent implements OnInit, OnChanges {
|
|||
@Input() filterServices: Map<string, boolean>;
|
||||
@Input() finished: boolean;
|
||||
|
||||
infras: Infra[];
|
||||
existTargets: Target[];
|
||||
|
||||
discoverySubscription: Subscription;
|
||||
zoneNode: TreeNode[] = [];
|
||||
hostNode: TreeNode[] = [];
|
||||
|
@ -37,20 +40,17 @@ export class SearchResultComponent implements OnInit, OnChanges {
|
|||
msgs: Message[];
|
||||
error$: Observable<any>;
|
||||
|
||||
targetSaveSucceed: boolean;
|
||||
displayTargetDone: boolean;
|
||||
|
||||
discoveredHosts: Host[] = [];
|
||||
discoveredServices: Service[] = [];
|
||||
infraSaved: boolean;
|
||||
targetSaved: boolean;
|
||||
|
||||
pending$: Observable<boolean>;
|
||||
|
||||
constructor(
|
||||
private targetService: TargetService,
|
||||
private infraRegistService: InfraRegistService
|
||||
private infraRegistService: InfraRegistService,
|
||||
private targetService: TargetService
|
||||
) {
|
||||
this.targetSaveSucceed = false;
|
||||
this.displayTargetDone = false;
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
|
@ -62,17 +62,65 @@ export class SearchResultComponent implements OnInit, OnChanges {
|
|||
children: this.hostNode,
|
||||
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 {
|
||||
if (changes['finished'] && changes['finished'].currentValue === true) {
|
||||
this.saveDiscoveredInfras();
|
||||
}
|
||||
}
|
||||
|
||||
displayInform() {
|
||||
this.msgs = [];
|
||||
this.msgs.push({
|
||||
severity: 'success',
|
||||
summary: 'Discovery가 완료되었습니다. 모니터링 대상(들)을 선택 후 저장하세요.',
|
||||
});
|
||||
this.saveDiscoveredInfras();
|
||||
}
|
||||
|
||||
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)
|
||||
.pipe(
|
||||
tap(() => {
|
||||
this.infraSaved = false;
|
||||
this.pending$ = of(true);
|
||||
}),
|
||||
map((infras: Infra[]) => {
|
||||
console.log(infras);
|
||||
if (infras) {
|
||||
this.infras = infras;
|
||||
this.rerenderInfras();
|
||||
this.displayInform();
|
||||
}
|
||||
}),
|
||||
catchError(error => {
|
||||
this.error$ = of(error);
|
||||
return of();
|
||||
}),
|
||||
tap(() => {
|
||||
this.infraSaved = true;
|
||||
this.pending$ = of(false);
|
||||
}),
|
||||
take(1),
|
||||
).subscribe();
|
||||
}
|
||||
|
||||
|
||||
addHost(host: Host) {
|
||||
const idx = this.findHostIndex(host);
|
||||
this.hostNode.splice(idx, 0, {
|
||||
type: 'HOST',
|
||||
label: host.address,
|
||||
data: {
|
||||
exist: false,
|
||||
ip: this.convertIPtoNumber(host.address),
|
||||
mac: host.mac,
|
||||
openPorts: [],
|
||||
target: host
|
||||
},
|
||||
expanded: true,
|
||||
|
@ -120,8 +171,8 @@ export class SearchResultComponent implements OnInit, OnChanges {
|
|||
}
|
||||
|
||||
addService(service: Service) {
|
||||
const targetHostNode = this.findHostNodeByService(service);
|
||||
const idx = this.findServiceIndex(targetHostNode.children, service);
|
||||
const targetHostNode = this.findHostNodeByService(service.port.host.address);
|
||||
const idx = this.findServiceIndex(targetHostNode.children, service.name);
|
||||
targetHostNode.children.splice(idx, 0, {
|
||||
type: 'SERVICE',
|
||||
label: service.name + ' (' + service.port.portNumber + ')',
|
||||
|
@ -135,14 +186,38 @@ export class SearchResultComponent implements OnInit, OnChanges {
|
|||
this.discoveredServices.push(service);
|
||||
}
|
||||
|
||||
addPort(port: Port) {
|
||||
// this.hostNode.forEach(node => {
|
||||
// if (node.data.id === port.host.id) {
|
||||
// node.data.openPorts.push(port);
|
||||
// return;
|
||||
// }
|
||||
// });
|
||||
addInfraHost(infraHost: InfraHost) {
|
||||
const host: Host = {
|
||||
address: infraHost.infraHostIPs[0].address,
|
||||
}
|
||||
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) {
|
||||
const data = node.data.target;
|
||||
|
@ -165,23 +240,23 @@ export class SearchResultComponent implements OnInit, OnChanges {
|
|||
return index;
|
||||
}
|
||||
|
||||
findServiceIndex(serviceNodes: TreeNode[], service: Service) {
|
||||
findServiceIndex(serviceNodes: TreeNode[], serviceName: string) {
|
||||
let index = 0;
|
||||
serviceNodes.forEach(node => {
|
||||
// if (node.data.portNumber < service.port.portNumber) {
|
||||
// index++;
|
||||
// }
|
||||
if (node.data.name.toUpperCase().localeCompare(service.name.toUpperCase()) === -1) {
|
||||
if (node.data.name.toUpperCase().localeCompare(serviceName.toUpperCase()) === -1) {
|
||||
index++;
|
||||
}
|
||||
});
|
||||
return index;
|
||||
}
|
||||
|
||||
findHostNodeByService(service: Service) {
|
||||
findHostNodeByService(serviceAddress: string) {
|
||||
let targetHost = null;
|
||||
this.hostNode.forEach((value, i) => {
|
||||
if (value.data.ip === this.convertIPtoNumber(service.port.host.address)) {
|
||||
if (value.data.ip === this.convertIPtoNumber(serviceAddress)) {
|
||||
targetHost = value;
|
||||
return;
|
||||
}
|
||||
|
@ -191,7 +266,6 @@ export class SearchResultComponent implements OnInit, OnChanges {
|
|||
|
||||
convertIPtoNumber(ip: string) {
|
||||
return ip.split('.').map((octet, index, array) => {
|
||||
// tslint:disable-next-line:radix
|
||||
return parseInt(octet) * Math.pow(256, (array.length - index - 1));
|
||||
}).reduce((prev, curr) => {
|
||||
return prev + curr;
|
||||
|
@ -209,36 +283,60 @@ export class SearchResultComponent implements OnInit, OnChanges {
|
|||
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() {
|
||||
// const hosts: Host[] = [];
|
||||
// const services: Service[] = [];
|
||||
// this.selectedItems.forEach(value => {
|
||||
// if (!value.port) {
|
||||
// hosts.push(value);
|
||||
// } else {
|
||||
// services.push(value);
|
||||
// }
|
||||
// });
|
||||
// this.targetService.registDiscoveredTargets(this.probeHost.probe.id, hosts, services)
|
||||
// .pipe(
|
||||
// tap(() => {
|
||||
// this.targetSaveSucceed = false;
|
||||
// }),
|
||||
// map((targets: Target[]) => {
|
||||
// if (targets) {
|
||||
// this.displayTargetDone = true;
|
||||
// }
|
||||
// }),
|
||||
// catchError(error => {
|
||||
// this.error$ = of(error);
|
||||
// return of();
|
||||
// }),
|
||||
// tap(() => {
|
||||
// this.targetSaveSucceed = true;
|
||||
// }),
|
||||
// take(1),
|
||||
// ).subscribe();
|
||||
const targets: Target[] = [];
|
||||
this.selectedItems.forEach(value => {
|
||||
const infra: Infra = value;
|
||||
let name: string;
|
||||
if (value.metaInfraType === toMetaInfraType(MetaInfraTypeEnum.ZONE)) {
|
||||
const infraZone: InfraZone = value;
|
||||
name = infraZone.network;
|
||||
} else if (value.metaInfraType === toMetaInfraType(MetaInfraTypeEnum.HOST)) {
|
||||
const infraHost: InfraHost = value;
|
||||
name = infraHost.infraHostIPs[0].address;
|
||||
} else if (value.metaInfraType === toMetaInfraType(MetaInfraTypeEnum.SERVICE)) {
|
||||
const infraService: InfraService = value;
|
||||
name = infraService.metaInfraType.name;
|
||||
}
|
||||
|
||||
const target: Target = {
|
||||
infra: {
|
||||
id: infra.id
|
||||
},
|
||||
name: name,
|
||||
sensorCount: 0,
|
||||
};
|
||||
targets.push(target);
|
||||
});
|
||||
this.targetService.registAll(targets, this.probeHost.probe.id)
|
||||
.pipe(
|
||||
tap(() => {
|
||||
}),
|
||||
map((targets: Target[]) => {
|
||||
if (targets) {
|
||||
this.targetSaved = true;
|
||||
}
|
||||
}),
|
||||
catchError(error => {
|
||||
this.error$ = of(error);
|
||||
return of();
|
||||
}),
|
||||
tap(() => {
|
||||
}),
|
||||
take(1),
|
||||
).subscribe();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import { catchError, exhaustMap, map, tap, take } from 'rxjs/operators';
|
|||
import { TreeNode, MenuItem, ContextMenu } from 'primeng/primeng';
|
||||
import { PageParams, Page } from '@overflow/commons-typescript/core/model';
|
||||
import { ProbeHost, MetaInfraTypeEnum } from '@overflow/commons-typescript';
|
||||
import { InfraService as InfraCRUDService } from '../service/infra.service';
|
||||
import { InfraService as InfraManageService } from '../service/infra.service';
|
||||
|
||||
@Component({
|
||||
selector: 'of-infra-tree',
|
||||
|
@ -34,7 +34,7 @@ export class InfraTreeComponent implements OnInit, OnChanges {
|
|||
@ViewChild('cmService') cmService: ContextMenu;
|
||||
|
||||
constructor(
|
||||
private infraService: InfraCRUDService,
|
||||
private infraService: InfraManageService,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
|
@ -32,13 +32,11 @@
|
|||
"strictPropertyInitialization": true /* Enable strict checking of property initialization in classes. */,
|
||||
// "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. */,
|
||||
|
||||
/* Additional Checks */
|
||||
// "noUnusedLocals": true /* Report errors on unused locals. */,
|
||||
// "noUnusedParameters": true /* Report errors on unused parameters. */,
|
||||
"noImplicitReturns": true /* Report error when not all code paths in function return a value. */,
|
||||
"noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */,
|
||||
|
||||
/* Debugging Options */
|
||||
"traceResolution": false /* Report module resolution log messages. */,
|
||||
"listEmittedFiles": false /* Print names of generated files part of the compilation. */,
|
||||
|
|
|
@ -125,6 +125,7 @@
|
|||
"use-life-cycle-interface": true,
|
||||
"use-pipe-transform-interface": true,
|
||||
"component-class-suffix": true,
|
||||
"directive-class-suffix": true
|
||||
"directive-class-suffix": true,
|
||||
"no-unused-variable": true
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user