Add multi-layer RIC instance selector
[portal/ric-dashboard.git] / dashboard / webapp-frontend / src / app / services / e2-mgr / e2-mgr.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 import { HttpClient, HttpResponse } from '@angular/common/http';
21 import { Injectable } from '@angular/core';
22 import { Observable } from 'rxjs';
23 import { map } from 'rxjs/operators';
24 import { DashboardSuccessTransport } from '../../interfaces/dashboard.types';
25 import { E2RanDetails, E2SetupRequest } from '../../interfaces/e2-mgr.types';
26 import { DashboardService } from '../dashboard/dashboard.service';
27
28 @Injectable({
29   providedIn: 'root'
30 })
31
32 export class E2ManagerService {
33
34   private component = 'e2mgr';
35   private nodebPath = 'nodeb';
36
37   constructor(
38     private dashboardSvc: DashboardService,
39     private httpClient: HttpClient) {
40   }
41
42   /**
43    * Gets E2 client version details
44    * @returns Observable that yields a String
45    */
46   getVersion(instanceKey: string): Observable<string> {
47     const path = this.dashboardSvc.buildPath(this.component, null, 'version');
48     return this.httpClient.get<DashboardSuccessTransport>(path).pipe(
49       // Extract the string here
50       map(res => res['data'])
51     );
52   }
53
54   /**
55    * Gets RAN details
56    * @returns Observable that yields an array of E2RanDetails objects
57    */
58   getRan(instanceKey: string): Observable<Array<E2RanDetails>> {
59     const path = this.dashboardSvc.buildPath(this.component, instanceKey, this.nodebPath, 'ran');
60     return this.httpClient.get<Array<E2RanDetails>>(path);
61   }
62
63   /**
64    * Sends a request to setup an ENDC/gNodeB connection
65    * @returns Observable. On success there is no data, only a code.
66    */
67   endcSetup(instanceKey: string, req: E2SetupRequest): Observable<HttpResponse<Object>> {
68     const path = this.dashboardSvc.buildPath(this.component, instanceKey,  this.nodebPath, 'endc-setup');
69     return this.httpClient.post(path, req, { observe: 'response' });
70   }
71
72   /**
73    * Sends a request to setup an X2/eNodeB connection
74    * @returns Observable. On success there is no data, only a code.
75    */
76   x2Setup(instanceKey: string, req: E2SetupRequest): Observable<HttpResponse<Object>> {
77     const path = this.dashboardSvc.buildPath(this.component, instanceKey,  this.nodebPath, 'x2-setup');
78     return this.httpClient.post(path, req, { observe: 'response' });
79   }
80
81   /**
82    * Sends a request to drop all RAN connections
83    * @returns Observable with body.
84    */
85   nodebPut(instanceKey: string): Observable<any> {
86     const path = this.dashboardSvc.buildPath(this.component, instanceKey,  this.nodebPath, 'shutdown');
87     return this.httpClient.put(path, { observe: 'body' });
88   }
89
90 }