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