discovery

This commit is contained in:
insanity 2018-06-21 20:11:32 +09:00
parent b37da1441d
commit 0f6057e765
3 changed files with 75 additions and 96 deletions

View File

@ -23,21 +23,18 @@
[style]="{'width':'200px'}" (onChange)="onTargetSelect($event, node)"></p-toggleButton> {{node.data.date | date: 'yy/MM/dd'}} [style]="{'width':'200px'}" (onChange)="onTargetSelect($event, node)"></p-toggleButton> {{node.data.date | date: 'yy/MM/dd'}}
</div> </div>
<!-- 새로 Discovery된 Host -->
<div *ngIf="!node.data.date" @discoveryResultAnim> <div *ngIf="!node.data.date" @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'}" <p-toggleButton onLabel="{{node.label}}" offLabel="{{node.label}}" onIcon="fa-check" offIcon="fa-square" [style]="{'width':'200px'}"
(onChange)="onTargetSelect($event, node)"></p-toggleButton> New!! (onChange)="onTargetSelect($event, node)"></p-toggleButton> New!!
</div> </div>
<!-- <div @discoveryResultAnim>
<div *ngIf="checkHighlight(node.label, 0) else unhighlightHost">
<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> <ng-template #unhighlightHost>
<p-toggleButton [disabled]="checkExistTarget(node.data.target)" onLabel="{{node.label}}" offLabel="{{node.label}}" onIcon="fa-check" <p-toggleButton onLabel="{{node.label}}" offLabel="{{node.label}}" onIcon="fa-check" offIcon="fa-square" [style]="{'width':'200px', 'opacity':'0.2'}"
offIcon="fa-square" [style]="{'width':'200px', 'opacity': '0.2'}" (onChange)="onTargetSelect($event, node)"></p-toggleButton> (onChange)="onTargetSelect($event, node)"></p-toggleButton> New!!
</ng-template> </ng-template>
</div> --> </div>
</ng-template> </ng-template>
<!-- SERVICE node template --> <!-- SERVICE node template -->
@ -45,24 +42,21 @@
<!-- 이미 저장된 Infra인 Node--> <!-- 이미 저장된 Infra인 Node-->
<div *ngIf="node.data.date"> <div *ngIf="node.data.date">
<p-toggleButton [disabled]="node.data.target" onLabel="{{node.label}}" offLabel="{{node.label}}" onIcon="fa-check" offIcon="fa-square" <p-toggleButton [disabled]="node.data.target" onLabel="{{node.label}}" offLabel="{{node.label}}" onIcon="fa-check" offIcon="fa-square"
[style]="{'width':'400px'}" (onChange)="onTargetSelect($event, node)"></p-toggleButton> {{node.data.date | date: 'yy/MM/dd'}} [style]="{'width':'200px'}" (onChange)="onTargetSelect($event, node)"></p-toggleButton> {{node.data.date | date: 'yy/MM/dd'}}
</div> </div>
<!-- 새로 Discovery된 Service -->
<div *ngIf="!node.data.date" @discoveryResultAnim> <div *ngIf="!node.data.date" @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'}" <p-toggleButton onLabel="{{node.label}}" offLabel="{{node.label}}" onIcon="fa-check" offIcon="fa-square" [style]="{'width':'200px'}"
(onChange)="onTargetSelect($event, node)"></p-toggleButton> New!! (onChange)="onTargetSelect($event, node)"></p-toggleButton> New!!
</div> </div>
<!-- <div @discoveryResultAnim>
<div *ngIf="checkHighlight(node.data.name, 1) else unhighlightServ">
<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> <ng-template #unhighlightHost>
<p-toggleButton [disabled]="checkExistTarget(node.data.target)" onLabel="{{node.label}} {{node.data.portType}}" offLabel="{{node.label}} {{node.data.portType}} {{node.data.portNumber}}" <p-toggleButton onLabel="{{node.label}}" offLabel="{{node.label}}" onIcon="fa-check" offIcon="fa-square" [style]="{'width':'200px', 'opacity':'0.2'}"
onIcon="fa-check" offIcon="fa-square" [style]="{'width':'300px', 'opacity': '0.2'}" (onChange)="onTargetSelect($event, node)"></p-toggleButton> (onChange)="onTargetSelect($event, node)"></p-toggleButton> New!!
</ng-template> </ng-template>
</div> --> </div>
</ng-template> </ng-template>
</p-tree> </p-tree>

