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