Merge "Add AC and ANR services"
[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 and Nokia
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 { DashboardSuccessTransport } from '../../interfaces/dashboard.types';
25 import { ANRNeighborCellRelation, ANRNeighborCellRelationMod } from '../../interfaces/anr-xapp.types';
26
27 @Injectable({
28   providedIn: 'root'
29 })
30 export class AnrXappService {
31
32   private basePath = 'api/xapp/anr/';
33   private cellPath = 'cell/cellIdentifier/';
34
35   constructor(private httpClient: HttpClient) {
36     // injects to variable httpClient
37   }
38
39   /**
40    * Gets ANR xApp client version details
41    * @returns Observable that should yield a DashboardSuccessTransport
42    */
43   getVersion(): Observable<DashboardSuccessTransport> {
44     return this.httpClient.get<DashboardSuccessTransport>(this.basePath + 'version');
45   }
46
47   /**
48    * Performs a liveness probe
49    * @returns Observable that should yield a response code (no data)
50    */
51   getHealthAlive(): Observable<any> {
52     return this.httpClient.get(this.basePath + 'health/alive');
53   }
54
55   /**
56    * Performs a readiness probe
57    * @returns Observable that should yield a response code (no data)
58    */
59   getHealthReady(): Observable<any> {
60     return this.httpClient.get(this.basePath + 'health/ready');
61   }
62
63   /**
64    * Query NCRT of all cells, all or one gNB(s)
65    * @param ggnbId Optional parameter for the gNB ID
66    * @param startIndex Optional parameter for the start index
67    * @param limit Optional parameter for the limit (page size)
68    * @returns Observable of ANRNeighborCellRelation
69    */
70   getNcrtInfo(ggnbId?: string, startIndex?: string, limit?: number): Observable<ANRNeighborCellRelation[]> {
71     const queryParams = new HttpParams();
72     if (ggnbId) {
73       queryParams.set('ggnbid', ggnbId);
74     }
75     if (startIndex) {
76       queryParams.set('startIndex', startIndex);
77     }
78     if (limit) {
79       queryParams.set('limit', limit.toString());
80     }
81     return this.httpClient.get<ANRNeighborCellRelation[]>(this.basePath + 'cell', { params: queryParams } );
82   }
83
84   /**
85    * Query NCRT of a single serving cell, all or one gNB(s)
86    * @param cellId cell ID
87    * @param ggnbid Optional parameter for the gNB ID
88    * @param startIndex Optional parameter for the start index
89    * @param limit Optional parameter for the limit (page size)
90    * @returns Observable of ANRNeighborCellRelation
91    */
92   getCellNcrtInfo(cellId: string, ggnbId?: string, startIndex?: string, limit?: number): Observable<ANRNeighborCellRelation[]> {
93     const queryParams = new HttpParams();
94     if (ggnbId) {
95       queryParams.set('ggnbid', ggnbId);
96     }
97     if (startIndex) {
98       queryParams.set('startIndex', startIndex);
99     }
100     if (limit) {
101       queryParams.set('limit', limit.toString());
102     }
103     return this.httpClient.get<ANRNeighborCellRelation[]>(this.basePath + this.cellPath + cellId, { params: queryParams } );
104   }
105
106   /**
107    * Modify neighbor cell relations based on Source Cell NR CGI and Target Cell NR PCI / NR CGI
108    * @param cellId cell ID
109    * @param table Array of ANRNeighborCellRelationMod
110    * @returns Observable that should yield a response code (no data)
111    */
112   modifyNcrt(cellId: string, table: ANRNeighborCellRelationMod []): Observable<any> {
113     return this.httpClient.put(this.basePath + this.cellPath + cellId, table);
114   }
115
116   /** TODO: deleteNcrt */
117
118 }