Drop Nokia from file header copyright line
[portal/ric-dashboard.git] / webapp-frontend / src / app / services / anr-xapp / anr-xapp.service.ts
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2019 AT&T Intellectual Property
6  * %%
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ========================LICENSE_END===================================
19  */
20
21 import { Injectable } from '@angular/core';
22 import { HttpClient, HttpParams } from '@angular/common/http';
23 import { Observable } from 'rxjs';
24 import { map } from 'rxjs/operators';
25 import { DashboardSuccessTransport } from '../../interfaces/dashboard.types';
26 import { ANRNeighborCellRelation, ANRNeighborCellRelationMod } from '../../interfaces/anr-xapp.types';
27
28 @Injectable({
29   providedIn: 'root'
30 })
31 export class ANRXappService {
32
33   // Trailing slashes are confusing so omit them here
34   private basePath = 'api/xapp/anr';
35   private ncrtPath = 'ncrt';
36   private servingPath = 'servingcells';
37   private neighborPath = 'neighborcells';
38
39   constructor(private httpClient: HttpClient) {
40     // injects to variable httpClient
41   }
42
43   private buildPath(...args: any[]) {
44     let result = this.basePath;
45     args.forEach(part => {
46       result = result + '/' + part;
47     });
48     return result;
49   }
50
51   /**
52    * Gets ANR xApp client version details
53    * @returns Observable that should yield a String
54    */
55   getVersion(): Observable<string> {
56     const url = this.buildPath('version');
57     return this.httpClient.get<DashboardSuccessTransport>(url).pipe(
58       // Extract the string here
59       map(res => res['data'])
60     );
61   }
62
63   /**
64    * Performs a liveness probe
65    * @returns Observable that should yield a response code (no data)
66    */
67   getHealthAlive(): Observable<any> {
68     const url = this.buildPath('health/alive');
69     return this.httpClient.get(url, { observe: 'response' });
70   }
71
72   /**
73    * Performs a readiness probe
74    * @returns Observable that should yield a response code (no data)
75    */
76   getHealthReady(): Observable<any> {
77     const url = this.buildPath('health/ready');
78     return this.httpClient.get(url, { observe: 'response' });
79   }
80
81 /**
82  * Gets array of gNodeB IDs
83  * @returns Observable that should yield a string array
84  */
85   getgNodeBs(): Observable<string[]> {
86     const url = this.buildPath('gnodebs');
87     return this.httpClient.get<string[]>(url).pipe(
88       // Extract the array of IDs here
89       map(res => res['gNodeBIds'])
90     );
91   }
92
93   /**
94    * Gets the neighbor cell relation table for all gNodeBs or based on query parameters
95    * @param ggnbId Optional parameter for the gNB ID
96    * @param servingCellNrcgi Serving cell NRCGI
97    * @param neighborCellNrpci Neighbor cell NRPCI
98    * @returns Observable of ANR neighbor cell relation array
99    */
100   getNcrtInfo(ggnodeb: string = '', servingCellNrcgi: string = '', neighborCellNrpci: string = ''): Observable<ANRNeighborCellRelation[]> {
101     const url = this.buildPath(this.ncrtPath);
102     return this.httpClient.get<ANRNeighborCellRelation[]>(url, {
103       params: new HttpParams()
104         .set('ggnodeb', ggnodeb)
105         .set('servingCellNrcgi', servingCellNrcgi)
106         .set('neighborCellNrpci', neighborCellNrpci)
107     }).pipe(
108       // Extract the array of relations here
109       map(res => res['ncrtRelations'])
110     );
111   }
112
113   /**
114    * Modify neighbor cell relation based on Serving Cell NRCGI and Neighbor Cell NRPCI
115    * @param servingCellNrcgi Serving cell NRCGI
116    * @param neighborCellNrpci Neighbor cell NRPCI
117    * @param mod Values to store in the specified relation
118    * @returns Observable that yields a response code only, no data
119    */
120   modifyNcr(servingCellNrcgi: string, neighborCellNrpci: string, mod: ANRNeighborCellRelationMod): Observable<Object> {
121     const url = this.buildPath(this.ncrtPath, this.servingPath, servingCellNrcgi, this.neighborPath, neighborCellNrpci);
122     return this.httpClient.put(url, mod, { observe: 'response' });
123   }
124
125   /**
126    * Deletes neighbor cell relation based on Serving Cell NRCGI and Neighbor Cell NRPCI
127    * @param servingCellNrcgi Serving cell NRCGI
128    * @param neighborCellNrpci Neighbor cell NRPCI
129    * @returns Observable that yields a response code only, no data
130    */
131   deleteNcr(servingCellNrcgi: string, neighborCellNrpci: string): Observable<Object> {
132     const url = this.buildPath(this.ncrtPath, this.servingPath, servingCellNrcgi, this.neighborPath, neighborCellNrpci);
133     return this.httpClient.delete(url, { observe: 'response' });
134   }
135
136 }