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 { NsUpdateComponent } from 'NsUpdateComponent';
33 import { RestService } from 'RestService';
34 import { forkJoin, Observable } from 'rxjs';
35 import { ScalingComponent } from 'ScalingComponent';
36 import { SharedService } from 'SharedService';
37 import { ShowInfoComponent } from 'ShowInfoComponent';
38 import { StartStopRebuildComponent } from 'StartStopRebuildComponent';
39 import { isNullOrUndefined } from 'util';
40 import { VmMigrationComponent } from 'VmMigrationComponent';
41 import { DF, VDU, VNFD } from 'VNFDModel';
44 * @Component takes NSInstancesActionComponent.html as template url
47 templateUrl: './NSInstancesActionComponent.html',
48 styleUrls: ['./NSInstancesActionComponent.scss'],
49 changeDetection: ChangeDetectionStrategy.OnPush
51 /** Exporting a class @exports NSInstancesActionComponent */
52 export class NSInstancesActionComponent {
53 /** To get the value from the nspackage via valuePrepareFunction default Property of ng-smarttable @public */
54 public value: NSDInstanceData;
56 /** Invoke service injectors @public */
57 public injector: Injector;
59 /** Instance of the modal service @public */
60 public restService: RestService;
62 /** Config Status Check @public */
63 public configStatus: string;
65 /** Operational Status Check @public */
66 public operationalStatus: string;
68 /** get Admin Details @public */
69 public getAdminDetails: {};
71 /** Scaling is accepted @public */
72 public isScalingPresent: boolean = false;
74 /** Check the loading results for loader status @public */
75 public isLoadingNSInstanceAction: boolean = false;
77 /** Give the message for the loading @public */
78 public message: string = 'PLEASEWAIT';
80 /** Assign the VNF Details @public */
81 public vnfDetails: VNFD[] = [];
83 /** Contains instance ID @public */
84 public instanceID: string;
86 /** Contains operational dashboard view @public */
87 public isShowOperationalDashboard: boolean = false;
89 /** Instance of the modal service @private */
90 private modalService: NgbModal;
92 /** Holds teh instance of AuthService class of type AuthService @private */
93 private router: Router;
95 /** Contains all methods related to shared @private */
96 private sharedService: SharedService;
98 /** Notifier service to popup notification @private */
99 private notifierService: NotifierService;
101 /** Contains tranlsate instance @private */
102 private translateService: TranslateService;
104 /** Detect changes for the User Input */
105 private cd: ChangeDetectorRef;
107 /** Set timeout @private */
108 private timeOut: number = 100;
110 constructor(injector: Injector) {
111 this.injector = injector;
112 this.modalService = this.injector.get(NgbModal);
113 this.restService = this.injector.get(RestService);
114 this.router = this.injector.get(Router);
115 this.sharedService = this.injector.get(SharedService);
116 this.notifierService = this.injector.get(NotifierService);
117 this.translateService = this.injector.get(TranslateService);
118 this.cd = this.injector.get(ChangeDetectorRef);
122 * Lifecyle Hooks the trigger before component is instantiate
124 public ngOnInit(): void {
125 this.configStatus = this.value.ConfigStatus;
126 this.operationalStatus = this.value.OperationalStatus;
127 this.instanceID = this.value.identifier;
128 this.getAdminDetails = this.value.adminDetails;
129 this.isShowOperationalDashboard = !isNullOrUndefined(this.value.vcaStatus) ?
130 Object.keys(this.value.vcaStatus).length === 0 && typeof this.value.vcaStatus === 'object' : true;
133 /** Shows information using modalservice @public */
134 public infoNs(): void {
135 this.modalService.open(ShowInfoComponent, { backdrop: 'static' }).componentInstance.params = {
138 titleName: 'INSTANCEDETAILS'
142 /** Delete NS Instanace @public */
143 public deleteNSInstance(forceAction: boolean): void {
144 const modalRef: NgbModalRef = this.modalService.open(DeleteComponent, { backdrop: 'static' });
145 modalRef.componentInstance.params = { forceDeleteType: forceAction };
146 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
148 this.sharedService.callData();
153 /** History of operations for an Instanace @public */
154 public historyOfOperations(): void {
155 this.router.navigate(['/instances/ns/history-operations/', this.instanceID]).catch((): void => {
156 // Catch Navigation Error
161 public nsTopology(): void {
162 this.router.navigate(['/instances/ns/', this.instanceID]).catch((): void => {
163 // Catch Navigation Error
167 /** Exec NS Primitive @public */
168 public execNSPrimitiveModal(): void {
169 this.modalService.open(NSPrimitiveComponent, { backdrop: 'static' }).componentInstance.params = {
170 memberIndex: this.value.memberIndex,
171 nsConfig: this.value.nsConfig,
172 name: this.value.NsdName
176 /** Redirect to Grafana Metrics @public */
177 public metrics(): void {
178 this.isLoadingNSInstanceAction = true;
179 this.restService.getResource(environment.NSDINSTANCES_URL + '/' + this.instanceID).subscribe((nsData: NSDDetails[]): void => {
180 nsData['vnfd-id'].forEach((vnfdID: string[]): void => {
181 this.restService.getResource(environment.VNFPACKAGES_URL + '/' + vnfdID)
182 .subscribe((vnfd: VNFD): void => {
183 vnfd.vdu.forEach((vduData: VDU): void => {
184 if (vduData['monitoring-parameter'] !== undefined && vduData['monitoring-parameter'].length > 0) {
185 this.isLoadingNSInstanceAction = false;
186 const location: string = environment.GRAFANA_URL + '/' + this.instanceID + '/osm-ns-metrics-metrics';
187 window.open(location);
189 this.isLoadingNSInstanceAction = false;
190 this.notifierService.notify('error', this.translateService.instant('PAGE.NSMETRIC.METRICERROR'));
194 }, (error: ERRORDATA): void => {
195 this.restService.handleError(error, 'get');
196 this.isLoadingNSInstanceAction = false;
199 }, (error: ERRORDATA): void => {
200 this.restService.handleError(error, 'get');
201 this.isLoadingNSInstanceAction = false;
206 * Do the manual scaling
207 * Here we are going to get a list of VNFD ID used in the instances
208 * and have this in array with URL created then pass to checkscaling method for forkjoin to get the data @public
210 public manualScaling(): void {
211 this.isLoadingNSInstanceAction = true;
212 const tempURL: Observable<{}>[] = [];
213 this.value.vnfID.forEach((id: string): void => {
214 const apiUrl: string = environment.VNFPACKAGESCONTENT_URL + '/' + id;
215 tempURL.push(this.restService.getResource(apiUrl));
217 this.checkScaling(tempURL);
221 * Used to forkjoin to all the request to send parallely, get the data and check 'scaling-aspect' key is present @public
223 public checkScaling(URLS: Observable<{}>[]): void {
224 forkJoin(URLS).subscribe((data: VNFD[]): void => {
225 this.vnfDetails = data;
226 if (this.vnfDetails.length > 0) {
227 this.vnfDetails.forEach((vnfdData: VNFD): void => {
228 vnfdData.df.forEach((dfData: DF): void => {
229 if (!isNullOrUndefined(dfData['scaling-aspect']) && dfData['scaling-aspect'].length > 0) {
230 this.isScalingPresent = true;
235 this.isLoadingNSInstanceAction = false;
236 if (this.isScalingPresent) {
239 this.notifierService.notify('error', this.translateService.instant('SCALINGNOTFOUND'));
245 /** Open the scaling pop-up @public */
246 public openScaling(): void {
247 const modalRef: NgbModalRef = this.modalService.open(ScalingComponent, { backdrop: 'static' });
248 modalRef.componentInstance.params = {
250 vnfID: this.value.vnfID,
251 nsID: this.value['nsd-id'],
253 data: this.vnfDetails
255 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
257 this.sharedService.callData();
262 /** To open VM Migration in NS Instances */
263 public openVmMigration(): void {
264 const modalRef: NgbModalRef = this.modalService.open(VmMigrationComponent, { backdrop: 'static' });
265 modalRef.componentInstance.params = {
268 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
270 this.sharedService.callData();
275 /** To open the Ns Update pop-up */
276 public openNsUpdate(): void {
277 const modalRef: NgbModalRef = this.modalService.open(NsUpdateComponent, { backdrop: 'static' });
278 modalRef.componentInstance.params = {
281 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
283 this.sharedService.callData();
288 /** To open the Start, Stop & Rebuild pop-up */
289 public openStart(actionType: string): void {
290 const modalRef: NgbModalRef = this.modalService.open(StartStopRebuildComponent, { backdrop: 'static' });
291 modalRef.componentInstance.params = {
294 if (actionType === 'start') {
295 modalRef.componentInstance.instanceTitle = this.translateService.instant('START');
296 } else if (actionType === 'stop') {
297 modalRef.componentInstance.instanceTitle = this.translateService.instant('STOP');
299 modalRef.componentInstance.instanceTitle = this.translateService.instant('REBUILD');
301 modalRef.componentInstance.instanceType = actionType;
302 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
304 this.sharedService.callData();
310 * Check any changes in the child component @public
312 public doChanges(): void {
313 setTimeout((): void => {
314 this.cd.detectChanges();