2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 AT&T Intellectual Property
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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===================================
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';
30 * Services for calling the Dashboard's A1 endpoints to get/put AC policies.
35 export class ACXappService {
37 private component = 'a1-p';
38 private policyTypePath = 'poltype';
39 private policyInstPath = 'polinst';
40 private acPolicyType = '21000';
41 private acPolicyInst = 'admission_control_policy';
44 private dashboardSvc: DashboardService,
45 private httpClient: HttpClient) {
49 * Gets AC client version details
50 * @returns Observable that yields a String
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'])
61 * Gets admission control policy.
62 * @returns Observable that yields an ACAdmissionIntervalControl
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);
71 * Puts admission control policy.
72 * @param policy an instance of ACAdmissionIntervalControl
73 * @returns Observable that yields a response code, no data
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' });