2018-05-31 11:53:11 +00:00
|
|
|
import {
|
|
|
|
Component, Input, Output, EventEmitter,
|
|
|
|
} from '@angular/core';
|
|
|
|
import { Probe, ProbeHost } from '@overflow/commons-typescript/model/probe';
|
|
|
|
import { Anim } from './animation';
|
|
|
|
import { Store, select } from '@ngrx/store';
|
|
|
|
import { Observable, of, Subscription } from 'rxjs';
|
|
|
|
import { DiscoveryService } from '../service/discovery.service';
|
|
|
|
import { catchError, exhaustMap, map, tap } from 'rxjs/operators';
|
|
|
|
import { DiscoverZone, Zone, Host, Port, Service } from '@overflow/commons-typescript/model/discovery';
|
2018-05-31 13:11:23 +00:00
|
|
|
import { DiscoverySubscriber, DiscoveryNotify } from '../subscriber/discovery.subscriber';
|
2018-05-31 11:53:11 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'of-discovery',
|
|
|
|
templateUrl: './discovery.component.html',
|
|
|
|
animations: Anim
|
|
|
|
})
|
|
|
|
export class DiscoveryComponent {
|
|
|
|
|
|
|
|
@Input() probeHostID;
|
|
|
|
pending$: Observable<boolean>;
|
|
|
|
error$: Observable<any>;
|
|
|
|
discoverySubscription: Subscription;
|
|
|
|
|
|
|
|
selectedProbe: ProbeHost;
|
|
|
|
requested: boolean;
|
|
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private discoveryService: DiscoveryService,
|
2018-05-31 12:44:11 +00:00
|
|
|
private discoverySubscriber: DiscoverySubscriber,
|
2018-05-31 11:53:11 +00:00
|
|
|
private store: Store<any>
|
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
|
|
|
onRequestDiscovery(dz: DiscoverZone) {
|
|
|
|
this.requested = true;
|
|
|
|
|
|
|
|
this.requested = true;
|
|
|
|
|
2018-05-31 13:11:23 +00:00
|
|
|
this.discoverySubscriber.observable().pipe(
|
2018-05-31 12:44:11 +00:00
|
|
|
tap(() => {
|
|
|
|
this.discoveryService.discoverZone(this.selectedProbe.probe.probeKey, dz);
|
|
|
|
}),
|
2018-05-31 11:53:11 +00:00
|
|
|
map((discoveryNotify: DiscoveryNotify) => {
|
|
|
|
switch (discoveryNotify.method) {
|
|
|
|
case 'DiscoveryService.discoveryStart': {
|
|
|
|
const startDate = discoveryNotify.params as Date;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'DiscoveryService.discoveryStop': {
|
|
|
|
const stopDate = discoveryNotify.params as Date;
|
|
|
|
|
|
|
|
this.discoverySubscription.unsubscribe();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'DiscoveryService.discoveredZone': {
|
|
|
|
const zone = discoveryNotify.params as Zone;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'DiscoveryService.discoveredHost': {
|
|
|
|
const host = discoveryNotify.params as Host;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'DiscoveryService.discoveredPort': {
|
|
|
|
const port = discoveryNotify.params as Port;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'DiscoveryService.discoveredService': {
|
|
|
|
const service = discoveryNotify.params as Service;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
catchError(error => {
|
|
|
|
|
|
|
|
return of();
|
|
|
|
}),
|
|
|
|
).subscribe();
|
|
|
|
}
|
|
|
|
|
|
|
|
onRequestDiscoveryStop() {
|
|
|
|
this.requested = false;
|
|
|
|
}
|
|
|
|
}
|