From 0f6057e765ed985c17d2a2d03c313305f02dacae Mon Sep 17 00:00:00 2001 From: insanity Date: Thu, 21 Jun 2018 20:11:32 +0900 Subject: [PATCH] discovery --- .../discovery-infra-tree.component.html | 36 +++-- .../discovery-infra-tree.component.ts | 126 ++++++++---------- @overflow/infra/service/infra.service.ts | 9 +- 3 files changed, 75 insertions(+), 96 deletions(-) diff --git a/@overflow/discovery/component/discovery-infra-tree.component.html b/@overflow/discovery/component/discovery-infra-tree.component.html index beb2e13..95c748e 100644 --- a/@overflow/discovery/component/discovery-infra-tree.component.html +++ b/@overflow/discovery/component/discovery-infra-tree.component.html @@ -23,21 +23,18 @@ [style]="{'width':'200px'}" (onChange)="onTargetSelect($event, node)"> {{node.data.date | date: 'yy/MM/dd'}} +
- New!! -
- + @@ -45,24 +42,21 @@
{{node.data.date | date: 'yy/MM/dd'}} + [style]="{'width':'200px'}" (onChange)="onTargetSelect($event, node)"> {{node.data.date | date: 'yy/MM/dd'}}
+
- New!! -
- + diff --git a/@overflow/discovery/component/discovery-infra-tree.component.ts b/@overflow/discovery/component/discovery-infra-tree.component.ts index b1bd755..3bea84a 100644 --- a/@overflow/discovery/component/discovery-infra-tree.component.ts +++ b/@overflow/discovery/component/discovery-infra-tree.component.ts @@ -5,13 +5,13 @@ import { SimpleChanges, } from '@angular/core'; 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 { Anim } from './animation'; 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 { Observable, of, Subscription } from 'rxjs'; +import { Observable, of } from 'rxjs'; import { catchError, map, tap, take } from 'rxjs/operators'; @Component({ @@ -62,19 +62,13 @@ export class DiscoveryInfraTreeComponent implements OnChanges { } getInfras() { - const pageParams: PageParams = { - pageNo: 0, - countPerPage: 99999, - sortCol: 'id', - sortDirection: 'descending' - }; - this.infraManageService.readAllByProbeID(this.probeHost.probe.id, pageParams) + this.infraManageService.readAllByProbeID(this.probeHost.probe.id) .pipe( tap(() => { this.pending$ = of(true); }), - map((infraPage: Page) => { - this.generateTree(infraPage.content); + map((infras: Infra[]) => { + this.generateTree(infras); }), catchError(error => { this.error$ = of(error); @@ -88,19 +82,13 @@ export class DiscoveryInfraTreeComponent implements OnChanges { } getTargets() { - const pageParams: PageParams = { - pageNo: 0, - countPerPage: 99999, - sortCol: 'id', - sortDirection: 'descending' - }; - this.targetService.readAllByProbeID(this.probeHost.probe.id, pageParams) + this.targetService.readAllByProbeID(this.probeHost.probe.id) .pipe( tap(() => { this.pending$ = of(true); }), - map((targetPage: Page) => { - this.targets = targetPage.content; + map((targets: Target[]) => { + this.targets = targets; this.getInfras(); }), catchError(error => { @@ -177,13 +165,12 @@ export class DiscoveryInfraTreeComponent implements OnChanges { } addInfraService(infraService: InfraService) { - console.log(infraService); const target: Target = this.checkAlreadyTarget(infraService.id); const targetHostNode = this.findHostNodeByService(infraService.infraHostPort.infraHostIP.address); - // const idx = this.findServiceIndex(targetHostNode.children, infraService.metaTargetServiceType.name); - targetHostNode.children.push({ + const idx = this.findServiceIndex(targetHostNode.children, infraService.metaTargetServiceType.name); + targetHostNode.children.splice(idx, 0, { type: 'SERVICE', - label: 'metaTargetServiceType이 현재 null ' + ' (' + infraService.infraHostPort.port + ')', + label: infraService.metaTargetServiceType.name + ' (' + infraService.infraHostPort.port + ')', data: { target: target, date: infraService.createDate, @@ -191,6 +178,7 @@ export class DiscoveryInfraTreeComponent implements OnChanges { portNumber: infraService.infraHostPort.port, object: infraService, infraID: infraService.id, + name: infraService.metaTargetServiceType.name }, }); } @@ -273,7 +261,7 @@ export class DiscoveryInfraTreeComponent implements OnChanges { addService(service: Service) { let exist = false; this.infraServices.forEach(infraService => { - if (//infraService.metaTargetServiceType.name === service.name && + if (infraService.metaTargetServiceType.name === service.name && infraService.infraHostPort.port === service.port.portNumber && 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 idx = this.findServiceIndex(targetHostNode.children, infraService.metaTargetServiceType.name); - targetHostNode.children.push({ + const idx = this.findServiceIndex(targetHostNode.children, service.name); + targetHostNode.children.splice(idx, 0, { type: 'SERVICE', label: service.name + ' (' + service.port.portNumber + ')', data: { @@ -297,6 +285,7 @@ export class DiscoveryInfraTreeComponent implements OnChanges { portNumber: service.port.portNumber, object: service, InfraID: null, + name: service.name }, }); @@ -314,12 +303,9 @@ export class DiscoveryInfraTreeComponent implements OnChanges { return index; } - findServiceIndex(serviceNodes: TreeNode[], serviceName: string) { + findServiceIndex(serviceNodes: TreeNode[], serviceName: string): number { let index = 0; serviceNodes.forEach(node => { - // if (node.data.portNumber < service.port.portNumber) { - // index++; - // } if (node.data.name.toUpperCase().localeCompare(serviceName.toUpperCase()) === -1) { index++; } @@ -327,7 +313,7 @@ export class DiscoveryInfraTreeComponent implements OnChanges { return index; } - findHostNodeByService(serviceAddress: string) { + findHostNodeByService(serviceAddress: string): TreeNode { let targetHost = null; this.hostNode.forEach((value, i) => { if (value.data.ip === this.convertIPtoNumber(serviceAddress)) { @@ -338,7 +324,7 @@ export class DiscoveryInfraTreeComponent implements OnChanges { return targetHost; } - convertIPtoNumber(ip: string) { + convertIPtoNumber(ip: string): number { return ip.split('.').map((octet, index, array) => { return parseInt(octet) * Math.pow(256, (array.length - index - 1)); }).reduce((prev, curr) => { @@ -369,52 +355,52 @@ export class DiscoveryInfraTreeComponent implements OnChanges { saveTargets() { const targets: Target[] = []; this.selectedItems.forEach(node => { - const infraID = node.data.infraID; - if (null === infraID) { // 새로 발견된 Host / Service - + let infraID = node.data.infraID; + 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 = { infra: { id: infraID }, - name: '', + name: node.label, sensorCount: 0, }; targets.push(target); }); - console.log(targets); - - // 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(); + 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(); } } diff --git a/@overflow/infra/service/infra.service.ts b/@overflow/infra/service/infra.service.ts index 91d1955..b974ab0 100644 --- a/@overflow/infra/service/infra.service.ts +++ b/@overflow/infra/service/infra.service.ts @@ -2,7 +2,6 @@ import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; import { RPCService } from '@loafer/ng-rpc'; 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 { gzip } from 'pako'; @@ -37,12 +36,12 @@ export class InfraService { return this.rpcService.call('InfraService.read', id); } - public readAllByProbeID(probeID: number, pageParams: PageParams): Observable> { - return this.rpcService.call>('InfraService.readAllByProbeID', probeID, pageParams); + public readAllByProbeID(probeID: number): Observable { + return this.rpcService.call('InfraService.readAllByProbeID', probeID); } - public readAllByDomainID(domainID: number, pageParams: PageParams): Observable> { - return this.rpcService.call>('InfraService.readAllByDomainID', domainID, pageParams); + public readAllByDomainID(domainID: number): Observable { + return this.rpcService.call('InfraService.readAllByDomainID', domainID); } public readAllInfraZoneByProbeDomainID(probeDomainID: number): Observable {