File

src/app/history/shared/history.service.ts

Extends

HelixService

Index

Methods

Methods

getControllerHistory
getControllerHistory(clusterName: string)
Parameters :
Name Type Optional
clusterName string No
Returns : any
getInstanceHistory
getInstanceHistory(clusterName: string, instanceName: string)
Parameters :
Name Type Optional
clusterName string No
instanceName string No
Returns : any
Protected parseHistory
parseHistory(data: any)
Parameters :
Name Type Optional
data any No
Returns : History[]
Public can
can()
Inherited from HelixService
Defined in HelixService:14
Returns : Observable<any>
Protected delete
delete(path: string)
Inherited from HelixService
Defined in HelixService:48
Parameters :
Name Type Optional
path string No
Returns : Observable<any>
Protected errorHandler
errorHandler(error: any)
Inherited from HelixService
Defined in HelixService:68
Parameters :
Name Type Optional
error any No
Returns : any
Protected getHeaders
getHeaders()
Inherited from HelixService
Defined in HelixService:61
Returns : any
Protected getHelixKey
getHelixKey()
Inherited from HelixService
Defined in HelixService:56
Returns : string
Protected post
post(path: string, data: any)
Inherited from HelixService
Defined in HelixService:32
Parameters :
Name Type Optional
path string No
data any No
Returns : Observable<any>
Protected put
put(path: string, data: string)
Inherited from HelixService
Defined in HelixService:40
Parameters :
Name Type Optional
path string No
data string No
Returns : Observable<any>
Protected request
request(path: string, helix?: string)
Inherited from HelixService
Defined in HelixService:20
Parameters :
Name Type Optional
path string No
helix string Yes
Returns : Observable<any>
import { Injectable } from '@angular/core';
import { map } from 'rxjs/operators';
import * as _ from 'lodash';

import { HelixService } from '../../core/helix.service';
import { History } from './history.model';

@Injectable()
export class HistoryService extends HelixService {
  getControllerHistory(clusterName: string) {
    return this.request(`/clusters/${clusterName}/controller/history`).pipe(
      map((data) => this.parseHistory(data.history))
    );
  }

  getInstanceHistory(clusterName: string, instanceName: string) {
    return this.request(
      `/clusters/${clusterName}/instances/${instanceName}/history`
    ).pipe(map((data) => this.parseHistory(data.listFields.HISTORY)));
    // TODO: implement data.simpleFields.LAST_OFFLINE_TIME
  }

  protected parseHistory(data: any): History[] {
    const histories: History[] = [];

    if (data) {
      for (const record of data) {
        // controller: {DATE=2017-04-13-22:33:55, CONTROLLER=ltx1-app1133.stg.linkedin.com_12923, TIME=1492122835198}
        // instance: {DATE=2017-05-01T08:21:42:114, SESSION=55a8e28052bcb56, TIME=1493626902114}
        const history = new History();

        for (const seg of _.words(record, /[^{}, ]+/g)) {
          const name = _.words(seg, /[^=]+/g)[0];
          const value = _.words(seg, /[^=]+/g)[1];
          if (name == 'DATE') {
            history.date = value;
          } else if (name == 'CONTROLLER') {
            history.controller = value;
          } else if (name == 'SESSION') {
            history.session = value;
          } else if (name == 'TIME') {
            history.time = +value;
          }
        }

        histories.push(history);
      }
    }

    return histories;
  }
}

results matching ""

    No results matching ""