2 Copyright 2020 TATA ELXSI
4 Licensed under the Apache License, Version 2.0 (the 'License');
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
16 Author: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.in), BARATH KUMAR R (barath.r@tataelxsi.co.in)
19 * @file NS InstancesAction Component
21 import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Injector } from '@angular/core';
22 import { Router } from '@angular/router';
23 import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
24 import { TranslateService } from '@ngx-translate/core';
25 import { NotifierService } from 'angular-notifier';
26 import { ERRORDATA, MODALCLOSERESPONSEDATA } from 'CommonModel';
27 import { DeleteComponent } from 'DeleteComponent';
28 import { environment } from 'environment';
29 import { NSDDetails } from 'NSDModel';
30 import { NSDInstanceData } from 'NSInstanceModel';
31 import { NSPrimitiveComponent } from 'NSPrimitiveComponent';
32 import { RestService } from 'RestService';
33 import { forkJoin, Observable } from 'rxjs';
34 import { ScalingComponent } from 'ScalingComponent';
35 import { SharedService } from 'SharedService';
36 import { ShowInfoComponent } from 'ShowInfoComponent';
37 import { isNullOrUndefined } from 'util';
38 import { VmMigrationComponent } from 'VmMigrationComponent';
39 import { DF, VDU, VNFD } from 'VNFDModel';
42 * @Component takes NSInstancesActionComponent.html as template url
45 templateUrl: './NSInstancesActionComponent.html',
46 styleUrls: ['./NSInstancesActionComponent.scss'],
47 changeDetection: ChangeDetectionStrategy.OnPush
49 /** Exporting a class @exports NSInstancesActionComponent */
50 export class NSInstancesActionComponent {
51 /** To get the value from the nspackage via valuePrepareFunction default Property of ng-smarttable @public */
52 public value: NSDInstanceData;
54 /** Invoke service injectors @public */
55 public injector: Injector;
57 /** Instance of the modal service @public */
58 public restService: RestService;
60 /** Config Status Check @public */
61 public configStatus: string;
63 /** Operational Status Check @public */
64 public operationalStatus: string;
66 /** get Admin Details @public */
67 public getAdminDetails: {};
69 /** Scaling is accepted @public */
70 public isScalingPresent: boolean = false;
72 /** Check the loading results for loader status @public */
73 public isLoadingNSInstanceAction: boolean = false;
75 /** Give the message for the loading @public */
76 public message: string = 'PLEASEWAIT';
78 /** Assign the VNF Details @public */
79 public vnfDetails: VNFD[] = [];
81 /** Contains instance ID @public */
82 public instanceID: string;
84 /** Contains operational dashboard view @public */
85 public isShowOperationalDashboard: boolean = false;
87 /** Instance of the modal service @private */
88 private modalService: NgbModal;
90 /** Holds teh instance of AuthService class of type AuthService @private */
91 private router: Router;
93 /** Contains all methods related to shared @private */
94 private sharedService: SharedService;
96 /** Notifier service to popup notification @private */
97 private notifierService: NotifierService;
99 /** Contains tranlsate instance @private */
100 private translateService: TranslateService;
102 /** Detect changes for the User Input */
103 private cd: ChangeDetectorRef;
105 /** Set timeout @private */
106 private timeOut: number = 100;
108 constructor(injector: Injector) {
109 this.injector = injector;
110 this.modalService = this.injector.get(NgbModal);
111 this.restService = this.injector.get(RestService);
112 this.router = this.injector.get(Router);
113 this.sharedService = this.injector.get(SharedService);
114 this.notifierService = this.injector.get(NotifierService);
115 this.translateService = this.injector.get(TranslateService);
116 this.cd = this.injector.get(ChangeDetectorRef);
120 * Lifecyle Hooks the trigger before component is instantiate
122 public ngOnInit(): void {
123 this.configStatus = this.value.ConfigStatus;
124 this.operationalStatus = this.value.OperationalStatus;
125 this.instanceID = this.value.identifier;
126 this.getAdminDetails = this.value.adminDetails;
127 this.isShowOperationalDashboard = !isNullOrUndefined(this.value.vcaStatus) ?
128 Object.keys(this.value.vcaStatus).length === 0 && typeof this.value.vcaStatus === 'object' : true;
131 /** Shows information using modalservice @public */
132 public infoNs(): void {
133 this.modalService.open(ShowInfoComponent, { backdrop: 'static' }).componentInstance.params = {
136 titleName: 'INSTANCEDETAILS'
140 /** Delete NS Instanace @public */
141 public deleteNSInstance(forceAction: boolean): void {
142 const modalRef: NgbModalRef = this.modalService.open(DeleteComponent, { backdrop: 'static' });
143 modalRef.componentInstance.params = { forceDeleteType: forceAction };
144 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
146 this.sharedService.callData();
151 /** History of operations for an Instanace @public */
152 public historyOfOperations(): void {
153 this.router.navigate(['/instances/ns/history-operations/', this.instanceID]).catch((): void => {
154 // Catch Navigation Error
159 public nsTopology(): void {
160 this.router.navigate(['/instances/ns/', this.instanceID]).catch((): void => {
161 // Catch Navigation Error
165 /** Exec NS Primitive @public */
166 public execNSPrimitiveModal(): void {
167 this.modalService.open(NSPrimitiveComponent, { backdrop: 'static' }).componentInstance.params = {
168 memberIndex: this.value.memberIndex,
169 nsConfig: this.value.nsConfig,
170 name: this.value.NsdName
174 /** Redirect to Grafana Metrics @public */
175 public metrics(): void {
176 this.isLoadingNSInstanceAction = true;
177 this.restService.getResource(environment.NSDINSTANCES_URL + '/' + this.instanceID).subscribe((nsData: NSDDetails[]): void => {
178 nsData['vnfd-id'].forEach((vnfdID: string[]): void => {
179 this.restService.getResource(environment.VNFPACKAGES_URL + '/' + vnfdID)
180 .subscribe((vnfd: VNFD): void => {
181 vnfd.vdu.forEach((vduData: VDU): void => {
182 if (vduData['monitoring-parameter'] !== undefined && vduData['monitoring-parameter'].length > 0) {
183 this.isLoadingNSInstanceAction = false;
184 const location: string = environment.GRAFANA_URL + '/' + this.instanceID + '/osm-ns-metrics-metrics';
185 window.open(location);
187 this.isLoadingNSInstanceAction = false;
188 this.notifierService.notify('error', this.translateService.instant('PAGE.NSMETRIC.METRICERROR'));
192 }, (error: ERRORDATA): void => {
193 this.restService.handleError(error, 'get');
194 this.isLoadingNSInstanceAction = false;
197 }, (error: ERRORDATA): void => {
198 this.restService.handleError(error, 'get');
199 this.isLoadingNSInstanceAction = false;
204 * Do the manual scaling
205 * Here we are going to get a list of VNFD ID used in the instances
206 * and have this in array with URL created then pass to checkscaling method for forkjoin to get the data @public
208 public manualScaling(): void {
209 this.isLoadingNSInstanceAction = true;
210 const tempURL: Observable<{}>[] = [];
211 this.value.vnfID.forEach((id: string): void => {
212 const apiUrl: string = environment.VNFPACKAGESCONTENT_URL + '/' + id;
213 tempURL.push(this.restService.getResource(apiUrl));
215 this.checkScaling(tempURL);
219 * Used to forkjoin to all the request to send parallely, get the data and check 'scaling-aspect' key is present @public
221 public checkScaling(URLS: Observable<{}>[]): void {
222 forkJoin(URLS).subscribe((data: VNFD[]): void => {
223 this.vnfDetails = data;
224 if (this.vnfDetails.length > 0) {
225 this.vnfDetails.forEach((vnfdData: VNFD): void => {
226 vnfdData.df.forEach((dfData: DF): void => {
227 if (!isNullOrUndefined(dfData['scaling-aspect']) && dfData['scaling-aspect'].length > 0) {
228 this.isScalingPresent = true;
233 this.isLoadingNSInstanceAction = false;
234 if (this.isScalingPresent) {
237 this.notifierService.notify('error', this.translateService.instant('SCALINGNOTFOUND'));
243 /** Open the scaling pop-up @public */
244 public openScaling(): void {
245 const modalRef: NgbModalRef = this.modalService.open(ScalingComponent, { backdrop: 'static' });
246 modalRef.componentInstance.params = {
248 vnfID: this.value.vnfID,
249 nsID: this.value['nsd-id'],
251 data: this.vnfDetails
253 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
255 this.sharedService.callData();
260 /** To open VM Migration in NS Instances */
261 public openVmMigration(): void {
262 const modalRef: NgbModalRef = this.modalService.open(VmMigrationComponent, { backdrop: 'static' });
263 modalRef.componentInstance.params = {
266 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
268 this.sharedService.callData();
274 * Check any changes in the child component @public
276 public doChanges(): void {
277 setTimeout((): void => {
278 this.cd.detectChanges();