blob: 1c3f1f293af926c65f8f7fbc06c497f4661e797f [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';
29import { NSDDetails } from 'NSDModel';
30import { NSDInstanceData } from 'NSInstanceModel';
31import { NSPrimitiveComponent } from 'NSPrimitiveComponent';
SANDHYA.JS99144582022-04-27 17:22:35 +053032import { NsUpdateComponent } from 'NsUpdateComponent';
kumaran.m3b4814a2020-05-01 19:48:54 +053033import { RestService } from 'RestService';
Barath Kumar R07698ab2021-03-30 11:50:42 +053034import { forkJoin, Observable } from 'rxjs';
35import { ScalingComponent } from 'ScalingComponent';
kumaran.m3b4814a2020-05-01 19:48:54 +053036import { SharedService } from 'SharedService';
37import { ShowInfoComponent } from 'ShowInfoComponent';
SANDHYA.JS3d81a282022-05-02 08:25:39 +053038import { StartStopRebuildComponent } from 'StartStopRebuildComponent';
Barath Kumar R07698ab2021-03-30 11:50:42 +053039import { isNullOrUndefined } from 'util';
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
Barath Kumar R07698ab2021-03-30 11:50:42 +053068 /** get Admin Details @public */
69 public getAdminDetails: {};
70
71 /** Scaling is accepted @public */
72 public isScalingPresent: boolean = false;
73
kumaran.m3b4814a2020-05-01 19:48:54 +053074 /** Check the loading results for loader status @public */
Barath Kumar R07698ab2021-03-30 11:50:42 +053075 public isLoadingNSInstanceAction: boolean = false;
kumaran.m3b4814a2020-05-01 19:48:54 +053076
77 /** Give the message for the loading @public */
78 public message: string = 'PLEASEWAIT';
79
Barath Kumar R07698ab2021-03-30 11:50:42 +053080 /** Assign the VNF Details @public */
81 public vnfDetails: VNFD[] = [];
82
Barath Kumar Rf2ae5462021-03-01 12:52:33 +053083 /** Contains instance ID @public */
84 public instanceID: string;
85
86 /** Contains operational dashboard view @public */
87 public isShowOperationalDashboard: boolean = false;
88
kumaran.m3b4814a2020-05-01 19:48:54 +053089 /** Instance of the modal service @private */
90 private modalService: NgbModal;
91
92 /** Holds teh instance of AuthService class of type AuthService @private */
93 private router: Router;
94
kumaran.m3b4814a2020-05-01 19:48:54 +053095 /** Contains all methods related to shared @private */
96 private sharedService: SharedService;
97
98 /** Notifier service to popup notification @private */
99 private notifierService: NotifierService;
100
101 /** Contains tranlsate instance @private */
102 private translateService: TranslateService;
103
104 /** Detect changes for the User Input */
105 private cd: ChangeDetectorRef;
106
107 /** Set timeout @private */
Barath Kumar R07698ab2021-03-30 11:50:42 +0530108 private timeOut: number = 100;
kumaran.m3b4814a2020-05-01 19:48:54 +0530109
110 constructor(injector: Injector) {
111 this.injector = injector;
112 this.modalService = this.injector.get(NgbModal);
113 this.restService = this.injector.get(RestService);
114 this.router = this.injector.get(Router);
115 this.sharedService = this.injector.get(SharedService);
116 this.notifierService = this.injector.get(NotifierService);
117 this.translateService = this.injector.get(TranslateService);
118 this.cd = this.injector.get(ChangeDetectorRef);
119 }
120
121 /**
122 * Lifecyle Hooks the trigger before component is instantiate
123 */
124 public ngOnInit(): void {
125 this.configStatus = this.value.ConfigStatus;
126 this.operationalStatus = this.value.OperationalStatus;
127 this.instanceID = this.value.identifier;
Barath Kumar R07698ab2021-03-30 11:50:42 +0530128 this.getAdminDetails = this.value.adminDetails;
Barath Kumar Rf2ae5462021-03-01 12:52:33 +0530129 this.isShowOperationalDashboard = !isNullOrUndefined(this.value.vcaStatus) ?
130 Object.keys(this.value.vcaStatus).length === 0 && typeof this.value.vcaStatus === 'object' : true;
kumaran.m3b4814a2020-05-01 19:48:54 +0530131 }
132
133 /** Shows information using modalservice @public */
134 public infoNs(): void {
135 this.modalService.open(ShowInfoComponent, { backdrop: 'static' }).componentInstance.params = {
136 id: this.instanceID,
137 page: 'ns-instance',
138 titleName: 'INSTANCEDETAILS'
139 };
140 }
141
142 /** Delete NS Instanace @public */
143 public deleteNSInstance(forceAction: boolean): void {
144 const modalRef: NgbModalRef = this.modalService.open(DeleteComponent, { backdrop: 'static' });
145 modalRef.componentInstance.params = { forceDeleteType: forceAction };
Barath Kumar R1a34b832021-03-05 11:32:19 +0530146 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530147 if (result) {
148 this.sharedService.callData();
149 }
150 }).catch();
151 }
152
153 /** History of operations for an Instanace @public */
154 public historyOfOperations(): void {
Barath Kumar R1a34b832021-03-05 11:32:19 +0530155 this.router.navigate(['/instances/ns/history-operations/', this.instanceID]).catch((): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530156 // Catch Navigation Error
157 });
158 }
159
160 /** NS Topology */
161 public nsTopology(): void {
Barath Kumar R1a34b832021-03-05 11:32:19 +0530162 this.router.navigate(['/instances/ns/', this.instanceID]).catch((): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530163 // Catch Navigation Error
164 });
165 }
166
167 /** Exec NS Primitive @public */
168 public execNSPrimitiveModal(): void {
Barath Kumar Rd3ce0c52020-08-13 11:44:01 +0530169 this.modalService.open(NSPrimitiveComponent, { backdrop: 'static' }).componentInstance.params = {
kumaran.m3b4814a2020-05-01 19:48:54 +0530170 memberIndex: this.value.memberIndex,
Barath Kumar R54d693c2020-07-13 20:54:13 +0530171 nsConfig: this.value.nsConfig,
172 name: this.value.NsdName
kumaran.m3b4814a2020-05-01 19:48:54 +0530173 };
174 }
175
176 /** Redirect to Grafana Metrics @public */
177 public metrics(): void {
Barath Kumar R07698ab2021-03-30 11:50:42 +0530178 this.isLoadingNSInstanceAction = true;
Barath Kumar R1a34b832021-03-05 11:32:19 +0530179 this.restService.getResource(environment.NSDINSTANCES_URL + '/' + this.instanceID).subscribe((nsData: NSDDetails[]): void => {
180 nsData['vnfd-id'].forEach((vnfdID: string[]): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530181 this.restService.getResource(environment.VNFPACKAGES_URL + '/' + vnfdID)
Barath Kumar R1a34b832021-03-05 11:32:19 +0530182 .subscribe((vnfd: VNFD): void => {
183 vnfd.vdu.forEach((vduData: VDU): void => {
184 if (vduData['monitoring-parameter'] !== undefined && vduData['monitoring-parameter'].length > 0) {
Barath Kumar R07698ab2021-03-30 11:50:42 +0530185 this.isLoadingNSInstanceAction = false;
Barath Kumar R1a34b832021-03-05 11:32:19 +0530186 const location: string = environment.GRAFANA_URL + '/' + this.instanceID + '/osm-ns-metrics-metrics';
187 window.open(location);
188 } else {
Barath Kumar R07698ab2021-03-30 11:50:42 +0530189 this.isLoadingNSInstanceAction = false;
SANDHYA.JS9bae4602022-04-05 07:28:32 +0530190 this.notifierService.notify('error', this.translateService.instant('PAGE.NSMETRIC.METRICERROR'));
Barath Kumar R1a34b832021-03-05 11:32:19 +0530191 }
192 });
Barath Kumar R07698ab2021-03-30 11:50:42 +0530193 this.doChanges();
Barath Kumar R1a34b832021-03-05 11:32:19 +0530194 }, (error: ERRORDATA): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530195 this.restService.handleError(error, 'get');
Barath Kumar R07698ab2021-03-30 11:50:42 +0530196 this.isLoadingNSInstanceAction = false;
kumaran.m3b4814a2020-05-01 19:48:54 +0530197 });
198 });
Barath Kumar R1a34b832021-03-05 11:32:19 +0530199 }, (error: ERRORDATA): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530200 this.restService.handleError(error, 'get');
Barath Kumar R07698ab2021-03-30 11:50:42 +0530201 this.isLoadingNSInstanceAction = false;
kumaran.m3b4814a2020-05-01 19:48:54 +0530202 });
203 }
Barath Kumar R07698ab2021-03-30 11:50:42 +0530204
205 /**
206 * Do the manual scaling
207 * Here we are going to get a list of VNFD ID used in the instances
208 * and have this in array with URL created then pass to checkscaling method for forkjoin to get the data @public
209 */
210 public manualScaling(): void {
211 this.isLoadingNSInstanceAction = true;
212 const tempURL: Observable<{}>[] = [];
213 this.value.vnfID.forEach((id: string): void => {
214 const apiUrl: string = environment.VNFPACKAGESCONTENT_URL + '/' + id;
215 tempURL.push(this.restService.getResource(apiUrl));
216 });
217 this.checkScaling(tempURL);
218 }
219
220 /**
221 * Used to forkjoin to all the request to send parallely, get the data and check 'scaling-aspect' key is present @public
222 */
223 public checkScaling(URLS: Observable<{}>[]): void {
224 forkJoin(URLS).subscribe((data: VNFD[]): void => {
225 this.vnfDetails = data;
226 if (this.vnfDetails.length > 0) {
227 this.vnfDetails.forEach((vnfdData: VNFD): void => {
228 vnfdData.df.forEach((dfData: DF): void => {
229 if (!isNullOrUndefined(dfData['scaling-aspect']) && dfData['scaling-aspect'].length > 0) {
230 this.isScalingPresent = true;
231 }
232 });
233 });
234 }
235 this.isLoadingNSInstanceAction = false;
236 if (this.isScalingPresent) {
237 this.openScaling();
238 } else {
239 this.notifierService.notify('error', this.translateService.instant('SCALINGNOTFOUND'));
240 }
241 this.doChanges();
242 });
243 }
244
245 /** Open the scaling pop-up @public */
246 public openScaling(): void {
247 const modalRef: NgbModalRef = this.modalService.open(ScalingComponent, { backdrop: 'static' });
248 modalRef.componentInstance.params = {
249 id: this.instanceID,
250 vnfID: this.value.vnfID,
251 nsID: this.value['nsd-id'],
252 nsd: this.value.nsd,
253 data: this.vnfDetails
254 };
255 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
256 if (result) {
257 this.sharedService.callData();
258 }
259 }).catch();
260 }
261
SANDHYA.JSfced3d42022-04-28 20:28:17 +0530262 /** To open VM Migration in NS Instances */
263 public openVmMigration(): void {
264 const modalRef: NgbModalRef = this.modalService.open(VmMigrationComponent, { backdrop: 'static' });
265 modalRef.componentInstance.params = {
266 id: this.instanceID
267 };
268 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
269 if (result) {
270 this.sharedService.callData();
271 }
272 }).catch();
273 }
274
SANDHYA.JS99144582022-04-27 17:22:35 +0530275 /** To open the Ns Update pop-up */
276 public openNsUpdate(): void {
277 const modalRef: NgbModalRef = this.modalService.open(NsUpdateComponent, { backdrop: 'static' });
278 modalRef.componentInstance.params = {
279 id: this.instanceID
280 };
281 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
282 if (result) {
283 this.sharedService.callData();
284 }
285 }).catch();
286 }
287
SANDHYA.JS3d81a282022-05-02 08:25:39 +0530288 /** To open the Start, Stop & Rebuild pop-up */
289 public openStart(actionType: string): void {
290 const modalRef: NgbModalRef = this.modalService.open(StartStopRebuildComponent, { backdrop: 'static' });
291 modalRef.componentInstance.params = {
292 id: this.instanceID
293 };
294 if (actionType === 'start') {
295 modalRef.componentInstance.instanceTitle = this.translateService.instant('START');
296 } else if (actionType === 'stop') {
297 modalRef.componentInstance.instanceTitle = this.translateService.instant('STOP');
298 } else {
299 modalRef.componentInstance.instanceTitle = this.translateService.instant('REBUILD');
300 }
301 modalRef.componentInstance.instanceType = actionType;
302 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
303 if (result) {
304 this.sharedService.callData();
305 }
306 }).catch();
307 }
308
Barath Kumar R07698ab2021-03-30 11:50:42 +0530309 /**
310 * Check any changes in the child component @public
311 */
312 public doChanges(): void {
313 setTimeout((): void => {
314 this.cd.detectChanges();
315 }, this.timeOut);
316 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530317}