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 policyPath = 'policies';
39 private acPolicyName = 'admission_control_policy';
42 private dashboardSvc: DashboardService,
43 private httpClient: HttpClient) {
47 * Gets AC client version details
48 * @returns Observable that yields a String
50 getVersion(instanceKey: string): Observable<string> {
51 const path = this.dashboardSvc.buildPath(this.component, null, 'version');
52 return this.httpClient.get<DashboardSuccessTransport>(path).pipe(
53 // Extract the string here
54 map(res => res['data'])
59 * Gets admission control policy.
60 * @returns Observable that yields an ACAdmissionIntervalControl
62 getPolicy(instanceKey: string): Observable<ACAdmissionIntervalControl> {
63 const path = this.dashboardSvc.buildPath(this.component, instanceKey, this.policyPath, this.acPolicyName);
64 return this.httpClient.get<ACAdmissionIntervalControl>(path);
68 * Puts admission control policy.
69 * @param policy an instance of ACAdmissionIntervalControl
70 * @returns Observable that yields a response code, no data
72 putPolicy(instanceKey: string, policy: ACAdmissionIntervalControl): Observable<any> {
73 const path = this.dashboardSvc.buildPath(this.component, instanceKey, this.policyPath, this.acPolicyName);
74 return this.httpClient.put<ACAdmissionIntervalControlAck>(path, policy, { observe: 'response' });