update configure workflow
[portal/ric-dashboard.git] / dashboard / webapp-frontend / src / app / services / app-mgr / app-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 { XMAllDeployedXapps, XMAllXappConfig, XMDashboardDeployableXapps,
24           XMXappConfig, XMXappDescriptor } from '../../interfaces/app-mgr.types';
25 import { DashboardService } from '../dashboard/dashboard.service';
26
27 @Injectable()
28 export class AppMgrService {
29
30   private component = 'appmgr';
31   private xappsPath = 'xapps';
32
33   constructor(
34     private dashboardSvc: DashboardService,
35     private httpClient: HttpClient) {
36   }
37
38   getDeployable(instanceKey: string): Observable<XMDashboardDeployableXapps> {
39     const path = this.dashboardSvc.buildPath(this.component, instanceKey, this.xappsPath, 'list');
40     return this.httpClient.get<XMDashboardDeployableXapps>(path);
41   }
42
43   getDeployed(instanceKey: string): Observable<XMAllDeployedXapps> {
44     const path = this.dashboardSvc.buildPath(this.component, instanceKey, this.xappsPath);
45     return this.httpClient.get<XMAllDeployedXapps>(path);
46   }
47
48   deployXapp(instanceKey: string, xappDescriptor: XMXappDescriptor): Observable<HttpResponse<Object>> {
49     const path = this.dashboardSvc.buildPath(this.component, instanceKey, this.xappsPath);
50     return this.httpClient.post(path, xappDescriptor, { observe: 'response' });
51   }
52
53   undeployXapp(instanceKey: string, name: string): Observable<HttpResponse<Object>> {
54     const path = this.dashboardSvc.buildPath(this.component, instanceKey, this.xappsPath, name);
55     return this.httpClient.delete(path, { observe: 'response' });
56   }
57
58   getConfig(instanceKey: string): Observable<XMAllXappConfig> {
59     // For demo purpose, pull example config from local
60     //return this.httpClient.get<XMAllXappConfig>('/assets/mockdata/config.json');
61     // Once Xapp manager contains layout, should call backend to get xapp config
62     const path = this.dashboardSvc.buildPath(this.component, instanceKey, 'config');
63     return this.httpClient.get<any[]>(path);
64   }
65
66   putConfig(instanceKey: string, config: XMXappConfig): Observable<HttpResponse<Object>> {
67     const path = this.dashboardSvc.buildPath(this.component, instanceKey, 'config');
68     return this.httpClient.put(path, config, { observe: 'response' });
69   }
70
71 }