blob: fb5242325921cd003b4cde6bda0eac635301fd4c [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';
32import { RestService } from 'RestService';
Barath Kumar R07698ab2021-03-30 11:50:42 +053033import { forkJoin, Observable } from 'rxjs';
34import { ScalingComponent } from 'ScalingComponent';
kumaran.m3b4814a2020-05-01 19:48:54 +053035import { SharedService } from 'SharedService';
36import { ShowInfoComponent } from 'ShowInfoComponent';
Barath Kumar R07698ab2021-03-30 11:50:42 +053037import { isNullOrUndefined } from 'util';
SANDHYA.JSfced3d42022-04-28 20:28:17 +053038import { VmMigrationComponent } from 'VmMigrationComponent';
Barath Kumar R07698ab2021-03-30 11:50:42 +053039import { DF, VDU, VNFD } from 'VNFDModel';
kumaran.m3b4814a2020-05-01 19:48:54 +053040/**
41 * Creating component
42 * @Component takes NSInstancesActionComponent.html as template url
43 */
44@Component({
45 templateUrl: './NSInstancesActionComponent.html',
46 styleUrls: ['./NSInstancesActionComponent.scss'],
47 changeDetection: ChangeDetectionStrategy.OnPush
48})
49/** Exporting a class @exports NSInstancesActionComponent */
50export class NSInstancesActionComponent {
51 /** To get the value from the nspackage via valuePrepareFunction default Property of ng-smarttable @public */
52 public value: NSDInstanceData;
53
54 /** Invoke service injectors @public */
55 public injector: Injector;
56
57 /** Instance of the modal service @public */
58 public restService: RestService;
59
60 /** Config Status Check @public */
61 public configStatus: string;
62
63 /** Operational Status Check @public */
64 public operationalStatus: string;
65
Barath Kumar R07698ab2021-03-30 11:50:42 +053066 /** get Admin Details @public */
67 public getAdminDetails: {};
68
69 /** Scaling is accepted @public */
70 public isScalingPresent: boolean = false;
71
kumaran.m3b4814a2020-05-01 19:48:54 +053072 /** Check the loading results for loader status @public */
Barath Kumar R07698ab2021-03-30 11:50:42 +053073 public isLoadingNSInstanceAction: boolean = false;
kumaran.m3b4814a2020-05-01 19:48:54 +053074
75 /** Give the message for the loading @public */
76 public message: string = 'PLEASEWAIT';
77
Barath Kumar R07698ab2021-03-30 11:50:42 +053078 /** Assign the VNF Details @public */
79 public vnfDetails: VNFD[] = [];
80
Barath Kumar Rf2ae5462021-03-01 12:52:33 +053081 /** Contains instance ID @public */
82 public instanceID: string;
83
84 /** Contains operational dashboard view @public */
85 public isShowOperationalDashboard: boolean = false;
86
kumaran.m3b4814a2020-05-01 19:48:54 +053087 /** Instance of the modal service @private */
88 private modalService: NgbModal;
89
90 /** Holds teh instance of AuthService class of type AuthService @private */
91 private router: Router;
92
kumaran.m3b4814a2020-05-01 19:48:54 +053093 /** Contains all methods related to shared @private */
94 private sharedService: SharedService;
95
96 /** Notifier service to popup notification @private */
97 private notifierService: NotifierService;
98
99 /** Contains tranlsate instance @private */
100 private translateService: TranslateService;
101
102 /** Detect changes for the User Input */
103 private cd: ChangeDetectorRef;
104
105 /** Set timeout @private */
Barath Kumar R07698ab2021-03-30 11:50:42 +0530106 private timeOut: number = 100;
kumaran.m3b4814a2020-05-01 19:48:54 +0530107
108 constructor(injector: Injector) {
109 this.injector = injector;
110 this.modalService = this.injector.get(NgbModal);
111 this.restService = this.injector.get(RestService);
112 this.router = this.injector.get(Router);
113 this.sharedService = this.injector.get(SharedService);
114 this.notifierService = this.injector.get(NotifierService);
115 this.translateService = this.injector.get(TranslateService);
116 this.cd = this.injector.get(ChangeDetectorRef);
117 }
118
119 /**
120 * Lifecyle Hooks the trigger before component is instantiate
121 */
122 public ngOnInit(): void {
123 this.configStatus = this.value.ConfigStatus;
124 this.operationalStatus = this.value.OperationalStatus;
125 this.instanceID = this.value.identifier;
Barath Kumar R07698ab2021-03-30 11:50:42 +0530126 this.getAdminDetails = this.value.adminDetails;
Barath Kumar Rf2ae5462021-03-01 12:52:33 +0530127 this.isShowOperationalDashboard = !isNullOrUndefined(this.value.vcaStatus) ?
128 Object.keys(this.value.vcaStatus).length === 0 && typeof this.value.vcaStatus === 'object' : true;
kumaran.m3b4814a2020-05-01 19:48:54 +0530129 }
130
131 /** Shows information using modalservice @public */
132 public infoNs(): void {
133 this.modalService.open(ShowInfoComponent, { backdrop: 'static' }).componentInstance.params = {
134 id: this.instanceID,
135 page: 'ns-instance',
136 titleName: 'INSTANCEDETAILS'
137 };
138 }
139
140 /** Delete NS Instanace @public */
141 public deleteNSInstance(forceAction: boolean): void {
142 const modalRef: NgbModalRef = this.modalService.open(DeleteComponent, { backdrop: 'static' });
143 modalRef.componentInstance.params = { forceDeleteType: forceAction };
Barath Kumar R1a34b832021-03-05 11:32:19 +0530144 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530145 if (result) {
146 this.sharedService.callData();
147 }
148 }).catch();
149 }
150
151 /** History of operations for an Instanace @public */
152 public historyOfOperations(): void {
Barath Kumar R1a34b832021-03-05 11:32:19 +0530153 this.router.navigate(['/instances/ns/history-operations/', this.instanceID]).catch((): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530154 // Catch Navigation Error
155 });
156 }
157
158 /** NS Topology */
159 public nsTopology(): void {
Barath Kumar R1a34b832021-03-05 11:32:19 +0530160 this.router.navigate(['/instances/ns/', this.instanceID]).catch((): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530161 // Catch Navigation Error
162 });
163 }
164
165 /** Exec NS Primitive @public */
166 public execNSPrimitiveModal(): void {
Barath Kumar Rd3ce0c52020-08-13 11:44:01 +0530167 this.modalService.open(NSPrimitiveComponent, { backdrop: 'static' }).componentInstance.params = {
kumaran.m3b4814a2020-05-01 19:48:54 +0530168 memberIndex: this.value.memberIndex,
Barath Kumar R54d693c2020-07-13 20:54:13 +0530169 nsConfig: this.value.nsConfig,
170 name: this.value.NsdName
kumaran.m3b4814a2020-05-01 19:48:54 +0530171 };
172 }
173
174 /** Redirect to Grafana Metrics @public */
175 public metrics(): void {
Barath Kumar R07698ab2021-03-30 11:50:42 +0530176 this.isLoadingNSInstanceAction = true;
Barath Kumar R1a34b832021-03-05 11:32:19 +0530177 this.restService.getResource(environment.NSDINSTANCES_URL + '/' + this.instanceID).subscribe((nsData: NSDDetails[]): void => {
178 nsData['vnfd-id'].forEach((vnfdID: string[]): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530179 this.restService.getResource(environment.VNFPACKAGES_URL + '/' + vnfdID)
Barath Kumar R1a34b832021-03-05 11:32:19 +0530180 .subscribe((vnfd: VNFD): void => {
181 vnfd.vdu.forEach((vduData: VDU): void => {
182 if (vduData['monitoring-parameter'] !== undefined && vduData['monitoring-parameter'].length > 0) {
Barath Kumar R07698ab2021-03-30 11:50:42 +0530183 this.isLoadingNSInstanceAction = false;
Barath Kumar R1a34b832021-03-05 11:32:19 +0530184 const location: string = environment.GRAFANA_URL + '/' + this.instanceID + '/osm-ns-metrics-metrics';
185 window.open(location);
186 } else {
Barath Kumar R07698ab2021-03-30 11:50:42 +0530187 this.isLoadingNSInstanceAction = false;
SANDHYA.JS9bae4602022-04-05 07:28:32 +0530188 this.notifierService.notify('error', this.translateService.instant('PAGE.NSMETRIC.METRICERROR'));
Barath Kumar R1a34b832021-03-05 11:32:19 +0530189 }
190 });
Barath Kumar R07698ab2021-03-30 11:50:42 +0530191 this.doChanges();
Barath Kumar R1a34b832021-03-05 11:32:19 +0530192 }, (error: ERRORDATA): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530193 this.restService.handleError(error, 'get');
Barath Kumar R07698ab2021-03-30 11:50:42 +0530194 this.isLoadingNSInstanceAction = false;
kumaran.m3b4814a2020-05-01 19:48:54 +0530195 });
196 });
Barath Kumar R1a34b832021-03-05 11:32:19 +0530197 }, (error: ERRORDATA): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530198 this.restService.handleError(error, 'get');
Barath Kumar R07698ab2021-03-30 11:50:42 +0530199 this.isLoadingNSInstanceAction = false;
kumaran.m3b4814a2020-05-01 19:48:54 +0530200 });
201 }
Barath Kumar R07698ab2021-03-30 11:50:42 +0530202
203 /**
204 * Do the manual scaling
205 * Here we are going to get a list of VNFD ID used in the instances
206 * and have this in array with URL created then pass to checkscaling method for forkjoin to get the data @public
207 */
208 public manualScaling(): void {
209 this.isLoadingNSInstanceAction = true;
210 const tempURL: Observable<{}>[] = [];
211 this.value.vnfID.forEach((id: string): void => {
212 const apiUrl: string = environment.VNFPACKAGESCONTENT_URL + '/' + id;
213 tempURL.push(this.restService.getResource(apiUrl));
214 });
215 this.checkScaling(tempURL);
216 }
217
218 /**
219 * Used to forkjoin to all the request to send parallely, get the data and check 'scaling-aspect' key is present @public
220 */
221 public checkScaling(URLS: Observable<{}>[]): void {
222 forkJoin(URLS).subscribe((data: VNFD[]): void => {
223 this.vnfDetails = data;
224 if (this.vnfDetails.length > 0) {
225 this.vnfDetails.forEach((vnfdData: VNFD): void => {
226 vnfdData.df.forEach((dfData: DF): void => {
227 if (!isNullOrUndefined(dfData['scaling-aspect']) && dfData['scaling-aspect'].length > 0) {
228 this.isScalingPresent = true;
229 }
230 });
231 });
232 }
233 this.isLoadingNSInstanceAction = false;
234 if (this.isScalingPresent) {
235 this.openScaling();
236 } else {
237 this.notifierService.notify('error', this.translateService.instant('SCALINGNOTFOUND'));
238 }
239 this.doChanges();
240 });
241 }
242
243 /** Open the scaling pop-up @public */
244 public openScaling(): void {
245 const modalRef: NgbModalRef = this.modalService.open(ScalingComponent, { backdrop: 'static' });
246 modalRef.componentInstance.params = {
247 id: this.instanceID,
248 vnfID: this.value.vnfID,
249 nsID: this.value['nsd-id'],
250 nsd: this.value.nsd,
251 data: this.vnfDetails
252 };
253 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
254 if (result) {
255 this.sharedService.callData();
256 }
257 }).catch();
258 }
259
SANDHYA.JSfced3d42022-04-28 20:28:17 +0530260 /** To open VM Migration in NS Instances */
261 public openVmMigration(): void {
262 const modalRef: NgbModalRef = this.modalService.open(VmMigrationComponent, { backdrop: 'static' });
263 modalRef.componentInstance.params = {
264 id: this.instanceID
265 };
266 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
267 if (result) {
268 this.sharedService.callData();
269 }
270 }).catch();
271 }
272
Barath Kumar R07698ab2021-03-30 11:50:42 +0530273 /**
274 * Check any changes in the child component @public
275 */
276 public doChanges(): void {
277 setTimeout((): void => {
278 this.cd.detectChanges();
279 }, this.timeOut);
280 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530281}