Upgrade component API versions to Amber
[portal/ric-dashboard.git] / webapp-frontend / src / app / services / ac-xapp / ac-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 { HttpClient } from '@angular/common/http';
22 import { Injectable } from '@angular/core';
23 import { Observable } from 'rxjs';
24 import { map } from 'rxjs/operators';
25 import { ACAdmissionIntervalControl, ACAdmissionIntervalControlAck } from '../../interfaces/ac-xapp.types';
26 import { DashboardSuccessTransport } from '../../interfaces/dashboard.types';
27 import { DashboardService } from '../dashboard/dashboard.service';
28
29 /**
30  * Services for calling the Dashboard's A1 endpoints to get/put AC policies.
31  */
32 @Injectable({
33   providedIn: 'root'
34 })
35 export class ACXappService {
36
37   private component = 'a1-p';
38   private policyTypePath = 'poltype';
39   private policyInstPath = 'polinst';
40   private acPolicyType = '21000';
41   private acPolicyInst = 'admission_control_policy';
42
43   constructor(
44     private dashboardSvc: DashboardService,
45     private httpClient: HttpClient) {
46   }
47
48   /**
49    * Gets AC client version details
50    * @returns Observable that yields a String
51    */
52   getVersion(instanceKey: string): Observable<string> {
53     const path = this.dashboardSvc.buildPath(this.component, null, 'version');
54     return this.httpClient.get<DashboardSuccessTransport>(path).pipe(
55       // Extract the string here
56       map(res => res['data'])
57     );
58   }
59
60   /**
61    * Gets admission control policy.
62    * @returns Observable that yields an ACAdmissionIntervalControl
63    */
64   getPolicy(instanceKey: string): Observable<ACAdmissionIntervalControl> {
65     const path = this.dashboardSvc.buildPath(this.component, instanceKey, this.policyTypePath, this.acPolicyType,
66       this.policyInstPath, this.acPolicyInst);
67     return this.httpClient.get<ACAdmissionIntervalControl>(path);
68   }
69
70   /**
71    * Puts admission control policy.
72    * @param policy an instance of ACAdmissionIntervalControl
73    * @returns Observable that yields a response code, no data
74    */
75   putPolicy(instanceKey: string, policy: ACAdmissionIntervalControl): Observable<any> {
76     const path = this.dashboardSvc.buildPath(this.component, instanceKey, this.policyTypePath, this.acPolicyType,
77       this.policyInstPath, this.acPolicyInst);
78     return this.httpClient.put<ACAdmissionIntervalControlAck>(path, policy, { observe: 'response' });
79   }
80
81 }