2018-06-07 06:07:45 +00:00
|
|
|
import {
|
2018-06-08 11:37:13 +00:00
|
|
|
Component, Input, OnChanges, SimpleChanges, OnInit
|
2018-06-07 06:07:45 +00:00
|
|
|
} from '@angular/core';
|
2018-06-08 11:37:13 +00:00
|
|
|
import { Infra } from '@overflow/commons-typescript/model/infra';
|
|
|
|
import { InfraHost as InfraTypeHost } from '@overflow/commons-typescript/model/infra';
|
|
|
|
import { InfraService as InfraTypeService } from '@overflow/commons-typescript/model/infra';
|
|
|
|
import { Observable, of } from 'rxjs';
|
|
|
|
import { catchError, exhaustMap, map, tap, take } from 'rxjs/operators';
|
|
|
|
import { TreeNode } from 'primeng/primeng';
|
|
|
|
import { PageParams, Page } from '@overflow/commons-typescript/core/model';
|
|
|
|
import { ProbeHost } from '@overflow/commons-typescript';
|
|
|
|
import { InfraService } from '../service/infra.service';
|
2018-06-07 06:07:45 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'of-infra-tree',
|
|
|
|
templateUrl: './infra-tree.component.html',
|
|
|
|
})
|
2018-06-08 11:37:13 +00:00
|
|
|
export class InfraTreeComponent implements OnInit, OnChanges {
|
|
|
|
|
|
|
|
@Input() probeHost: ProbeHost;
|
|
|
|
|
|
|
|
infras: Infra[];
|
|
|
|
pending$: Observable<boolean>;
|
|
|
|
error$: Observable<any>;
|
|
|
|
|
|
|
|
zoneNode: TreeNode[] = [];
|
|
|
|
hostNode: TreeNode[] = [];
|
2018-06-07 06:07:45 +00:00
|
|
|
|
|
|
|
constructor(
|
2018-06-08 11:37:13 +00:00
|
|
|
private infraService: InfraService,
|
2018-06-07 06:07:45 +00:00
|
|
|
) {
|
|
|
|
}
|
2018-06-08 11:37:13 +00:00
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
this.zoneNode.push({
|
|
|
|
label: this.probeHost.probe.cidr,
|
|
|
|
type: 'ZONE',
|
|
|
|
data: {
|
|
|
|
},
|
|
|
|
children: this.hostNode,
|
|
|
|
expanded: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnChanges(changes: SimpleChanges): void {
|
|
|
|
this.getInfras();
|
|
|
|
}
|
|
|
|
|
|
|
|
getInfras() {
|
|
|
|
const pageParams: PageParams = {
|
|
|
|
pageNo: 0,
|
|
|
|
countPerPage: 99999,
|
|
|
|
sortCol: 'id',
|
|
|
|
sortDirection: 'descending'
|
|
|
|
};
|
|
|
|
this.infraService.readAllByProbeID(this.probeHost.probe.id, pageParams)
|
|
|
|
.pipe(
|
|
|
|
tap(() => {
|
|
|
|
this.pending$ = of(true);
|
|
|
|
}),
|
|
|
|
map((infraPage: Page<Infra>) => {
|
|
|
|
this.infras = infraPage.content;
|
|
|
|
this.generateTreeData(this.infras);
|
|
|
|
}),
|
|
|
|
catchError(error => {
|
|
|
|
this.error$ = of(error);
|
|
|
|
return of();
|
|
|
|
}),
|
|
|
|
tap(() => {
|
|
|
|
this.pending$ = of(false);
|
|
|
|
}),
|
|
|
|
take(1),
|
|
|
|
).subscribe();
|
|
|
|
}
|
|
|
|
|
|
|
|
generateTreeData(infras: Infra[]) {
|
|
|
|
infras.forEach(infra => {
|
|
|
|
switch (infra.metaInfraType.id) { // TODO: fix to enum
|
|
|
|
case 2: // InfraHost
|
|
|
|
this.addHost(infra);
|
|
|
|
break;
|
|
|
|
case 7: // InfraService
|
|
|
|
// this.addService(infra);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
addHost(infraHost: InfraTypeHost) {
|
|
|
|
this.hostNode.push({
|
|
|
|
type: 'HOST',
|
|
|
|
label: infraHost.ipv4,
|
|
|
|
data: {
|
|
|
|
target: infraHost
|
|
|
|
},
|
|
|
|
expanded: true,
|
|
|
|
children: []
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
addService(infraService: InfraTypeService) {
|
|
|
|
this.hostNode[0].children.push({
|
|
|
|
type: 'SERVICE',
|
|
|
|
label: 'TODO',
|
|
|
|
data: {
|
|
|
|
target: infraService
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2018-06-07 06:07:45 +00:00
|
|
|
}
|