From 3e69af1763ea2ce5f9485ab1cb5a39b089b109a7 Mon Sep 17 00:00:00 2001 From: jh245g Date: Sun, 19 May 2019 17:23:13 -0400 Subject: [PATCH 1/1] use XappMgrService to replace Catalog and Control Change-Id: I431f24a5f55482c2fd2186db96507321cc6727bd Signed-off-by: Jun (Nicolas) Hu Change-Id: Idb48a2b028cb7dffe08e7e1ed765e87a2f4308d7 --- docs/release-notes.rst | 1 + webapp-frontend/src/app/app.module.ts | 6 +-- .../src/app/catalog/catalog.component.ts | 17 ++++--- .../src/app/control/control.component.ts | 31 ++++++++++--- .../app/services/control/control.service.spec.ts | 31 ------------- .../src/app/services/control/control.service.ts | 54 ---------------------- .../xapp-mgr.service.spec.ts} | 12 ++--- .../xapp-mgr.service.ts} | 19 +++++--- 8 files changed, 56 insertions(+), 115 deletions(-) delete mode 100644 webapp-frontend/src/app/services/control/control.service.spec.ts delete mode 100644 webapp-frontend/src/app/services/control/control.service.ts rename webapp-frontend/src/app/services/{catalog/catalog.service.spec.ts => xapp-mgr/xapp-mgr.service.spec.ts} (85%) rename webapp-frontend/src/app/services/{catalog/catalog.service.ts => xapp-mgr/xapp-mgr.service.ts} (72%) diff --git a/docs/release-notes.rst b/docs/release-notes.rst index c544a9b0..86c1791e 100644 --- a/docs/release-notes.rst +++ b/docs/release-notes.rst @@ -30,6 +30,7 @@ Version 1.0.3, 20 May 2019 * Add simple page footer with copyright and version * Add AC and ANR xApp services * Rename signal service to E2 Manager service +* Use XappMgrService to replace ControlService and CatalogService Version 1.0.2, 13 May 2019 -------------------------- diff --git a/webapp-frontend/src/app/app.module.ts b/webapp-frontend/src/app/app.module.ts index e9dc34d8..353e1274 100644 --- a/webapp-frontend/src/app/app.module.ts +++ b/webapp-frontend/src/app/app.module.ts @@ -37,8 +37,7 @@ import { LoginComponent } from './login/login.component'; import { CatalogComponent } from './catalog/catalog.component'; import { UiService } from './services/ui/ui.service'; import { AdminService } from './services/admin/admin.service'; -import { CatalogService } from './services/catalog/catalog.service'; -import { ControlService } from './services/control/control.service'; +import { XappMgrService } from './services/xapp-mgr/xapp-mgr.service'; import { DashboardService } from './services/dashboard/dashboard.service'; import { E2ManagerService } from './services/e2-mgr/e2-mgr.service'; import { SidenavListComponent } from './navigation/sidenav-list/sidenav-list.component'; @@ -128,8 +127,7 @@ import { AnrXappComponent } from './anr-xapp/anr-xapp.component'; providers: [ UiService, AdminService, - CatalogService, - ControlService, + XappMgrService, DashboardService, E2ManagerService ], diff --git a/webapp-frontend/src/app/catalog/catalog.component.ts b/webapp-frontend/src/app/catalog/catalog.component.ts index f0fcbce8..fd28f0a3 100644 --- a/webapp-frontend/src/app/catalog/catalog.component.ts +++ b/webapp-frontend/src/app/catalog/catalog.component.ts @@ -17,18 +17,19 @@ * limitations under the License. * ========================LICENSE_END=================================== */ -import { Component, Inject } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; import { LocalDataSource } from 'ng2-smart-table'; -import { CatalogService } from '../services/catalog/catalog.service'; +import { XappMgrService } from '../services/xapp-mgr/xapp-mgr.service'; import { ConfirmDialogService } from './../services/ui/confirm-dialog.service' import { NotificationService } from './../services/ui/notification.service' +import { XMXapp } from '../interfaces/xapp-mgr.types'; @Component({ selector: 'app-catalog', templateUrl: './catalog.component.html', styleUrls: ['./catalog.component.css'] }) -export class CatalogComponent { +export class CatalogComponent implements OnInit{ settings = { hideSubHeader: true, @@ -62,17 +63,19 @@ export class CatalogComponent { source: LocalDataSource = new LocalDataSource(); constructor( - private service: CatalogService, + private xappMgrSvc: XappMgrService, private confirmDialogService: ConfirmDialogService, - private notification: NotificationService) { - this.service.getAll().subscribe((val: any[]) => this.source.load(val)); + private notification: NotificationService) { } + + ngOnInit() { + this.xappMgrSvc.getAll().subscribe((xapps: XMXapp[]) => this.source.load(xapps)); } onDeployxApp(event): void { this.confirmDialogService.openConfirmDialog('Are you sure you want to deploy this xApp?') .afterClosed().subscribe(res => { if (res) { - this.service.deployXapp(event.data.name).subscribe( + this.xappMgrSvc.deployXapp(event.data.name).subscribe( response => { switch (response.status) { case 200: diff --git a/webapp-frontend/src/app/control/control.component.ts b/webapp-frontend/src/app/control/control.component.ts index 1c883932..067077ed 100644 --- a/webapp-frontend/src/app/control/control.component.ts +++ b/webapp-frontend/src/app/control/control.component.ts @@ -19,10 +19,11 @@ */ import { Component, OnInit, ViewEncapsulation } from '@angular/core'; import { LocalDataSource } from 'ng2-smart-table'; -import { ControlService } from '../services/control/control.service'; +import { XappMgrService } from '../services/xapp-mgr/xapp-mgr.service'; import { Router } from '@angular/router'; import { ConfirmDialogService } from './../services/ui/confirm-dialog.service' import { NotificationService } from './../services/ui/notification.service' +import { XMXapp } from '../interfaces/xapp-mgr.types'; @Component({ @@ -31,7 +32,7 @@ import { NotificationService } from './../services/ui/notification.service' styleUrls: ['./control.component.css'], encapsulation: ViewEncapsulation.Emulated, }) -export class ControlComponent { +export class ControlComponent implements OnInit { settings = { hideSubHeader: true, @@ -82,11 +83,13 @@ export class ControlComponent { source: LocalDataSource = new LocalDataSource(); constructor( - private service: ControlService, + private xappMgrSvc: XappMgrService, private router: Router, private confirmDialogService: ConfirmDialogService, - private notification: NotificationService) { - this.service.getxAppInstances((instances) => { this.source.load(instances); }); + private notification: NotificationService) { } + + ngOnInit() { + this.xappMgrSvc.getAll().subscribe((xapps: XMXapp[]) => this.source.load(this.getInstance(xapps))); } onxAppControlAction(event) { @@ -109,9 +112,9 @@ export class ControlComponent { this.confirmDialogService.openConfirmDialog('Are you sure you want to undeploy this xApp ?') .afterClosed().subscribe(res => { if (res) { - this.service.undeployxApp(event.data.xapp).subscribe( + this.xappMgrSvc.undeployXapp(event.data.xapp).subscribe( response => { - this.service.getxAppInstances((instances) => { this.source.load(instances); }); + this.xappMgrSvc.getAll().subscribe((xapps: XMXapp[]) => this.source.load(this.getInstance(xapps))); switch (response.status) { case 200: this.notification.success('xApp undeployed successfully!'); @@ -125,5 +128,19 @@ export class ControlComponent { }); } + getInstance(allxappdata: XMXapp[]) { + const xAppInstances = []; + for (const xappindex in allxappdata) { + const instancelist = allxappdata[xappindex].instances; + for (const instanceindex in instancelist) { + var instance: any; + instance = instancelist[instanceindex]; + instance.xapp = allxappdata[xappindex].name; + xAppInstances.push(instance); + } + } + return xAppInstances; + } + } diff --git a/webapp-frontend/src/app/services/control/control.service.spec.ts b/webapp-frontend/src/app/services/control/control.service.spec.ts deleted file mode 100644 index 6ec98f82..00000000 --- a/webapp-frontend/src/app/services/control/control.service.spec.ts +++ /dev/null @@ -1,31 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * O-RAN-SC - * %% - * Copyright (C) 2019 AT&T Intellectual Property and Nokia - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ========================LICENSE_END=================================== - */ -import { TestBed } from '@angular/core/testing'; - -import { ControlService } from './control.service'; - -describe('ControlService', () => { - beforeEach(() => TestBed.configureTestingModule({})); - - it('should be created', () => { - const service: ControlService = TestBed.get(ControlService); - expect(service).toBeTruthy(); - }); -}); diff --git a/webapp-frontend/src/app/services/control/control.service.ts b/webapp-frontend/src/app/services/control/control.service.ts deleted file mode 100644 index 24b4024a..00000000 --- a/webapp-frontend/src/app/services/control/control.service.ts +++ /dev/null @@ -1,54 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * O-RAN-SC - * %% - * Copyright (C) 2019 AT&T Intellectual Property and Nokia - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ========================LICENSE_END=================================== - */ -import { Injectable } from '@angular/core'; -import { HttpClient } from '@angular/common/http'; - -@Injectable() -export class ControlService { - - constructor(private http: HttpClient) { - } - - getxAppInstances(xAppInstances) { - return this.http.get('api/xappmgr/xapps').subscribe( - (val: any[]) => { - xAppInstances(this.fetchInstance(val)); - } - ); - } - - undeployxApp(xapp) { - return this.http.delete(('api/xappmgr/xapps/' + xapp), { observe: 'response' }); - } - - fetchInstance(allxappdata) { - const xAppInstances = []; - for (const xappindex in allxappdata) { - const instancelist = allxappdata[xappindex].instances; - for (const instanceindex in instancelist) { - const instance = instancelist[instanceindex]; - instance.xapp = allxappdata[xappindex].name; - xAppInstances.push(instance); - } - } - return xAppInstances; - } - -} diff --git a/webapp-frontend/src/app/services/catalog/catalog.service.spec.ts b/webapp-frontend/src/app/services/xapp-mgr/xapp-mgr.service.spec.ts similarity index 85% rename from webapp-frontend/src/app/services/catalog/catalog.service.spec.ts rename to webapp-frontend/src/app/services/xapp-mgr/xapp-mgr.service.spec.ts index 37fe1044..c62fd8b4 100644 --- a/webapp-frontend/src/app/services/catalog/catalog.service.spec.ts +++ b/webapp-frontend/src/app/services/xapp-mgr/xapp-mgr.service.spec.ts @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,15 +17,15 @@ * limitations under the License. * ========================LICENSE_END=================================== */ -import { TestBed } from '@angular/core/testing'; -import { CatalogService } from './catalog.service'; +import { TestBed } from '@angular/core/testing'; +import { XappMgrService } from './xapp-mgr.service'; -describe('CatalogService', () => { +describe('XappMgrService', () => { beforeEach(() => TestBed.configureTestingModule({})); it('should be created', () => { - const service: CatalogService = TestBed.get(CatalogService); + const service: XappMgrService = TestBed.get(XappMgrService); expect(service).toBeTruthy(); }); }); diff --git a/webapp-frontend/src/app/services/catalog/catalog.service.ts b/webapp-frontend/src/app/services/xapp-mgr/xapp-mgr.service.ts similarity index 72% rename from webapp-frontend/src/app/services/catalog/catalog.service.ts rename to webapp-frontend/src/app/services/xapp-mgr/xapp-mgr.service.ts index 4946f24b..daef3e07 100644 --- a/webapp-frontend/src/app/services/catalog/catalog.service.ts +++ b/webapp-frontend/src/app/services/xapp-mgr/xapp-mgr.service.ts @@ -20,22 +20,29 @@ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable } from 'rxjs'; -import { XMXappInfo } from '../../interfaces/xapp-mgr.types'; +import { XMXappInfo, XMXapp} from '../../interfaces/xapp-mgr.types'; + @Injectable() -export class CatalogService { +export class XappMgrService { constructor(private httpClient: HttpClient) { // injects to variable httpClient } - getAll() { - return this.httpClient.get('api/xappmgr/xapps'); + private basePath = 'api/xappmgr/xapps'; + + getAll(){ + return this.httpClient.get(this.basePath); } deployXapp(name: string) { const xappInfo: XMXappInfo = { xAppName: name }; - return this.httpClient.post('api/xappmgr/xapps', xappInfo, { observe: 'response' }); + return this.httpClient.post(this.basePath, xappInfo, { observe: 'response' }); + } + + undeployXapp(name: string) { + return this.httpClient.delete((this.basePath + '/' + name), { observe: 'response' }); } -} +} \ No newline at end of file -- 2.16.6