blob: 08e5e97272e8d4479100d591b9a3997af03f5c2c [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 */
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +053021import { isNullOrUndefined } from 'util';
kumaran.m3b4814a2020-05-01 19:48:54 +053022import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Injector } from '@angular/core';
23import { Router } from '@angular/router';
24import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
25import { TranslateService } from '@ngx-translate/core';
26import { NotifierService } from 'angular-notifier';
27import { ERRORDATA, MODALCLOSERESPONSEDATA } from 'CommonModel';
28import { DeleteComponent } from 'DeleteComponent';
29import { environment } from 'environment';
SANDHYA.JS219fe612024-01-23 15:52:43 +053030import { HealingComponent } from 'HealingComponent';
kumaran.m3b4814a2020-05-01 19:48:54 +053031import { NSDDetails } from 'NSDModel';
32import { NSDInstanceData } from 'NSInstanceModel';
33import { NSPrimitiveComponent } from 'NSPrimitiveComponent';
SANDHYA.JS99144582022-04-27 17:22:35 +053034import { NsUpdateComponent } from 'NsUpdateComponent';
kumaran.m3b4814a2020-05-01 19:48:54 +053035import { RestService } from 'RestService';
Barath Kumar R07698ab2021-03-30 11:50:42 +053036import { forkJoin, Observable } from 'rxjs';
37import { ScalingComponent } from 'ScalingComponent';
kumaran.m3b4814a2020-05-01 19:48:54 +053038import { SharedService } from 'SharedService';
39import { ShowInfoComponent } from 'ShowInfoComponent';
SANDHYA.JS3d81a282022-05-02 08:25:39 +053040import { StartStopRebuildComponent } from 'StartStopRebuildComponent';
SANDHYA.JS017df362022-05-02 06:57:11 +053041import { VerticalScalingComponent } from 'VerticalScalingComponent';
SANDHYA.JSfced3d42022-04-28 20:28:17 +053042import { VmMigrationComponent } from 'VmMigrationComponent';
Barath Kumar R07698ab2021-03-30 11:50:42 +053043import { DF, VDU, VNFD } from 'VNFDModel';
kumaran.m3b4814a2020-05-01 19:48:54 +053044/**
45 * Creating component
46 * @Component takes NSInstancesActionComponent.html as template url
47 */
48@Component({
49 templateUrl: './NSInstancesActionComponent.html',
50 styleUrls: ['./NSInstancesActionComponent.scss'],
51 changeDetection: ChangeDetectionStrategy.OnPush
52})
53/** Exporting a class @exports NSInstancesActionComponent */
54export class NSInstancesActionComponent {
55 /** To get the value from the nspackage via valuePrepareFunction default Property of ng-smarttable @public */
56 public value: NSDInstanceData;
57
58 /** Invoke service injectors @public */
59 public injector: Injector;
60
61 /** Instance of the modal service @public */
62 public restService: RestService;
63
64 /** Config Status Check @public */
65 public configStatus: string;
66
67 /** Operational Status Check @public */
68 public operationalStatus: string;
69
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +053070 /** CNF Status Check @public */
71 public k8sStatus: boolean = false;
72
Barath Kumar R07698ab2021-03-30 11:50:42 +053073 /** get Admin Details @public */
74 public getAdminDetails: {};
75
76 /** Scaling is accepted @public */
77 public isScalingPresent: boolean = false;
78
kumaran.m3b4814a2020-05-01 19:48:54 +053079 /** Check the loading results for loader status @public */
Barath Kumar R07698ab2021-03-30 11:50:42 +053080 public isLoadingNSInstanceAction: boolean = false;
kumaran.m3b4814a2020-05-01 19:48:54 +053081
82 /** Give the message for the loading @public */
83 public message: string = 'PLEASEWAIT';
84
Barath Kumar R07698ab2021-03-30 11:50:42 +053085 /** Assign the VNF Details @public */
86 public vnfDetails: VNFD[] = [];
87
Barath Kumar Rf2ae5462021-03-01 12:52:33 +053088 /** Contains instance ID @public */
89 public instanceID: string;
90
91 /** Contains operational dashboard view @public */
92 public isShowOperationalDashboard: boolean = false;
93
kumaran.m3b4814a2020-05-01 19:48:54 +053094 /** Instance of the modal service @private */
95 private modalService: NgbModal;
96
97 /** Holds teh instance of AuthService class of type AuthService @private */
98 private router: Router;
99
kumaran.m3b4814a2020-05-01 19:48:54 +0530100 /** Contains all methods related to shared @private */
101 private sharedService: SharedService;
102
103 /** Notifier service to popup notification @private */
104 private notifierService: NotifierService;
105
106 /** Contains tranlsate instance @private */
107 private translateService: TranslateService;
108
109 /** Detect changes for the User Input */
110 private cd: ChangeDetectorRef;
111
112 /** Set timeout @private */
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530113 // eslint-disable-next-line @typescript-eslint/no-magic-numbers
Barath Kumar R07698ab2021-03-30 11:50:42 +0530114 private timeOut: number = 100;
kumaran.m3b4814a2020-05-01 19:48:54 +0530115
116 constructor(injector: Injector) {
117 this.injector = injector;
118 this.modalService = this.injector.get(NgbModal);
119 this.restService = this.injector.get(RestService);
120 this.router = this.injector.get(Router);
121 this.sharedService = this.injector.get(SharedService);
122 this.notifierService = this.injector.get(NotifierService);
123 this.translateService = this.injector.get(TranslateService);
124 this.cd = this.injector.get(ChangeDetectorRef);
125 }
126
127 /**
128 * Lifecyle Hooks the trigger before component is instantiate
129 */
130 public ngOnInit(): void {
131 this.configStatus = this.value.ConfigStatus;
132 this.operationalStatus = this.value.OperationalStatus;
133 this.instanceID = this.value.identifier;
Barath Kumar R07698ab2021-03-30 11:50:42 +0530134 this.getAdminDetails = this.value.adminDetails;
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530135 for (const key of Object.keys(this.getAdminDetails)) {
136 if (key === 'deployed') {
137 // eslint-disable-next-line security/detect-object-injection
138 const adminData: {} = this.getAdminDetails[key];
139 for (const k8sData of Object.keys(adminData)) {
140 if (k8sData === 'K8s') {
141 // eslint-disable-next-line security/detect-object-injection
142 if (adminData[k8sData].length !== 0) {
143 this.k8sStatus = true;
144 }
145 }
146 }
147 }
148 }
Barath Kumar Rf2ae5462021-03-01 12:52:33 +0530149 this.isShowOperationalDashboard = !isNullOrUndefined(this.value.vcaStatus) ?
150 Object.keys(this.value.vcaStatus).length === 0 && typeof this.value.vcaStatus === 'object' : true;
kumaran.m3b4814a2020-05-01 19:48:54 +0530151 }
152
153 /** Shows information using modalservice @public */
154 public infoNs(): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530155 // eslint-disable-next-line security/detect-non-literal-fs-filename
kumaran.m3b4814a2020-05-01 19:48:54 +0530156 this.modalService.open(ShowInfoComponent, { backdrop: 'static' }).componentInstance.params = {
157 id: this.instanceID,
158 page: 'ns-instance',
159 titleName: 'INSTANCEDETAILS'
160 };
161 }
162
163 /** Delete NS Instanace @public */
164 public deleteNSInstance(forceAction: boolean): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530165 // eslint-disable-next-line security/detect-non-literal-fs-filename
kumaran.m3b4814a2020-05-01 19:48:54 +0530166 const modalRef: NgbModalRef = this.modalService.open(DeleteComponent, { backdrop: 'static' });
167 modalRef.componentInstance.params = { forceDeleteType: forceAction };
Barath Kumar R1a34b832021-03-05 11:32:19 +0530168 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530169 if (result) {
170 this.sharedService.callData();
171 }
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530172 }).catch((): void => {
173 // Catch Navigation Error
SANDHYA.JS219fe612024-01-23 15:52:43 +0530174 });
kumaran.m3b4814a2020-05-01 19:48:54 +0530175 }
176
177 /** History of operations for an Instanace @public */
178 public historyOfOperations(): void {
Barath Kumar R1a34b832021-03-05 11:32:19 +0530179 this.router.navigate(['/instances/ns/history-operations/', this.instanceID]).catch((): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530180 // Catch Navigation Error
181 });
182 }
183
184 /** NS Topology */
185 public nsTopology(): void {
Barath Kumar R1a34b832021-03-05 11:32:19 +0530186 this.router.navigate(['/instances/ns/', this.instanceID]).catch((): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530187 // Catch Navigation Error
188 });
189 }
190
191 /** Exec NS Primitive @public */
192 public execNSPrimitiveModal(): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530193 // eslint-disable-next-line security/detect-non-literal-fs-filename
Barath Kumar Rd3ce0c52020-08-13 11:44:01 +0530194 this.modalService.open(NSPrimitiveComponent, { backdrop: 'static' }).componentInstance.params = {
kumaran.m3b4814a2020-05-01 19:48:54 +0530195 memberIndex: this.value.memberIndex,
Barath Kumar R54d693c2020-07-13 20:54:13 +0530196 nsConfig: this.value.nsConfig,
SANDHYA.JS1584e3e2022-10-31 20:11:50 +0530197 name: this.value.NsdName,
198 id: this.value.constituent
kumaran.m3b4814a2020-05-01 19:48:54 +0530199 };
200 }
201
202 /** Redirect to Grafana Metrics @public */
203 public metrics(): void {
Barath Kumar R07698ab2021-03-30 11:50:42 +0530204 this.isLoadingNSInstanceAction = true;
Barath Kumar R1a34b832021-03-05 11:32:19 +0530205 this.restService.getResource(environment.NSDINSTANCES_URL + '/' + this.instanceID).subscribe((nsData: NSDDetails[]): void => {
206 nsData['vnfd-id'].forEach((vnfdID: string[]): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530207 this.restService.getResource(environment.VNFPACKAGES_URL + '/' + vnfdID)
Barath Kumar R1a34b832021-03-05 11:32:19 +0530208 .subscribe((vnfd: VNFD): void => {
209 vnfd.vdu.forEach((vduData: VDU): void => {
210 if (vduData['monitoring-parameter'] !== undefined && vduData['monitoring-parameter'].length > 0) {
Barath Kumar R07698ab2021-03-30 11:50:42 +0530211 this.isLoadingNSInstanceAction = false;
Barath Kumar R1a34b832021-03-05 11:32:19 +0530212 const location: string = environment.GRAFANA_URL + '/' + this.instanceID + '/osm-ns-metrics-metrics';
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530213 // eslint-disable-next-line security/detect-non-literal-fs-filename
Barath Kumar R1a34b832021-03-05 11:32:19 +0530214 window.open(location);
215 } else {
Barath Kumar R07698ab2021-03-30 11:50:42 +0530216 this.isLoadingNSInstanceAction = false;
SANDHYA.JS9bae4602022-04-05 07:28:32 +0530217 this.notifierService.notify('error', this.translateService.instant('PAGE.NSMETRIC.METRICERROR'));
Barath Kumar R1a34b832021-03-05 11:32:19 +0530218 }
219 });
Barath Kumar R07698ab2021-03-30 11:50:42 +0530220 this.doChanges();
Barath Kumar R1a34b832021-03-05 11:32:19 +0530221 }, (error: ERRORDATA): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530222 this.restService.handleError(error, 'get');
Barath Kumar R07698ab2021-03-30 11:50:42 +0530223 this.isLoadingNSInstanceAction = false;
kumaran.m3b4814a2020-05-01 19:48:54 +0530224 });
225 });
Barath Kumar R1a34b832021-03-05 11:32:19 +0530226 }, (error: ERRORDATA): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530227 this.restService.handleError(error, 'get');
Barath Kumar R07698ab2021-03-30 11:50:42 +0530228 this.isLoadingNSInstanceAction = false;
kumaran.m3b4814a2020-05-01 19:48:54 +0530229 });
230 }
Barath Kumar R07698ab2021-03-30 11:50:42 +0530231
232 /**
233 * Do the manual scaling
234 * Here we are going to get a list of VNFD ID used in the instances
235 * and have this in array with URL created then pass to checkscaling method for forkjoin to get the data @public
236 */
237 public manualScaling(): void {
238 this.isLoadingNSInstanceAction = true;
239 const tempURL: Observable<{}>[] = [];
240 this.value.vnfID.forEach((id: string): void => {
241 const apiUrl: string = environment.VNFPACKAGESCONTENT_URL + '/' + id;
242 tempURL.push(this.restService.getResource(apiUrl));
243 });
244 this.checkScaling(tempURL);
245 }
246
247 /**
248 * Used to forkjoin to all the request to send parallely, get the data and check 'scaling-aspect' key is present @public
249 */
250 public checkScaling(URLS: Observable<{}>[]): void {
251 forkJoin(URLS).subscribe((data: VNFD[]): void => {
252 this.vnfDetails = data;
253 if (this.vnfDetails.length > 0) {
254 this.vnfDetails.forEach((vnfdData: VNFD): void => {
255 vnfdData.df.forEach((dfData: DF): void => {
256 if (!isNullOrUndefined(dfData['scaling-aspect']) && dfData['scaling-aspect'].length > 0) {
257 this.isScalingPresent = true;
258 }
259 });
260 });
261 }
262 this.isLoadingNSInstanceAction = false;
263 if (this.isScalingPresent) {
264 this.openScaling();
265 } else {
266 this.notifierService.notify('error', this.translateService.instant('SCALINGNOTFOUND'));
267 }
268 this.doChanges();
269 });
270 }
271
272 /** Open the scaling pop-up @public */
273 public openScaling(): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530274 // eslint-disable-next-line security/detect-non-literal-fs-filename
Barath Kumar R07698ab2021-03-30 11:50:42 +0530275 const modalRef: NgbModalRef = this.modalService.open(ScalingComponent, { backdrop: 'static' });
276 modalRef.componentInstance.params = {
277 id: this.instanceID,
278 vnfID: this.value.vnfID,
279 nsID: this.value['nsd-id'],
280 nsd: this.value.nsd,
281 data: this.vnfDetails
282 };
283 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
284 if (result) {
285 this.sharedService.callData();
286 }
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530287 }).catch((): void => {
288 // Catch Navigation Error
SANDHYA.JS219fe612024-01-23 15:52:43 +0530289 });
Barath Kumar R07698ab2021-03-30 11:50:42 +0530290 }
291
SANDHYA.JSfced3d42022-04-28 20:28:17 +0530292 /** To open VM Migration in NS Instances */
293 public openVmMigration(): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530294 // eslint-disable-next-line security/detect-non-literal-fs-filename
SANDHYA.JSfced3d42022-04-28 20:28:17 +0530295 const modalRef: NgbModalRef = this.modalService.open(VmMigrationComponent, { backdrop: 'static' });
296 modalRef.componentInstance.params = {
297 id: this.instanceID
298 };
299 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
300 if (result) {
301 this.sharedService.callData();
302 }
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530303 }).catch((): void => {
304 // Catch Navigation Error
SANDHYA.JS219fe612024-01-23 15:52:43 +0530305 });
SANDHYA.JSfced3d42022-04-28 20:28:17 +0530306 }
307
SANDHYA.JS99144582022-04-27 17:22:35 +0530308 /** To open the Ns Update pop-up */
309 public openNsUpdate(): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530310 // eslint-disable-next-line security/detect-non-literal-fs-filename
SANDHYA.JS99144582022-04-27 17:22:35 +0530311 const modalRef: NgbModalRef = this.modalService.open(NsUpdateComponent, { backdrop: 'static' });
312 modalRef.componentInstance.params = {
313 id: this.instanceID
314 };
315 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
316 if (result) {
317 this.sharedService.callData();
318 }
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530319 }).catch((): void => {
320 // Catch Navigation Error
SANDHYA.JS219fe612024-01-23 15:52:43 +0530321 });
SANDHYA.JS99144582022-04-27 17:22:35 +0530322 }
323
SANDHYA.JS3d81a282022-05-02 08:25:39 +0530324 /** To open the Start, Stop & Rebuild pop-up */
325 public openStart(actionType: string): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530326 // eslint-disable-next-line security/detect-non-literal-fs-filename
SANDHYA.JS3d81a282022-05-02 08:25:39 +0530327 const modalRef: NgbModalRef = this.modalService.open(StartStopRebuildComponent, { backdrop: 'static' });
328 modalRef.componentInstance.params = {
329 id: this.instanceID
330 };
331 if (actionType === 'start') {
332 modalRef.componentInstance.instanceTitle = this.translateService.instant('START');
333 } else if (actionType === 'stop') {
334 modalRef.componentInstance.instanceTitle = this.translateService.instant('STOP');
335 } else {
336 modalRef.componentInstance.instanceTitle = this.translateService.instant('REBUILD');
337 }
338 modalRef.componentInstance.instanceType = actionType;
339 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
340 if (result) {
341 this.sharedService.callData();
342 }
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530343 }).catch((): void => {
344 // Catch Navigation Error
SANDHYA.JS219fe612024-01-23 15:52:43 +0530345 });
SANDHYA.JS3d81a282022-05-02 08:25:39 +0530346 }
347
SANDHYA.JS017df362022-05-02 06:57:11 +0530348 /** To open the vertical Scaling pop-up */
349 public openVerticalScaling(): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530350 // eslint-disable-next-line security/detect-non-literal-fs-filename
SANDHYA.JS017df362022-05-02 06:57:11 +0530351 const modalRef: NgbModalRef = this.modalService.open(VerticalScalingComponent, { backdrop: 'static' });
352 modalRef.componentInstance.params = {
353 id: this.instanceID
354 };
355 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
356 if (result) {
357 this.sharedService.callData();
358 }
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530359 }).catch((): void => {
360 // Catch Navigation Error
SANDHYA.JS219fe612024-01-23 15:52:43 +0530361 });
362 }
363
364 /** Open the Healing pop-up @public */
365 public openHealing(): void {
366 // eslint-disable-next-line security/detect-non-literal-fs-filename
367 const modalRef: NgbModalRef = this.modalService.open(HealingComponent, { backdrop: 'static' });
368 modalRef.componentInstance.params = {
369 id: this.instanceID
370 };
371 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
372 if (result) {
373 this.sharedService.callData();
374 }
375 }).catch((): void => {
376 // Catch Navigation Error
377 });
SANDHYA.JS017df362022-05-02 06:57:11 +0530378 }
379
Barath Kumar R07698ab2021-03-30 11:50:42 +0530380 /**
381 * Check any changes in the child component @public
382 */
383 public doChanges(): void {
384 setTimeout((): void => {
385 this.cd.detectChanges();
386 }, this.timeOut);
387 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530388}