* limitations under the License.
* ========================LICENSE_END===================================
*/
-import { Injectable } from '@angular/core';
import { HttpClient, HttpResponse } from '@angular/common/http';
+import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
-import { XMXappInfo, XMDeployableApp, XMDeployedApp } from '../../interfaces/app-mgr.types';
+import { XMDeployableApp, XMDeployedApp, XMXappInfo } from '../../interfaces/app-mgr.types';
+import { DashboardService } from '../dashboard/dashboard.service';
@Injectable()
export class AppMgrService {
- constructor(private httpClient: HttpClient) {
- // injects to variable httpClient
- }
+ private component = 'appmgr';
+ private xappsPath = 'xapps';
- private basePath = 'api/appmgr';
+ constructor(
+ private dashboardSvc: DashboardService,
+ private httpClient: HttpClient) {
+ }
- getDeployable(): Observable<XMDeployableApp[]> {
- return this.httpClient.get<XMDeployableApp[]>(this.basePath + '/xapps/list');
+ getDeployable(instanceKey: string): Observable<XMDeployableApp[]> {
+ const path = this.dashboardSvc.buildPath(this.component, instanceKey, this.xappsPath, 'list');
+ return this.httpClient.get<XMDeployableApp[]>(path);
}
- getDeployed(): Observable<XMDeployedApp[]> {
- return this.httpClient.get<XMDeployedApp[]>(this.basePath + '/xapps');
+ getDeployed(instanceKey: string): Observable<XMDeployedApp[]> {
+ const path = this.dashboardSvc.buildPath(this.component, instanceKey, this.xappsPath);
+ return this.httpClient.get<XMDeployedApp[]>(path);
}
- deployXapp(name: string): Observable<HttpResponse<Object>> {
+ deployXapp(instanceKey: string, name: string): Observable<HttpResponse<Object>> {
const xappInfo: XMXappInfo = { name: name };
- return this.httpClient.post((this.basePath + '/xapps'), xappInfo, { observe: 'response' });
+ const path = this.dashboardSvc.buildPath(this.component, instanceKey, this.xappsPath);
+ return this.httpClient.post(path, xappInfo, { observe: 'response' });
}
- undeployXapp(name: string): Observable<HttpResponse<Object>> {
- return this.httpClient.delete((this.basePath + '/xapps'+ '/' + name), { observe: 'response' });
+ undeployXapp(instanceKey: string, name: string): Observable<HttpResponse<Object>> {
+ const path = this.dashboardSvc.buildPath(this.component, instanceKey, this.xappsPath, name);
+ return this.httpClient.delete(path, { observe: 'response' });
}
- getConfig(): Observable<any[]>{
- return this.httpClient.get<any[]>("/assets/mockdata/config.json");
- //return this.httpClient.get<any[]>((this.basePath + '/config'));
+ getConfig(instanceKey: string): Observable<any[]> {
+ // For demo purpose, pull example config from local
+ return this.httpClient.get<any[]>('/assets/mockdata/config.json');
+ // Once Xapp manager contains layout, should call backend to get xapp config
+ // const path = this.dashboardSvc.buildPath(this.component, instanceKey, 'config');
+ // return this.httpClient.get<any[]>(path);
}
- putConfig(config: any): Observable<HttpResponse<Object>> {
- return this.httpClient.put((this.basePath + '/config' ), config, { observe: 'response' });
+ putConfig(instanceKey: string, config: any): Observable<HttpResponse<Object>> {
+ const path = this.dashboardSvc.buildPath(this.component, instanceKey, 'config');
+ return this.httpClient.put(path, config, { observe: 'response' });
}
-
}