| 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 Compose 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 { HttpHeaders } from '@angular/common/http'; |
| 23 | import { Component, ElementRef, Injector, ViewChild, ViewEncapsulation } from '@angular/core'; |
| 24 | import { ActivatedRoute, Router } from '@angular/router'; |
| 25 | import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'; |
| 26 | import { TranslateService } from '@ngx-translate/core'; |
| 27 | import { NotifierService } from 'angular-notifier'; |
| 28 | import { APIURLHEADER, CONSTANTNUMBER, ERRORDATA, MODALCLOSERESPONSEDATA, MODALCLOSERESPONSEWITHCP } from 'CommonModel'; |
| 29 | import { ConfirmationTopologyComponent } from 'ConfirmationTopology'; |
| 30 | import * as d3 from 'd3'; |
| 31 | import { DataService } from 'DataService'; |
| 32 | import { environment } from 'environment'; |
| 33 | import * as HttpStatus from 'http-status-codes'; |
| 34 | import * as jsyaml from 'js-yaml'; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 35 | import { |
| 36 | CCI, |
| 37 | COMPOSERNODES, |
| 38 | DF, |
| 39 | GRAPHDETAILS, |
| 40 | NSData, |
| 41 | NSDATACREATION, |
| 42 | NSDDetails, |
| 43 | Tick, TickPath, VLC, VLD, VNFPROFILE |
| 44 | } from 'NSDModel'; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 45 | import { RestService } from 'RestService'; |
| 46 | import { SharedService } from 'SharedService'; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 47 | import { VNFD, VNFData } from 'VNFDModel'; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 48 | |
| 49 | /** |
| 50 | * Creating component |
| 51 | * @Component takes NSComposerComponent.html as template url |
| 52 | */ |
| 53 | @Component({ |
| 54 | selector: 'app-ns-composer', |
| 55 | templateUrl: './NSComposerComponent.html', |
| 56 | styleUrls: ['./NSComposerComponent.scss'], |
| 57 | encapsulation: ViewEncapsulation.None |
| 58 | }) |
| 59 | /** Exporting a class @exports NSComposerComponent */ |
| 60 | export class NSComposerComponent { |
| 61 | /** To inject services @public */ |
| 62 | public injector: Injector; |
| 63 | /** View child contains graphContainer ref @public */ |
| 64 | @ViewChild('graphContainer', { static: true }) public graphContainer: ElementRef; |
| 65 | /** dataService to pass the data from one component to another @public */ |
| 66 | public dataService: DataService; |
| 67 | /** Contains VNFD Informations @public */ |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 68 | public nsPackageDetails: NSData = { id: '', name: '', description: '', version: '', designer: '' }; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 69 | /** Contains VL Details @public */ |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 70 | public virtualLinkDesc: VLD = { |
| 71 | id: '', |
| 72 | 'mgmt-network': true |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 73 | }; |
| 74 | /** Contains the information of the type of modification @public */ |
| 75 | public putType: string; |
| SANDHYA.JS | 50e53af | 2023-04-27 13:15:44 +0530 | [diff] [blame^] | 76 | /** Contains index of old VLD @public */ |
| 77 | public getOldVLDIndex: string[]; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 78 | /** Conatins mousedown action @public */ |
| 79 | public mousedownNode: COMPOSERNODES = null; |
| 80 | /** Conatins mouseup action @public */ |
| 81 | public mouseupNode: COMPOSERNODES = null; |
| 82 | /** Conatins mousedownLink action @public */ |
| 83 | public mousedownLink: COMPOSERNODES = null; |
| 84 | /** Conatins current Selection node action @public */ |
| 85 | public currentSelectedNode: COMPOSERNODES = null; |
| 86 | /** Conatins current Selection node action @public */ |
| 87 | public currentSelectedLink: COMPOSERNODES = null; |
| 88 | /** Need to show the NSD Details @public */ |
| 89 | public isShowNSDDetails: boolean = true; |
| 90 | /** Contains the node information of VL @public */ |
| 91 | public vlNodes: {}[] = []; |
| 92 | /** Need to show the VL Details @public */ |
| 93 | public isShowVLDetails: boolean = false; |
| 94 | /** Contains the node information of VNF @public */ |
| 95 | public vnfNodes: {}[] = []; |
| 96 | /** contains the VNF Details @public */ |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 97 | public vnfData: VNFPROFILE; |
| 98 | /** contains the Virtual Link connectivity Details @public */ |
| 99 | public virtualLinkProfileID: string; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 100 | /** Need to show the VNF Details @public */ |
| 101 | public isShowVNFDetails: boolean = false; |
| 102 | /** Contains the node information of CP @public */ |
| 103 | public cpNodes: {}[] = []; |
| 104 | /** Need to show the CP Details */ |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 105 | public cpData: CCI; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 106 | /** Need to show the VNF Details @public */ |
| 107 | public isShowCPDetails: boolean = false; |
| 108 | /** random number count @public */ |
| 109 | public randomNumberLength: number; |
| 110 | /** Contains the vnfd information @public */ |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 111 | public vnfList: VNFD[] = []; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 112 | /** Add the activeclass for the selected @public */ |
| 113 | public activeClass: string = 'active'; |
| 114 | /** Add the fixed class for the freeze @public */ |
| 115 | public fixedClass: string = 'fixed'; |
| 116 | /** Check the loading results @public */ |
| 117 | public isLoadingResults: boolean = true; |
| 118 | /** Give the message for the loading @public */ |
| 119 | public message: string = 'PLEASEWAIT'; |
| 120 | /** Get VNF selected node @public */ |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 121 | public getVNFSelectedData: VNFD; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 122 | /** Assign the forcesimulation active @public */ |
| 123 | public forceSimulationActive: boolean = false; |
| 124 | /** Assign pinned class for the button when freezed @public */ |
| 125 | public classApplied: boolean = false; |
| 126 | /** Contains sidebar open status @public */ |
| 127 | public sideBarOpened: boolean = false; |
| 128 | /** Contains SVG attributes @private */ |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 129 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 130 | private svg: any; |
| 131 | /** Contains the Drag line */ |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 132 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 133 | private dragLine: any; |
| 134 | /** Contains VL node @private */ |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 135 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 136 | private vlNode: any; |
| 137 | /** Contains VNFD node @private */ |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 138 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 139 | private vnfdnode: any; |
| 140 | /** Contains CP node @private */ |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 141 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 142 | private cpnode: any; |
| 143 | /** Rendered nodes represent VL @private */ |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 144 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 145 | private gvlNode: any; |
| 146 | /** Rendered nodes represent VL @private */ |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 147 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 148 | private gvnfdNode: any; |
| 149 | /** Rendered nodes represent VL @private */ |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 150 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 151 | private gcpNode: any; |
| 152 | /** Contains forced node animations @private */ |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 153 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 154 | private force: any; |
| 155 | /** Contains all the selected node @private */ |
| 156 | private selectedNode: COMPOSERNODES[] = []; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 157 | /** Contains the connected point @private */ |
| 158 | private connectionPoint: string; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 159 | /** Contains id of the node @private */ |
| 160 | private identifier: string; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 161 | /** Contains copy of NSD information @private */ |
| 162 | private nsdCopy: string; |
| 163 | /** Contains the VNFD copy @private */ |
| 164 | private vnfdCopy: string; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 165 | /** Contains path information of the node */ |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 166 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 167 | private path: any; |
| 168 | /** Contains the node information @private */ |
| 169 | private nodes: COMPOSERNODES[] = []; |
| 170 | /** Contains the link information of nodes @private */ |
| 171 | private links: {}[] = []; |
| 172 | /** Contains the NS information @private */ |
| 173 | private nsData: NSDDetails; |
| 174 | /** Instance of the rest service @private */ |
| 175 | private restService: RestService; |
| 176 | /** Service holds the router information @private */ |
| 177 | private router: Router; |
| 178 | /** Holds teh instance of AuthService class of type AuthService @private */ |
| 179 | private activatedRoute: ActivatedRoute; |
| 180 | /** Notifier service to popup notification @private */ |
| 181 | private notifierService: NotifierService; |
| 182 | /** Controls the header form @private */ |
| 183 | private headers: HttpHeaders; |
| 184 | /** Contains tranlsate instance @private */ |
| 185 | private translateService: TranslateService; |
| 186 | /** Contains lastkeypressed instance @private */ |
| 187 | private lastKeyDown: number = -1; |
| 188 | /** Instance of the modal service @private */ |
| 189 | private modalService: NgbModal; |
| 190 | /** Setting the Value of connection point refrence of the CP @private */ |
| 191 | private setVnfdConnectionPointRef: string; |
| 192 | /** Setting the Value of VL name for confirmation @private */ |
| 193 | private vlName: string; |
| 194 | /** Setting the Value of VNFD name for confirmation @private */ |
| 195 | private setVnfdName: string; |
| 196 | /** Contains all methods related to shared @private */ |
| 197 | private sharedService: SharedService; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 198 | /** Contains selected node VNF profile objects @private */ |
| 199 | private selectedVNFProfile: VNFPROFILE[]; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 200 | |
| 201 | constructor(injector: Injector) { |
| 202 | this.injector = injector; |
| 203 | this.restService = this.injector.get(RestService); |
| 204 | this.dataService = this.injector.get(DataService); |
| 205 | this.router = this.injector.get(Router); |
| 206 | this.activatedRoute = this.injector.get(ActivatedRoute); |
| 207 | this.notifierService = this.injector.get(NotifierService); |
| 208 | this.translateService = this.injector.get(TranslateService); |
| 209 | this.modalService = this.injector.get(NgbModal); |
| 210 | this.sharedService = this.injector.get(SharedService); |
| 211 | } |
| harshini.r | 92d376d | 2022-04-05 12:35:14 +0530 | [diff] [blame] | 212 | /** Lifecyle Hooks the trigger before component is instantiated @public */ |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 213 | public ngOnInit(): void { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 214 | this.identifier = this.activatedRoute.snapshot.paramMap.get('id'); |
| 215 | this.generateData(); |
| 216 | this.headers = new HttpHeaders({ |
| harshini.r | 92d376d | 2022-04-05 12:35:14 +0530 | [diff] [blame] | 217 | 'Content-Type': 'application/gzip', |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 218 | Accept: 'application/json', |
| 219 | 'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0' |
| 220 | }); |
| 221 | } |
| 222 | /** Events handles at drag on D3 region @public */ |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 223 | // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 224 | public drag(ev: any): void { |
| 225 | if (ev.target.id === 'vl') { |
| 226 | ev.dataTransfer.setData('text', ev.target.id); |
| 227 | } else { |
| 228 | ev.dataTransfer.setData('text', ev.target.attributes['data-id'].value); |
| 229 | } |
| 230 | } |
| 231 | /** On clicking redirect to NS edit page @public */ |
| 232 | public onEdit(): void { |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 233 | this.router.navigate(['/packages/ns/edit/', this.identifier]).catch((): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 234 | // Catch Navigation Error |
| 235 | }); |
| 236 | } |
| 237 | /** Events handles drop at D3 region @public */ |
| 238 | public drop(ev: DragEvent): void { |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 239 | ev.preventDefault(); |
| 240 | const getDropedName: string = ev.dataTransfer.getData('text'); |
| 241 | if (getDropedName === 'vl') { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 242 | this.svg.selectAll('*').remove(); |
| 243 | this.vldropComposer(); |
| 244 | } else { |
| 245 | this.svg.selectAll('*').remove(); |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 246 | const vnfdName: string = ev.dataTransfer.getData('text'); |
| 247 | this.vnfdropComposer(vnfdName); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 248 | } |
| 249 | } |
| 250 | /** Drop VL Composer Data @public */ |
| 251 | public vldropComposer(): void { |
| 252 | this.randomNumberLength = CONSTANTNUMBER.randomNumber; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 253 | const generateId: string = 'ns_vl_' + this.sharedService.randomString(); |
| 254 | if (this.nsData['virtual-link-desc'] === undefined) { |
| 255 | this.nsData['virtual-link-desc'] = []; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 256 | } |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 257 | this.nsData['virtual-link-desc'].push({ |
| 258 | id: generateId, |
| 259 | 'mgmt-network': false |
| 260 | }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 261 | this.putType = 'nsdadd'; |
| 262 | this.addData(environment.NSDESCRIPTORS_URL, this.identifier, this.nsData, this.putType); |
| 263 | } |
| 264 | /** Drop VNFD Composer Data @public */ |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 265 | public vnfdropComposer(vnfdName: string): void { |
| 266 | const vnfID: string = 'ns_vnfd_' + this.sharedService.randomString(); |
| 267 | if (this.nsData.df.length > 0) { |
| 268 | this.addVNFDID(vnfdName); |
| 269 | this.nsData.df.forEach((res: DF): void => { |
| 270 | if (res['vnf-profile'] === undefined) { |
| 271 | res['vnf-profile'] = []; |
| 272 | } |
| 273 | res['vnf-profile'].push({ |
| 274 | id: vnfID, |
| 275 | 'virtual-link-connectivity': [], |
| 276 | 'vnfd-id': vnfdName |
| 277 | }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 278 | }); |
| 279 | } else { |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 280 | Object.assign(this.nsData.df, { |
| 281 | id: 'default-df', |
| 282 | 'vnf-profile': [{ |
| 283 | id: vnfID, |
| 284 | 'virtual-link-connectivity': [], |
| 285 | 'vnfd-id': vnfdName |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 286 | }] |
| 287 | }); |
| 288 | } |
| 289 | this.putType = 'vnfdadd'; |
| 290 | this.addData(environment.NSDESCRIPTORS_URL, this.identifier, this.nsData, this.putType); |
| 291 | } |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 292 | /** Add the VNFD-ID while drop VNFD if not exists @public */ |
| 293 | public addVNFDID(vnfdName: string): void { |
| 294 | const vnfdIDArray: string[] = this.nsData['vnfd-id']; |
| 295 | if (vnfdIDArray !== undefined) { |
| 296 | if (vnfdIDArray.indexOf(vnfdName) === -1) { |
| 297 | vnfdIDArray.push(vnfdName); |
| 298 | } |
| 299 | } else { |
| 300 | Object.assign(this.nsData, { |
| 301 | 'vnfd-id': [vnfdName] |
| 302 | }); |
| 303 | } |
| 304 | } |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 305 | /** Events handles allow drop on D3 region @public */ |
| 306 | public allowDrop(ev: DragEvent): void { |
| 307 | ev.preventDefault(); |
| 308 | } |
| 309 | /** Save NSD Information @public */ |
| 310 | public saveNSD(): void { |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 311 | if (this.nsPackageDetails.id !== undefined) { |
| 312 | this.nsData.id = this.nsPackageDetails.id; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 313 | } |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 314 | if (this.nsPackageDetails.name !== undefined) { |
| 315 | this.nsData.name = this.nsPackageDetails.name; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 316 | } |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 317 | if (this.nsPackageDetails.description !== undefined) { |
| 318 | this.nsData.description = this.nsPackageDetails.description; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 319 | } |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 320 | if (this.nsPackageDetails.version !== undefined) { |
| 321 | this.nsData.version = this.nsPackageDetails.version; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 322 | } |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 323 | if (this.nsPackageDetails.designer !== undefined) { |
| 324 | this.nsData.designer = this.nsPackageDetails.designer; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 325 | } |
| 326 | this.putType = 'nsdUpdate'; |
| 327 | this.addData(environment.NSDESCRIPTORS_URL, this.identifier, this.nsData, this.putType); |
| 328 | } |
| 329 | /** Save Virtual Link @public */ |
| 330 | public saveVL(vlid: string): void { |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 331 | this.nsData['virtual-link-desc'].forEach((result: VLD): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 332 | if (result.id === vlid) { |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 333 | result['mgmt-network'] = !isNullOrUndefined(this.virtualLinkDesc['mgmt-network']) ? this.virtualLinkDesc['mgmt-network'] : true; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 334 | } |
| 335 | }); |
| 336 | this.putType = 'vlUpdate'; |
| 337 | this.addData(environment.NSDESCRIPTORS_URL, this.identifier, this.nsData, this.putType); |
| 338 | } |
| 339 | /** Add the new Data @public */ |
| 340 | public addData(apiURL: string, identifier: string, data: NSDDetails, putType: string): void { |
| 341 | this.isLoadingResults = true; |
| 342 | let successMessage: string = ''; |
| 343 | if (putType === 'nsdadd') { |
| 344 | successMessage = 'PAGE.NSPACKAGE.NSCOMPOSE.ADDNSD'; |
| 345 | } else if (putType === 'vnfdadd') { |
| 346 | successMessage = 'PAGE.NSPACKAGE.NSCOMPOSE.ADDVNFD'; |
| 347 | } else if (putType === 'cpAdded') { |
| 348 | successMessage = 'PAGE.NSPACKAGE.NSCOMPOSE.ADDNS'; |
| 349 | } else if (putType === 'nsdUpdate') { |
| 350 | successMessage = 'PAGE.NSPACKAGE.NSCOMPOSE.UPDATEDSUCCESSFULLY'; |
| 351 | } else if (putType === 'vlUpdate') { |
| 352 | successMessage = 'PAGE.NSPACKAGE.NSCOMPOSE.UPDATEDSUCCESSFULLY'; |
| 353 | } else if (putType === 'nsddelete') { |
| 354 | successMessage = 'PAGE.NSPACKAGE.NSCOMPOSE.DELETENSD'; |
| 355 | } else if (putType === 'vnfddelete') { |
| 356 | successMessage = 'PAGE.NSPACKAGE.NSCOMPOSE.DELETEVNFD'; |
| 357 | } else if (putType === 'nsdelete') { |
| 358 | successMessage = 'PAGE.NSPACKAGE.NSCOMPOSE.DELETENS'; |
| 359 | } else if (putType === 'linkdelete') { |
| 360 | successMessage = 'PAGE.NSPACKAGE.NSCOMPOSE.DELETELINK'; |
| 361 | } |
| 362 | /** Below hide for conflicts with light weight UI */ |
| 363 | const apiURLHeader: APIURLHEADER = { |
| 364 | url: apiURL + '/' + identifier + '/nsd_content', |
| 365 | httpOptions: { headers: this.headers } |
| 366 | }; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 367 | const nsData: NSDATACREATION = { nsd: { nsd: [] } }; |
| 368 | nsData.nsd.nsd = []; |
| 369 | nsData.nsd.nsd.push(data); |
| 370 | const descriptorInfo: string = jsyaml.dump(nsData, { sortKeys: true }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 371 | this.sharedService.targzFile({ packageType: 'nsd', id: this.identifier, descriptor: descriptorInfo }) |
| 372 | .then((content: ArrayBuffer): void => { |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 373 | this.restService.putResource(apiURLHeader, content).subscribe((res: {}): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 374 | this.generateData(); |
| 375 | this.notifierService.notify('success', this.translateService.instant(successMessage)); |
| 376 | this.isLoadingResults = false; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 377 | }, (error: ERRORDATA): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 378 | this.generateData(); |
| 379 | this.restService.handleError(error, 'put'); |
| 380 | this.isLoadingResults = false; |
| 381 | }); |
| 382 | }).catch((): void => { |
| 383 | this.notifierService.notify('error', this.translateService.instant('ERROR')); |
| 384 | this.isLoadingResults = false; |
| 385 | }); |
| 386 | } |
| 387 | /** Show Info @public */ |
| 388 | public showInfo(): void { |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 389 | // eslint-disable-next-line security/detect-non-literal-fs-filename |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 390 | const modalRef: NgbModalRef = this.modalService.open(ConfirmationTopologyComponent, { backdrop: 'static' }); |
| 391 | modalRef.componentInstance.topologyType = 'Info'; |
| 392 | modalRef.componentInstance.topologytitle = this.translateService.instant('PAGE.TOPOLOGY.INFO'); |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 393 | modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 394 | if (result) { |
| 395 | // empty |
| 396 | } |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 397 | }).catch((): void => { |
| 398 | // Catch Navigation Error |
| SANDHYA.JS | 50e53af | 2023-04-27 13:15:44 +0530 | [diff] [blame^] | 399 | }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 400 | } |
| 401 | /** Event to freeze the animation @public */ |
| 402 | public onFreeze(): void { |
| 403 | this.classApplied = !this.classApplied; |
| 404 | const alreadyFixedIsActive: boolean = d3.select('svg#graphContainer').classed(this.fixedClass); |
| 405 | d3.select('svg#graphContainer').classed(this.fixedClass, !alreadyFixedIsActive); |
| 406 | if (alreadyFixedIsActive) { |
| 407 | this.force.stop(); |
| 408 | } |
| 409 | this.forceSimulationActive = alreadyFixedIsActive; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 410 | this.nodes.forEach((d: COMPOSERNODES): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 411 | d.fx = (alreadyFixedIsActive) ? null : d.x; |
| 412 | d.fy = (alreadyFixedIsActive) ? null : d.y; |
| 413 | }); |
| 414 | if (alreadyFixedIsActive) { |
| 415 | this.force.restart(); |
| 416 | } |
| 417 | } |
| 418 | /** Events handles when dragended @public */ |
| 419 | public toggleSidebar(): void { |
| 420 | this.sideBarOpened = !this.sideBarOpened; |
| 421 | this.deselectAllNodes(); |
| 422 | this.showRightSideInfo(true, false, false, false); |
| 423 | } |
| 424 | /** Prepare information for node creation of VNFD @private */ |
| 425 | private generateData(): void { |
| 426 | this.generateVNFData(); |
| 427 | this.generateDataNSDTopology(); |
| 428 | this.sideBarOpened = false; |
| 429 | } |
| 430 | /** Prepare the information of the VNFD @private */ |
| 431 | private generateVNFData(): void { |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 432 | this.restService.getResource(environment.VNFPACKAGESCONTENT_URL).subscribe((vnfdPackageData: VNFD[]): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 433 | this.vnfList = vnfdPackageData; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 434 | }, (error: ERRORDATA): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 435 | this.restService.handleError(error, 'get'); |
| 436 | }); |
| 437 | } |
| 438 | /** Prepare information for node creation of NSD Topology @private */ |
| 439 | private generateDataNSDTopology(): void { |
| 440 | this.nodes = []; |
| 441 | this.links = []; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 442 | this.restService.getResource(environment.NSDESCRIPTORSCONTENT_URL + '/' + this.identifier).subscribe((nsData: NSDDetails): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 443 | delete nsData._admin; |
| 444 | delete nsData._id; |
| Barath Kumar R | 218e881 | 2020-09-02 16:43:05 +0530 | [diff] [blame] | 445 | delete nsData._links; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 446 | this.nsData = nsData; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 447 | this.generateNSInfo(nsData); |
| 448 | if (nsData['virtual-link-desc'] !== undefined) { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 449 | /** Details of the VL */ |
| 450 | this.nsDataVLD(nsData); |
| 451 | } |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 452 | if (this.nsData.df.length > 0) { |
| 453 | this.nsData.df.forEach((res: DF): void => { |
| 454 | if (res['vnf-profile'] !== undefined) { |
| 455 | /** Details of the VNFD */ |
| 456 | this.nsDataConstituentVNFD(nsData); |
| 457 | } |
| 458 | }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 459 | } |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 460 | if (nsData.df.length > 0) { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 461 | this.nsDataVLDLinkCreation(nsData); |
| 462 | } |
| 463 | this.separateAndCreatenode(); |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 464 | }, (error: ERRORDATA): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 465 | if (error.error.status === HttpStatus.NOT_FOUND || error.error.status === HttpStatus.UNAUTHORIZED) { |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 466 | this.router.navigateByUrl('404', { skipLocationChange: true }).catch((): void => { |
| 467 | // Catch Navigation Error |
| SANDHYA.JS | 50e53af | 2023-04-27 13:15:44 +0530 | [diff] [blame^] | 468 | }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 469 | } else { |
| 470 | this.restService.handleError(error, 'get'); |
| 471 | } |
| 472 | this.isLoadingResults = false; |
| 473 | this.isShowNSDDetails = false; |
| 474 | }); |
| 475 | } |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 476 | /** Generate the NS Package Information */ |
| 477 | private generateNSInfo(nsData: NSDDetails): void { |
| 478 | this.nsPackageDetails.id = nsData.id; |
| 479 | this.nsPackageDetails.name = nsData.name; |
| 480 | this.nsPackageDetails.description = nsData.description; |
| 481 | this.nsPackageDetails.version = nsData.version; |
| 482 | this.nsPackageDetails.designer = nsData.designer; |
| 483 | } |
| 484 | /** nsData VL node creation function @private */ |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 485 | private nsDataVLD(nsData: NSDDetails): void { |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 486 | nsData['virtual-link-desc'].forEach((res: VLD): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 487 | this.nodes.push({ id: res.id, reflexive: false, type: 'vld', name: res.id, selectorId: res.id }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 488 | }); |
| 489 | } |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 490 | /** nsData VNFD node creation function @private */ |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 491 | private nsDataConstituentVNFD(nsData: NSDDetails): void { |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 492 | nsData.df.forEach((resDF: DF): void => { |
| 493 | resDF['vnf-profile'].forEach((resVNF: VNFPROFILE): void => { |
| 494 | this.nodes.push( |
| 495 | { |
| 496 | id: resVNF['vnfd-id'] + ':' + resVNF.id, |
| 497 | reflexive: false, |
| 498 | type: 'vnfd', |
| 499 | name: resVNF['vnfd-id'], |
| 500 | nodeIndex: resVNF.id, |
| 501 | selectorId: resVNF['vnfd-id'] + '_' + resVNF.id |
| 502 | }); |
| 503 | if (resVNF['virtual-link-connectivity'] !== undefined) { |
| 504 | this.nsDataCP(resVNF, resVNF.id); |
| 505 | } |
| 506 | }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 507 | }); |
| 508 | } |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 509 | /** nsData CP node creation function @private */ |
| 510 | private nsDataCP(resVNF: VNFPROFILE, vnfID: string): void { |
| 511 | resVNF['virtual-link-connectivity'].forEach((resultVLC: VLC, index: number): void => { |
| 512 | resultVLC['constituent-cpd-id'].forEach((resultCCI: CCI): void => { |
| 513 | this.nodes.push( |
| 514 | { |
| 515 | id: vnfID + ':' + resultCCI['constituent-base-element-id'] + index + ':' + resultCCI['constituent-cpd-id'], |
| 516 | reflexive: false, |
| 517 | type: 'ns', |
| 518 | name: resultCCI['constituent-cpd-id'], |
| 519 | nodeIndex: resultCCI['constituent-base-element-id'], |
| 520 | selectorId: 'osm-' + resultCCI['constituent-cpd-id'] + '-' + vnfID + resultCCI['constituent-base-element-id'] + index |
| 521 | }); |
| 522 | }); |
| 523 | }); |
| 524 | } |
| 525 | /** nsData Link node creation function @private */ |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 526 | private nsDataVLDLinkCreation(nsData: NSDDetails): void { |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 527 | nsData.df.forEach((resDF: DF): void => { |
| 528 | if (resDF['vnf-profile'] !== undefined) { |
| 529 | resDF['vnf-profile'].forEach((resVNF: VNFPROFILE): void => { |
| 530 | this.nsdCopy = resVNF['vnfd-id'] + ':' + resVNF.id; |
| 531 | if (resVNF['virtual-link-connectivity'] !== undefined) { |
| 532 | this.nsDataVNFDConnectionPointRefrence(resVNF); |
| 533 | } |
| 534 | }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 535 | } |
| 536 | }); |
| 537 | } |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 538 | /** nsDataVNFDConnectionPointRefrence undefined Call this function @private */ |
| 539 | private nsDataVNFDConnectionPointRefrence(resVNF: VNFPROFILE): void { |
| 540 | resVNF['virtual-link-connectivity'].forEach((resultVLC: VLC, index: number): void => { |
| 541 | resultVLC['constituent-cpd-id'].forEach((resultCCI: CCI): void => { |
| 542 | this.vnfdCopy = resultVLC['virtual-link-profile-id']; |
| 543 | this.connectionPoint = resVNF.id + ':' + resultCCI['constituent-base-element-id'] + index + ':' + resultCCI['constituent-cpd-id']; |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 544 | const connectionPointPos: number = this.nodes.map((e: COMPOSERNODES): string => e.id).indexOf(this.connectionPoint); |
| 545 | const nsdPos: number = this.nodes.map((e: COMPOSERNODES): string => e.id).indexOf(this.nsdCopy); |
| 546 | const vnfdPos: number = this.nodes.map((e: COMPOSERNODES): string => e.id).indexOf(this.vnfdCopy); |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 547 | this.links.push( |
| 548 | { |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 549 | // eslint-disable-next-line security/detect-object-injection |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 550 | source: this.nodes[connectionPointPos], |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 551 | // eslint-disable-next-line security/detect-object-injection |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 552 | target: this.nodes[nsdPos] |
| 553 | }, |
| 554 | { |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 555 | // eslint-disable-next-line security/detect-object-injection |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 556 | source: this.nodes[connectionPointPos], |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 557 | // eslint-disable-next-line security/detect-object-injection |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 558 | target: this.nodes[vnfdPos] |
| 559 | }); |
| 560 | }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 561 | }); |
| 562 | } |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 563 | /** Separate and create node @private */ |
| 564 | private separateAndCreatenode(): void { |
| 565 | this.seprateNodes(this.nodes); |
| 566 | this.createnode(this.nodes); |
| 567 | this.isLoadingResults = false; |
| 568 | } |
| 569 | /** Get the default Configuration of containers @private */ |
| 570 | private getGraphContainerAttr(): GRAPHDETAILS { |
| 571 | return { |
| 572 | width: 700, |
| 573 | height: 400, |
| 574 | nodeHeight: 50, |
| 575 | nodeWidth: 35, |
| 576 | textX: -35, |
| 577 | textY: 30, |
| 578 | radius: 5, |
| 579 | distance: 50, |
| 580 | strength: -500, |
| 581 | forcex: 2, |
| 582 | forcey: 2, |
| 583 | sourcePaddingYes: 17, |
| 584 | sourcePaddingNo: 12, |
| 585 | targetPaddingYes: 4, |
| 586 | targetPaddingNo: 3, |
| 587 | alphaTarget: 0.3, |
| 588 | imageX: -25, |
| 589 | imageY: -25, |
| 590 | shiftKeyCode: 17 |
| 591 | }; |
| 592 | } |
| 593 | /** Separate the nodes along with its tyep @private */ |
| 594 | private seprateNodes(node: COMPOSERNODES[]): void { |
| 595 | this.vlNodes = []; this.vnfNodes = []; this.cpNodes = []; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 596 | node.forEach((nodeList: COMPOSERNODES): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 597 | if (nodeList.type === 'vld') { |
| 598 | this.vlNodes.push(nodeList); |
| 599 | } else if (nodeList.type === 'vnfd') { |
| 600 | this.vnfNodes.push(nodeList); |
| 601 | } else if (nodeList.type === 'ns') { |
| 602 | this.cpNodes.push(nodeList); |
| 603 | } |
| 604 | }); |
| 605 | } |
| 606 | /** Node is created and render at D3 region @private */ |
| 607 | private createnode(node: COMPOSERNODES[]): void { |
| 608 | const graphContainerAttr: GRAPHDETAILS = this.getGraphContainerAttr(); |
| 609 | d3.selectAll('svg#graphContainer > *').remove(); |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 610 | d3.select(window).on('keydown', (): void => { this.keyDown(); }); |
| 611 | d3.select(window).on('keyup', (): void => { this.keyUp(); }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 612 | this.svg = d3.select('#graphContainer') |
| 613 | .attr('oncontextmenu', 'return false;') |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 614 | .attr('viewBox', `0 0 ${graphContainerAttr.width} ${graphContainerAttr.height}`) |
| 615 | .on('mousemove', (): void => { this.mousemove(); }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 616 | this.force = d3.forceSimulation() |
| 617 | .force('charge', d3.forceManyBody().strength(graphContainerAttr.strength)) |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 618 | .force('link', d3.forceLink().id((d: TickPath): string => d.id).distance(graphContainerAttr.distance)) |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 619 | .force('center', d3.forceCenter(graphContainerAttr.width / graphContainerAttr.forcex, |
| 620 | graphContainerAttr.height / graphContainerAttr.forcey)) |
| 621 | .force('x', d3.forceX(graphContainerAttr.width / graphContainerAttr.forcex)) |
| 622 | .force('y', d3.forceY(graphContainerAttr.height / graphContainerAttr.forcey)) |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 623 | .on('tick', (): void => { this.tick(); }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 624 | this.dragLine = this.svg.append('svg:path').attr('class', 'link dragline hidden').attr('d', 'M0,0L0,0'); |
| 625 | this.path = this.svg.append('svg:g').selectAll('path'); |
| 626 | this.vlNode = this.svg.append('svg:g').selectAll('vlnode'); |
| 627 | this.vnfdnode = this.svg.append('svg:g').selectAll('vnfdnode'); |
| 628 | this.cpnode = this.svg.append('svg:g').selectAll('cpnode'); |
| 629 | // app starts here |
| 630 | this.restart(node); |
| 631 | } |
| 632 | /** update force layout (called automatically each iteration) @private */ |
| 633 | private tick(): void { |
| 634 | const graphContainerAttr: GRAPHDETAILS = this.getGraphContainerAttr(); |
| 635 | // draw directed edges with proper padding from node centers |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 636 | this.path.attr('class', 'link').attr('d', (d: Tick): string => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 637 | const deltaX: number = d.target.x - d.source.x; |
| 638 | const deltaY: number = d.target.y - d.source.y; |
| 639 | const dist: number = Math.sqrt(deltaX * deltaX + deltaY * deltaY); |
| 640 | const normX: number = deltaX / dist; |
| 641 | const normY: number = deltaY / dist; |
| 642 | const sourcePadding: number = d.left ? graphContainerAttr.sourcePaddingYes : graphContainerAttr.sourcePaddingNo; |
| 643 | const targetPadding: number = d.right ? graphContainerAttr.targetPaddingYes : graphContainerAttr.targetPaddingNo; |
| 644 | const sourceX: number = d.source.x + (sourcePadding * normX); |
| 645 | const sourceY: number = d.source.y + (sourcePadding * normY); |
| 646 | const targetX: number = d.target.x - (targetPadding * normX); |
| 647 | const targetY: number = d.target.y - (targetPadding * normY); |
| 648 | return `M${sourceX},${sourceY}L${targetX},${targetY}`; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 649 | }).on('dblclick', (d: Tick): void => { this.getDeleteLinkConfirmation(d); }); |
| 650 | this.vlNode.attr('transform', (t: TickPath): string => `translate(${t.x},${t.y})`); |
| 651 | this.vnfdnode.attr('transform', (t: TickPath): string => `translate(${t.x},${t.y})`); |
| 652 | this.cpnode.attr('transform', (t: TickPath): string => `translate(${t.x},${t.y})`); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 653 | } |
| 654 | /** Update graph (called when needed) at D3 region @private */ |
| 655 | private restart(node: COMPOSERNODES[]): void { |
| 656 | const graphContainerAttr: GRAPHDETAILS = this.getGraphContainerAttr(); |
| 657 | this.path = this.path.data(this.links); |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 658 | this.vlNode = this.vlNode.data(this.vlNodes, (d: COMPOSERNODES): string => d.id); |
| 659 | this.vnfdnode = this.vnfdnode.data(this.vnfNodes, (d: COMPOSERNODES): string => d.id); |
| 660 | this.cpnode = this.cpnode.data(this.cpNodes, (d: COMPOSERNODES): string => d.id); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 661 | this.resetAndCreateNodes(); |
| 662 | this.force.nodes(node).force('link').links(this.links); |
| 663 | this.force.alphaTarget(graphContainerAttr.alphaTarget).restart(); |
| 664 | } |
| 665 | /** Rest and create nodes @private */ |
| 666 | private resetAndCreateNodes(): void { |
| 667 | this.path.exit().remove(); |
| 668 | this.vlNode.exit().remove(); |
| 669 | this.vnfdnode.exit().remove(); |
| 670 | this.cpnode.exit().remove(); |
| 671 | this.getPathNodes(); |
| 672 | this.getVLNodes(); |
| 673 | this.getVNFDNodes(); |
| 674 | this.getCPNodes(); |
| 675 | this.path.merge(this.path); |
| 676 | this.vlNode = this.gvlNode.merge(this.vlNode); |
| 677 | this.vnfdnode = this.gvnfdNode.merge(this.vnfdnode); |
| 678 | this.cpnode = this.gcpNode.merge(this.cpnode); |
| 679 | } |
| 680 | /** setting the Path @private */ |
| 681 | private getPathNodes(): void { |
| 682 | this.path = this.path.enter().append('svg:path'); |
| 683 | } |
| 684 | /** Setting all the VL nodes @private */ |
| 685 | private getVLNodes(): void { |
| 686 | const graphContainerAttr: GRAPHDETAILS = this.getGraphContainerAttr(); |
| 687 | this.gvlNode = this.vlNode.enter().append('svg:g'); |
| 688 | this.gvlNode.append('svg:circle').attr('r', graphContainerAttr.radius).style('fill', '#eeeeee'); |
| 689 | this.gvlNode.append('svg:image') |
| 690 | .style('opacity', 1) |
| 691 | .attr('x', graphContainerAttr.imageX) |
| 692 | .attr('y', graphContainerAttr.imageY) |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 693 | .call(this.onDragDrop()) |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 694 | .attr('id', (d: COMPOSERNODES): string => d.selectorId) |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 695 | .attr('class', 'node').attr('width', graphContainerAttr.nodeWidth).attr('height', graphContainerAttr.nodeHeight) |
| 696 | .attr('xlink:href', 'assets/images/VL.svg') |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 697 | .on('mousedown', (d: COMPOSERNODES): void => { this.mouseDown(d); }) |
| 698 | .on('mouseup', (d: COMPOSERNODES): void => { this.mouseUp(d); }) |
| 699 | .on('click', (d: COMPOSERNODES): void => { this.singleClick(this.vlNode, d); this.onNodeClickToggleSidebar(); }) |
| 700 | .on('dblclick', (d: COMPOSERNODES): void => { this.getDeleteConfirmation(d); this.onNodedblClickToggleSidebar(); }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 701 | this.gvlNode.append('svg:text') |
| 702 | .attr('class', 'node_text') |
| 703 | .attr('y', graphContainerAttr.textY) |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 704 | .text((d: COMPOSERNODES): string => d.id); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 705 | } |
| 706 | /** Setting all the VNFD nodes @private */ |
| 707 | private getVNFDNodes(): void { |
| 708 | const graphContainerAttr: GRAPHDETAILS = this.getGraphContainerAttr(); |
| 709 | this.gvnfdNode = this.vnfdnode.enter().append('svg:g'); |
| 710 | this.gvnfdNode.append('svg:circle').attr('r', graphContainerAttr.radius).style('fill', '#eeeeee'); |
| 711 | this.gvnfdNode.append('svg:image') |
| 712 | .style('opacity', 1) |
| 713 | .attr('x', graphContainerAttr.imageX) |
| 714 | .attr('y', graphContainerAttr.imageY) |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 715 | .call(this.onDragDrop()) |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 716 | .attr('id', (d: COMPOSERNODES): string => d.selectorId) |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 717 | .attr('class', 'node').attr('width', graphContainerAttr.nodeWidth).attr('height', graphContainerAttr.nodeHeight) |
| 718 | .attr('xlink:href', 'assets/images/VNFD.svg') |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 719 | .on('mousedown', (d: COMPOSERNODES): void => { this.mouseDown(d); }) |
| 720 | .on('mouseup', (d: COMPOSERNODES): void => { this.mouseUp(d); }) |
| 721 | .on('click', (d: COMPOSERNODES): void => { this.singleClick(this.vnfdnode, d); this.onNodeClickToggleSidebar(); }) |
| 722 | .on('dblclick', (d: COMPOSERNODES): void => { this.getDeleteConfirmation(d); this.onNodedblClickToggleSidebar(); }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 723 | this.gvnfdNode.append('svg:text') |
| 724 | .attr('class', 'node_text') |
| 725 | .attr('y', graphContainerAttr.textY) |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 726 | .text((d: COMPOSERNODES): string => d.name); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 727 | } |
| 728 | /** Setting all the CP nodes @private */ |
| 729 | private getCPNodes(): void { |
| 730 | const graphContainerAttr: GRAPHDETAILS = this.getGraphContainerAttr(); |
| 731 | this.gcpNode = this.cpnode.enter().append('svg:g'); |
| 732 | this.gcpNode.append('svg:circle').attr('r', graphContainerAttr.radius).style('fill', '#eeeeee'); |
| 733 | this.gcpNode.append('svg:image') |
| 734 | .style('opacity', 1) |
| 735 | .attr('x', graphContainerAttr.imageX) |
| 736 | .attr('y', graphContainerAttr.imageY) |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 737 | .call(this.onDragDrop()) |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 738 | .attr('id', (d: COMPOSERNODES): string => d.selectorId) |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 739 | .attr('class', 'node').attr('width', graphContainerAttr.nodeWidth).attr('height', graphContainerAttr.nodeHeight) |
| 740 | .attr('xlink:href', 'assets/images/CP.svg') |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 741 | .on('mousedown', (d: COMPOSERNODES): void => { this.mouseDown(d); }) |
| 742 | .on('mouseup', (d: COMPOSERNODES): void => { this.mouseUp(d); }) |
| 743 | .on('click', (d: COMPOSERNODES): void => { this.singleClick(this.cpnode, d); this.onNodeClickToggleSidebar(); }) |
| 744 | .on('dblclick', (d: COMPOSERNODES): void => { this.getDeleteConfirmation(d); this.onNodedblClickToggleSidebar(); }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 745 | this.gcpNode.append('svg:text') |
| 746 | .attr('class', 'node_text') |
| 747 | .attr('y', graphContainerAttr.textY) |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 748 | .text((d: COMPOSERNODES): string => d.name); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 749 | } |
| 750 | /** Events handles when mousemove it will capture the selected node data @private */ |
| 751 | private mousemove(): void { |
| 752 | if (!this.mousedownNode) { return; } |
| 753 | this.dragLine.attr('d', |
| 754 | `M${this.mousedownNode.x},${this.mousedownNode.y}L${d3.mouse(d3.event.currentTarget)[0]},${d3.mouse(d3.event.currentTarget)[1]}`); |
| 755 | } |
| 756 | /** Get confirmation Before Deleting the Link in Topology @private */ |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 757 | private getAddConfirmation(mouseData: COMPOSERNODES, getNsData: NSDDetails, addType: string, getVLDIndex: string): void { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 758 | let findVNFName: string = ''; |
| 759 | let findVLDID: string = ''; |
| 760 | if (mouseData.type === 'vld') { |
| 761 | findVNFName = this.mouseupNode.name; |
| 762 | findVLDID = this.mousedownNode.id; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 763 | this.vlName = this.mousedownNode.name; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 764 | } else { |
| 765 | findVNFName = this.mousedownNode.name; |
| 766 | findVLDID = this.mouseupNode.id; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 767 | this.vlName = this.mouseupNode.name; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 768 | } |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 769 | if (getNsData['vnfd-id'] !== undefined) { |
| 770 | getNsData['vnfd-id'].forEach((resVNFid: string): void => { |
| 771 | if (resVNFid === findVNFName) { |
| 772 | this.getVNFSelectedData = this.vnfList.filter((vnfList: VNFD): boolean => vnfList.id === findVNFName)[0]; |
| 773 | this.setVnfdConnectionPointRef = this.getVNFSelectedData['mgmt-cp']; |
| 774 | this.setVnfdName = this.getVNFSelectedData['product-name']; |
| 775 | this.selectedVNFProfile = getNsData.df[0]['vnf-profile']; |
| 776 | } |
| 777 | }); |
| 778 | } |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 779 | if (this.vlName !== undefined && this.setVnfdName !== undefined && this.setVnfdConnectionPointRef !== undefined) { |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 780 | // eslint-disable-next-line security/detect-non-literal-fs-filename |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 781 | const modalRef: NgbModalRef = this.modalService.open(ConfirmationTopologyComponent, { backdrop: 'static' }); |
| 782 | modalRef.componentInstance.topologyType = 'Add'; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 783 | modalRef.componentInstance.cpDetails = this.getVNFSelectedData['ext-cpd']; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 784 | this.translateService.get('PAGE.TOPOLOGY.ADDINGCP', { |
| 785 | vlname: '<b>' + this.vlName + '</b>', |
| 786 | vnfdname: '<b>' + this.setVnfdName + '</b>', |
| 787 | cpname: '<b>' + this.setVnfdConnectionPointRef + '</b>' |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 788 | }).subscribe((res: string): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 789 | modalRef.componentInstance.topologyname = res; |
| 790 | }); |
| 791 | modalRef.componentInstance.topologytitle = this.translateService.instant('PAGE.TOPOLOGY.CONNECTIONPOINT'); |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 792 | modalRef.result.then((result: MODALCLOSERESPONSEWITHCP): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 793 | if (result) { |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 794 | this.generateCPForVNF(this.selectedVNFProfile, result.connection_point, getVLDIndex); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 795 | this.addData(environment.NSDESCRIPTORS_URL, this.identifier, getNsData, addType); |
| 796 | } else { |
| 797 | this.deselectPath(); |
| 798 | } |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 799 | }).catch((): void => { |
| 800 | // Catch Navigation Error |
| SANDHYA.JS | 50e53af | 2023-04-27 13:15:44 +0530 | [diff] [blame^] | 801 | }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 802 | } else { |
| 803 | this.deselectPath(); |
| 804 | this.notifierService.notify('error', this.translateService.instant('ERROR')); |
| 805 | } |
| 806 | } |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 807 | /** Generate connection point for vnf using vld @private */ |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 808 | private generateCPForVNF(result: VNFPROFILE[], cp: string, getVLDIndex: string): void { |
| 809 | if (result !== undefined) { |
| 810 | result.forEach((resultVNFPROFILE: VNFPROFILE, index: number): void => { |
| 811 | if (getVLDIndex === resultVNFPROFILE.id) { |
| 812 | resultVNFPROFILE['virtual-link-connectivity'].push({ |
| 813 | 'constituent-cpd-id': [{ |
| 814 | 'constituent-base-element-id': getVLDIndex, |
| 815 | 'constituent-cpd-id': cp |
| 816 | }], |
| 817 | 'virtual-link-profile-id': this.vlName |
| 818 | }); |
| 819 | } |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 820 | }); |
| 821 | } else { |
| 822 | Object.assign(result, { |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 823 | 'virtual-link-connectivity': [{ |
| 824 | 'constituent-cpd-id': [{ |
| 825 | 'constituent-base-element-id': getVLDIndex, |
| 826 | 'constituent-cpd-id': cp |
| 827 | }], |
| 828 | 'virtual-link-profile-id': this.vlName |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 829 | }] |
| 830 | }); |
| 831 | } |
| 832 | } |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 833 | /** Events handles when mousedown click it will capture the selected node data @private */ |
| 834 | private mouseDown(d: COMPOSERNODES): void { |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 835 | // eslint-disable-next-line deprecation/deprecation |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 836 | event.preventDefault(); |
| 837 | if (d3.event.ctrlKey) { return; } |
| 838 | if (d3.event.shiftKey) { |
| 839 | if (d.type === 'vnfd') { |
| 840 | this.selectedNode.push(d); |
| 841 | } |
| 842 | this.mousedownNode = d; |
| 843 | this.currentSelectedNode = (this.mousedownNode === this.currentSelectedNode) ? null : this.mousedownNode; |
| 844 | this.currentSelectedLink = null; |
| 845 | this.dragLine.style('marker-end', 'url(#end-arrow)').classed('hidden', false) |
| 846 | .attr('d', `M${this.mousedownNode.x},${this.mousedownNode.y}L${this.mousedownNode.x},${this.mousedownNode.y}`); |
| 847 | } |
| 848 | } |
| 849 | /** Event handles when mouseup event occures @private */ |
| 850 | private mouseUp(d: COMPOSERNODES): void { |
| 851 | if (!this.mousedownNode) { return; } |
| 852 | this.dragLine.classed('hidden', true).style('marker-end', ''); |
| 853 | this.mouseupNode = d; |
| SANDHYA.JS | 50e53af | 2023-04-27 13:15:44 +0530 | [diff] [blame^] | 854 | if ((this.mousedownNode.type === 'vld' && this.mouseupNode.type === 'vnfd') || |
| 855 | (this.mousedownNode.type === 'vnfd' && this.mouseupNode.type === 'vld')) { |
| 856 | if (this.mouseupNode.type === 'vnfd') { |
| 857 | this.getOldVLDIndex = this.mouseupNode.id.split(':'); |
| 858 | } else if (this.mousedownNode.type === 'vnfd') { |
| 859 | this.getOldVLDIndex = this.mousedownNode.id.split(':'); |
| 860 | } |
| 861 | const setOldVLDindex: string = this.getOldVLDIndex[1]; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 862 | this.putType = 'cpAdded'; |
| 863 | this.getAddConfirmation(this.mousedownNode, this.nsData, this.putType, setOldVLDindex); |
| 864 | } else if (this.mousedownNode.type === 'vnfd' && this.mouseupNode.type === 'ns') { |
| 865 | this.deselectPath(); |
| 866 | this.notifierService.notify('warning', this.translateService.instant('PAGE.NSPACKAGE.NSCOMPOSE.CANNOTLINKVNFCP')); |
| 867 | } else if (this.mousedownNode.type === 'vld' && this.mouseupNode.type === 'ns') { |
| 868 | this.deselectPath(); |
| 869 | this.notifierService.notify('warning', this.translateService.instant('PAGE.NSPACKAGE.NSCOMPOSE.CANNOTLINKVNFCP')); |
| 870 | } else if (this.mousedownNode.type === 'vld' && this.mouseupNode.type === 'vld') { |
| 871 | this.deselectPath(); |
| 872 | this.notifierService.notify('warning', this.translateService.instant('PAGE.NSPACKAGE.NSCOMPOSE.CANNOTLINKVL')); |
| 873 | } else if (this.mousedownNode.type === 'vnfd' && this.mouseupNode.type === 'vnfd') { |
| 874 | this.deselectPath(); |
| 875 | this.notifierService.notify('warning', this.translateService.instant('PAGE.NSPACKAGE.NSCOMPOSE.CANNOTLINKVNF')); |
| 876 | } else if (this.mousedownNode.type === 'ns' && this.mouseupNode.type === 'ns') { |
| 877 | this.deselectPath(); |
| 878 | this.notifierService.notify('warning', this.translateService.instant('PAGE.NSPACKAGE.NSCOMPOSE.CANNOTLINKCP')); |
| 879 | } else { |
| 880 | this.deselectPath(); |
| 881 | this.notifierService.notify('warning', this.translateService.instant('PAGE.NSPACKAGE.NSCOMPOSE.CANNOTLINKVLVNF')); |
| 882 | } |
| 883 | this.resetMouseVars(); |
| 884 | // select new link |
| 885 | this.currentSelectedLink = d; |
| 886 | this.currentSelectedNode = null; |
| 887 | } |
| 888 | /** Mosue Drag Line false if it is not satisfied @private */ |
| 889 | private deselectPath(): void { |
| 890 | this.dragLine.classed('hidden', true).style('marker-end', '').attr('d', 'M0,0L0,0'); |
| 891 | } |
| 892 | /** reset Mouse varaibles @private */ |
| 893 | private resetMouseVars(): void { |
| 894 | this.mousedownNode = null; |
| 895 | this.mouseupNode = null; |
| 896 | this.mousedownLink = null; |
| 897 | } |
| 898 | /** De-select all the selected nodes @private */ |
| 899 | private deselectAllNodes(): void { |
| 900 | this.vlNode.select('image').classed(this.activeClass, false); |
| 901 | this.vnfdnode.select('image').classed(this.activeClass, false); |
| 902 | this.cpnode.select('image').classed(this.activeClass, false); |
| 903 | } |
| 904 | /** Show the right-side information @private */ |
| 905 | private showRightSideInfo(nsdDetails: boolean, vldDetails: boolean, vnfDeails: boolean, cpDetails: boolean): void { |
| 906 | this.isShowNSDDetails = nsdDetails; |
| 907 | this.isShowVLDetails = vldDetails; |
| 908 | this.isShowVNFDetails = vnfDeails; |
| 909 | this.isShowCPDetails = cpDetails; |
| 910 | } |
| 911 | /** Events handles when Shift Click to perform create cp @private */ |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 912 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 913 | private singleClick(nodeSelected: any, d: COMPOSERNODES): void { |
| 914 | this.selectNodeExclusive(nodeSelected, d); |
| 915 | } |
| 916 | /** Selected nodes @private */ |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 917 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 918 | private selectNodeExclusive(nodeSeleced: any, d: COMPOSERNODES): void { |
| 919 | const alreadyIsActive: boolean = nodeSeleced.select('#' + d.selectorId).classed(this.activeClass); |
| 920 | this.deselectAllNodes(); |
| 921 | nodeSeleced.select('#' + d.selectorId).classed(this.activeClass, !alreadyIsActive); |
| 922 | if (d.type === 'vld' && !alreadyIsActive) { |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 923 | this.nsData['virtual-link-desc'].forEach((result: VLD): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 924 | if (result.id === d.id) { |
| 925 | this.showRightSideInfo(false, true, false, false); |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 926 | this.virtualLinkDesc = result; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 927 | } |
| 928 | }); |
| 929 | } else if (d.type === 'vnfd' && !alreadyIsActive) { |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 930 | this.nsData.df.forEach((res: DF): void => { |
| 931 | if (res['vnf-profile'] !== undefined) { |
| 932 | res['vnf-profile'].forEach((resVNF: VNFPROFILE): void => { |
| 933 | if (resVNF.id === d.nodeIndex && resVNF['vnfd-id'] === d.name) { |
| 934 | this.showRightSideInfo(false, false, true, false); |
| 935 | this.vnfData = resVNF; |
| 936 | } |
| 937 | }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 938 | } |
| 939 | }); |
| 940 | } else if (d.type === 'ns' && !alreadyIsActive) { |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 941 | this.nsData.df.forEach((resultDF: DF): void => { |
| 942 | if (resultDF['vnf-profile'] !== undefined) { |
| 943 | resultDF['vnf-profile'].forEach((resVNF: VNFPROFILE): void => { |
| 944 | if (resVNF['virtual-link-connectivity'] !== undefined) { |
| 945 | resVNF['virtual-link-connectivity'].forEach((resultVLC: VLC, index: number): void => { |
| 946 | resultVLC['constituent-cpd-id'].forEach((resultCCI: CCI): void => { |
| 947 | const connectionPointID: string = resVNF.id + ':' + resultCCI['constituent-base-element-id'] + index + ':' + resultCCI['constituent-cpd-id']; |
| 948 | if (connectionPointID === d.id) { |
| 949 | this.cpData = resultCCI; |
| 950 | this.vnfData = resVNF; |
| 951 | this.virtualLinkProfileID = resultVLC['virtual-link-profile-id']; |
| 952 | this.showRightSideInfo(false, false, false, true); |
| 953 | } |
| 954 | }); |
| 955 | }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 956 | } |
| 957 | }); |
| 958 | } |
| 959 | }); |
| 960 | } else { |
| 961 | this.showRightSideInfo(true, false, false, false); |
| 962 | } |
| 963 | } |
| 964 | /** Get confirmation Before Deleting the Link in Topology @private */ |
| 965 | private getDeleteLinkConfirmation(d: Tick): void { |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 966 | // eslint-disable-next-line security/detect-non-literal-fs-filename |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 967 | const modalRef: NgbModalRef = this.modalService.open(ConfirmationTopologyComponent, { backdrop: 'static' }); |
| 968 | modalRef.componentInstance.topologyType = 'Delete'; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 969 | modalRef.componentInstance.topologyname = this.translateService.instant('PAGE.TOPOLOGY.LINK') + ' - ' + d.source.id; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 970 | modalRef.componentInstance.topologytitle = 'PAGE.TOPOLOGY.LINK'; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 971 | modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 972 | if (result) { |
| 973 | this.doubleClickLink(d); |
| 974 | } |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 975 | }).catch((): void => { |
| 976 | // Catch Navigation Error |
| SANDHYA.JS | 50e53af | 2023-04-27 13:15:44 +0530 | [diff] [blame^] | 977 | }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 978 | } |
| 979 | /** Events handles when Double Click to Delete the link @private */ |
| 980 | private doubleClickLink(d: Tick): void { |
| 981 | let getID: string = ''; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 982 | let getName: string = ''; |
| 983 | let getNodeIndex: string; |
| 984 | if (d.source.type === 'ns') { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 985 | getID = d.source.id; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 986 | getName = d.source.name; |
| 987 | getNodeIndex = d.source.nodeIndex; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 988 | } |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 989 | /** Split the selected node of connectionpoint */ |
| 990 | const selectedNode: string[] = getID.split(':'); |
| 991 | this.nsData.df.forEach((resultDF: DF): void => { |
| 992 | if (resultDF['vnf-profile'] !== undefined) { |
| 993 | resultDF['vnf-profile'].forEach((elementVNF: VNFPROFILE): void => { |
| 994 | const selectedVNFProfileID: string = selectedNode[0]; |
| 995 | /** If VNF ID is equal to selected VNFProfile ID check the VLC of CCI to match the id and name to remove the VLC index */ |
| 996 | if (selectedVNFProfileID === elementVNF.id) { |
| 997 | elementVNF['virtual-link-connectivity'].forEach((elementVLC: VLC, index: number): void => { |
| 998 | const posCCI: number = elementVLC['constituent-cpd-id'].findIndex((e: CCI): boolean => { |
| 999 | const getCID: string = elementVNF.id + ':' + e['constituent-base-element-id'] + index + ':' + e['constituent-cpd-id']; |
| 1000 | return getID === getCID; |
| 1001 | }); |
| 1002 | if (posCCI !== -1) { |
| 1003 | elementVNF['virtual-link-connectivity'].splice(index, 1); |
| 1004 | } |
| 1005 | }); |
| 1006 | } |
| 1007 | }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 1008 | } |
| 1009 | }); |
| 1010 | this.putType = 'linkdelete'; |
| 1011 | this.addData(environment.NSDESCRIPTORS_URL, this.identifier, this.nsData, this.putType); |
| 1012 | } |
| 1013 | /** Get confirmation Before Deleting the Node in Topology @private */ |
| 1014 | private getDeleteConfirmation(d: COMPOSERNODES): void { |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 1015 | // eslint-disable-next-line security/detect-non-literal-fs-filename |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 1016 | const modalRef: NgbModalRef = this.modalService.open(ConfirmationTopologyComponent, { backdrop: 'static' }); |
| 1017 | modalRef.componentInstance.topologyType = 'Delete'; |
| 1018 | modalRef.componentInstance.topologyname = d.name; |
| 1019 | if (d.type === 'vld') { |
| 1020 | modalRef.componentInstance.topologytitle = 'PAGE.TOPOLOGY.VIRTUALLINK'; |
| 1021 | } else if (d.type === 'vnfd') { |
| 1022 | modalRef.componentInstance.topologytitle = 'PAGE.TOPOLOGY.VNF'; |
| 1023 | } else if (d.type === 'ns') { |
| 1024 | modalRef.componentInstance.topologytitle = 'PAGE.TOPOLOGY.CONNECTIONPOINT'; |
| 1025 | } |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 1026 | modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 1027 | if (result) { |
| 1028 | this.doubleClick(d); |
| 1029 | } |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 1030 | }).catch((): void => { |
| 1031 | // Catch Navigation Error |
| SANDHYA.JS | 50e53af | 2023-04-27 13:15:44 +0530 | [diff] [blame^] | 1032 | }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 1033 | } |
| 1034 | /** Events handles when Double Click to Delete @private */ |
| 1035 | private doubleClick(d: COMPOSERNODES): void { |
| 1036 | const deletedNode: COMPOSERNODES = d; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 1037 | this.nodes.forEach((res: COMPOSERNODES, i: number): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 1038 | if (res.id === d.id) { |
| 1039 | if (deletedNode.type === 'vld') { |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 1040 | /** Remove the virtual-link-desc related to VL */ |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 1041 | const pos: number = this.nsData['virtual-link-desc'].map((e: VLD): string => e.id).indexOf(d.id); |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 1042 | this.nsData['virtual-link-desc'].splice(pos, 1); |
| 1043 | /** Remove the virtual-link-connectivity between VL and VNFD */ |
| 1044 | this.nsData.df.forEach((resultDF: DF): void => { |
| 1045 | if (resultDF['vnf-profile'] !== undefined) { |
| 1046 | resultDF['vnf-profile'].forEach((resVNF: VNFPROFILE): void => { |
| 1047 | const getVLArray: number[] = resVNF['virtual-link-connectivity'].map((e: VLC, index: number): number => { |
| 1048 | if (e['virtual-link-profile-id'] === d.id) { |
| 1049 | return index; |
| 1050 | } |
| 1051 | }); |
| 1052 | if (getVLArray.length > 0) { |
| 1053 | getVLArray.forEach((removeIndex: number): void => { |
| 1054 | const index: string = removeIndex.toString(); |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 1055 | // eslint-disable-next-line security/detect-object-injection |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 1056 | resVNF['virtual-link-connectivity'].splice(resVNF['virtual-link-connectivity'][index], 1); |
| 1057 | }); |
| 1058 | } |
| 1059 | }); |
| 1060 | } |
| 1061 | }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 1062 | this.putType = 'nsddelete'; |
| 1063 | } else if (deletedNode.type === 'vnfd') { |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 1064 | this.nsData.df.forEach((resultDF: DF): void => { |
| 1065 | if (resultDF['vnf-profile'] !== undefined) { |
| 1066 | /** Remove the vnf-profile related to VNFD */ |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 1067 | const posVNF: number = resultDF['vnf-profile'].findIndex((e: VNFPROFILE): boolean => e['vnfd-id'] === d.name && e.id === d.nodeIndex); |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 1068 | resultDF['vnf-profile'].splice(posVNF, 1); |
| 1069 | /** Check the VNFD exists in any vnf-profile */ |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 1070 | const isVNFDExists: boolean = resultDF['vnf-profile'].some((e: VNFPROFILE): boolean => e['vnfd-id'] === d.name); |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 1071 | /** If VNFD not exists in the vnf-profile remove from vnfd-id */ |
| 1072 | if (!isVNFDExists) { |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 1073 | const posVNFD: number = this.nsData['vnfd-id'].findIndex((e: string): boolean => e === d.name); |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 1074 | this.nsData['vnfd-id'].splice(posVNFD, 1); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 1075 | } |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 1076 | } |
| 1077 | }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 1078 | this.putType = 'vnfddelete'; |
| 1079 | } else if (deletedNode.type === 'ns') { |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 1080 | /** Split the selected node */ |
| 1081 | const selectedNode: string[] = d.id.split(':'); |
| 1082 | this.nsData.df.forEach((resultDF: DF): void => { |
| 1083 | if (resultDF['vnf-profile'] !== undefined) { |
| 1084 | resultDF['vnf-profile'].forEach((elementVNF: VNFPROFILE): void => { |
| 1085 | const selectedVNFProfileID: string = selectedNode[0]; |
| 1086 | /** If VNF ID is equal to selected VNFProfile ID check the VLC of CCI to match the id and name to remove the VLC index */ |
| 1087 | if (selectedVNFProfileID === elementVNF.id) { |
| 1088 | elementVNF['virtual-link-connectivity'].forEach((elementVLC: VLC, index: number): void => { |
| 1089 | const posCCI: number = elementVLC['constituent-cpd-id'].findIndex((e: CCI): boolean => { |
| 1090 | const getID: string = elementVNF.id + ':' + e['constituent-base-element-id'] + index + ':' + e['constituent-cpd-id']; |
| 1091 | return d.id === getID; |
| 1092 | }); |
| 1093 | if (posCCI !== -1) { |
| 1094 | elementVNF['virtual-link-connectivity'].splice(index, 1); |
| 1095 | } |
| 1096 | }); |
| 1097 | } |
| 1098 | }); |
| 1099 | } |
| 1100 | }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 1101 | this.putType = 'nsdelete'; |
| 1102 | } |
| 1103 | this.addData(environment.NSDESCRIPTORS_URL, this.identifier, this.nsData, this.putType); |
| 1104 | } |
| 1105 | }); |
| 1106 | } |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 1107 | /** drag event @private */ |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 1108 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 1109 | private onDragDrop(): any { |
| 1110 | return d3.drag().filter(this.dragFilter) |
| 1111 | .on('start', this.dragstarted) |
| 1112 | .on('drag', this.dragged) |
| 1113 | .on('end', this.dragended); |
| 1114 | } |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 1115 | /** Key press event @private */ |
| 1116 | private keyDown(): void { |
| 1117 | const graphContainerAttr: GRAPHDETAILS = this.getGraphContainerAttr(); |
| 1118 | if (this.lastKeyDown !== -1) { return; } |
| 1119 | this.lastKeyDown = d3.event.keyCode; |
| 1120 | if (d3.event.keyCode === graphContainerAttr.shiftKeyCode) { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 1121 | this.svg.classed('ctrl', true); |
| 1122 | } |
| 1123 | } |
| 1124 | /** Key realse event @private */ |
| 1125 | private keyUp(): void { |
| 1126 | const graphContainerAttr: GRAPHDETAILS = this.getGraphContainerAttr(); |
| 1127 | this.lastKeyDown = -1; |
| 1128 | if (d3.event.keyCode === graphContainerAttr.shiftKeyCode) { |
| 1129 | this.gvlNode.on('.drag', null); |
| 1130 | this.gvnfdNode.on('.drag', null); |
| 1131 | this.gcpNode.on('.drag', null); |
| 1132 | this.svg.classed('ctrl', false); |
| 1133 | } |
| 1134 | } |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 1135 | /** Events handles when to drag using filter for the keys @private */ |
| 1136 | private dragFilter(): boolean { |
| 1137 | return d3.event.ctrlKey && !d3.event.button; |
| 1138 | } |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 1139 | /** Events handles when dragstarted @private */ |
| 1140 | private dragstarted(d: COMPOSERNODES): void { |
| 1141 | d.fx = d.x; |
| 1142 | d.fy = d.y; |
| 1143 | } |
| 1144 | /** Events handles when dragged @private */ |
| 1145 | private dragged(d: COMPOSERNODES): void { |
| 1146 | d.fx = d.x = d3.event.x; |
| 1147 | d.fy = d.y = d3.event.y; |
| 1148 | } |
| 1149 | /** Events handles when dragended @private */ |
| 1150 | private dragended(d: COMPOSERNODES): void { |
| 1151 | if (this.forceSimulationActive) { |
| 1152 | d.fx = null; |
| 1153 | d.fy = null; |
| 1154 | } else { |
| 1155 | d.fx = d.x; |
| 1156 | d.fy = d.y; |
| 1157 | this.forceSimulationActive = false; |
| 1158 | } |
| 1159 | } |
| 1160 | /** Events handles when node double click @private */ |
| 1161 | private onNodedblClickToggleSidebar(): void { |
| 1162 | this.sideBarOpened = false; |
| 1163 | } |
| 1164 | /** Events handles when node single click @private */ |
| 1165 | private onNodeClickToggleSidebar(): void { |
| 1166 | this.sideBarOpened = true; |
| 1167 | } |
| 1168 | } |