View File

@ -5,13 +5,13 @@ import {
SimpleChanges, SimpleChanges,
} from '@angular/core'; } from '@angular/core';
import { Host, Service } from '@overflow/commons-typescript/model/discovery'; import { Host, Service } from '@overflow/commons-typescript/model/discovery';
import { TreeNode, Message, Tree } from 'primeng/primeng'; import { TreeNode, Message } 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, Infra, MetaInfraTypeEnum, toMetaInfraTypeEnum, toMetaInfraType, InfraZone, Target, Page, PageParams } from '@overflow/commons-typescript'; import { InfraService, InfraHost, Infra, MetaInfraTypeEnum, toMetaInfraType, InfraZone, Target, Page, PageParams } from '@overflow/commons-typescript';
import { InfraService as InfraManageService } from '../../infra/service/infra.service'; import { InfraService as InfraManageService } from '../../infra/service/infra.service';
import { Observable, of, Subscription } from 'rxjs'; import { Observable, of } from 'rxjs';
import { catchError, map, tap, take } from 'rxjs/operators'; import { catchError, map, tap, take } from 'rxjs/operators';
@Component({ @Component({
@ -62,19 +62,13 @@ export class DiscoveryInfraTreeComponent implements OnChanges {
} }
getInfras() { getInfras() {
const pageParams: PageParams = { this.infraManageService.readAllByProbeID(this.probeHost.probe.id)
pageNo: 0,
countPerPage: 99999,
sortCol: 'id',
sortDirection: 'descending'
};
this.infraManageService.readAllByProbeID(this.probeHost.probe.id, pageParams)
.pipe( .pipe(
tap(() => { tap(() => {
this.pending$ = of(true); this.pending$ = of(true);
}), }),
map((infraPage: Page<Infra>) => { map((infras: Infra[]) => {
this.generateTree(infraPage.content); this.generateTree(infras);
}), }),
catchError(error => { catchError(error => {
this.error$ = of(error); this.error$ = of(error);
@ -88,19 +82,13 @@ export class DiscoveryInfraTreeComponent implements OnChanges {
} }
getTargets() { getTargets() {
const pageParams: PageParams = { this.targetService.readAllByProbeID(this.probeHost.probe.id)
pageNo: 0,
countPerPage: 99999,
sortCol: 'id',
sortDirection: 'descending'
};
this.targetService.readAllByProbeID(this.probeHost.probe.id, pageParams)
.pipe( .pipe(
tap(() => { tap(() => {
this.pending$ = of(true); this.pending$ = of(true);
}), }),
map((targetPage: Page<Target>) => { map((targets: Target[]) => {
this.targets = targetPage.content; this.targets = targets;
this.getInfras(); this.getInfras();
}), }),
catchError(error => { catchError(error => {
@ -177,13 +165,12 @@ export class DiscoveryInfraTreeComponent implements OnChanges {
} }
addInfraService(infraService: InfraService) { addInfraService(infraService: InfraService) {
console.log(infraService);
const target: Target = this.checkAlreadyTarget(infraService.id); const target: Target = this.checkAlreadyTarget(infraService.id);
const targetHostNode = this.findHostNodeByService(infraService.infraHostPort.infraHostIP.address); const targetHostNode = this.findHostNodeByService(infraService.infraHostPort.infraHostIP.address);
// const idx = this.findServiceIndex(targetHostNode.children, infraService.metaTargetServiceType.name); const idx = this.findServiceIndex(targetHostNode.children, infraService.metaTargetServiceType.name);
targetHostNode.children.push({ targetHostNode.children.splice(idx, 0, {
type: 'SERVICE', type: 'SERVICE',
label: 'metaTargetServiceType이 현재 null ' + ' (' + infraService.infraHostPort.port + ')', label: infraService.metaTargetServiceType.name + ' (' + infraService.infraHostPort.port + ')',
data: { data: {
target: target, target: target,
date: infraService.createDate, date: infraService.createDate,
@ -191,6 +178,7 @@ export class DiscoveryInfraTreeComponent implements OnChanges {
portNumber: infraService.infraHostPort.port, portNumber: infraService.infraHostPort.port,
object: infraService, object: infraService,
infraID: infraService.id, infraID: infraService.id,
name: infraService.metaTargetServiceType.name
}, },
}); });
} }
@ -273,7 +261,7 @@ export class DiscoveryInfraTreeComponent implements OnChanges {
addService(service: Service) { addService(service: Service) {
let exist = false; let exist = false;
this.infraServices.forEach(infraService => { this.infraServices.forEach(infraService => {
if (//infraService.metaTargetServiceType.name === service.name && if (infraService.metaTargetServiceType.name === service.name &&
infraService.infraHostPort.port === service.port.portNumber && infraService.infraHostPort.port === service.port.portNumber &&
infraService.infraHostPort.infraHostIP.address === service.port.host.address infraService.infraHostPort.infraHostIP.address === service.port.host.address
) { ) {
@ -286,8 +274,8 @@ export class DiscoveryInfraTreeComponent implements OnChanges {
} }
const targetHostNode = this.findHostNodeByService(service.port.host.address); const targetHostNode = this.findHostNodeByService(service.port.host.address);
// const idx = this.findServiceIndex(targetHostNode.children, infraService.metaTargetServiceType.name); const idx = this.findServiceIndex(targetHostNode.children, service.name);
targetHostNode.children.push({ targetHostNode.children.splice(idx, 0, {
type: 'SERVICE', type: 'SERVICE',
label: service.name + ' (' + service.port.portNumber + ')', label: service.name + ' (' + service.port.portNumber + ')',
data: { data: {
@ -297,6 +285,7 @@ export class DiscoveryInfraTreeComponent implements OnChanges {
portNumber: service.port.portNumber, portNumber: service.port.portNumber,
object: service, object: service,
InfraID: null, InfraID: null,
name: service.name
}, },
}); });
@ -314,12 +303,9 @@ export class DiscoveryInfraTreeComponent implements OnChanges {
return index; return index;
} }
findServiceIndex(serviceNodes: TreeNode[], serviceName: string) { findServiceIndex(serviceNodes: TreeNode[], serviceName: string): number {
let index = 0; let index = 0;
serviceNodes.forEach(node => { serviceNodes.forEach(node => {
// if (node.data.portNumber < service.port.portNumber) {
// index++;
// }
if (node.data.name.toUpperCase().localeCompare(serviceName.toUpperCase()) === -1) { if (node.data.name.toUpperCase().localeCompare(serviceName.toUpperCase()) === -1) {
index++; index++;
} }
@ -327,7 +313,7 @@ export class DiscoveryInfraTreeComponent implements OnChanges {
return index; return index;
} }
findHostNodeByService(serviceAddress: string) { findHostNodeByService(serviceAddress: string): TreeNode {
let targetHost = null; let targetHost = null;
this.hostNode.forEach((value, i) => { this.hostNode.forEach((value, i) => {
if (value.data.ip === this.convertIPtoNumber(serviceAddress)) { if (value.data.ip === this.convertIPtoNumber(serviceAddress)) {
@ -338,7 +324,7 @@ export class DiscoveryInfraTreeComponent implements OnChanges {
return targetHost; return targetHost;
} }
convertIPtoNumber(ip: string) { convertIPtoNumber(ip: string): number {
return ip.split('.').map((octet, index, array) => { return ip.split('.').map((octet, index, array) => {
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) => {
@ -369,52 +355,52 @@ export class DiscoveryInfraTreeComponent implements OnChanges {
saveTargets() { saveTargets() {
const targets: Target[] = []; const targets: Target[] = [];
this.selectedItems.forEach(node => { this.selectedItems.forEach(node => {
const infraID = node.data.infraID; let infraID = node.data.infraID;
if (null === infraID) { // 새로 발견된 Host / Service if (null === infraID) { // 새로 발견된 Host or Service
for (const infra of this.savedInfras) {
if (infra.metaInfraType.key === toMetaInfraType(MetaInfraTypeEnum.HOST).key) {
const infraHost: InfraHost = infra;
const host: Host = node.data.object;
if (infraHost.infraHostIPs[0].address === host.address) {
infraID = infraHost.id;
}
} else if (infra.metaInfraType.key === toMetaInfraType(MetaInfraTypeEnum.SERVICE).key) {
const infraService: InfraService = infra;
const service: Service = node.data.object;
if (infraService.metaTargetServiceType.name === service.name &&
infraService.infraHostPort.infraHostIP.address === service.port.host.address) {
infraID = infraService.id;
}
}
}
} }
// 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 = { const target: Target = {
infra: { infra: {
id: infraID id: infraID
}, },
name: '', name: node.label,
sensorCount: 0, sensorCount: 0,
}; };
targets.push(target); targets.push(target);
}); });
console.log(targets); this.targetService.registAll(targets, this.probeHost.probe.id)
.pipe(
// this.targetService.registAll(targets, this.probeHost.probe.id) tap(() => {
// .pipe( }),
// tap(() => { map((targets: Target[]) => {
// }), if (targets) {
// map((targets: Target[]) => { this.targetSaved = true;
// if (targets) { }
// this.targetSaved = true; }),
// } catchError(error => {
// }), this.error$ = of(error);
// catchError(error => { return of();
// this.error$ = of(error); }),
// return of(); tap(() => {
// }), }),
// tap(() => { take(1),
// }), ).subscribe();
// take(1),
// ).subscribe();
} }
} }

View File

@ -2,7 +2,6 @@ import { Injectable } from '@angular/core';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { RPCService } from '@loafer/ng-rpc'; import { RPCService } from '@loafer/ng-rpc';
import { Infra } from '@overflow/commons-typescript/model/infra'; import { Infra } from '@overflow/commons-typescript/model/infra';
import { Page, PageParams } from '@overflow/commons-typescript/core/model';
import { Host, Service } from '@overflow/commons-typescript'; import { Host, Service } from '@overflow/commons-typescript';
import { gzip } from 'pako'; import { gzip } from 'pako';
@ -37,12 +36,12 @@ export class InfraService {
return this.rpcService.call<Infra>('InfraService.read', id); return this.rpcService.call<Infra>('InfraService.read', id);
} }
public readAllByProbeID(probeID: number, pageParams: PageParams): Observable<Page<Infra>> { public readAllByProbeID(probeID: number): Observable<Infra[]> {
return this.rpcService.call<Page<Infra>>('InfraService.readAllByProbeID', probeID, pageParams); return this.rpcService.call<Infra[]>('InfraService.readAllByProbeID', probeID);
} }
public readAllByDomainID(domainID: number, pageParams: PageParams): Observable<Page<Infra>> { public readAllByDomainID(domainID: number): Observable<Infra[]> {
return this.rpcService.call<Page<Infra>>('InfraService.readAllByDomainID', domainID, pageParams); return this.rpcService.call<Infra[]>('InfraService.readAllByDomainID', domainID);
} }
public readAllInfraZoneByProbeDomainID(probeDomainID: number): Observable<Infra[]> { public readAllInfraZoneByProbeDomainID(probeDomainID: number): Observable<Infra[]> {