Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 1 | /* |
| 2 | ============LICENSE_START========================================== |
| 3 | =================================================================== |
| 4 | Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. |
Arundathi Patil | 9d5e8e7 | 2018-07-17 15:46:17 +0530 | [diff] [blame] | 5 | |
| 6 | Copyright (C) 2018 IBM Intellectual Property. All rights reserved. |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 7 | =================================================================== |
Sandeep J | 3d0d6a3 | 2018-07-13 15:10:51 +0530 | [diff] [blame] | 8 | Copyright (C) 2018 IBM. |
| 9 | =================================================================== |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 10 | |
| 11 | Unless otherwise specified, all software contained herein is licensed |
| 12 | under the Apache License, Version 2.0 (the License); |
| 13 | you may not use this software except in compliance with the License. |
| 14 | You may obtain a copy of the License at |
| 15 | |
| 16 | http://www.apache.org/licenses/LICENSE-2.0 |
| 17 | |
| 18 | Unless required by applicable law or agreed to in writing, software |
| 19 | distributed under the License is distributed on an "AS IS" BASIS, |
| 20 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 21 | See the License for the specific language governing permissions and |
| 22 | limitations under the License. |
| 23 | |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 24 | ============LICENSE_END============================================ |
| 25 | */ |
| 26 | |
| 27 | import { Component, OnInit, ViewChild } from '@angular/core'; |
| 28 | import { saveAs } from 'file-saver'; |
| 29 | import { ParamShareService } from '../../../shared/services/paramShare.service'; |
| 30 | import { MappingEditorService } from '../../../shared/services/mapping-editor.service'; |
| 31 | import { ModalComponent } from '../../../shared/modal/modal.component'; |
| 32 | import { HttpUtilService } from '../../../shared/services/httpUtil/http-util.service'; |
| 33 | import { UtilityService } from '../../../shared/services/utilityService/utility.service'; |
| 34 | import { environment } from '../../../../environments/environment'; |
| 35 | import { NotificationsService } from 'angular2-notifications'; |
| 36 | import { ParameterDefinitionService } from './parameter-definition.service'; |
| 37 | import 'rxjs/add/operator/map'; |
| 38 | import { NgProgress } from 'ngx-progressbar'; |
Sandeep J | d2917a8 | 2018-07-19 16:41:13 +0530 | [diff] [blame] | 39 | import { NgxSpinnerService } from 'ngx-spinner'; |
Arundathi Patil | 9d5e8e7 | 2018-07-17 15:46:17 +0530 | [diff] [blame] | 40 | import { appConstants } from '../../../../constants/app-constants'; |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 41 | |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 42 | let YAML = require('yamljs'); |
| 43 | |
| 44 | declare var $: any; |
| 45 | |
| 46 | @Component({ |
| 47 | selector: 'parameter-form', |
| 48 | templateUrl: './parameter.component.html', |
| 49 | styleUrls: ['../reference-dataform/reference-dataform.component.css'], |
| 50 | providers: [ParameterDefinitionService] |
| 51 | }) |
| 52 | export class ParameterComponent implements OnInit { |
| 53 | public paramForm: any; |
| 54 | public actionType: any; |
| 55 | public showFilterFields: boolean; |
Arundathi Patil | 9d5e8e7 | 2018-07-17 15:46:17 +0530 | [diff] [blame] | 56 | public filterByFieldvalues = appConstants.filterByFieldvalues; |
| 57 | public ruleTypeConfiguaration = appConstants.ruleTypeConfiguaration; |
| 58 | public requiredValues: boolean[] = appConstants.requiredValues; |
| 59 | public sourceValues = appConstants.sourceValues; |
| 60 | public ruleTypeValues = appConstants.ruleTypeValues; |
| 61 | public typeValues = appConstants.typeValues; |
| 62 | public responseKeyNameValues = appConstants.responseKeyNameValues; |
| 63 | public responseKeyValues = appConstants.responseKeyValues; |
| 64 | public requestKeyNameValues = appConstants.requestKeyNameValues; |
| 65 | public requestKeyValues = appConstants.requestKeyValues; |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 66 | public myKeyFileName = null; |
| 67 | public myPdFileName = null; |
| 68 | public disposable: any; |
| 69 | public confirmation: boolean; |
| 70 | public showConfirmation: boolean; |
| 71 | public test: boolean; |
| 72 | apiToken = localStorage['apiToken']; |
| 73 | userId = localStorage['userId']; |
| 74 | public initialData: any; |
| 75 | public intialData: any; |
| 76 | public initialAction: any; |
| 77 | public item: any = {}; |
| 78 | public subscription: any; |
| 79 | public Actions = [ |
Arundathi Patil | 9d5e8e7 | 2018-07-17 15:46:17 +0530 | [diff] [blame] | 80 | { action: appConstants.Actions.configBackup, value: appConstants.Actions.configBackup }, |
| 81 | { action: appConstants.Actions.ConfigModify, value: appConstants.Actions.ConfigModify }, |
| 82 | { action: appConstants.Actions.configRestore, value: appConstants.Actions.configRestore }, |
| 83 | { action: appConstants.Actions.configure, value: appConstants.Actions.configure }, |
| 84 | { action: appConstants.Actions.getRunningConfig, value: appConstants.Actions.getRunningConfig }, |
| 85 | { action: appConstants.Actions.healthCheck, value: appConstants.Actions.healthCheck }, |
| 86 | { action: appConstants.Actions.startApplication, value: appConstants.Actions.startApplication }, |
Lukasz Rajewski | 1fe55d3 | 2018-08-28 15:18:35 +0200 | [diff] [blame] | 87 | { action: appConstants.Actions.stopApplication, value: appConstants.Actions.stopApplication }, |
| 88 | { action: appConstants.Actions.distributeTraffic, value: appConstants.Actions.distributeTraffic } |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 89 | ]; |
Arundathi Patil | 9d5e8e7 | 2018-07-17 15:46:17 +0530 | [diff] [blame] | 90 | public uploadTypes = appConstants.uploadTypes; |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 91 | |
Arundathi Patil | 9d5e8e7 | 2018-07-17 15:46:17 +0530 | [diff] [blame] | 92 | options = appConstants.optionsToNotificationComponent; |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 93 | public vnfcTypeData: string = ''; |
| 94 | public selectedUploadType: string; |
| 95 | @ViewChild(ModalComponent) modalComponent: ModalComponent; |
| 96 | public title: string; |
| 97 | public parameterDefinitionMap: { [index: string]: string; } = {}; |
| 98 | public parameterNameValues = {}; |
| 99 | public displayParamObjects; |
| 100 | public modelParamDefinitionObjects; |
| 101 | public vnfType: any; |
| 102 | vnfcType: any; |
| 103 | protocol: any; |
| 104 | public refNameObj = {}; |
| 105 | public action; |
| 106 | public artifactName; |
| 107 | public appDataObject: any; |
| 108 | public downloadDataObject: any; |
Arundathi Patil | 9d5e8e7 | 2018-07-17 15:46:17 +0530 | [diff] [blame] | 109 | public artifact_fileName = ""; |
od7427 | b1ce3d4 | 2018-08-23 11:49:12 -0400 | [diff] [blame] | 110 | template_id: any; |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 111 | private selectedActionReference: any; |
| 112 | |
sj108s | f27d554 | 2018-04-02 14:46:25 +0530 | [diff] [blame] | 113 | constructor(private httpService: HttpUtilService, |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 114 | private parameterDefinitionService: ParameterDefinitionService, |
| 115 | private paramShareService: ParamShareService, |
| 116 | private mappingEditorService: MappingEditorService, |
| 117 | private httpUtil: HttpUtilService, |
| 118 | private utilService: UtilityService, |
| 119 | private nService: NotificationsService, |
Sandeep J | d2917a8 | 2018-07-19 16:41:13 +0530 | [diff] [blame] | 120 | private ngProgress: NgProgress, |
| 121 | private spinner: NgxSpinnerService) { |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | ngOnInit() { |
| 125 | this.selectedActionReference = this.parameterDefinitionService.prepareFileName(); |
| 126 | if (this.selectedActionReference && this.selectedActionReference != undefined) { |
| 127 | |
| 128 | this.vnfType = this.selectedActionReference.scope['vnf-type']; |
| 129 | this.vnfcType = this.selectedActionReference.scope['vnfc-type']; |
| 130 | this.protocol = this.selectedActionReference['device-protocol']; |
| 131 | this.action = this.selectedActionReference.action; |
| 132 | |
| 133 | for (let i = 0; i < this.selectedActionReference['artifact-list'].length; i++) { |
| 134 | let artifactList = this.selectedActionReference['artifact-list']; |
| 135 | if (artifactList[i]['artifact-type'] === 'parameter_definitions') { |
sj108s | f27d554 | 2018-04-02 14:46:25 +0530 | [diff] [blame] | 136 | var artifactName = artifactList[i]['artifact-name']; |
| 137 | var artifactNameWithoutExtension = ''; |
Mohamed Asgar Samiulla(ma926a) | 7f0939f | 2018-04-17 15:14:28 +0530 | [diff] [blame] | 138 | if (artifactName) { |
| 139 | artifactNameWithoutExtension = artifactName.substring(0, artifactName.lastIndexOf(".")); |
| 140 | } |
Arundathi Patil | 9d5e8e7 | 2018-07-17 15:46:17 +0530 | [diff] [blame] | 141 | if (this.mappingEditorService.identifier) { |
| 142 | if (artifactNameWithoutExtension.endsWith(this.mappingEditorService.identifier)) { |
Mohamed Asgar Samiulla(ma926a) | 7f0939f | 2018-04-17 15:14:28 +0530 | [diff] [blame] | 143 | this.artifact_fileName = artifactName; |
| 144 | } |
sj108s | f27d554 | 2018-04-02 14:46:25 +0530 | [diff] [blame] | 145 | |
| 146 | } |
| 147 | else { |
| 148 | this.artifact_fileName = artifactName; |
| 149 | } |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 150 | } |
| 151 | } |
| 152 | this.parameterDefinitionService.setValues(this.vnfType, this.vnfcType, this.protocol, this.action, this.artifact_fileName); |
| 153 | } |
| 154 | else { |
| 155 | this.selectedActionReference = { |
| 156 | 'action': '', |
| 157 | 'scope': { 'vnf-type': '', 'vnfc-type': '' }, |
| 158 | 'vm': [], |
| 159 | 'protocol': '', |
| 160 | 'download-dg-reference': '', |
| 161 | 'user-name': '', |
| 162 | 'port-number': '', |
| 163 | 'artifact-list': [], |
| 164 | 'deviceTemplate': '', |
| 165 | 'scopeType': '' |
| 166 | }; |
| 167 | } |
| 168 | |
od7427 | b1ce3d4 | 2018-08-23 11:49:12 -0400 | [diff] [blame] | 169 | this.template_id = this.mappingEditorService.identifier; |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | ngAfterViewInit() { |
| 173 | if (this.mappingEditorService.latestAction) { |
| 174 | this.displayParamObjects = []; |
| 175 | this.modelParamDefinitionObjects = []; |
| 176 | if (this.paramShareService.getSessionParamData() != undefined && this.paramShareService.getSessionParamData().length > 0) { |
sj108s | f50c516 | 2018-04-27 16:34:48 +0530 | [diff] [blame] | 177 | this.getPDFromSession(); |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 178 | } else { |
Sandeep J | 3d0d6a3 | 2018-07-13 15:10:51 +0530 | [diff] [blame] | 179 | this.ngProgress.start(); |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 180 | this.getPD(); |
Sandeep J | 3d0d6a3 | 2018-07-13 15:10:51 +0530 | [diff] [blame] | 181 | setTimeout(() => { |
| 182 | this.ngProgress.done(); |
| 183 | }, 3500); |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 184 | } |
| 185 | } else { |
Arundathi Patil | 9d5e8e7 | 2018-07-17 15:46:17 +0530 | [diff] [blame] | 186 | this.nService.error(appConstants.errors.error, appConstants.errors["noAction&VNFTypeInRDscreenError"]); |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 187 | } |
| 188 | return this.displayParamObjects; |
| 189 | } |
| 190 | |
| 191 | |
| 192 | public getPD() { |
| 193 | let result: any; |
Sandeep J | 2b68632 | 2018-07-20 13:53:22 +0530 | [diff] [blame] | 194 | let input=this.utilService.createPayloadForRetrieve(false, this.action, this.vnfType,this.artifact_fileName); |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 195 | let artifactContent: any; |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 196 | return this.httpService.post({ |
| 197 | url: environment.getDesigns, |
| 198 | data: input |
| 199 | }).subscribe(data => { |
| 200 | if (this.utilService.checkResult(data)) { |
| 201 | let result: any = JSON.parse(data.output.data.block).artifactInfo[0]; |
| 202 | var pdObject = YAML.parse(result['artifact-content']); |
| 203 | let fileModel = pdObject['vnf-parameter-list']; |
| 204 | this.displayParamObjects = this.parameterDefinitionService.populatePD(fileModel); |
| 205 | } |
Sandeep J | 3d0d6a3 | 2018-07-13 15:10:51 +0530 | [diff] [blame] | 206 | |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 207 | }, |
| 208 | |
Arundathi Patil | 9d5e8e7 | 2018-07-17 15:46:17 +0530 | [diff] [blame] | 209 | error => this.nService.error(appConstants.errors.error, appConstants.errors.connectionError)); |
| 210 | |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 211 | } |
| 212 | |
sj108s | f50c516 | 2018-04-27 16:34:48 +0530 | [diff] [blame] | 213 | public getPDFromSession() { |
Arundathi Patil | 9d5e8e7 | 2018-07-17 15:46:17 +0530 | [diff] [blame] | 214 | |
sj108s | f50c516 | 2018-04-27 16:34:48 +0530 | [diff] [blame] | 215 | this.ngProgress.start(); |
| 216 | return this.httpService.get({ |
| 217 | url: 'testurl', |
| 218 | }).subscribe(data => { |
Arundathi Patil | 9d5e8e7 | 2018-07-17 15:46:17 +0530 | [diff] [blame] | 219 | this.displayParamObjects = this.paramShareService.getSessionParamData(); |
sj108s | f50c516 | 2018-04-27 16:34:48 +0530 | [diff] [blame] | 220 | this.ngProgress.done(); |
| 221 | }, |
| 222 | error => { |
Arundathi Patil | 9d5e8e7 | 2018-07-17 15:46:17 +0530 | [diff] [blame] | 223 | this.displayParamObjects = this.paramShareService.getSessionParamData(); |
| 224 | this.ngProgress.done(); |
sj108s | f50c516 | 2018-04-27 16:34:48 +0530 | [diff] [blame] | 225 | }); |
| 226 | } |
| 227 | |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 228 | //========================== End of NGInit() Method============================================ |
| 229 | selectedNavItem(item: any) { |
| 230 | this.item = item; |
| 231 | } |
| 232 | |
| 233 | //========================== End of selectedNavItem() Method============================================ |
| 234 | browsePdFile() { |
| 235 | $('#inputFile1').trigger('click'); |
| 236 | } |
| 237 | |
| 238 | //========================== End of browsePdFile() Method============================================ |
| 239 | browseKeyFile() { |
| 240 | $('#inputFile2').trigger('click'); |
| 241 | |
| 242 | } |
| 243 | |
| 244 | //========================== End of browseKeyFile() Method============================================ |
| 245 | |
| 246 | |
| 247 | //========================== End of appendSlashes() Method============================================ |
| 248 | |
| 249 | |
| 250 | //========================== End of prepareFileName() Method============================================ |
| 251 | ngOnDestroy() { |
| 252 | this.parameterDefinitionService.destroy(this.displayParamObjects); |
| 253 | } |
| 254 | |
| 255 | //========================== End of ngOnDestroy() Method============================================ |
| 256 | |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 257 | public showUpload() { |
| 258 | this.selectedUploadType = this.uploadTypes[0].value; |
| 259 | }; |
| 260 | |
| 261 | //========================== End of showUpload() Method============================================ |
| 262 | //This is called when the user selects new files from the upload button |
| 263 | public fileChange(input, uploadType) { |
| 264 | if (input.files && input.files[0]) { |
Sandeep J | d2917a8 | 2018-07-19 16:41:13 +0530 | [diff] [blame] | 265 | this.spinner.show(); |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 266 | // Create the file reader |
| 267 | let reader = new FileReader(); |
| 268 | this.readFile(input.files[0], reader, (result) => { |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 269 | if ('pdfile' === uploadType) { |
| 270 | this.myPdFileName = input.files[0].name; |
| 271 | this.displayParamObjects = this.parameterDefinitionService.processPDfile(this.myPdFileName, result); |
| 272 | } |
| 273 | }); |
Sandeep J | d2917a8 | 2018-07-19 16:41:13 +0530 | [diff] [blame] | 274 | setTimeout(() => { |
| 275 | /** spinner ends after 3.5 seconds */ |
| 276 | this.spinner.hide(); |
| 277 | }, 3500); |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 278 | } |
| 279 | } |
| 280 | |
| 281 | //========================== End of fileChange() Method============================================ |
| 282 | public readFile(file, reader, callback) { |
| 283 | // Set a callback funtion to fire after the file is fully loaded |
| 284 | reader.onload = () => { |
| 285 | // callback with the results |
| 286 | callback(reader.result); |
| 287 | }; |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 288 | // Read the file |
| 289 | reader.readAsText(file, 'UTF-8'); |
| 290 | } |
| 291 | |
| 292 | //========================== End of readFile() Method============================================ |
| 293 | fileChangeEvent(fileInput: any) { |
| 294 | let obj: any = fileInput.target.files; |
| 295 | } |
| 296 | |
| 297 | |
| 298 | sourceChanged(data, obj) { |
| 299 | if (data == 'A&AI') { |
Arundathi Patil | 9d5e8e7 | 2018-07-17 15:46:17 +0530 | [diff] [blame] | 300 | obj.ruleTypeValues = appConstants.ruleTypeValues; |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 301 | for (let x = 0; x < 5; x++) { |
| 302 | obj['response-keys'][x]['key-name'] = null; |
| 303 | obj['response-keys'][x]['key-value'] = null; |
| 304 | } |
| 305 | } else if (data == 'Manual') { |
| 306 | obj.ruleTypeValues = [null]; |
| 307 | obj['rule-type'] = null; |
| 308 | obj.showFilterFields = false; |
| 309 | for (let x = 0; x < 5; x++) { |
| 310 | obj['response-keys'][x]['key-name'] = null; |
| 311 | obj['response-keys'][x]['key-value'] = null; |
| 312 | } |
| 313 | } |
| 314 | else { |
| 315 | obj.ruleTypeValues = [null]; |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | //========================== End of sourceChanged() Method============================================ |
| 320 | ruleTypeChanged(data, obj) { |
| 321 | if (data == null || data == undefined || data == 'null') { |
| 322 | obj.showFilterFields = false; |
| 323 | obj['rule-type'] = null; |
| 324 | for (let x = 0; x < 5; x++) { |
| 325 | obj['response-keys'][x]['key-name'] = null; |
| 326 | obj['response-keys'][x]['key-value'] = null; |
| 327 | } |
| 328 | } else { |
| 329 | let sourceObject = this.ruleTypeConfiguaration[data]; |
| 330 | if (data == 'vm-name-list' || data == 'vnfc-name-list' || data == 'vnfc-oam-ipv4-address-list') { |
| 331 | this.showFilterFields = false; |
| 332 | obj.showFilterFields = true; |
| 333 | this.filetrByFieldChanged(obj['response-keys'][3]['key-value'], obj); |
| 334 | } else { |
| 335 | obj.showFilterFields = false; |
| 336 | obj['response-keys'][3]['key-name'] = null; |
| 337 | obj['response-keys'][3]['key-value'] = null; |
| 338 | obj['response-keys'][4]['key-name'] = null; |
| 339 | obj['response-keys'][4]['key-value'] = null; |
| 340 | } |
| 341 | for (let x = 0; x < sourceObject.length; x++) { |
| 342 | obj['response-keys'][x]['key-name'] = sourceObject[x]['key-name']; |
| 343 | obj['response-keys'][x]['key-value'] = sourceObject[x]['key-value']; |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | } |
| 348 | |
| 349 | //========================== End of ruleTypeChanged() Method============================================ |
| 350 | filetrByFieldChanged(data, obj) { |
| 351 | if (data == null || data == undefined || data == 'null') { |
| 352 | obj.enableFilterByValue = false; |
| 353 | obj['response-keys'][4]['key-value'] = null; |
| 354 | } else { |
| 355 | obj.enableFilterByValue = true; |
| 356 | } |
| 357 | |
| 358 | } |
| 359 | |
| 360 | |
Arundathi Patil | 9d5e8e7 | 2018-07-17 15:46:17 +0530 | [diff] [blame] | 361 | } |