blob: 2d2575ed1a3e54837921377dc53cd88c6e574e31 [file] [log] [blame]
kumaran.m3b4814a2020-05-01 19:48:54 +05301/*
2 Copyright 2020 TATA ELXSI
3
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
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
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.
15
16 Author: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.in), BARATH KUMAR R (barath.r@tataelxsi.co.in)
17*/
18/**
19 * @file NS InstancesAction Component
20 */
21import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Injector } from '@angular/core';
22import { Router } from '@angular/router';
23import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
24import { TranslateService } from '@ngx-translate/core';
25import { NotifierService } from 'angular-notifier';
26import { ERRORDATA, MODALCLOSERESPONSEDATA } from 'CommonModel';
27import { DeleteComponent } from 'DeleteComponent';
28import { environment } from 'environment';
SANDHYA.JS219fe612024-01-23 15:52:43 +053029import { HealingComponent } from 'HealingComponent';
kumaran.m3b4814a2020-05-01 19:48:54 +053030import { NSDDetails } from 'NSDModel';
31import { NSDInstanceData } from 'NSInstanceModel';
32import { NSPrimitiveComponent } from 'NSPrimitiveComponent';
SANDHYA.JS99144582022-04-27 17:22:35 +053033import { NsUpdateComponent } from 'NsUpdateComponent';
kumaran.m3b4814a2020-05-01 19:48:54 +053034import { RestService } from 'RestService';
Barath Kumar R07698ab2021-03-30 11:50:42 +053035import { forkJoin, Observable } from 'rxjs';
36import { ScalingComponent } from 'ScalingComponent';
SANDHYA.JSc84f1122024-06-04 21:50:03 +053037import { SharedService, isNullOrUndefined } from 'SharedService';
kumaran.m3b4814a2020-05-01 19:48:54 +053038import { ShowInfoComponent } from 'ShowInfoComponent';
Isabel Lloret523d6752025-04-29 08:06:54 +000039import { ShowVduConsoleComponent } from 'ShowVduConsoleComponent';
SANDHYA.JS3d81a282022-05-02 08:25:39 +053040import { StartStopRebuildComponent } from 'StartStopRebuildComponent';
SANDHYA.JSfced3d42022-04-28 20:28:17 +053041import { VmMigrationComponent } from 'VmMigrationComponent';
Barath Kumar R07698ab2021-03-30 11:50:42 +053042import { DF, VDU, VNFD } from 'VNFDModel';
kumaran.m3b4814a2020-05-01 19:48:54 +053043/**
44 * Creating component
45 * @Component takes NSInstancesActionComponent.html as template url
46 */
47@Component({
48 templateUrl: './NSInstancesActionComponent.html',
49 styleUrls: ['./NSInstancesActionComponent.scss'],
50 changeDetection: ChangeDetectionStrategy.OnPush
51})
52/** Exporting a class @exports NSInstancesActionComponent */
53export class NSInstancesActionComponent {
54 /** To get the value from the nspackage via valuePrepareFunction default Property of ng-smarttable @public */
55 public value: NSDInstanceData;
56
57 /** Invoke service injectors @public */
58 public injector: Injector;
59
60 /** Instance of the modal service @public */
61 public restService: RestService;
62
63 /** Config Status Check @public */
64 public configStatus: string;
65
66 /** Operational Status Check @public */
67 public operationalStatus: string;
68
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +053069 /** CNF Status Check @public */
70 public k8sStatus: boolean = false;
71
Barath Kumar R07698ab2021-03-30 11:50:42 +053072 /** get Admin Details @public */
73 public getAdminDetails: {};
74
75 /** Scaling is accepted @public */
76 public isScalingPresent: boolean = false;
77
kumaran.m3b4814a2020-05-01 19:48:54 +053078 /** Check the loading results for loader status @public */
Barath Kumar R07698ab2021-03-30 11:50:42 +053079 public isLoadingNSInstanceAction: boolean = false;
kumaran.m3b4814a2020-05-01 19:48:54 +053080
81 /** Give the message for the loading @public */
82 public message: string = 'PLEASEWAIT';
83
Barath Kumar R07698ab2021-03-30 11:50:42 +053084 /** Assign the VNF Details @public */
85 public vnfDetails: VNFD[] = [];
86
Barath Kumar Rf2ae5462021-03-01 12:52:33 +053087 /** Contains instance ID @public */
88 public instanceID: string;
89
90 /** Contains operational dashboard view @public */
91 public isShowOperationalDashboard: boolean = false;
92
Isabel Lloret523d6752025-04-29 08:06:54 +000093 /** Controls to show additional operations buttons */
94 public showConsoleAction: boolean = false;
95
96 /** Vim types for wich console operation button must be show */
97 private static readonly NS_CONSOLE_OPERATION_VIM_TYPES: string[] = ['vcenter'];
98
kumaran.m3b4814a2020-05-01 19:48:54 +053099 /** Instance of the modal service @private */
100 private modalService: NgbModal;
101
102 /** Holds teh instance of AuthService class of type AuthService @private */
103 private router: Router;
104
kumaran.m3b4814a2020-05-01 19:48:54 +0530105 /** Contains all methods related to shared @private */
106 private sharedService: SharedService;
107
108 /** Notifier service to popup notification @private */
109 private notifierService: NotifierService;
110
111 /** Contains tranlsate instance @private */
112 private translateService: TranslateService;
113
114 /** Detect changes for the User Input */
115 private cd: ChangeDetectorRef;
116
117 /** Set timeout @private */
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530118 // eslint-disable-next-line @typescript-eslint/no-magic-numbers
Barath Kumar R07698ab2021-03-30 11:50:42 +0530119 private timeOut: number = 100;
kumaran.m3b4814a2020-05-01 19:48:54 +0530120
121 constructor(injector: Injector) {
122 this.injector = injector;
123 this.modalService = this.injector.get(NgbModal);
124 this.restService = this.injector.get(RestService);
125 this.router = this.injector.get(Router);
126 this.sharedService = this.injector.get(SharedService);
127 this.notifierService = this.injector.get(NotifierService);
128 this.translateService = this.injector.get(TranslateService);
129 this.cd = this.injector.get(ChangeDetectorRef);
130 }
131
132 /**
133 * Lifecyle Hooks the trigger before component is instantiate
134 */
135 public ngOnInit(): void {
136 this.configStatus = this.value.ConfigStatus;
137 this.operationalStatus = this.value.OperationalStatus;
138 this.instanceID = this.value.identifier;
Barath Kumar R07698ab2021-03-30 11:50:42 +0530139 this.getAdminDetails = this.value.adminDetails;
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530140 for (const key of Object.keys(this.getAdminDetails)) {
141 if (key === 'deployed') {
142 // eslint-disable-next-line security/detect-object-injection
143 const adminData: {} = this.getAdminDetails[key];
144 for (const k8sData of Object.keys(adminData)) {
145 if (k8sData === 'K8s') {
146 // eslint-disable-next-line security/detect-object-injection
147 if (adminData[k8sData].length !== 0) {
148 this.k8sStatus = true;
149 }
150 }
151 }
152 }
153 }
Barath Kumar Rf2ae5462021-03-01 12:52:33 +0530154 this.isShowOperationalDashboard = !isNullOrUndefined(this.value.vcaStatus) ?
155 Object.keys(this.value.vcaStatus).length === 0 && typeof this.value.vcaStatus === 'object' : true;
Isabel Lloret523d6752025-04-29 08:06:54 +0000156 // Check if additional operations buttons must be showns
157 this.checkShowExtraActionsButtons();
158 }
159
160 /** Checks if the console option in the actions dropdown must be shown */
161 private checkShowExtraActionsButtons() {
162 if (NSInstancesActionComponent.NS_CONSOLE_OPERATION_VIM_TYPES.includes(this.value.vimType)) {
163 this.showConsoleAction = true;
164 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530165 }
166
167 /** Shows information using modalservice @public */
168 public infoNs(): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530169 // eslint-disable-next-line security/detect-non-literal-fs-filename
kumaran.m3b4814a2020-05-01 19:48:54 +0530170 this.modalService.open(ShowInfoComponent, { backdrop: 'static' }).componentInstance.params = {
171 id: this.instanceID,
172 page: 'ns-instance',
173 titleName: 'INSTANCEDETAILS'
174 };
175 }
176
177 /** Delete NS Instanace @public */
178 public deleteNSInstance(forceAction: boolean): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530179 // eslint-disable-next-line security/detect-non-literal-fs-filename
kumaran.m3b4814a2020-05-01 19:48:54 +0530180 const modalRef: NgbModalRef = this.modalService.open(DeleteComponent, { backdrop: 'static' });
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530181 modalRef.componentInstance.params = {
182 forceDeleteType: forceAction,
183 name: this.value.name,
184 page: 'ns-instance',
185 id: this.instanceID
186 };
Barath Kumar R1a34b832021-03-05 11:32:19 +0530187 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530188 if (result) {
189 this.sharedService.callData();
190 }
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530191 }).catch((): void => {
192 // Catch Navigation Error
SANDHYA.JS219fe612024-01-23 15:52:43 +0530193 });
kumaran.m3b4814a2020-05-01 19:48:54 +0530194 }
195
196 /** History of operations for an Instanace @public */
197 public historyOfOperations(): void {
Barath Kumar R1a34b832021-03-05 11:32:19 +0530198 this.router.navigate(['/instances/ns/history-operations/', this.instanceID]).catch((): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530199 // Catch Navigation Error
200 });
201 }
202
203 /** NS Topology */
204 public nsTopology(): void {
Barath Kumar R1a34b832021-03-05 11:32:19 +0530205 this.router.navigate(['/instances/ns/', this.instanceID]).catch((): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530206 // Catch Navigation Error
207 });
208 }
209
210 /** Exec NS Primitive @public */
211 public execNSPrimitiveModal(): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530212 // eslint-disable-next-line security/detect-non-literal-fs-filename
Barath Kumar Rd3ce0c52020-08-13 11:44:01 +0530213 this.modalService.open(NSPrimitiveComponent, { backdrop: 'static' }).componentInstance.params = {
kumaran.m3b4814a2020-05-01 19:48:54 +0530214 memberIndex: this.value.memberIndex,
Barath Kumar R54d693c2020-07-13 20:54:13 +0530215 nsConfig: this.value.nsConfig,
SANDHYA.JS1584e3e2022-10-31 20:11:50 +0530216 name: this.value.NsdName,
SANDHYA.JSa53db0c2025-05-23 11:44:39 +0530217 id: this.value.constituent,
218 nsID: this.instanceID
kumaran.m3b4814a2020-05-01 19:48:54 +0530219 };
220 }
221
222 /** Redirect to Grafana Metrics @public */
223 public metrics(): void {
Barath Kumar R07698ab2021-03-30 11:50:42 +0530224 this.isLoadingNSInstanceAction = true;
Barath Kumar R1a34b832021-03-05 11:32:19 +0530225 this.restService.getResource(environment.NSDINSTANCES_URL + '/' + this.instanceID).subscribe((nsData: NSDDetails[]): void => {
226 nsData['vnfd-id'].forEach((vnfdID: string[]): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530227 this.restService.getResource(environment.VNFPACKAGES_URL + '/' + vnfdID)
Barath Kumar R1a34b832021-03-05 11:32:19 +0530228 .subscribe((vnfd: VNFD): void => {
229 vnfd.vdu.forEach((vduData: VDU): void => {
230 if (vduData['monitoring-parameter'] !== undefined && vduData['monitoring-parameter'].length > 0) {
Barath Kumar R07698ab2021-03-30 11:50:42 +0530231 this.isLoadingNSInstanceAction = false;
Barath Kumar R1a34b832021-03-05 11:32:19 +0530232 const location: string = environment.GRAFANA_URL + '/' + this.instanceID + '/osm-ns-metrics-metrics';
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530233 // eslint-disable-next-line security/detect-non-literal-fs-filename
Barath Kumar R1a34b832021-03-05 11:32:19 +0530234 window.open(location);
235 } else {
Barath Kumar R07698ab2021-03-30 11:50:42 +0530236 this.isLoadingNSInstanceAction = false;
SANDHYA.JS9bae4602022-04-05 07:28:32 +0530237 this.notifierService.notify('error', this.translateService.instant('PAGE.NSMETRIC.METRICERROR'));
Barath Kumar R1a34b832021-03-05 11:32:19 +0530238 }
239 });
Barath Kumar R07698ab2021-03-30 11:50:42 +0530240 this.doChanges();
Barath Kumar R1a34b832021-03-05 11:32:19 +0530241 }, (error: ERRORDATA): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530242 this.restService.handleError(error, 'get');
Barath Kumar R07698ab2021-03-30 11:50:42 +0530243 this.isLoadingNSInstanceAction = false;
kumaran.m3b4814a2020-05-01 19:48:54 +0530244 });
245 });
Barath Kumar R1a34b832021-03-05 11:32:19 +0530246 }, (error: ERRORDATA): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530247 this.restService.handleError(error, 'get');
Barath Kumar R07698ab2021-03-30 11:50:42 +0530248 this.isLoadingNSInstanceAction = false;
kumaran.m3b4814a2020-05-01 19:48:54 +0530249 });
250 }
Barath Kumar R07698ab2021-03-30 11:50:42 +0530251
252 /**
253 * Do the manual scaling
254 * Here we are going to get a list of VNFD ID used in the instances
255 * and have this in array with URL created then pass to checkscaling method for forkjoin to get the data @public
256 */
257 public manualScaling(): void {
258 this.isLoadingNSInstanceAction = true;
259 const tempURL: Observable<{}>[] = [];
260 this.value.vnfID.forEach((id: string): void => {
261 const apiUrl: string = environment.VNFPACKAGESCONTENT_URL + '/' + id;
262 tempURL.push(this.restService.getResource(apiUrl));
263 });
264 this.checkScaling(tempURL);
265 }
266
267 /**
268 * Used to forkjoin to all the request to send parallely, get the data and check 'scaling-aspect' key is present @public
269 */
270 public checkScaling(URLS: Observable<{}>[]): void {
271 forkJoin(URLS).subscribe((data: VNFD[]): void => {
272 this.vnfDetails = data;
273 if (this.vnfDetails.length > 0) {
274 this.vnfDetails.forEach((vnfdData: VNFD): void => {
275 vnfdData.df.forEach((dfData: DF): void => {
276 if (!isNullOrUndefined(dfData['scaling-aspect']) && dfData['scaling-aspect'].length > 0) {
277 this.isScalingPresent = true;
278 }
279 });
280 });
281 }
282 this.isLoadingNSInstanceAction = false;
283 if (this.isScalingPresent) {
284 this.openScaling();
285 } else {
286 this.notifierService.notify('error', this.translateService.instant('SCALINGNOTFOUND'));
287 }
288 this.doChanges();
289 });
290 }
291
292 /** Open the scaling pop-up @public */
293 public openScaling(): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530294 // eslint-disable-next-line security/detect-non-literal-fs-filename
Barath Kumar R07698ab2021-03-30 11:50:42 +0530295 const modalRef: NgbModalRef = this.modalService.open(ScalingComponent, { backdrop: 'static' });
296 modalRef.componentInstance.params = {
297 id: this.instanceID,
298 vnfID: this.value.vnfID,
299 nsID: this.value['nsd-id'],
300 nsd: this.value.nsd,
301 data: this.vnfDetails
302 };
303 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
304 if (result) {
305 this.sharedService.callData();
306 }
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530307 }).catch((): void => {
308 // Catch Navigation Error
SANDHYA.JS219fe612024-01-23 15:52:43 +0530309 });
Barath Kumar R07698ab2021-03-30 11:50:42 +0530310 }
311
SANDHYA.JSfced3d42022-04-28 20:28:17 +0530312 /** To open VM Migration in NS Instances */
313 public openVmMigration(): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530314 // eslint-disable-next-line security/detect-non-literal-fs-filename
SANDHYA.JSfced3d42022-04-28 20:28:17 +0530315 const modalRef: NgbModalRef = this.modalService.open(VmMigrationComponent, { backdrop: 'static' });
316 modalRef.componentInstance.params = {
317 id: this.instanceID
318 };
319 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
320 if (result) {
321 this.sharedService.callData();
322 }
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530323 }).catch((): void => {
324 // Catch Navigation Error
SANDHYA.JS219fe612024-01-23 15:52:43 +0530325 });
SANDHYA.JSfced3d42022-04-28 20:28:17 +0530326 }
327
SANDHYA.JS99144582022-04-27 17:22:35 +0530328 /** To open the Ns Update pop-up */
329 public openNsUpdate(): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530330 // eslint-disable-next-line security/detect-non-literal-fs-filename
SANDHYA.JS99144582022-04-27 17:22:35 +0530331 const modalRef: NgbModalRef = this.modalService.open(NsUpdateComponent, { backdrop: 'static' });
332 modalRef.componentInstance.params = {
333 id: this.instanceID
334 };
335 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
336 if (result) {
337 this.sharedService.callData();
338 }
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530339 }).catch((): void => {
340 // Catch Navigation Error
SANDHYA.JS219fe612024-01-23 15:52:43 +0530341 });
SANDHYA.JS99144582022-04-27 17:22:35 +0530342 }
343
SANDHYA.JS3d81a282022-05-02 08:25:39 +0530344 /** To open the Start, Stop & Rebuild pop-up */
345 public openStart(actionType: string): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530346 // eslint-disable-next-line security/detect-non-literal-fs-filename
SANDHYA.JS3d81a282022-05-02 08:25:39 +0530347 const modalRef: NgbModalRef = this.modalService.open(StartStopRebuildComponent, { backdrop: 'static' });
348 modalRef.componentInstance.params = {
349 id: this.instanceID
350 };
351 if (actionType === 'start') {
352 modalRef.componentInstance.instanceTitle = this.translateService.instant('START');
353 } else if (actionType === 'stop') {
354 modalRef.componentInstance.instanceTitle = this.translateService.instant('STOP');
355 } else {
356 modalRef.componentInstance.instanceTitle = this.translateService.instant('REBUILD');
357 }
358 modalRef.componentInstance.instanceType = actionType;
359 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
360 if (result) {
361 this.sharedService.callData();
362 }
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530363 }).catch((): void => {
364 // Catch Navigation Error
SANDHYA.JS219fe612024-01-23 15:52:43 +0530365 });
SANDHYA.JS3d81a282022-05-02 08:25:39 +0530366 }
367
Isabel Lloret523d6752025-04-29 08:06:54 +0000368 /** Open the show remote console pop-up @public */
369 public openConsole(): void {
370 const modalRef: NgbModalRef = this.modalService.open(ShowVduConsoleComponent, { backdrop: 'static' });
371 modalRef.componentInstance.params = {
372 id: this.instanceID
373 };
374 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
375 if (result) {
376 this.sharedService.callData();
377 }
378 }).catch((): void => {
379 // Catch Navigation Error
380 });
381 }
382
SANDHYA.JS219fe612024-01-23 15:52:43 +0530383 /** Open the Healing pop-up @public */
384 public openHealing(): void {
385 // eslint-disable-next-line security/detect-non-literal-fs-filename
386 const modalRef: NgbModalRef = this.modalService.open(HealingComponent, { backdrop: 'static' });
387 modalRef.componentInstance.params = {
388 id: this.instanceID
389 };
390 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
391 if (result) {
392 this.sharedService.callData();
393 }
394 }).catch((): void => {
395 // Catch Navigation Error
396 });
SANDHYA.JS017df362022-05-02 06:57:11 +0530397 }
398
Barath Kumar R07698ab2021-03-30 11:50:42 +0530399 /**
400 * Check any changes in the child component @public
401 */
402 public doChanges(): void {
403 setTimeout((): void => {
404 this.cd.detectChanges();
405 }, this.timeOut);
406 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530407}