| 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 Dashboard Component |
| 20 | */ |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 21 | import { isNullOrUndefined } from 'util'; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 22 | import { Component, Injector, OnInit } from '@angular/core'; |
| 23 | import { TranslateService } from '@ngx-translate/core'; |
| SANDHYA.JS | 4a7a542 | 2021-05-15 15:35:22 +0530 | [diff] [blame] | 24 | import { NotifierService } from 'angular-notifier'; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 25 | import { AuthenticationService } from 'AuthenticationService'; |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 26 | import { Chart, ChartType, LineController, LineElement, PointElement, LinearScale, Title, ChartEvent, ActiveElement } from 'chart.js'; |
| 27 | import ChartDataLabels from 'chartjs-plugin-datalabels'; |
| 28 | Chart.register(LineController, LineElement, PointElement, LinearScale, Title, ChartDataLabels); |
| SANDHYA.JS | 4a7a542 | 2021-05-15 15:35:22 +0530 | [diff] [blame] | 29 | import { ERRORDATA, TYPESECTION, VIM_TYPES } from 'CommonModel'; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 30 | import { environment } from 'environment'; |
| 31 | import { NSDDetails } from 'NSDModel'; |
| 32 | import { NSInstanceDetails } from 'NSInstanceModel'; |
| 33 | import { ProjectData, ProjectDetails } from 'ProjectModel'; |
| 34 | import { ProjectService } from 'ProjectService'; |
| 35 | import { RestService } from 'RestService'; |
| 36 | import { Observable, Subscription } from 'rxjs'; |
| 37 | import { SDNControllerModel } from 'SDNControllerModel'; |
| 38 | import { SharedService } from 'SharedService'; |
| 39 | import { ProjectRoleMappings, UserDetail } from 'UserModel'; |
| 40 | import { VimAccountDetails } from 'VimAccountModel'; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 41 | import { VNFInstanceDetails } from 'VNFInstanceModel'; |
| 42 | |
| 43 | /** |
| 44 | * Creating component |
| 45 | * @Component takes DashboardComponent.html as template url |
| 46 | */ |
| 47 | @Component({ |
| 48 | styleUrls: ['./DashboardComponent.scss'], |
| 49 | templateUrl: './DashboardComponent.html' |
| 50 | }) |
| 51 | |
| 52 | /** |
| 53 | * This file created during the angular project creation |
| 54 | */ |
| 55 | |
| 56 | /** Exporting a class @exports DashboardComponent */ |
| 57 | export class DashboardComponent implements OnInit { |
| 58 | /** Invoke service injectors @public */ |
| 59 | public injector: Injector; |
| 60 | |
| harshini.r | 3649a5c | 2022-04-28 12:43:12 +0530 | [diff] [blame] | 61 | /** Handle translate @public */ |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 62 | public translateService: TranslateService; |
| 63 | |
| 64 | /** Observable holds logined value @public */ |
| 65 | public username$: Observable<string>; |
| 66 | |
| 67 | /** Variables holds admin is logged or not @public */ |
| 68 | public isAdmin: boolean; |
| 69 | |
| 70 | /** List of NS failed Instances @public */ |
| 71 | public nsFailedInstances: {}[] = []; |
| 72 | |
| 73 | /** Setting up count for vnfdPackages @public */ |
| 74 | public vnfdPackageCount: number; |
| 75 | |
| 76 | /** Setting up count for nsdPackage @public */ |
| 77 | public nsdPackageCount: number; |
| 78 | |
| 79 | /** Setting up count for nsInstance @public */ |
| 80 | public nsInstanceCount: number; |
| 81 | |
| 82 | /** Setting up count for vnfInstance @public */ |
| 83 | public vnfInstanceCount: number; |
| 84 | |
| 85 | /** Setting up count for vimAccount @public */ |
| 86 | public vimAccountCount: number; |
| 87 | |
| 88 | /** Setting up count for sdnController @public */ |
| 89 | public sdnControllerCount: number; |
| 90 | |
| 91 | /** Variables holds current project details @public */ |
| 92 | public currentProjectDetails: {}; |
| 93 | |
| 94 | /** Array holds all the projects @public */ |
| 95 | public projectList: {}[] = []; |
| 96 | |
| 97 | /** Array holds all the projects @public */ |
| 98 | public allProjectList: {}[] = []; |
| 99 | |
| 100 | /** Variables holds the selected project @public */ |
| 101 | public selectedProject: Observable<string>; |
| 102 | |
| 103 | /** Check the Instances loading results @public */ |
| 104 | public isCanvasLoadingResults: boolean = true; |
| 105 | |
| 106 | /** Check the Projects loading results @public */ |
| 107 | public isProjectsLoadingResults: boolean = true; |
| 108 | |
| 109 | /** Give the message for the loading @public */ |
| 110 | public message: string = 'PLEASEWAIT'; |
| 111 | |
| Barath Kumar R | 208bef2 | 2020-07-07 12:28:04 +0530 | [diff] [blame] | 112 | /** List of NS Success Instances @public */ |
| Barath Kumar R | 5abb274 | 2020-11-22 20:15:10 +0530 | [diff] [blame] | 113 | public nsRunningInstance: string[] = []; |
| Barath Kumar R | 208bef2 | 2020-07-07 12:28:04 +0530 | [diff] [blame] | 114 | |
| SANDHYA.JS | 4a7a542 | 2021-05-15 15:35:22 +0530 | [diff] [blame] | 115 | /** Contains VIM Account details @public */ |
| 116 | public vimData: VimAccountDetails[] = []; |
| 117 | |
| 118 | /** Contains Selected VIM Details @public */ |
| 119 | public selectedVIMDetails: VimAccountDetails = null; |
| 120 | |
| 121 | /** List of VIM_TYPES @public */ |
| 122 | public vimTypes: TYPESECTION[] = VIM_TYPES; |
| 123 | |
| 124 | /** Array holds Vim data filtered with selected vimtype */ |
| 125 | public vimList: VimAccountDetails[] = []; |
| 126 | |
| SANDHYA.JS | 0e9c0a4 | 2022-04-04 18:44:53 +0530 | [diff] [blame] | 127 | /** Model value used to hold selected vimtype Data @public */ |
| 128 | public vimListData: string; |
| 129 | |
| Barath Kumar R | 208bef2 | 2020-07-07 12:28:04 +0530 | [diff] [blame] | 130 | /** List of color for Instances @private */ |
| 131 | private backgroundColor: string[] = []; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 132 | |
| 133 | /** Utilizes rest service for any CRUD operations @private */ |
| 134 | private restService: RestService; |
| 135 | |
| 136 | /** Utilizes auth service for any auth operations @private */ |
| 137 | private authService: AuthenticationService; |
| 138 | |
| 139 | /** Used to subscribe vnfdPackage @private */ |
| 140 | private vnfdPackageCountSub: Subscription; |
| 141 | |
| 142 | /** Used to subscribe nsdPackage @private */ |
| 143 | private nsdPackageCountSub: Subscription; |
| 144 | |
| 145 | /** Used to subscribe nsInstance @private */ |
| 146 | private nsInstanceCountSub: Subscription; |
| 147 | |
| 148 | /** Used to subscribe vnfInstance @private */ |
| 149 | private vnfInstanceCountSub: Subscription; |
| 150 | |
| 151 | /** Used to subscribe vimAccount @private */ |
| 152 | private vimAccountCountSub: Subscription; |
| 153 | |
| 154 | /** Used to subscribe sdnController @private */ |
| 155 | private sdnControllerCountSub: Subscription; |
| 156 | |
| 157 | /** No of Hours of NS Success Instances @private */ |
| 158 | private noOfHours: number[] = []; |
| 159 | |
| 160 | /** collects charts objects @private */ |
| 161 | private charts: object = []; |
| 162 | |
| 163 | /** Contains all methods related to projects @private */ |
| 164 | private projectService: ProjectService; |
| 165 | |
| 166 | /** Contains all methods related to shared @private */ |
| 167 | private sharedService: SharedService; |
| 168 | |
| 169 | /** Contains NS Instance Details */ |
| 170 | private nsInstancesDataArr: {}[]; |
| 171 | |
| 172 | /** Container created time array @private */ |
| 173 | private createdTimes: string[] = []; |
| 174 | |
| 175 | /** Contains slice limit const @private */ |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 176 | // eslint-disable-next-line @typescript-eslint/no-magic-numbers |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 177 | private sliceLimit: number = 10; |
| 178 | |
| 179 | /** Contians hour converter @private */ |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 180 | // eslint-disable-next-line @typescript-eslint/no-magic-numbers |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 181 | private hourConverter: number = 3600; |
| 182 | |
| harshini.r | 3649a5c | 2022-04-28 12:43:12 +0530 | [diff] [blame] | 183 | /** Converter used to round off time to one decimal point @private */ |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 184 | // eslint-disable-next-line @typescript-eslint/no-magic-numbers |
| harshini.r | 3649a5c | 2022-04-28 12:43:12 +0530 | [diff] [blame] | 185 | private converter: number = 10; |
| 186 | |
| SANDHYA.JS | 4a7a542 | 2021-05-15 15:35:22 +0530 | [diff] [blame] | 187 | /** Notifier service to popup notification @private */ |
| 188 | private notifierService: NotifierService; |
| 189 | |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 190 | constructor(injector: Injector) { |
| 191 | this.injector = injector; |
| 192 | this.restService = this.injector.get(RestService); |
| 193 | this.authService = this.injector.get(AuthenticationService); |
| 194 | this.projectService = this.injector.get(ProjectService); |
| 195 | this.sharedService = this.injector.get(SharedService); |
| 196 | this.translateService = this.injector.get(TranslateService); |
| SANDHYA.JS | 4a7a542 | 2021-05-15 15:35:22 +0530 | [diff] [blame] | 197 | this.notifierService = this.injector.get(NotifierService); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | /** |
| 201 | * Lifecyle Hooks the trigger before component is instantiate |
| 202 | */ |
| 203 | public ngOnInit(): void { |
| 204 | this.username$ = this.authService.username; |
| SANDHYA.JS | 5b35bcd | 2023-04-27 15:11:06 +0530 | [diff] [blame] | 205 | this.isAdmin = (sessionStorage.getItem('isAdmin') === 'true') ? true : false; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 206 | this.selectedProject = this.authService.ProjectName; |
| 207 | this.checkAdminPrivilege(); |
| 208 | this.getUserAccessedProjects(); |
| 209 | this.getAllProjects(); |
| 210 | this.getVnfdPackageCount(); |
| 211 | this.getNsdPackageCount(); |
| 212 | this.getNsInstanceCount(); |
| 213 | this.getVnfInstanceCount(); |
| 214 | this.getVimAccountCount(); |
| 215 | this.getSDNControllerCount(); |
| 216 | } |
| 217 | |
| 218 | /** Get all the projects @public */ |
| 219 | public getUserAccessedProjects(): void { |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 220 | this.projectService.getUserProjects().subscribe((projects: UserDetail): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 221 | const projectList: {}[] = projects.project_role_mappings; |
| 222 | this.projectList = projectList.filter( |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 223 | (thing: ProjectRoleMappings, i: number, arr: []): boolean => arr |
| 224 | .findIndex((t: ProjectRoleMappings): boolean => t.project_name === thing.project_name) === i |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 225 | ); |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 226 | }, (error: Error): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 227 | // TODO: Handle failure |
| 228 | }); |
| 229 | } |
| 230 | |
| 231 | /** Fetching all the Project in dashboard @public */ |
| 232 | public getAllProjects(): void { |
| 233 | this.isProjectsLoadingResults = true; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 234 | this.restService.getResource(environment.PROJECTS_URL).subscribe((projectsData: ProjectDetails[]): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 235 | this.allProjectList = []; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 236 | projectsData.forEach((projectData: ProjectDetails): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 237 | const projectDataObj: ProjectData = this.generateProjectData(projectData); |
| 238 | this.allProjectList.push(projectDataObj); |
| 239 | }); |
| 240 | this.isProjectsLoadingResults = false; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 241 | }, (error: ERRORDATA): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 242 | this.restService.handleError(error, 'get'); |
| 243 | this.isProjectsLoadingResults = false; |
| 244 | }); |
| 245 | } |
| 246 | |
| 247 | /** Generate Projects object from loop and return for the datasource @public */ |
| 248 | public generateProjectData(projectData: ProjectDetails): ProjectData { |
| 249 | return { |
| 250 | projectName: projectData.name, |
| 251 | modificationDate: this.sharedService.convertEpochTime(projectData._admin.modified), |
| 252 | creationDate: this.sharedService.convertEpochTime(projectData._admin.created), |
| 253 | id: projectData._id, |
| 254 | project: projectData._id |
| 255 | }; |
| 256 | } |
| 257 | |
| 258 | /** Function to check admin privilege @public */ |
| 259 | public checkAdminPrivilege(): void { |
| 260 | if (!this.isAdmin) { |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 261 | this.projectService.getCurrentProjectDetails().subscribe((projectDetails: {}): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 262 | this.currentProjectDetails = projectDetails; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 263 | }, (error: Error): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 264 | // TODO: Handle failure |
| 265 | }); |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | /** Get VNFD Package details @public */ |
| 270 | public getVnfdPackageCount(): void { |
| 271 | this.vnfdPackageCountSub = this.restService.getResource(environment.VNFPACKAGESCONTENT_URL) |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 272 | .subscribe((vnfdPackageData: []): void => { |
| Barath Kumar R | 208bef2 | 2020-07-07 12:28:04 +0530 | [diff] [blame] | 273 | this.vnfdPackageCount = vnfdPackageData.length; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 274 | }, (error: ERRORDATA): void => { |
| Barath Kumar R | 208bef2 | 2020-07-07 12:28:04 +0530 | [diff] [blame] | 275 | this.restService.handleError(error, 'get'); |
| 276 | }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | /** Get NSD Package details @public */ |
| 280 | public getNsdPackageCount(): void { |
| 281 | this.nsdPackageCountSub = this.restService.getResource(environment.NSDESCRIPTORSCONTENT_URL) |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 282 | .subscribe((nsdPackageData: NSDDetails[]): void => { |
| Barath Kumar R | 208bef2 | 2020-07-07 12:28:04 +0530 | [diff] [blame] | 283 | this.nsdPackageCount = nsdPackageData.length; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 284 | }, (error: ERRORDATA): void => { |
| Barath Kumar R | 208bef2 | 2020-07-07 12:28:04 +0530 | [diff] [blame] | 285 | this.restService.handleError(error, 'get'); |
| 286 | }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | /** Get NS Instance details @public */ |
| 290 | public getNsInstanceCount(): void { |
| 291 | this.isCanvasLoadingResults = true; |
| 292 | this.nsInstanceCountSub = this.restService.getResource(environment.NSDINSTANCES_URL) |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 293 | .subscribe((nsInstancesData: NSInstanceDetails[]): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 294 | this.nsInstancesDataArr = nsInstancesData; |
| 295 | this.nsInstanceCount = nsInstancesData.length; |
| 296 | this.nsInstanceChart(); |
| 297 | this.isCanvasLoadingResults = false; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 298 | }, (error: ERRORDATA): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 299 | this.restService.handleError(error, 'get'); |
| 300 | this.isCanvasLoadingResults = false; |
| 301 | }); |
| 302 | } |
| 303 | |
| 304 | /** Get NS Instance chart details @public */ |
| 305 | public nsInstanceChart(): void { |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 306 | this.nsInstancesDataArr.forEach((nsdInstanceData: NSDDetails): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 307 | const operationalStatus: string = nsdInstanceData['operational-status']; |
| 308 | const configStatus: string = nsdInstanceData['config-status']; |
| 309 | if (operationalStatus === 'failed' || configStatus === 'failed') { |
| 310 | this.nsFailedInstances.push(nsdInstanceData); |
| 311 | } else if (operationalStatus === 'running' && configStatus === 'configured') { |
| Barath Kumar R | 5abb274 | 2020-11-22 20:15:10 +0530 | [diff] [blame] | 312 | this.nsRunningInstance.push(nsdInstanceData.name); |
| Barath Kumar R | 208bef2 | 2020-07-07 12:28:04 +0530 | [diff] [blame] | 313 | this.backgroundColor.push(this.sharedService.generateColor()); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 314 | this.createdTimes.push(((nsdInstanceData._admin.created).toString()).slice(0, this.sliceLimit)); |
| 315 | } |
| 316 | }); |
| 317 | const now: Date = new Date(); |
| 318 | const currentTime: number = Number((now.getTime().toString().slice(0, this.sliceLimit))); |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 319 | this.createdTimes.forEach((createdTime: string): void => { |
| harshini.r | 3649a5c | 2022-04-28 12:43:12 +0530 | [diff] [blame] | 320 | this.noOfHours.push(Math.floor(((currentTime - Number(createdTime)) / this.hourConverter) * (this.converter)) / this.converter); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 321 | }); |
| 322 | this.drawNsChart(); |
| 323 | } |
| 324 | |
| 325 | /** Prepare and sketch NS instance chart */ |
| 326 | public drawNsChart(): void { |
| 327 | this.charts = new Chart('canvas', { |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 328 | type: 'bar' as ChartType, |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 329 | data: { |
| 330 | labels: this.nsRunningInstance, |
| 331 | datasets: [{ |
| 332 | data: this.noOfHours, |
| 333 | label: this.translateService.instant('NOOFHOURS'), |
| Barath Kumar R | 208bef2 | 2020-07-07 12:28:04 +0530 | [diff] [blame] | 334 | borderColor: this.backgroundColor, |
| Barath Kumar R | e53dbb6 | 2021-06-08 11:06:38 +0530 | [diff] [blame] | 335 | fill: false, |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 336 | backgroundColor: this.backgroundColor, |
| 337 | hoverBackgroundColor: this.backgroundColor |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 338 | }] |
| 339 | }, |
| 340 | options: { |
| SANDHYA.JS | 9bae460 | 2022-04-05 07:28:32 +0530 | [diff] [blame] | 341 | layout: { |
| 342 | padding: { |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 343 | top: 25 |
| SANDHYA.JS | 9bae460 | 2022-04-05 07:28:32 +0530 | [diff] [blame] | 344 | } |
| 345 | }, |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 346 | animation: false, |
| 347 | // eslint-disable-next-line prefer-arrow/prefer-arrow-functions |
| 348 | onHover(event: ChartEvent, item: ActiveElement[], chart: Chart): void { |
| 349 | const el: HTMLElement = document.getElementById('canvas'); |
| 350 | el.style.cursor = item[0] ? 'pointer' : 'default'; |
| Barath Kumar R | 208bef2 | 2020-07-07 12:28:04 +0530 | [diff] [blame] | 351 | }, |
| SANDHYA.JS | 4a7a542 | 2021-05-15 15:35:22 +0530 | [diff] [blame] | 352 | plugins: { |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 353 | legend: { display: false }, |
| 354 | datalabels: { |
| 355 | anchor: 'end', |
| 356 | align: 'top', |
| 357 | font: { |
| 358 | weight: 'bold' |
| 359 | } |
| SANDHYA.JS | 4a7a542 | 2021-05-15 15:35:22 +0530 | [diff] [blame] | 360 | } |
| 361 | }, |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 362 | scales: { |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 363 | x: { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 364 | display: true, |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 365 | title: { |
| Barath Kumar R | e53dbb6 | 2021-06-08 11:06:38 +0530 | [diff] [blame] | 366 | display: true, |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 367 | text: this.translateService.instant('NSINSTANCES') |
| Barath Kumar R | e53dbb6 | 2021-06-08 11:06:38 +0530 | [diff] [blame] | 368 | } |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 369 | }, |
| 370 | y: { |
| 371 | beginAtZero: true, |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 372 | display: true, |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 373 | title: { |
| Barath Kumar R | e53dbb6 | 2021-06-08 11:06:38 +0530 | [diff] [blame] | 374 | display: true, |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 375 | text: this.translateService.instant('NOOFHOURS') |
| Barath Kumar R | e53dbb6 | 2021-06-08 11:06:38 +0530 | [diff] [blame] | 376 | } |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 377 | } |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 378 | } |
| 379 | } |
| 380 | }); |
| 381 | } |
| 382 | |
| 383 | /** Get VNFD instance details @public */ |
| 384 | public getVnfInstanceCount(): void { |
| harshini.r | 3649a5c | 2022-04-28 12:43:12 +0530 | [diff] [blame] | 385 | this.vnfInstanceCountSub = this.restService.getResource(environment.VNFINSTANCES_URL) |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 386 | .subscribe((vnfInstanceData: VNFInstanceDetails[]): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 387 | this.vnfInstanceCount = vnfInstanceData.length; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 388 | }, (error: ERRORDATA): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 389 | this.restService.handleError(error, 'get'); |
| 390 | }); |
| 391 | } |
| 392 | |
| 393 | /** Get VIM account details @public */ |
| 394 | public getVimAccountCount(): void { |
| 395 | this.vimAccountCountSub = this.restService.getResource(environment.VIMACCOUNTS_URL) |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 396 | .subscribe((vimAccountData: VimAccountDetails[]): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 397 | this.vimAccountCount = vimAccountData.length; |
| SANDHYA.JS | 4a7a542 | 2021-05-15 15:35:22 +0530 | [diff] [blame] | 398 | this.vimData = vimAccountData; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 399 | }, (error: ERRORDATA): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 400 | this.restService.handleError(error, 'get'); |
| 401 | }); |
| 402 | } |
| 403 | |
| 404 | /** Get SDN Controller Count @public */ |
| 405 | public getSDNControllerCount(): void { |
| 406 | this.sdnControllerCountSub = this.restService.getResource(environment.SDNCONTROLLER_URL) |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 407 | .subscribe((sdnControllerData: SDNControllerModel[]): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 408 | this.sdnControllerCount = sdnControllerData.length; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 409 | }, (error: ERRORDATA): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 410 | this.restService.handleError(error, 'get'); |
| 411 | }); |
| 412 | } |
| 413 | |
| SANDHYA.JS | 4a7a542 | 2021-05-15 15:35:22 +0530 | [diff] [blame] | 414 | /** Get Vim data filtered by the selected Vim Type @public */ |
| 415 | public getSelectedVimTypeList(selectedVIMType: string): void { |
| 416 | this.vimList = this.vimData.filter((vimData: VimAccountDetails): boolean => |
| 417 | vimData.vim_type === selectedVIMType); |
| SANDHYA.JS | 0e9c0a4 | 2022-04-04 18:44:53 +0530 | [diff] [blame] | 418 | if (this.vimList.length === 0) { |
| 419 | this.vimListData = null; |
| 420 | } |
| SANDHYA.JS | 4a7a542 | 2021-05-15 15:35:22 +0530 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | /** Get Selected VIM details @public */ |
| 424 | public getSelectedVIMDetails(vimDetails: VimAccountDetails): void { |
| 425 | if (!isNullOrUndefined(vimDetails.resources)) { |
| 426 | this.selectedVIMDetails = vimDetails; |
| 427 | } else { |
| 428 | this.notifierService.notify('error', this.translateService.instant('RESOURCESNOTFOUND')); |
| 429 | } |
| 430 | } |
| 431 | |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 432 | /** |
| 433 | * Lifecyle Hooks the trigger before component is deleted |
| 434 | */ |
| 435 | public ngOnDestroy(): void { |
| 436 | this.vnfdPackageCountSub.unsubscribe(); |
| 437 | this.nsdPackageCountSub.unsubscribe(); |
| 438 | this.nsInstanceCountSub.unsubscribe(); |
| 439 | this.vnfInstanceCountSub.unsubscribe(); |
| 440 | this.vimAccountCountSub.unsubscribe(); |
| 441 | this.sdnControllerCountSub.unsubscribe(); |
| 442 | } |
| 443 | } |