2018-04-06 20:02:18 +09:00
|
|
|
import { Injectable } from '@angular/core';
|
2018-06-04 17:25:29 +09:00
|
|
|
import { Observable } from 'rxjs';
|
2018-05-24 15:44:13 +09:00
|
|
|
import { RPCService } from '@loafer/ng-rpc';
|
2018-05-02 17:09:39 +09:00
|
|
|
import { Infra } from '@overflow/commons-typescript/model/infra';
|
2018-06-12 22:21:53 +09:00
|
|
|
import { Host, Service } from '@overflow/commons-typescript';
|
2018-06-21 18:24:37 +09:00
|
|
|
import { gzip } from 'pako';
|
2018-06-21 18:05:07 +09:00
|
|
|
|
|
|
|
|
2018-04-06 20:02:18 +09:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class InfraService {
|
|
|
|
|
|
|
|
public constructor(
|
|
|
|
private rpcService: RPCService,
|
|
|
|
) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-06-12 22:21:53 +09:00
|
|
|
public regist(infra: Infra): Observable<Infra> {
|
|
|
|
return this.rpcService.call<Infra>('InfraService.regist', infra);
|
|
|
|
}
|
|
|
|
|
|
|
|
public registDiscoverd(probeID: number, hosts: Host[], services: Service[]): Observable<Infra[]> {
|
2018-06-21 18:05:07 +09:00
|
|
|
const discoverd = {
|
|
|
|
hosts: hosts,
|
|
|
|
services: services,
|
|
|
|
};
|
|
|
|
|
|
|
|
const json = JSON.stringify(discoverd);
|
2018-06-21 18:24:37 +09:00
|
|
|
const compressed = gzip(json, { to: 'string' });
|
2018-06-21 18:05:07 +09:00
|
|
|
const base64 = btoa(compressed);
|
|
|
|
return this.rpcService.call<Infra[]>('InfraService.registDiscoverd', probeID, base64);
|
2018-06-12 22:21:53 +09:00
|
|
|
}
|
2018-04-06 20:02:18 +09:00
|
|
|
|
2018-06-14 13:38:51 +09:00
|
|
|
public read(id: string): Observable<Infra> {
|
|
|
|
return this.rpcService.call<Infra>('InfraService.read', id);
|
|
|
|
}
|
|
|
|
|
2018-06-21 20:11:32 +09:00
|
|
|
public readAllByProbeID(probeID: number): Observable<Infra[]> {
|
|
|
|
return this.rpcService.call<Infra[]>('InfraService.readAllByProbeID', probeID);
|
2018-06-07 15:07:45 +09:00
|
|
|
}
|
2018-04-19 19:26:39 +09:00
|
|
|
|
2018-06-21 20:11:32 +09:00
|
|
|
public readAllByDomainID(domainID: number): Observable<Infra[]> {
|
|
|
|
return this.rpcService.call<Infra[]>('InfraService.readAllByDomainID', domainID);
|
2018-04-19 19:26:39 +09:00
|
|
|
}
|
2018-06-12 14:45:21 +09:00
|
|
|
|
2018-06-12 22:21:53 +09:00
|
|
|
public readAllInfraZoneByProbeDomainID(probeDomainID: number): Observable<Infra[]> {
|
|
|
|
return this.rpcService.call<Infra[]>('InfraService.readAllInfraZoneByProbeDomainID', probeDomainID);
|
2018-06-12 14:45:21 +09:00
|
|
|
}
|
2018-06-21 18:35:24 +09:00
|
|
|
|
|
|
|
public readAllByMetaInfraTypeKeyAndProbeID(metaInfraTypeKey: string, probeID: number): Observable<Infra[]> {
|
|
|
|
return this.rpcService.call<Infra[]>('InfraService.readAllByMetaInfraTypeKeyAndProbeID', metaInfraTypeKey, probeID);
|
|
|
|
}
|
|
|
|
|
2018-04-06 20:02:18 +09:00
|
|
|
}
|