X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=webapp-frontend%2Fsrc%2Fapp%2Fservices%2Fstats%2Fstats.service.ts;h=086214234d655021630357ad0e1c280d2f6ff00f;hb=a0180adc6a1e1ec09472549596428b70d48db3fc;hp=d0bdc4c174122493a8f1f0b903acf687b79c84e0;hpb=e2cbc4d0304646febf7e2cbe0dccdf9840189222;p=portal%2Fric-dashboard.git diff --git a/webapp-frontend/src/app/services/stats/stats.service.ts b/webapp-frontend/src/app/services/stats/stats.service.ts index d0bdc4c1..08621423 100644 --- a/webapp-frontend/src/app/services/stats/stats.service.ts +++ b/webapp-frontend/src/app/services/stats/stats.service.ts @@ -1,8 +1,8 @@ /*- * ========================LICENSE_START================================= - * ORAN-OSC + * O-RAN-SC * %% - * Copyright (C) 2019 AT&T Intellectual Property and Nokia + * Copyright (C) 2019 AT&T Intellectual Property * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,17 +17,19 @@ * limitations under the License. * ========================LICENSE_END=================================== */ +import { HttpClient, HttpErrorResponse, HttpHeaders, HttpParams } from '@angular/common/http'; import { Injectable } from '@angular/core'; -import { HttpClient } from '@angular/common/http'; -import { HttpHeaders } from "@angular/common/http"; -import { Observable } from "rxjs"; -import { HttpErrorResponse } from "@angular/common/http"; +import { Observable } from 'rxjs'; +import { DashboardService } from '../dashboard/dashboard.service'; @Injectable({ providedIn: 'root' }) export class StatsService { + + private component = 'admin'; + baseJSONServerUrl = 'http://localhost:3000'; dataMetrics = [{}]; latencyMetrics; @@ -49,15 +51,15 @@ export class StatsService { 'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept, Authorization' }) }; - - constructor(private httpClient: HttpClient) { - //this.loadConfig(); - //this.getLoad(); - + + constructor( + private dashboardSvc: DashboardService, + private httpClient: HttpClient) { + // this.loadConfig(); + // this.getLoad(); } getMetrics() { - return this.dataMetrics; // @TODO implement the service to fetch the backend data } @@ -67,7 +69,7 @@ export class StatsService { } getLoad(): Observable { - //this.loadMetrics = this.getRandomValue(); + // this.loadMetrics = this.getRandomValue(); this.httpClient.get(this.hostURL + this.loadPath).subscribe((res) => { console.log(res); console.log('stats.service.getLoad(): ' + res['load']); @@ -76,50 +78,34 @@ export class StatsService { }); return this.load; } - - putLoad(value: number) { - //this.loadMetrics = this.getRandomValue(); - const jsonValue = '{ "load": ' + value + ' }'; - console.log(jsonValue); - this.httpClient.put(this.hostURL + this.loadPath, jsonValue , this.httpOptions).subscribe((res) => { - console.log(res); - }); + + getRandomValue() { + return Math.round((Math.random() * (20 - 0)) + 0); } - putDelay(value: number) { - //this.loadMetrics = this.getRandomValue(); - const jsonValue = '{ "delay": ' + value + ' }'; - console.log(jsonValue); - this.httpClient.put(this.hostURL + this.delayPath, jsonValue , this.httpOptions).subscribe((res) => { - console.log(res); + // Gets xApp metrics Kibana url for the named application + getAppMetricsUrl(appName: string) { + const path = this.dashboardSvc.buildPath(this.component, null, 'metrics'); + return this.httpClient.get(path, { + params: new HttpParams() + .set('app', appName) }); } - - getCpuMetrics() { - this.cpuMetrics = this.getRandomValue(); - return this.cpuMetrics; - } - getRandomValue() { - return Math.round((Math.random() * (20 - 0)) + 0); - } - saveConfig(key: string, value: string) { - if(key == 'jsonURL') + if (key === 'jsonURL') { this.baseJSONServerUrl = value; - - console.log('save this.baseJSONServerUrl '+this.baseJSONServerUrl); - const jsonValue = '{"id": "' + key + '", "value": "' + value + '"}'; - console.log(jsonValue); - this.httpClient.put(this.baseJSONServerUrl + '/config/' + key , jsonValue, this.httpOptions).subscribe((res) => { - console.log(res); - }); - - + } + console.log('save this.baseJSONServerUrl ' + this.baseJSONServerUrl); + const jsonValue = '{"id": "' + key + '", "value": "' + value + '"}'; + console.log(jsonValue); + this.httpClient.put(this.baseJSONServerUrl + '/config/' + key , jsonValue, this.httpOptions).subscribe((res) => { + console.log(res); + }); } - + loadConfig() { - console.log('load this.baseJSONServerUrl '+this.baseJSONServerUrl); + console.log('load this.baseJSONServerUrl ' + this.baseJSONServerUrl); const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' @@ -135,8 +121,8 @@ export class StatsService { this.delayMax = res[5].value; this.loadMax = res[6].value; }, - (err: HttpErrorResponse) => { - console.log (err.message); + (her: HttpErrorResponse) => { + console.log ('loadConfig failed: ' + her.message); }); } }