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