| 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 | fced3d4 | 2022-04-28 20:28:17 +0530 | [diff] [blame] | 40 | import { VmMigrationComponent } from 'VmMigrationComponent'; |
| Barath Kumar R | 07698ab | 2021-03-30 11:50:42 +0530 | [diff] [blame] | 41 | import { DF, VDU, VNFD } from 'VNFDModel'; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 42 | /** |
| 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 */ |
| 52 | export 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 R | 07698ab | 2021-03-30 11:50:42 +0530 | [diff] [blame] | 68 | /** get Admin Details @public */ |
| 69 | public getAdminDetails: {}; |
| 70 | |
| 71 | /** Scaling is accepted @public */ |
| 72 | public isScalingPresent: boolean = false; |
| 73 | |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 74 | /** Check the loading results for loader status @public */ |
| Barath Kumar R | 07698ab | 2021-03-30 11:50:42 +0530 | [diff] [blame] | 75 | public isLoadingNSInstanceAction: boolean = false; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 76 | |
| 77 | /** Give the message for the loading @public */ |
| 78 | public message: string = 'PLEASEWAIT'; |
| 79 | |
| Barath Kumar R | 07698ab | 2021-03-30 11:50:42 +0530 | [diff] [blame] | 80 | /** Assign the VNF Details @public */ |
| 81 | public vnfDetails: VNFD[] = []; |
| 82 | |
| Barath Kumar R | f2ae546 | 2021-03-01 12:52:33 +0530 | [diff] [blame] | 83 | /** Contains instance ID @public */ |
| 84 | public instanceID: string; |
| 85 | |
| 86 | /** Contains operational dashboard view @public */ |
| 87 | public isShowOperationalDashboard: boolean = false; |
| 88 | |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 89 | /** 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.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 95 | /** 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 R | 07698ab | 2021-03-30 11:50:42 +0530 | [diff] [blame] | 108 | private timeOut: number = 100; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 109 | |
| 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 R | 07698ab | 2021-03-30 11:50:42 +0530 | [diff] [blame] | 128 | this.getAdminDetails = this.value.adminDetails; |
| Barath Kumar R | f2ae546 | 2021-03-01 12:52:33 +0530 | [diff] [blame] | 129 | this.isShowOperationalDashboard = !isNullOrUndefined(this.value.vcaStatus) ? |
| 130 | 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] | 131 | } |
| 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 R | 1a34b83 | 2021-03-05 11:32:19 +0530 | [diff] [blame] | 146 | modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 147 | 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 R | 1a34b83 | 2021-03-05 11:32:19 +0530 | [diff] [blame] | 155 | this.router.navigate(['/instances/ns/history-operations/', this.instanceID]).catch((): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 156 | // Catch Navigation Error |
| 157 | }); |
| 158 | } |
| 159 | |
| 160 | /** NS Topology */ |
| 161 | public nsTopology(): void { |
| Barath Kumar R | 1a34b83 | 2021-03-05 11:32:19 +0530 | [diff] [blame] | 162 | this.router.navigate(['/instances/ns/', this.instanceID]).catch((): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 163 | // Catch Navigation Error |
| 164 | }); |
| 165 | } |
| 166 | |
| 167 | /** Exec NS Primitive @public */ |
| 168 | public execNSPrimitiveModal(): void { |
| Barath Kumar R | d3ce0c5 | 2020-08-13 11:44:01 +0530 | [diff] [blame] | 169 | this.modalService.open(NSPrimitiveComponent, { backdrop: 'static' }).componentInstance.params = { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 170 | memberIndex: this.value.memberIndex, |
| Barath Kumar R | 54d693c | 2020-07-13 20:54:13 +0530 | [diff] [blame] | 171 | nsConfig: this.value.nsConfig, |
| 172 | name: this.value.NsdName |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 173 | }; |
| 174 | } |
| 175 | |
| 176 | /** Redirect to Grafana Metrics @public */ |
| 177 | public metrics(): void { |
| Barath Kumar R | 07698ab | 2021-03-30 11:50:42 +0530 | [diff] [blame] | 178 | this.isLoadingNSInstanceAction = true; |
| Barath Kumar R | 1a34b83 | 2021-03-05 11:32:19 +0530 | [diff] [blame] | 179 | this.restService.getResource(environment.NSDINSTANCES_URL + '/' + this.instanceID).subscribe((nsData: NSDDetails[]): void => { |
| 180 | nsData['vnfd-id'].forEach((vnfdID: string[]): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 181 | this.restService.getResource(environment.VNFPACKAGES_URL + '/' + vnfdID) |
| Barath Kumar R | 1a34b83 | 2021-03-05 11:32:19 +0530 | [diff] [blame] | 182 | .subscribe((vnfd: VNFD): void => { |
| 183 | vnfd.vdu.forEach((vduData: VDU): void => { |
| 184 | if (vduData['monitoring-parameter'] !== undefined && vduData['monitoring-parameter'].length > 0) { |
| Barath Kumar R | 07698ab | 2021-03-30 11:50:42 +0530 | [diff] [blame] | 185 | this.isLoadingNSInstanceAction = false; |
| Barath Kumar R | 1a34b83 | 2021-03-05 11:32:19 +0530 | [diff] [blame] | 186 | const location: string = environment.GRAFANA_URL + '/' + this.instanceID + '/osm-ns-metrics-metrics'; |
| 187 | window.open(location); |
| 188 | } else { |
| Barath Kumar R | 07698ab | 2021-03-30 11:50:42 +0530 | [diff] [blame] | 189 | this.isLoadingNSInstanceAction = false; |
| SANDHYA.JS | 9bae460 | 2022-04-05 07:28:32 +0530 | [diff] [blame] | 190 | this.notifierService.notify('error', this.translateService.instant('PAGE.NSMETRIC.METRICERROR')); |
| Barath Kumar R | 1a34b83 | 2021-03-05 11:32:19 +0530 | [diff] [blame] | 191 | } |
| 192 | }); |
| Barath Kumar R | 07698ab | 2021-03-30 11:50:42 +0530 | [diff] [blame] | 193 | this.doChanges(); |
| Barath Kumar R | 1a34b83 | 2021-03-05 11:32:19 +0530 | [diff] [blame] | 194 | }, (error: ERRORDATA): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 195 | this.restService.handleError(error, 'get'); |
| Barath Kumar R | 07698ab | 2021-03-30 11:50:42 +0530 | [diff] [blame] | 196 | this.isLoadingNSInstanceAction = false; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 197 | }); |
| 198 | }); |
| Barath Kumar R | 1a34b83 | 2021-03-05 11:32:19 +0530 | [diff] [blame] | 199 | }, (error: ERRORDATA): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 200 | this.restService.handleError(error, 'get'); |
| Barath Kumar R | 07698ab | 2021-03-30 11:50:42 +0530 | [diff] [blame] | 201 | this.isLoadingNSInstanceAction = false; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 202 | }); |
| 203 | } |
| Barath Kumar R | 07698ab | 2021-03-30 11:50:42 +0530 | [diff] [blame] | 204 | |
| 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.JS | fced3d4 | 2022-04-28 20:28:17 +0530 | [diff] [blame] | 262 | /** 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.JS | 9914458 | 2022-04-27 17:22:35 +0530 | [diff] [blame] | 275 | /** 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.JS | 3d81a28 | 2022-05-02 08:25:39 +0530 | [diff] [blame^] | 288 | /** 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 R | 07698ab | 2021-03-30 11:50:42 +0530 | [diff] [blame] | 309 | /** |
| 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.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 317 | } |