| 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'; |
| 32 | import { RestService } from 'RestService'; |
| 33 | import { SharedService } from 'SharedService'; |
| 34 | import { ShowInfoComponent } from 'ShowInfoComponent'; |
| 35 | /** |
| 36 | * Creating component |
| 37 | * @Component takes NSInstancesActionComponent.html as template url |
| 38 | */ |
| 39 | @Component({ |
| 40 | templateUrl: './NSInstancesActionComponent.html', |
| 41 | styleUrls: ['./NSInstancesActionComponent.scss'], |
| 42 | changeDetection: ChangeDetectionStrategy.OnPush |
| 43 | }) |
| 44 | /** Exporting a class @exports NSInstancesActionComponent */ |
| 45 | export class NSInstancesActionComponent { |
| 46 | /** To get the value from the nspackage via valuePrepareFunction default Property of ng-smarttable @public */ |
| 47 | public value: NSDInstanceData; |
| 48 | |
| 49 | /** Invoke service injectors @public */ |
| 50 | public injector: Injector; |
| 51 | |
| 52 | /** Instance of the modal service @public */ |
| 53 | public restService: RestService; |
| 54 | |
| 55 | /** Config Status Check @public */ |
| 56 | public configStatus: string; |
| 57 | |
| 58 | /** Operational Status Check @public */ |
| 59 | public operationalStatus: string; |
| 60 | |
| 61 | /** Check the loading results for loader status @public */ |
| 62 | public isLoadingMetricsResult: boolean = false; |
| 63 | |
| 64 | /** Give the message for the loading @public */ |
| 65 | public message: string = 'PLEASEWAIT'; |
| 66 | |
| 67 | /** Instance of the modal service @private */ |
| 68 | private modalService: NgbModal; |
| 69 | |
| 70 | /** Holds teh instance of AuthService class of type AuthService @private */ |
| 71 | private router: Router; |
| 72 | |
| 73 | /** Contains instance ID @private */ |
| 74 | private instanceID: string; |
| 75 | |
| 76 | /** Contains all methods related to shared @private */ |
| 77 | private sharedService: SharedService; |
| 78 | |
| 79 | /** Notifier service to popup notification @private */ |
| 80 | private notifierService: NotifierService; |
| 81 | |
| 82 | /** Contains tranlsate instance @private */ |
| 83 | private translateService: TranslateService; |
| 84 | |
| 85 | /** Detect changes for the User Input */ |
| 86 | private cd: ChangeDetectorRef; |
| 87 | |
| 88 | /** Set timeout @private */ |
| 89 | private timeOut: number = 1000; |
| 90 | |
| 91 | constructor(injector: Injector) { |
| 92 | this.injector = injector; |
| 93 | this.modalService = this.injector.get(NgbModal); |
| 94 | this.restService = this.injector.get(RestService); |
| 95 | this.router = this.injector.get(Router); |
| 96 | this.sharedService = this.injector.get(SharedService); |
| 97 | this.notifierService = this.injector.get(NotifierService); |
| 98 | this.translateService = this.injector.get(TranslateService); |
| 99 | this.cd = this.injector.get(ChangeDetectorRef); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Lifecyle Hooks the trigger before component is instantiate |
| 104 | */ |
| 105 | public ngOnInit(): void { |
| 106 | this.configStatus = this.value.ConfigStatus; |
| 107 | this.operationalStatus = this.value.OperationalStatus; |
| 108 | this.instanceID = this.value.identifier; |
| 109 | } |
| 110 | |
| 111 | /** Shows information using modalservice @public */ |
| 112 | public infoNs(): void { |
| 113 | this.modalService.open(ShowInfoComponent, { backdrop: 'static' }).componentInstance.params = { |
| 114 | id: this.instanceID, |
| 115 | page: 'ns-instance', |
| 116 | titleName: 'INSTANCEDETAILS' |
| 117 | }; |
| 118 | } |
| 119 | |
| 120 | /** Delete NS Instanace @public */ |
| 121 | public deleteNSInstance(forceAction: boolean): void { |
| 122 | const modalRef: NgbModalRef = this.modalService.open(DeleteComponent, { backdrop: 'static' }); |
| 123 | modalRef.componentInstance.params = { forceDeleteType: forceAction }; |
| 124 | modalRef.result.then((result: MODALCLOSERESPONSEDATA) => { |
| 125 | if (result) { |
| 126 | this.sharedService.callData(); |
| 127 | } |
| 128 | }).catch(); |
| 129 | } |
| 130 | |
| 131 | /** History of operations for an Instanace @public */ |
| 132 | public historyOfOperations(): void { |
| 133 | this.router.navigate(['/instances/ns/history-operations/', this.instanceID]).catch(() => { |
| 134 | // Catch Navigation Error |
| 135 | }); |
| 136 | } |
| 137 | |
| 138 | /** NS Topology */ |
| 139 | public nsTopology(): void { |
| 140 | this.router.navigate(['/instances/ns/', this.instanceID]).catch(() => { |
| 141 | // Catch Navigation Error |
| 142 | }); |
| 143 | } |
| 144 | |
| 145 | /** Exec NS Primitive @public */ |
| 146 | public execNSPrimitiveModal(): void { |
| 147 | this.modalService.open(NSPrimitiveComponent).componentInstance.params = { |
| 148 | memberIndex: this.value.memberIndex, |
| 149 | nsConfig: this.value.nsConfig |
| 150 | }; |
| 151 | } |
| 152 | |
| 153 | /** Redirect to Grafana Metrics @public */ |
| 154 | public metrics(): void { |
| 155 | this.isLoadingMetricsResult = true; |
| 156 | this.restService.getResource(environment.NSDINSTANCES_URL + '/' + this.instanceID).subscribe((nsData: NSDDetails[]) => { |
| 157 | nsData['vnfd-id'].forEach((vnfdID: string[]) => { |
| 158 | this.restService.getResource(environment.VNFPACKAGES_URL + '/' + vnfdID) |
| 159 | .subscribe((vnfd: {}[]) => { |
| 160 | if (vnfd['monitoring-param'] !== undefined && vnfd['monitoring-param'].length > 0) { |
| 161 | this.isLoadingMetricsResult = false; |
| 162 | const location: string = environment.GRAFANA_URL + '/' + this.instanceID + '/osm-ns-metrics-metrics'; |
| 163 | window.open(location); |
| 164 | } else { |
| 165 | this.isLoadingMetricsResult = false; |
| 166 | this.notifierService.notify('error', this.translateService.instant('GRAFANA.METRICSERROR')); |
| 167 | } |
| 168 | setTimeout(() => { |
| 169 | this.cd.detectChanges(); |
| 170 | }, this.timeOut); |
| 171 | }, (error: ERRORDATA) => { |
| 172 | this.restService.handleError(error, 'get'); |
| 173 | this.isLoadingMetricsResult = false; |
| 174 | }); |
| 175 | }); |
| 176 | }, (error: ERRORDATA) => { |
| 177 | this.restService.handleError(error, 'get'); |
| 178 | this.isLoadingMetricsResult = false; |
| 179 | }); |
| 180 | } |
| 181 | } |