blob: 065a56beaac549ea86438bddde11176a94c32d61 [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 Instance Component
20 */
SANDHYA.JS8ead52b2024-06-10 18:23:41 +053021import { Component, Injector, OnInit, ViewChild } from '@angular/core';
kumaran.m3b4814a2020-05-01 19:48:54 +053022import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
23import { TranslateService } from '@ngx-translate/core';
24import { CONFIGCONSTANT, ERRORDATA, MODALCLOSERESPONSEDATA } from 'CommonModel';
25import { DataService } from 'DataService';
SANDHYA.JS8ead52b2024-06-10 18:23:41 +053026import { DeleteComponent } from 'DeleteComponent';
kumaran.m3b4814a2020-05-01 19:48:54 +053027import { environment } from 'environment';
28import { InstantiateNsComponent } from 'InstantiateNs';
SANDHYA.JS8ead52b2024-06-10 18:23:41 +053029import { LocalDataSource, Ng2SmartTableComponent } from 'ng2-smart-table';
kumaran.m3b4814a2020-05-01 19:48:54 +053030import { NSDInstanceData, NSInstanceDetails } from 'NSInstanceModel';
31import { NSInstancesActionComponent } from 'NSInstancesActionComponent';
32import { RestService } from 'RestService';
Isabel Lloret523d6752025-04-29 08:06:54 +000033import { forkJoin, Subscription } from 'rxjs';
SANDHYA.JS8ead52b2024-06-10 18:23:41 +053034import { isNullOrUndefined } from 'SharedService';
kumaran.m3b4814a2020-05-01 19:48:54 +053035import { SharedService } from 'SharedService';
Isabel Lloret523d6752025-04-29 08:06:54 +000036import { VimAccountDetails } from 'VimAccountModel';
37
kumaran.m3b4814a2020-05-01 19:48:54 +053038
39/**
40 * Creating component
41 * @Component takes NSInstancesComponent.html as template url
42 */
43@Component({
44 templateUrl: './NSInstancesComponent.html',
45 styleUrls: ['./NSInstancesComponent.scss']
46})
47/** Exporting a class @exports NSInstancesComponent */
48export class NSInstancesComponent implements OnInit {
SANDHYA.JS8ead52b2024-06-10 18:23:41 +053049 @ViewChild('table') table: Ng2SmartTableComponent;
50
kumaran.m3b4814a2020-05-01 19:48:54 +053051 /** Injector to invoke other services @public */
52 public injector: Injector;
53
54 /** NS Instance array @public */
55 public nsInstanceData: object[] = [];
56
57 /** Datasource instance @public */
58 public dataSource: LocalDataSource = new LocalDataSource();
59
60 /** SelectedRows array @public */
SANDHYA.JS8ead52b2024-06-10 18:23:41 +053061 // eslint-disable-next-line @typescript-eslint/no-explicit-any
62 public selectedRows: any;
kumaran.m3b4814a2020-05-01 19:48:54 +053063
64 /** Selected list array @public */
SANDHYA.JS8ead52b2024-06-10 18:23:41 +053065 public selectList: [] = [];
kumaran.m3b4814a2020-05-01 19:48:54 +053066
67 /** Instance component are stored in settings @public */
68 public settings: {} = {};
69
70 /** Contains objects for menu settings @public */
71 public columnList: {} = {};
72
73 /** Check the loading results @public */
74 public isLoadingResults: boolean = true;
75
76 /** Give the message for the loading @public */
77 public message: string = 'PLEASEWAIT';
78
79 /** Class for empty and present data @public */
80 public checkDataClass: string;
81
82 /** operational State init data @public */
83 public operationalStateFirstStep: string = CONFIGCONSTANT.operationalStateFirstStep;
84
85 /** operational State running data @public */
86 public operationalStateSecondStep: string = CONFIGCONSTANT.operationalStateSecondStep;
87
88 /** operational State failed data @public */
89 public operationalStateThirdStep: string = CONFIGCONSTANT.operationalStateThirdStep;
90
Barath Kumar R07698ab2021-03-30 11:50:42 +053091 /** operational State scaling data @public */
92 public operationalStateFourthStep: string = CONFIGCONSTANT.operationalStateFourthStep;
93
SANDHYA.JS219fe612024-01-23 15:52:43 +053094 /** operational State healing data @public */
95 public operationalStateFifthStep: string = CONFIGCONSTANT.operationalStateFifthStep;
96
kumaran.m3b4814a2020-05-01 19:48:54 +053097 /** Config State init data @public */
98 public configStateFirstStep: string = CONFIGCONSTANT.configStateFirstStep;
99
100 /** Config State init data @public */
101 public configStateSecondStep: string = CONFIGCONSTANT.configStateSecondStep;
102
103 /** Config State init data @public */
104 public configStateThirdStep: string = CONFIGCONSTANT.configStateThirdStep;
105
106 /** Instance of the modal service @private */
107 private modalService: NgbModal;
108
109 /** dataService to pass the data from one component to another @private */
110 private dataService: DataService;
111
112 /** Utilizes rest service for any CRUD operations @private */
113 private restService: RestService;
114
115 /** Contains all methods related to shared @private */
116 private sharedService: SharedService;
117
118 /** Contains tranlsate instance @private */
119 private translateService: TranslateService;
120
121 /** Instance of subscriptions @private */
122 private generateDataSub: Subscription;
123
124 constructor(injector: Injector) {
125 this.injector = injector;
126 this.restService = this.injector.get(RestService);
127 this.dataService = this.injector.get(DataService);
128 this.sharedService = this.injector.get(SharedService);
129 this.translateService = this.injector.get(TranslateService);
130 this.modalService = this.injector.get(NgbModal);
131 }
132
133 /**
134 * Lifecyle Hooks the trigger before component is instantiate
135 */
136 public ngOnInit(): void {
137 this.generateTableColumn();
138 this.generateTableSettings();
139 this.generateData();
Barath Kumar R063a3f12020-12-29 16:35:09 +0530140 this.generateDataSub = this.sharedService.dataEvent.subscribe((): void => { this.generateData(); });
kumaran.m3b4814a2020-05-01 19:48:54 +0530141 }
142
143 /** Generate smart table row title and filters @public */
144 public generateTableSettings(): void {
145 this.settings = {
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530146 selectMode: 'multi',
kumaran.m3b4814a2020-05-01 19:48:54 +0530147 columns: this.columnList,
148 actions: { add: false, edit: false, delete: false, position: 'right' },
149 attr: this.sharedService.tableClassConfig(),
150 pager: this.sharedService.paginationPagerConfig(),
151 noDataMessage: this.translateService.instant('NODATAMSG')
152 };
153 }
154
155 /** Generate smart table row title and filters @public */
156 public generateTableColumn(): void {
157 this.columnList = {
SANDHYA.JS5f8c8022023-10-13 11:45:25 +0530158 name: { title: this.translateService.instant('NAME'), width: '15%' },
kumaran.m3b4814a2020-05-01 19:48:54 +0530159 identifier: { title: this.translateService.instant('IDENTIFIER'), width: '20%' },
160 NsdName: { title: this.translateService.instant('NSDNAME'), width: '15%' },
SANDHYA.JS5f8c8022023-10-13 11:45:25 +0530161 'create-time': {
162 title: this.translateService.instant('DATE'), width: '15%', sortDirection: 'desc',
163 compareFunction: this.sharedService.compareFunction
164 },
kumaran.m3b4814a2020-05-01 19:48:54 +0530165 OperationalStatus: {
166 title: this.translateService.instant('OPERATIONALSTATUS'), width: '10%', type: 'html',
167 filter: {
168 type: 'list',
169 config: {
170 selectText: 'Select',
171 list: [
172 { value: this.operationalStateFirstStep, title: this.operationalStateFirstStep },
173 { value: this.operationalStateSecondStep, title: this.operationalStateSecondStep },
Barath Kumar R07698ab2021-03-30 11:50:42 +0530174 { value: this.operationalStateThirdStep, title: this.operationalStateThirdStep },
SANDHYA.JS219fe612024-01-23 15:52:43 +0530175 { value: this.operationalStateFourthStep, title: this.operationalStateFourthStep },
176 { value: this.operationalStateFifthStep, title: this.operationalStateFifthStep }
kumaran.m3b4814a2020-05-01 19:48:54 +0530177 ]
178 }
179 },
180 valuePrepareFunction: (cell: NSDInstanceData, row: NSDInstanceData): string => {
181 if (row.OperationalStatus === this.operationalStateFirstStep) {
182 return `<span class="icon-label" title="${row.OperationalStatus}">
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530183 <i class="fas fa-clock text-warning"></i>
184 </span>`;
kumaran.m3b4814a2020-05-01 19:48:54 +0530185 } else if (row.OperationalStatus === this.operationalStateSecondStep) {
186 return `<span class="icon-label" title="${row.OperationalStatus}">
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530187 <i class="fas fa-check-circle text-success"></i>
188 </span>`;
kumaran.m3b4814a2020-05-01 19:48:54 +0530189 } else if (row.OperationalStatus === this.operationalStateThirdStep) {
190 return `<span class="icon-label" title="${row.OperationalStatus}">
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530191 <i class="fas fa-times-circle text-danger"></i>
192 </span>`;
Barath Kumar R07698ab2021-03-30 11:50:42 +0530193 } else if (row.OperationalStatus === this.operationalStateFourthStep) {
194 return `<span class="icon-label" title="${row.OperationalStatus}">
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530195 <i class="fas fa-compress-alt text-success"></i>
196 </span>`;
SANDHYA.JS219fe612024-01-23 15:52:43 +0530197 }
198 else if (row.OperationalStatus === this.operationalStateFifthStep) {
199 return `<span class="icon-label" title="${row.OperationalStatus}">
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530200 <i class="fas fa-briefcase-medical text-success"></i>
201 </span>`;
kumaran.m3b4814a2020-05-01 19:48:54 +0530202 } else {
203 return `<span>${row.OperationalStatus}</span>`;
204 }
205 }
206 },
207 ConfigStatus: {
208 title: this.translateService.instant('CONFIGSTATUS'), width: '10%', type: 'html',
209 filter: {
210 type: 'list',
211 config: {
212 selectText: 'Select',
213 list: [
214 { value: this.configStateFirstStep, title: this.configStateFirstStep },
215 { value: this.configStateSecondStep, title: this.configStateSecondStep },
216 { value: this.configStateThirdStep, title: this.configStateThirdStep }
217 ]
218 }
219 },
220 valuePrepareFunction: (cell: NSDInstanceData, row: NSDInstanceData): string => {
221 if (row.ConfigStatus === this.configStateFirstStep) {
222 return `<span class="icon-label" title="${row.ConfigStatus}">
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530223 <i class="fas fa-clock text-warning"></i>
224 </span>`;
kumaran.m3b4814a2020-05-01 19:48:54 +0530225 } else if (row.ConfigStatus === this.configStateSecondStep) {
226 return `<span class="icon-label" title="${row.ConfigStatus}">
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530227 <i class="fas fa-check-circle text-success"></i>
228 </span>`;
kumaran.m3b4814a2020-05-01 19:48:54 +0530229 } else if (row.ConfigStatus === this.configStateThirdStep) {
230 return `<span class="icon-label" title="${row.ConfigStatus}">
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530231 <i class="fas fa-times-circle text-danger"></i>
232 </span>`;
kumaran.m3b4814a2020-05-01 19:48:54 +0530233 } else {
234 return `<span>${row.ConfigStatus}</span>`;
235 }
236 }
237 },
238 DetailedStatus: { title: this.translateService.instant('DETAILEDSTATUS'), width: '15%' },
239 Actions: {
240 name: 'Action', width: '15%', filter: false, sort: false, type: 'custom',
241 title: this.translateService.instant('ACTIONS'),
242 valuePrepareFunction: (cell: NSDInstanceData, row: NSDInstanceData): NSDInstanceData => row,
243 renderComponent: NSInstancesActionComponent
244 }
245 };
246 }
247
248 /** generateData initiate the ns-instance list @public */
249 public generateData(): void {
250 this.isLoadingResults = true;
Isabel Lloret523d6752025-04-29 08:06:54 +0000251 forkJoin([
252 this.restService.getResource(environment.VIMACCOUNTS_URL),
253 this.restService.getResource(environment.NSDINSTANCES_URL)
254 ]).subscribe({
255 next: ([vimAccounts, nsdInstancesData]: [VimAccountDetails[], NSInstanceDetails[]]) => {
256 // Transforms vimAccounts to a map (will be used to enrich ns instance data)
257 const vimsMap = this.transformVimListToMap(vimAccounts);
258
259 // Transform nsInstances to the format needed in the web
260 this.nsInstanceData = [];
261 nsdInstancesData.forEach((nsdInstanceData: NSInstanceDetails): void => {
262 const nsDataObj: NSDInstanceData = {
263 name: nsdInstanceData.name,
264 identifier: nsdInstanceData.id,
265 NsdName: nsdInstanceData['nsd-name-ref'],
266 OperationalStatus: nsdInstanceData['operational-status'],
267 ConfigStatus: nsdInstanceData['config-status'],
268 DetailedStatus: nsdInstanceData['detailed-status'],
269 memberIndex: nsdInstanceData.nsd.df,
270 nsConfig: nsdInstanceData.nsd['ns-configuration'],
271 adminDetails: nsdInstanceData._admin,
272 vnfID: nsdInstanceData['vnfd-id'],
273 nsd: nsdInstanceData.nsd,
274 'nsd-id': nsdInstanceData['nsd-id'],
275 vcaStatus: nsdInstanceData.vcaStatus,
276 constituent: nsdInstanceData['constituent-vnfr-ref'],
277 'create-time': this.sharedService.convertEpochTime(Number(nsdInstanceData['create-time'])),
278 vimType: vimsMap.get(nsdInstanceData['datacenter'])?.vim_type
279 };
280 this.nsInstanceData.push(nsDataObj);
281 });
282 if (this.nsInstanceData.length > 0) {
283 this.checkDataClass = 'dataTables_present';
284 } else {
285 this.checkDataClass = 'dataTables_empty';
286 }
287 this.dataSource.load(this.nsInstanceData).then((data: {}): void => {
288 this.isLoadingResults = false;
289 }).catch((): void => {
290 // Catch Navigation Error
291 });
292 },
293 error: (error: ERRORDATA): void => {
294 this.restService.handleError(error, 'get');
kumaran.m3b4814a2020-05-01 19:48:54 +0530295 this.isLoadingResults = false;
Isabel Lloret523d6752025-04-29 08:06:54 +0000296 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530297 });
298 }
299
Isabel Lloret523d6752025-04-29 08:06:54 +0000300 /** transforms vim list to map to be able to recover vim data fast by name */
301 private transformVimListToMap(vimList: VimAccountDetails[]): Map<string, VimAccountDetails> {
302 const vimMap = new Map<string, VimAccountDetails>();
303 vimList.forEach((vim) => {
304 vimMap.set(vim._id, vim);
305 });
306 return vimMap;
307 }
308
kumaran.m3b4814a2020-05-01 19:48:54 +0530309 /** smart table listing manipulation @public */
310 public onChange(perPageValue: number): void {
311 this.dataSource.setPaging(1, perPageValue, true);
312 }
313
314 /** smart table listing manipulation @public */
315 public onUserRowSelect(event: MessageEvent): void {
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530316 if (!isNullOrUndefined(event)) {
317 this.selectedRows = event;
318 if (this.selectedRows.selected.length !== 0) {
319 this.selectList = this.selectedRows.selected;
320 } else {
321 if (!isNullOrUndefined(event.data)) {
322 Object.assign(event.data, { page: 'ns-instance' });
323 this.dataService.changeMessage(event.data);
324 }
325 this.selectList.length = 0;
326 }
327 }
328 }
329
330 /** delete NS using modalservice @public */
331 public deleteNS(): void {
332 // eslint-disable-next-line security/detect-non-literal-fs-filename
333 const modalRef: NgbModalRef = this.modalService.open(DeleteComponent, { backdrop: 'static' });
334 modalRef.componentInstance.params = {
335 identifierList: this.selectList,
336 page: 'instantiateNS'
337 };
338 modalRef.result.then((result: MODALCLOSERESPONSEDATA) => {
339 if (result) {
340 this.sharedService.callData();
341 this.table.isAllSelected = false;
342 this.selectList.length = 0;
343 }
344 }).catch((): void => {
345 // Catch Navigation Error
346 });
kumaran.m3b4814a2020-05-01 19:48:54 +0530347 }
348
349 /** Instantiate NS using modalservice @public */
350 public instantiateNS(): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530351 // eslint-disable-next-line security/detect-non-literal-fs-filename
kumaran.m3b4814a2020-05-01 19:48:54 +0530352 const modalRef: NgbModalRef = this.modalService.open(InstantiateNsComponent, { backdrop: 'static' });
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530353 modalRef.componentInstance.params = {
354 titleName: 'instantiateNS'
355 };
Barath Kumar R063a3f12020-12-29 16:35:09 +0530356 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530357 if (result) {
358 this.generateData();
359 }
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530360 }).catch((): void => {
361 // Catch Navigation Error
362 });
kumaran.m3b4814a2020-05-01 19:48:54 +0530363 }
364
365 /**
366 * Lifecyle hook which get trigger on component destruction
367 */
368 public ngOnDestroy(): void {
369 this.generateDataSub.unsubscribe();
370 }
371}