blob: 8ae776ffdb3e992a0ea27bd6fc547ee170eea08e [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';
SANDHYA.JS3d81a282022-05-02 08:25:39 +053039import { StartStopRebuildComponent } from 'StartStopRebuildComponent';
SANDHYA.JSfced3d42022-04-28 20:28:17 +053040import { VmMigrationComponent } from 'VmMigrationComponent';
Barath Kumar R07698ab2021-03-30 11:50:42 +053041import { DF, VDU, VNFD } from 'VNFDModel';
kumaran.m3b4814a2020-05-01 19:48:54 +053042/**
43 * Creating component
44 * @Component takes NSInstancesActionComponent.html as template url
45 */
46@Component({
47 templateUrl: './NSInstancesActionComponent.html',
48 styleUrls: ['./NSInstancesActionComponent.scss'],
49 changeDetection: ChangeDetectionStrategy.OnPush
50})
51/** Exporting a class @exports NSInstancesActionComponent */
52export class NSInstancesActionComponent {
53 /** To get the value from the nspackage via valuePrepareFunction default Property of ng-smarttable @public */
54 public value: NSDInstanceData;
55
56 /** Invoke service injectors @public */
57 public injector: Injector;
58
59 /** Instance of the modal service @public */
60 public restService: RestService;
61
62 /** Config Status Check @public */
63 public configStatus: string;
64
65 /** Operational Status Check @public */
66 public operationalStatus: string;
67
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +053068 /** CNF Status Check @public */
69 public k8sStatus: boolean = false;
70
Barath Kumar R07698ab2021-03-30 11:50:42 +053071 /** get Admin Details @public */
72 public getAdminDetails: {};
73
74 /** Scaling is accepted @public */
75 public isScalingPresent: boolean = false;
76
kumaran.m3b4814a2020-05-01 19:48:54 +053077 /** Check the loading results for loader status @public */
Barath Kumar R07698ab2021-03-30 11:50:42 +053078 public isLoadingNSInstanceAction: boolean = false;
kumaran.m3b4814a2020-05-01 19:48:54 +053079
80 /** Give the message for the loading @public */
81 public message: string = 'PLEASEWAIT';
82
Barath Kumar R07698ab2021-03-30 11:50:42 +053083 /** Assign the VNF Details @public */
84 public vnfDetails: VNFD[] = [];
85
Barath Kumar Rf2ae5462021-03-01 12:52:33 +053086 /** Contains instance ID @public */
87 public instanceID: string;
88
89 /** Contains operational dashboard view @public */
90 public isShowOperationalDashboard: boolean = false;
91
kumaran.m3b4814a2020-05-01 19:48:54 +053092 /** Instance of the modal service @private */
93 private modalService: NgbModal;
94
95 /** Holds teh instance of AuthService class of type AuthService @private */
96 private router: Router;
97
kumaran.m3b4814a2020-05-01 19:48:54 +053098 /** Contains all methods related to shared @private */
99 private sharedService: SharedService;
100
101 /** Notifier service to popup notification @private */
102 private notifierService: NotifierService;
103
104 /** Contains tranlsate instance @private */
105 private translateService: TranslateService;
106
107 /** Detect changes for the User Input */
108 private cd: ChangeDetectorRef;
109
110 /** Set timeout @private */
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530111 // eslint-disable-next-line @typescript-eslint/no-magic-numbers
Barath Kumar R07698ab2021-03-30 11:50:42 +0530112 private timeOut: number = 100;
kumaran.m3b4814a2020-05-01 19:48:54 +0530113
114 constructor(injector: Injector) {
115 this.injector = injector;
116 this.modalService = this.injector.get(NgbModal);
117 this.restService = this.injector.get(RestService);
118 this.router = this.injector.get(Router);
119 this.sharedService = this.injector.get(SharedService);
120 this.notifierService = this.injector.get(NotifierService);
121 this.translateService = this.injector.get(TranslateService);
122 this.cd = this.injector.get(ChangeDetectorRef);
123 }
124
125 /**
126 * Lifecyle Hooks the trigger before component is instantiate
127 */
128 public ngOnInit(): void {
129 this.configStatus = this.value.ConfigStatus;
130 this.operationalStatus = this.value.OperationalStatus;
131 this.instanceID = this.value.identifier;
Barath Kumar R07698ab2021-03-30 11:50:42 +0530132 this.getAdminDetails = this.value.adminDetails;
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530133 for (const key of Object.keys(this.getAdminDetails)) {
134 if (key === 'deployed') {
135 // eslint-disable-next-line security/detect-object-injection
136 const adminData: {} = this.getAdminDetails[key];
137 for (const k8sData of Object.keys(adminData)) {
138 if (k8sData === 'K8s') {
139 // eslint-disable-next-line security/detect-object-injection
140 if (adminData[k8sData].length !== 0) {
141 this.k8sStatus = true;
142 }
143 }
144 }
145 }
146 }
Barath Kumar Rf2ae5462021-03-01 12:52:33 +0530147 this.isShowOperationalDashboard = !isNullOrUndefined(this.value.vcaStatus) ?
148 Object.keys(this.value.vcaStatus).length === 0 && typeof this.value.vcaStatus === 'object' : true;
kumaran.m3b4814a2020-05-01 19:48:54 +0530149 }
150
151 /** Shows information using modalservice @public */
152 public infoNs(): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530153 // eslint-disable-next-line security/detect-non-literal-fs-filename
kumaran.m3b4814a2020-05-01 19:48:54 +0530154 this.modalService.open(ShowInfoComponent, { backdrop: 'static' }).componentInstance.params = {
155 id: this.instanceID,
156 page: 'ns-instance',
157 titleName: 'INSTANCEDETAILS'
158 };
159 }
160
161 /** Delete NS Instanace @public */
162 public deleteNSInstance(forceAction: boolean): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530163 // eslint-disable-next-line security/detect-non-literal-fs-filename
kumaran.m3b4814a2020-05-01 19:48:54 +0530164 const modalRef: NgbModalRef = this.modalService.open(DeleteComponent, { backdrop: 'static' });
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530165 modalRef.componentInstance.params = {
166 forceDeleteType: forceAction,
167 name: this.value.name,
168 page: 'ns-instance',
169 id: this.instanceID
170 };
Barath Kumar R1a34b832021-03-05 11:32:19 +0530171 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530172 if (result) {
173 this.sharedService.callData();
174 }
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530175 }).catch((): void => {
176 // Catch Navigation Error
SANDHYA.JS219fe612024-01-23 15:52:43 +0530177 });
kumaran.m3b4814a2020-05-01 19:48:54 +0530178 }
179
180 /** History of operations for an Instanace @public */
181 public historyOfOperations(): void {
Barath Kumar R1a34b832021-03-05 11:32:19 +0530182 this.router.navigate(['/instances/ns/history-operations/', this.instanceID]).catch((): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530183 // Catch Navigation Error
184 });
185 }
186
187 /** NS Topology */
188 public nsTopology(): void {
Barath Kumar R1a34b832021-03-05 11:32:19 +0530189 this.router.navigate(['/instances/ns/', this.instanceID]).catch((): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530190 // Catch Navigation Error
191 });
192 }
193
194 /** Exec NS Primitive @public */
195 public execNSPrimitiveModal(): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530196 // eslint-disable-next-line security/detect-non-literal-fs-filename
Barath Kumar Rd3ce0c52020-08-13 11:44:01 +0530197 this.modalService.open(NSPrimitiveComponent, { backdrop: 'static' }).componentInstance.params = {
kumaran.m3b4814a2020-05-01 19:48:54 +0530198 memberIndex: this.value.memberIndex,
Barath Kumar R54d693c2020-07-13 20:54:13 +0530199 nsConfig: this.value.nsConfig,
SANDHYA.JS1584e3e2022-10-31 20:11:50 +0530200 name: this.value.NsdName,
SANDHYA.JSa53db0c2025-05-23 11:44:39 +0530201 id: this.value.constituent,
202 nsID: this.instanceID
kumaran.m3b4814a2020-05-01 19:48:54 +0530203 };
204 }
205
206 /** Redirect to Grafana Metrics @public */
207 public metrics(): void {
Barath Kumar R07698ab2021-03-30 11:50:42 +0530208 this.isLoadingNSInstanceAction = true;
Barath Kumar R1a34b832021-03-05 11:32:19 +0530209 this.restService.getResource(environment.NSDINSTANCES_URL + '/' + this.instanceID).subscribe((nsData: NSDDetails[]): void => {
210 nsData['vnfd-id'].forEach((vnfdID: string[]): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530211 this.restService.getResource(environment.VNFPACKAGES_URL + '/' + vnfdID)
Barath Kumar R1a34b832021-03-05 11:32:19 +0530212 .subscribe((vnfd: VNFD): void => {
213 vnfd.vdu.forEach((vduData: VDU): void => {
214 if (vduData['monitoring-parameter'] !== undefined && vduData['monitoring-parameter'].length > 0) {
Barath Kumar R07698ab2021-03-30 11:50:42 +0530215 this.isLoadingNSInstanceAction = false;
Barath Kumar R1a34b832021-03-05 11:32:19 +0530216 const location: string = environment.GRAFANA_URL + '/' + this.instanceID + '/osm-ns-metrics-metrics';
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530217 // eslint-disable-next-line security/detect-non-literal-fs-filename
Barath Kumar R1a34b832021-03-05 11:32:19 +0530218 window.open(location);
219 } else {
Barath Kumar R07698ab2021-03-30 11:50:42 +0530220 this.isLoadingNSInstanceAction = false;
SANDHYA.JS9bae4602022-04-05 07:28:32 +0530221 this.notifierService.notify('error', this.translateService.instant('PAGE.NSMETRIC.METRICERROR'));
Barath Kumar R1a34b832021-03-05 11:32:19 +0530222 }
223 });
Barath Kumar R07698ab2021-03-30 11:50:42 +0530224 this.doChanges();
Barath Kumar R1a34b832021-03-05 11:32:19 +0530225 }, (error: ERRORDATA): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530226 this.restService.handleError(error, 'get');
Barath Kumar R07698ab2021-03-30 11:50:42 +0530227 this.isLoadingNSInstanceAction = false;
kumaran.m3b4814a2020-05-01 19:48:54 +0530228 });
229 });
Barath Kumar R1a34b832021-03-05 11:32:19 +0530230 }, (error: ERRORDATA): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530231 this.restService.handleError(error, 'get');
Barath Kumar R07698ab2021-03-30 11:50:42 +0530232 this.isLoadingNSInstanceAction = false;
kumaran.m3b4814a2020-05-01 19:48:54 +0530233 });
234 }
Barath Kumar R07698ab2021-03-30 11:50:42 +0530235
236 /**
237 * Do the manual scaling
238 * Here we are going to get a list of VNFD ID used in the instances
239 * and have this in array with URL created then pass to checkscaling method for forkjoin to get the data @public
240 */
241 public manualScaling(): void {
242 this.isLoadingNSInstanceAction = true;
243 const tempURL: Observable<{}>[] = [];
244 this.value.vnfID.forEach((id: string): void => {
245 const apiUrl: string = environment.VNFPACKAGESCONTENT_URL + '/' + id;
246 tempURL.push(this.restService.getResource(apiUrl));
247 });
248 this.checkScaling(tempURL);
249 }
250
251 /**
252 * Used to forkjoin to all the request to send parallely, get the data and check 'scaling-aspect' key is present @public
253 */
254 public checkScaling(URLS: Observable<{}>[]): void {
255 forkJoin(URLS).subscribe((data: VNFD[]): void => {
256 this.vnfDetails = data;
257 if (this.vnfDetails.length > 0) {
258 this.vnfDetails.forEach((vnfdData: VNFD): void => {
259 vnfdData.df.forEach((dfData: DF): void => {
260 if (!isNullOrUndefined(dfData['scaling-aspect']) && dfData['scaling-aspect'].length > 0) {
261 this.isScalingPresent = true;
262 }
263 });
264 });
265 }
266 this.isLoadingNSInstanceAction = false;
267 if (this.isScalingPresent) {
268 this.openScaling();
269 } else {
270 this.notifierService.notify('error', this.translateService.instant('SCALINGNOTFOUND'));
271 }
272 this.doChanges();
273 });
274 }
275
276 /** Open the scaling pop-up @public */
277 public openScaling(): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530278 // eslint-disable-next-line security/detect-non-literal-fs-filename
Barath Kumar R07698ab2021-03-30 11:50:42 +0530279 const modalRef: NgbModalRef = this.modalService.open(ScalingComponent, { backdrop: 'static' });
280 modalRef.componentInstance.params = {
281 id: this.instanceID,
282 vnfID: this.value.vnfID,
283 nsID: this.value['nsd-id'],
284 nsd: this.value.nsd,
285 data: this.vnfDetails
286 };
287 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
288 if (result) {
289 this.sharedService.callData();
290 }
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530291 }).catch((): void => {
292 // Catch Navigation Error
SANDHYA.JS219fe612024-01-23 15:52:43 +0530293 });
Barath Kumar R07698ab2021-03-30 11:50:42 +0530294 }
295
SANDHYA.JSfced3d42022-04-28 20:28:17 +0530296 /** To open VM Migration in NS Instances */
297 public openVmMigration(): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530298 // eslint-disable-next-line security/detect-non-literal-fs-filename
SANDHYA.JSfced3d42022-04-28 20:28:17 +0530299 const modalRef: NgbModalRef = this.modalService.open(VmMigrationComponent, { backdrop: 'static' });
300 modalRef.componentInstance.params = {
301 id: this.instanceID
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 });
SANDHYA.JSfced3d42022-04-28 20:28:17 +0530310 }
311
SANDHYA.JS99144582022-04-27 17:22:35 +0530312 /** To open the Ns Update pop-up */
313 public openNsUpdate(): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530314 // eslint-disable-next-line security/detect-non-literal-fs-filename
SANDHYA.JS99144582022-04-27 17:22:35 +0530315 const modalRef: NgbModalRef = this.modalService.open(NsUpdateComponent, { 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.JS99144582022-04-27 17:22:35 +0530326 }
327
SANDHYA.JS3d81a282022-05-02 08:25:39 +0530328 /** To open the Start, Stop & Rebuild pop-up */
329 public openStart(actionType: string): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530330 // eslint-disable-next-line security/detect-non-literal-fs-filename
SANDHYA.JS3d81a282022-05-02 08:25:39 +0530331 const modalRef: NgbModalRef = this.modalService.open(StartStopRebuildComponent, { backdrop: 'static' });
332 modalRef.componentInstance.params = {
333 id: this.instanceID
334 };
335 if (actionType === 'start') {
336 modalRef.componentInstance.instanceTitle = this.translateService.instant('START');
337 } else if (actionType === 'stop') {
338 modalRef.componentInstance.instanceTitle = this.translateService.instant('STOP');
339 } else {
340 modalRef.componentInstance.instanceTitle = this.translateService.instant('REBUILD');
341 }
342 modalRef.componentInstance.instanceType = actionType;
343 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
344 if (result) {
345 this.sharedService.callData();
346 }
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530347 }).catch((): void => {
348 // Catch Navigation Error
SANDHYA.JS219fe612024-01-23 15:52:43 +0530349 });
SANDHYA.JS3d81a282022-05-02 08:25:39 +0530350 }
351
SANDHYA.JS219fe612024-01-23 15:52:43 +0530352 /** Open the Healing pop-up @public */
353 public openHealing(): void {
354 // eslint-disable-next-line security/detect-non-literal-fs-filename
355 const modalRef: NgbModalRef = this.modalService.open(HealingComponent, { backdrop: 'static' });
356 modalRef.componentInstance.params = {
357 id: this.instanceID
358 };
359 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
360 if (result) {
361 this.sharedService.callData();
362 }
363 }).catch((): void => {
364 // Catch Navigation Error
365 });
SANDHYA.JS017df362022-05-02 06:57:11 +0530366 }
367
Barath Kumar R07698ab2021-03-30 11:50:42 +0530368 /**
369 * Check any changes in the child component @public
370 */
371 public doChanges(): void {
372 setTimeout((): void => {
373 this.cd.detectChanges();
374 }, this.timeOut);
375 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530376}