member_webapp/@overflow/discovery/component/discovery.component.ts

122 lines
3.8 KiB
TypeScript
Raw Normal View History

2018-05-31 20:53:11 +09:00
import {
2018-06-21 18:35:24 +09:00
Component, Input, OnDestroy, OnInit, ViewChild,
2018-05-31 20:53:11 +09:00
} from '@angular/core';
2018-06-04 17:55:47 +09:00
2018-05-31 20:53:11 +09:00
import { Observable, of, Subscription } from 'rxjs';
2018-06-21 18:35:24 +09:00
import { catchError, map, tap, take } from 'rxjs/operators';
2018-06-04 17:55:47 +09:00
2018-06-12 22:21:53 +09:00
import { ProbeHost } from '@overflow/commons-typescript/model/probe';
2018-05-31 20:53:11 +09:00
import { DiscoverZone, Zone, Host, Port, Service } from '@overflow/commons-typescript/model/discovery';
2018-06-04 17:55:47 +09:00
import { Anim } from './animation';
import { DiscoveryService } from '../service/discovery.service';
2018-05-31 22:11:23 +09:00
import { DiscoverySubscriber, DiscoveryNotify } from '../subscriber/discovery.subscriber';
2018-06-04 13:13:06 +09:00
import { SearchFilterComponent } from './search-filter.component';
2018-06-21 18:35:24 +09:00
import { DiscoveryInfraTreeComponent } from './discovery-infra-tree.component';
2018-05-31 20:53:11 +09:00
@Component({
selector: 'of-discovery',
templateUrl: './discovery.component.html',
2018-06-01 16:32:16 +09:00
animations: Anim,
2018-05-31 20:53:11 +09:00
})
2018-06-21 18:35:24 +09:00
export class DiscoveryComponent implements OnInit, OnDestroy {
2018-05-31 20:53:11 +09:00
@Input() probeHostID;
pending$: Observable<boolean>;
error$: Observable<any>;
discoverySubscription: Subscription;
selectedProbe: ProbeHost;
2018-06-01 11:47:37 +09:00
discoverZone: DiscoverZone;
2018-06-21 18:35:24 +09:00
startDate: Date;
stopDate: Date;
2018-05-31 20:53:11 +09:00
2018-06-04 17:31:00 +09:00
filterWord: string;
filterServices: Service[];
2018-06-21 18:35:24 +09:00
@ViewChild('infraTree') infraTree: DiscoveryInfraTreeComponent;
@ViewChild('filter') filter: SearchFilterComponent;
2018-06-01 20:25:51 +09:00
2018-05-31 20:53:11 +09:00
constructor(
private discoveryService: DiscoveryService,
2018-05-31 21:44:11 +09:00
private discoverySubscriber: DiscoverySubscriber,
2018-05-31 20:53:11 +09:00
) {
2018-06-04 12:42:30 +09:00
this.discoverySubscription = null;
2018-06-21 18:35:24 +09:00
this.startDate = null;
this.stopDate = null;
2018-05-31 20:53:11 +09:00
}
2018-06-21 18:35:24 +09:00
ngOnInit(): void {
}
2018-06-01 18:56:00 +09:00
ngOnDestroy(): void {
if (null !== this.discoverySubscription) {
this.discoverySubscription.unsubscribe();
}
}
2018-05-31 20:53:11 +09:00
onRequestDiscovery(dz: DiscoverZone) {
2018-06-01 11:47:37 +09:00
this.discoverZone = dz;
2018-06-04 21:50:46 +09:00
const zone: Zone = {
2018-06-15 20:03:25 +09:00
network: this.selectedProbe.infraHost.infraZone.network, // this.selectedProbe.probe.cidr
address: this.selectedProbe.infraHost.infraZone.address.split('/')[0],
iface: this.selectedProbe.infraHost.infraZone.iface,
mac: this.selectedProbe.infraHost.infraZone.mac,
2018-06-20 20:44:59 +09:00
metaIPType: this.selectedProbe.infraHost.infraZone.metaIPType,
2018-06-04 21:50:46 +09:00
};
2018-06-15 20:03:25 +09:00
2018-06-04 21:50:46 +09:00
this.discoveryService.discoverHost(this.selectedProbe.probe.probeKey, zone, dz.discoverHost);
2018-06-04 18:25:48 +09:00
2018-06-01 18:56:00 +09:00
this.discoverySubscription = this.discoverySubscriber.observable().pipe(
2018-05-31 20:53:11 +09:00
map((discoveryNotify: DiscoveryNotify) => {
switch (discoveryNotify.method) {
case 'DiscoveryService.discoveryStart': {
const startDate = discoveryNotify.params as Date;
2018-06-21 18:35:24 +09:00
this.startDate = startDate;
this.infraTree.discoveryStarted(startDate);
2018-05-31 20:53:11 +09:00
break;
}
case 'DiscoveryService.discoveryStop': {
const stopDate = discoveryNotify.params as Date;
2018-06-21 18:35:24 +09:00
this.stopDate = stopDate;
2018-05-31 20:53:11 +09:00
this.discoverySubscription.unsubscribe();
2018-06-01 18:56:00 +09:00
this.discoverySubscription = null;
2018-06-21 18:35:24 +09:00
this.infraTree.discoveryStopped(stopDate);
2018-05-31 20:53:11 +09:00
break;
}
case 'DiscoveryService.discoveredZone': {
2018-06-04 21:50:46 +09:00
const _zone = discoveryNotify.params as Zone;
2018-05-31 20:53:11 +09:00
break;
}
case 'DiscoveryService.discoveredHost': {
const host = discoveryNotify.params as Host;
2018-06-21 18:35:24 +09:00
this.infraTree.addHost(host);
2018-05-31 20:53:11 +09:00
break;
}
case 'DiscoveryService.discoveredPort': {
const port = discoveryNotify.params as Port;
2018-06-20 19:17:38 +09:00
// this.discoveryResult.addPort(port);
2018-05-31 20:53:11 +09:00
break;
}
case 'DiscoveryService.discoveredService': {
const service = discoveryNotify.params as Service;
2018-06-21 18:35:24 +09:00
this.infraTree.addService(service);
this.filter.addService(service);
2018-05-31 20:53:11 +09:00
break;
}
default: {
break;
}
}
}),
catchError(error => {
return of();
}),
).subscribe();
}
}