blob: 74f151829377c11a95ec318c3b1c8e5e1f587408 [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,
201 id: this.value.constituent
kumaran.m3b4814a2020-05-01 19:48:54 +0530202 };
203 }
204
205 /** Redirect to Grafana Metrics @public */
206 public metrics(): void {
Barath Kumar R07698ab2021-03-30 11:50:42 +0530207 this.isLoadingNSInstanceAction = true;
Barath Kumar R1a34b832021-03-05 11:32:19 +0530208 this.restService.getResource(environment.NSDINSTANCES_URL + '/' + this.instanceID).subscribe((nsData: NSDDetails[]): void => {
209 nsData['vnfd-id'].forEach((vnfdID: string[]): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530210 this.restService.getResource(environment.VNFPACKAGES_URL + '/' + vnfdID)
Barath Kumar R1a34b832021-03-05 11:32:19 +0530211 .subscribe((vnfd: VNFD): void => {
212 vnfd.vdu.forEach((vduData: VDU): void => {
213 if (vduData['monitoring-parameter'] !== undefined && vduData['monitoring-parameter'].length > 0) {
Barath Kumar R07698ab2021-03-30 11:50:42 +0530214 this.isLoadingNSInstanceAction = false;
Barath Kumar R1a34b832021-03-05 11:32:19 +0530215 const location: string = environment.GRAFANA_URL + '/' + this.instanceID + '/osm-ns-metrics-metrics';
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530216 // eslint-disable-next-line security/detect-non-literal-fs-filename
Barath Kumar R1a34b832021-03-05 11:32:19 +0530217 window.open(location);
218 } else {
Barath Kumar R07698ab2021-03-30 11:50:42 +0530219 this.isLoadingNSInstanceAction = false;
SANDHYA.JS9bae4602022-04-05 07:28:32 +0530220 this.notifierService.notify('error', this.translateService.instant('PAGE.NSMETRIC.METRICERROR'));
Barath Kumar R1a34b832021-03-05 11:32:19 +0530221 }
222 });
Barath Kumar R07698ab2021-03-30 11:50:42 +0530223 this.doChanges();
Barath Kumar R1a34b832021-03-05 11:32:19 +0530224 }, (error: ERRORDATA): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530225 this.restService.handleError(error, 'get');
Barath Kumar R07698ab2021-03-30 11:50:42 +0530226 this.isLoadingNSInstanceAction = false;
kumaran.m3b4814a2020-05-01 19:48:54 +0530227 });
228 });
Barath Kumar R1a34b832021-03-05 11:32:19 +0530229 }, (error: ERRORDATA): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530230 this.restService.handleError(error, 'get');
Barath Kumar R07698ab2021-03-30 11:50:42 +0530231 this.isLoadingNSInstanceAction = false;
kumaran.m3b4814a2020-05-01 19:48:54 +0530232 });
233 }
Barath Kumar R07698ab2021-03-30 11:50:42 +0530234
235 /**
236 * Do the manual scaling
237 * Here we are going to get a list of VNFD ID used in the instances
238 * and have this in array with URL created then pass to checkscaling method for forkjoin to get the data @public
239 */
240 public manualScaling(): void {
241 this.isLoadingNSInstanceAction = true;
242 const tempURL: Observable<{}>[] = [];
243 this.value.vnfID.forEach((id: string): void => {
244 const apiUrl: string = environment.VNFPACKAGESCONTENT_URL + '/' + id;
245 tempURL.push(this.restService.getResource(apiUrl));
246 });
247 this.checkScaling(tempURL);
248 }
249
250 /**
251 * Used to forkjoin to all the request to send parallely, get the data and check 'scaling-aspect' key is present @public
252 */
253 public checkScaling(URLS: Observable<{}>[]): void {
254 forkJoin(URLS).subscribe((data: VNFD[]): void => {
255 this.vnfDetails = data;
256 if (this.vnfDetails.length > 0) {
257 this.vnfDetails.forEach((vnfdData: VNFD): void => {
258 vnfdData.df.forEach((dfData: DF): void => {
259 if (!isNullOrUndefined(dfData['scaling-aspect']) && dfData['scaling-aspect'].length > 0) {
260 this.isScalingPresent = true;
261 }
262 });
263 });
264 }
265 this.isLoadingNSInstanceAction = false;
266 if (this.isScalingPresent) {
267 this.openScaling();
268 } else {
269 this.notifierService.notify('error', this.translateService.instant('SCALINGNOTFOUND'));
270 }
271 this.doChanges();
272 });
273 }
274
275 /** Open the scaling pop-up @public */
276 public openScaling(): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530277 // eslint-disable-next-line security/detect-non-literal-fs-filename
Barath Kumar R07698ab2021-03-30 11:50:42 +0530278 const modalRef: NgbModalRef = this.modalService.open(ScalingComponent, { backdrop: 'static' });
279 modalRef.componentInstance.params = {
280 id: this.instanceID,
281 vnfID: this.value.vnfID,
282 nsID: this.value['nsd-id'],
283 nsd: this.value.nsd,
284 data: this.vnfDetails
285 };
286 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
287 if (result) {
288 this.sharedService.callData();
289 }
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530290 }).catch((): void => {
291 // Catch Navigation Error
SANDHYA.JS219fe612024-01-23 15:52:43 +0530292 });
Barath Kumar R07698ab2021-03-30 11:50:42 +0530293 }
294
SANDHYA.JSfced3d42022-04-28 20:28:17 +0530295 /** To open VM Migration in NS Instances */
296 public openVmMigration(): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530297 // eslint-disable-next-line security/detect-non-literal-fs-filename
SANDHYA.JSfced3d42022-04-28 20:28:17 +0530298 const modalRef: NgbModalRef = this.modalService.open(VmMigrationComponent, { backdrop: 'static' });
299 modalRef.componentInstance.params = {
300 id: this.instanceID
301 };
302 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
303 if (result) {
304 this.sharedService.callData();
305 }
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530306 }).catch((): void => {
307 // Catch Navigation Error
SANDHYA.JS219fe612024-01-23 15:52:43 +0530308 });
SANDHYA.JSfced3d42022-04-28 20:28:17 +0530309 }
310
SANDHYA.JS99144582022-04-27 17:22:35 +0530311 /** To open the Ns Update pop-up */
312 public openNsUpdate(): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530313 // eslint-disable-next-line security/detect-non-literal-fs-filename
SANDHYA.JS99144582022-04-27 17:22:35 +0530314 const modalRef: NgbModalRef = this.modalService.open(NsUpdateComponent, { backdrop: 'static' });
315 modalRef.componentInstance.params = {
316 id: this.instanceID
317 };
318 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
319 if (result) {
320 this.sharedService.callData();
321 }
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530322 }).catch((): void => {
323 // Catch Navigation Error
SANDHYA.JS219fe612024-01-23 15:52:43 +0530324 });
SANDHYA.JS99144582022-04-27 17:22:35 +0530325 }
326
SANDHYA.JS3d81a282022-05-02 08:25:39 +0530327 /** To open the Start, Stop & Rebuild pop-up */
328 public openStart(actionType: string): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530329 // eslint-disable-next-line security/detect-non-literal-fs-filename
SANDHYA.JS3d81a282022-05-02 08:25:39 +0530330 const modalRef: NgbModalRef = this.modalService.open(StartStopRebuildComponent, { backdrop: 'static' });
331 modalRef.componentInstance.params = {
332 id: this.instanceID
333 };
334 if (actionType === 'start') {
335 modalRef.componentInstance.instanceTitle = this.translateService.instant('START');
336 } else if (actionType === 'stop') {
337 modalRef.componentInstance.instanceTitle = this.translateService.instant('STOP');
338 } else {
339 modalRef.componentInstance.instanceTitle = this.translateService.instant('REBUILD');
340 }
341 modalRef.componentInstance.instanceType = actionType;
342 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
343 if (result) {
344 this.sharedService.callData();
345 }
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530346 }).catch((): void => {
347 // Catch Navigation Error
SANDHYA.JS219fe612024-01-23 15:52:43 +0530348 });
SANDHYA.JS3d81a282022-05-02 08:25:39 +0530349 }
350
SANDHYA.JS219fe612024-01-23 15:52:43 +0530351 /** Open the Healing pop-up @public */
352 public openHealing(): void {
353 // eslint-disable-next-line security/detect-non-literal-fs-filename
354 const modalRef: NgbModalRef = this.modalService.open(HealingComponent, { backdrop: 'static' });
355 modalRef.componentInstance.params = {
356 id: this.instanceID
357 };
358 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
359 if (result) {
360 this.sharedService.callData();
361 }
362 }).catch((): void => {
363 // Catch Navigation Error
364 });
SANDHYA.JS017df362022-05-02 06:57:11 +0530365 }
366
Barath Kumar R07698ab2021-03-30 11:50:42 +0530367 /**
368 * Check any changes in the child component @public
369 */
370 public doChanges(): void {
371 setTimeout((): void => {
372 this.cd.detectChanges();
373 }, this.timeOut);
374 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530375}