| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 21 | import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Injector } from '@angular/core'; |
| 22 | import { Router } from '@angular/router'; |
| 23 | import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'; |
| 24 | import { TranslateService } from '@ngx-translate/core'; |
| 25 | import { NotifierService } from 'angular-notifier'; |
| 26 | import { ERRORDATA, MODALCLOSERESPONSEDATA } from 'CommonModel'; |
| 27 | import { DeleteComponent } from 'DeleteComponent'; |
| 28 | import { environment } from 'environment'; |
| 29 | import { NSDDetails } from 'NSDModel'; |
| 30 | import { NSDInstanceData } from 'NSInstanceModel'; |
| 31 | import { NSPrimitiveComponent } from 'NSPrimitiveComponent'; |
| SANDHYA.JS | 9914458 | 2022-04-27 17:22:35 +0530 | [diff] [blame] | 32 | import { NsUpdateComponent } from 'NsUpdateComponent'; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 33 | import { RestService } from 'RestService'; |
| Barath Kumar R | 07698ab | 2021-03-30 11:50:42 +0530 | [diff] [blame] | 34 | import { forkJoin, Observable } from 'rxjs'; |
| 35 | import { ScalingComponent } from 'ScalingComponent'; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 36 | import { SharedService } from 'SharedService'; |
| 37 | import { ShowInfoComponent } from 'ShowInfoComponent'; |
| SANDHYA.JS | 3d81a28 | 2022-05-02 08:25:39 +0530 | [diff] [blame] | 38 | import { StartStopRebuildComponent } from 'StartStopRebuildComponent'; |
| Barath Kumar R | 07698ab | 2021-03-30 11:50:42 +0530 | [diff] [blame] | 39 | import { isNullOrUndefined } from 'util'; |
| SANDHYA.JS | 017df36 | 2022-05-02 06:57:11 +0530 | [diff] [blame] | 40 | import { VerticalScalingComponent } from 'VerticalScalingComponent'; |
| SANDHYA.JS | fced3d4 | 2022-04-28 20:28:17 +0530 | [diff] [blame] | 41 | import { VmMigrationComponent } from 'VmMigrationComponent'; |
| Barath Kumar R | 07698ab | 2021-03-30 11:50:42 +0530 | [diff] [blame] | 42 | import { DF, VDU, VNFD } from 'VNFDModel'; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 43 | /** |
| 44 | * Creating component |
| 45 | * @Component takes NSInstancesActionComponent.html as template url |
| 46 | */ |
| 47 | @Component({ |
| 48 | templateUrl: './NSInstancesActionComponent.html', |
| 49 | styleUrls: ['./NSInstancesActionComponent.scss'], |
| 50 | changeDetection: ChangeDetectionStrategy.OnPush |
| 51 | }) |
| 52 | /** Exporting a class @exports NSInstancesActionComponent */ |
| 53 | export class NSInstancesActionComponent { |
| 54 | /** To get the value from the nspackage via valuePrepareFunction default Property of ng-smarttable @public */ |
| 55 | public value: NSDInstanceData; |
| 56 | |
| 57 | /** Invoke service injectors @public */ |
| 58 | public injector: Injector; |
| 59 | |
| 60 | /** Instance of the modal service @public */ |
| 61 | public restService: RestService; |
| 62 | |
| 63 | /** Config Status Check @public */ |
| 64 | public configStatus: string; |
| 65 | |
| 66 | /** Operational Status Check @public */ |
| 67 | public operationalStatus: string; |
| 68 | |
| Barath Kumar R | 07698ab | 2021-03-30 11:50:42 +0530 | [diff] [blame] | 69 | /** get Admin Details @public */ |
| 70 | public getAdminDetails: {}; |
| 71 | |
| 72 | /** Scaling is accepted @public */ |
| 73 | public isScalingPresent: boolean = false; |
| 74 | |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 75 | /** Check the loading results for loader status @public */ |
| Barath Kumar R | 07698ab | 2021-03-30 11:50:42 +0530 | [diff] [blame] | 76 | public isLoadingNSInstanceAction: boolean = false; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 77 | |
| 78 | /** Give the message for the loading @public */ |
| 79 | public message: string = 'PLEASEWAIT'; |
| 80 | |
| Barath Kumar R | 07698ab | 2021-03-30 11:50:42 +0530 | [diff] [blame] | 81 | /** Assign the VNF Details @public */ |
| 82 | public vnfDetails: VNFD[] = []; |
| 83 | |
| Barath Kumar R | f2ae546 | 2021-03-01 12:52:33 +0530 | [diff] [blame] | 84 | /** Contains instance ID @public */ |
| 85 | public instanceID: string; |
| 86 | |
| 87 | /** Contains operational dashboard view @public */ |
| 88 | public isShowOperationalDashboard: boolean = false; |
| 89 | |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 90 | /** Instance of the modal service @private */ |
| 91 | private modalService: NgbModal; |
| 92 | |
| 93 | /** Holds teh instance of AuthService class of type AuthService @private */ |
| 94 | private router: Router; |
| 95 | |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 96 | /** Contains all methods related to shared @private */ |
| 97 | private sharedService: SharedService; |
| 98 | |
| 99 | /** Notifier service to popup notification @private */ |
| 100 | private notifierService: NotifierService; |
| 101 | |
| 102 | /** Contains tranlsate instance @private */ |
| 103 | private translateService: TranslateService; |
| 104 | |
| 105 | /** Detect changes for the User Input */ |
| 106 | private cd: ChangeDetectorRef; |
| 107 | |
| 108 | /** Set timeout @private */ |
| Barath Kumar R | 07698ab | 2021-03-30 11:50:42 +0530 | [diff] [blame] | 109 | private timeOut: number = 100; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 110 | |
| 111 | constructor(injector: Injector) { |
| 112 | this.injector = injector; |
| 113 | this.modalService = this.injector.get(NgbModal); |
| 114 | this.restService = this.injector.get(RestService); |
| 115 | this.router = this.injector.get(Router); |
| 116 | this.sharedService = this.injector.get(SharedService); |
| 117 | this.notifierService = this.injector.get(NotifierService); |
| 118 | this.translateService = this.injector.get(TranslateService); |
| 119 | this.cd = this.injector.get(ChangeDetectorRef); |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Lifecyle Hooks the trigger before component is instantiate |
| 124 | */ |
| 125 | public ngOnInit(): void { |
| 126 | this.configStatus = this.value.ConfigStatus; |
| 127 | this.operationalStatus = this.value.OperationalStatus; |
| 128 | this.instanceID = this.value.identifier; |
| Barath Kumar R | 07698ab | 2021-03-30 11:50:42 +0530 | [diff] [blame] | 129 | this.getAdminDetails = this.value.adminDetails; |
| Barath Kumar R | f2ae546 | 2021-03-01 12:52:33 +0530 | [diff] [blame] | 130 | this.isShowOperationalDashboard = !isNullOrUndefined(this.value.vcaStatus) ? |
| 131 | Object.keys(this.value.vcaStatus).length === 0 && typeof this.value.vcaStatus === 'object' : true; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | /** Shows information using modalservice @public */ |
| 135 | public infoNs(): void { |
| 136 | this.modalService.open(ShowInfoComponent, { backdrop: 'static' }).componentInstance.params = { |
| 137 | id: this.instanceID, |
| 138 | page: 'ns-instance', |
| 139 | titleName: 'INSTANCEDETAILS' |
| 140 | }; |
| 141 | } |
| 142 | |
| 143 | /** Delete NS Instanace @public */ |
| 144 | public deleteNSInstance(forceAction: boolean): void { |
| 145 | const modalRef: NgbModalRef = this.modalService.open(DeleteComponent, { backdrop: 'static' }); |
| 146 | modalRef.componentInstance.params = { forceDeleteType: forceAction }; |
| Barath Kumar R | 1a34b83 | 2021-03-05 11:32:19 +0530 | [diff] [blame] | 147 | modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 148 | if (result) { |
| 149 | this.sharedService.callData(); |
| 150 | } |
| 151 | }).catch(); |
| 152 | } |
| 153 | |
| 154 | /** History of operations for an Instanace @public */ |
| 155 | public historyOfOperations(): void { |
| Barath Kumar R | 1a34b83 | 2021-03-05 11:32:19 +0530 | [diff] [blame] | 156 | this.router.navigate(['/instances/ns/history-operations/', this.instanceID]).catch((): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 157 | // Catch Navigation Error |
| 158 | }); |
| 159 | } |
| 160 | |
| 161 | /** NS Topology */ |
| 162 | public nsTopology(): void { |
| Barath Kumar R | 1a34b83 | 2021-03-05 11:32:19 +0530 | [diff] [blame] | 163 | this.router.navigate(['/instances/ns/', this.instanceID]).catch((): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 164 | // Catch Navigation Error |
| 165 | }); |
| 166 | } |
| 167 | |
| 168 | /** Exec NS Primitive @public */ |
| 169 | public execNSPrimitiveModal(): void { |
| Barath Kumar R | d3ce0c5 | 2020-08-13 11:44:01 +0530 | [diff] [blame] | 170 | this.modalService.open(NSPrimitiveComponent, { backdrop: 'static' }).componentInstance.params = { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 171 | memberIndex: this.value.memberIndex, |
| Barath Kumar R | 54d693c | 2020-07-13 20:54:13 +0530 | [diff] [blame] | 172 | nsConfig: this.value.nsConfig, |
| SANDHYA.JS | 1584e3e | 2022-10-31 20:11:50 +0530 | [diff] [blame] | 173 | name: this.value.NsdName, |
| 174 | id: this.value.constituent |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 175 | }; |
| 176 | } |
| 177 | |
| 178 | /** Redirect to Grafana Metrics @public */ |
| 179 | public metrics(): void { |
| Barath Kumar R | 07698ab | 2021-03-30 11:50:42 +0530 | [diff] [blame] | 180 | this.isLoadingNSInstanceAction = true; |
| Barath Kumar R | 1a34b83 | 2021-03-05 11:32:19 +0530 | [diff] [blame] | 181 | this.restService.getResource(environment.NSDINSTANCES_URL + '/' + this.instanceID).subscribe((nsData: NSDDetails[]): void => { |
| 182 | nsData['vnfd-id'].forEach((vnfdID: string[]): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 183 | this.restService.getResource(environment.VNFPACKAGES_URL + '/' + vnfdID) |
| Barath Kumar R | 1a34b83 | 2021-03-05 11:32:19 +0530 | [diff] [blame] | 184 | .subscribe((vnfd: VNFD): void => { |
| 185 | vnfd.vdu.forEach((vduData: VDU): void => { |
| 186 | if (vduData['monitoring-parameter'] !== undefined && vduData['monitoring-parameter'].length > 0) { |
| Barath Kumar R | 07698ab | 2021-03-30 11:50:42 +0530 | [diff] [blame] | 187 | this.isLoadingNSInstanceAction = false; |
| Barath Kumar R | 1a34b83 | 2021-03-05 11:32:19 +0530 | [diff] [blame] | 188 | const location: string = environment.GRAFANA_URL + '/' + this.instanceID + '/osm-ns-metrics-metrics'; |
| 189 | window.open(location); |
| 190 | } else { |
| Barath Kumar R | 07698ab | 2021-03-30 11:50:42 +0530 | [diff] [blame] | 191 | this.isLoadingNSInstanceAction = false; |
| SANDHYA.JS | 9bae460 | 2022-04-05 07:28:32 +0530 | [diff] [blame] | 192 | this.notifierService.notify('error', this.translateService.instant('PAGE.NSMETRIC.METRICERROR')); |
| Barath Kumar R | 1a34b83 | 2021-03-05 11:32:19 +0530 | [diff] [blame] | 193 | } |
| 194 | }); |
| Barath Kumar R | 07698ab | 2021-03-30 11:50:42 +0530 | [diff] [blame] | 195 | this.doChanges(); |
| Barath Kumar R | 1a34b83 | 2021-03-05 11:32:19 +0530 | [diff] [blame] | 196 | }, (error: ERRORDATA): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 197 | this.restService.handleError(error, 'get'); |
| Barath Kumar R | 07698ab | 2021-03-30 11:50:42 +0530 | [diff] [blame] | 198 | this.isLoadingNSInstanceAction = false; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 199 | }); |
| 200 | }); |
| Barath Kumar R | 1a34b83 | 2021-03-05 11:32:19 +0530 | [diff] [blame] | 201 | }, (error: ERRORDATA): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 202 | this.restService.handleError(error, 'get'); |
| Barath Kumar R | 07698ab | 2021-03-30 11:50:42 +0530 | [diff] [blame] | 203 | this.isLoadingNSInstanceAction = false; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 204 | }); |
| 205 | } |
| Barath Kumar R | 07698ab | 2021-03-30 11:50:42 +0530 | [diff] [blame] | 206 | |
| 207 | /** |
| 208 | * Do the manual scaling |
| 209 | * Here we are going to get a list of VNFD ID used in the instances |
| 210 | * and have this in array with URL created then pass to checkscaling method for forkjoin to get the data @public |
| 211 | */ |
| 212 | public manualScaling(): void { |
| 213 | this.isLoadingNSInstanceAction = true; |
| 214 | const tempURL: Observable<{}>[] = []; |
| 215 | this.value.vnfID.forEach((id: string): void => { |
| 216 | const apiUrl: string = environment.VNFPACKAGESCONTENT_URL + '/' + id; |
| 217 | tempURL.push(this.restService.getResource(apiUrl)); |
| 218 | }); |
| 219 | this.checkScaling(tempURL); |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * Used to forkjoin to all the request to send parallely, get the data and check 'scaling-aspect' key is present @public |
| 224 | */ |
| 225 | public checkScaling(URLS: Observable<{}>[]): void { |
| 226 | forkJoin(URLS).subscribe((data: VNFD[]): void => { |
| 227 | this.vnfDetails = data; |
| 228 | if (this.vnfDetails.length > 0) { |
| 229 | this.vnfDetails.forEach((vnfdData: VNFD): void => { |
| 230 | vnfdData.df.forEach((dfData: DF): void => { |
| 231 | if (!isNullOrUndefined(dfData['scaling-aspect']) && dfData['scaling-aspect'].length > 0) { |
| 232 | this.isScalingPresent = true; |
| 233 | } |
| 234 | }); |
| 235 | }); |
| 236 | } |
| 237 | this.isLoadingNSInstanceAction = false; |
| 238 | if (this.isScalingPresent) { |
| 239 | this.openScaling(); |
| 240 | } else { |
| 241 | this.notifierService.notify('error', this.translateService.instant('SCALINGNOTFOUND')); |
| 242 | } |
| 243 | this.doChanges(); |
| 244 | }); |
| 245 | } |
| 246 | |
| 247 | /** Open the scaling pop-up @public */ |
| 248 | public openScaling(): void { |
| 249 | const modalRef: NgbModalRef = this.modalService.open(ScalingComponent, { backdrop: 'static' }); |
| 250 | modalRef.componentInstance.params = { |
| 251 | id: this.instanceID, |
| 252 | vnfID: this.value.vnfID, |
| 253 | nsID: this.value['nsd-id'], |
| 254 | nsd: this.value.nsd, |
| 255 | data: this.vnfDetails |
| 256 | }; |
| 257 | modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => { |
| 258 | if (result) { |
| 259 | this.sharedService.callData(); |
| 260 | } |
| 261 | }).catch(); |
| 262 | } |
| 263 | |
| SANDHYA.JS | fced3d4 | 2022-04-28 20:28:17 +0530 | [diff] [blame] | 264 | /** To open VM Migration in NS Instances */ |
| 265 | public openVmMigration(): void { |
| 266 | const modalRef: NgbModalRef = this.modalService.open(VmMigrationComponent, { backdrop: 'static' }); |
| 267 | modalRef.componentInstance.params = { |
| 268 | id: this.instanceID |
| 269 | }; |
| 270 | modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => { |
| 271 | if (result) { |
| 272 | this.sharedService.callData(); |
| 273 | } |
| 274 | }).catch(); |
| 275 | } |
| 276 | |
| SANDHYA.JS | 9914458 | 2022-04-27 17:22:35 +0530 | [diff] [blame] | 277 | /** To open the Ns Update pop-up */ |
| 278 | public openNsUpdate(): void { |
| 279 | const modalRef: NgbModalRef = this.modalService.open(NsUpdateComponent, { backdrop: 'static' }); |
| 280 | modalRef.componentInstance.params = { |
| 281 | id: this.instanceID |
| 282 | }; |
| 283 | modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => { |
| 284 | if (result) { |
| 285 | this.sharedService.callData(); |
| 286 | } |
| 287 | }).catch(); |
| 288 | } |
| 289 | |
| SANDHYA.JS | 3d81a28 | 2022-05-02 08:25:39 +0530 | [diff] [blame] | 290 | /** To open the Start, Stop & Rebuild pop-up */ |
| 291 | public openStart(actionType: string): void { |
| 292 | const modalRef: NgbModalRef = this.modalService.open(StartStopRebuildComponent, { backdrop: 'static' }); |
| 293 | modalRef.componentInstance.params = { |
| 294 | id: this.instanceID |
| 295 | }; |
| 296 | if (actionType === 'start') { |
| 297 | modalRef.componentInstance.instanceTitle = this.translateService.instant('START'); |
| 298 | } else if (actionType === 'stop') { |
| 299 | modalRef.componentInstance.instanceTitle = this.translateService.instant('STOP'); |
| 300 | } else { |
| 301 | modalRef.componentInstance.instanceTitle = this.translateService.instant('REBUILD'); |
| 302 | } |
| 303 | modalRef.componentInstance.instanceType = actionType; |
| 304 | modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => { |
| 305 | if (result) { |
| 306 | this.sharedService.callData(); |
| 307 | } |
| 308 | }).catch(); |
| 309 | } |
| 310 | |
| SANDHYA.JS | 017df36 | 2022-05-02 06:57:11 +0530 | [diff] [blame] | 311 | /** To open the vertical Scaling pop-up */ |
| 312 | public openVerticalScaling(): void { |
| 313 | const modalRef: NgbModalRef = this.modalService.open(VerticalScalingComponent, { backdrop: 'static' }); |
| 314 | modalRef.componentInstance.params = { |
| 315 | id: this.instanceID |
| 316 | }; |
| 317 | modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => { |
| 318 | if (result) { |
| 319 | this.sharedService.callData(); |
| 320 | } |
| 321 | }).catch(); |
| 322 | } |
| 323 | |
| Barath Kumar R | 07698ab | 2021-03-30 11:50:42 +0530 | [diff] [blame] | 324 | /** |
| 325 | * Check any changes in the child component @public |
| 326 | */ |
| 327 | public doChanges(): void { |
| 328 | setTimeout((): void => { |
| 329 | this.cd.detectChanges(); |
| 330 | }, this.timeOut); |
| 331 | } |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 332 | } |