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. |
| 5 | =================================================================== |
Sandeep J | 77ebde8 | 2018-07-20 15:56:31 +0530 | [diff] [blame^] | 6 | Copyright (C) 2018 IBM. |
| 7 | =================================================================== |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 8 | Unless otherwise specified, all software contained herein is licensed |
| 9 | under the Apache License, Version 2.0 (the License); |
| 10 | you may not use this software except in compliance with the License. |
| 11 | You may obtain a copy of the License at |
| 12 | |
| 13 | http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | |
| 15 | Unless required by applicable law or agreed to in writing, software |
| 16 | distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | See the License for the specific language governing permissions and |
| 19 | limitations under the License. |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 20 | ============LICENSE_END============================================ |
| 21 | */ |
| 22 | |
| 23 | import { Component, OnInit } from '@angular/core'; |
Sandeep J | 77ebde8 | 2018-07-20 15:56:31 +0530 | [diff] [blame^] | 24 | import { NgxSpinnerService } from 'ngx-spinner'; |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 25 | import { saveAs } from 'file-saver'; |
| 26 | import { Location } from '@angular/common'; |
| 27 | import { ActivatedRoute, Router } from '@angular/router'; |
| 28 | import { NotificationService } from '.././shared/services/notification.service'; |
| 29 | import { ParamShareService } from '.././shared/services/paramShare.service'; |
| 30 | import { MappingEditorService } from '.././shared/services/mapping-editor.service'; |
| 31 | import { NotificationsService } from 'angular2-notifications'; |
| 32 | import { HttpUtilService } from '.././shared/services/httpUtil/http-util.service'; |
| 33 | import 'rxjs/add/observable/interval'; |
| 34 | import { Observable } from 'rxjs/Observable'; |
| 35 | import { environment } from '../.././environments/environment'; |
| 36 | import { UtilityService } from '.././shared/services/utilityService/utility.service'; |
| 37 | import 'rxjs/add/operator/map'; |
| 38 | import * as XLSX from 'xlsx'; |
| 39 | import { NgProgress } from 'ngx-progressbar'; |
| 40 | |
| 41 | |
| 42 | let YAML = require('yamljs'); |
| 43 | |
| 44 | type AOA = Array<Array<any>>; |
| 45 | declare var $: any; |
| 46 | |
| 47 | @Component({ selector: 'test', templateUrl: './test.component.html', styleUrls: ['./test.component.css'] }) |
| 48 | export class TestComponent implements OnInit { |
| 49 | public displayParamObjects; |
| 50 | options = { |
| 51 | timeOut: 1000, |
| 52 | showProgressBar: true, |
| 53 | pauseOnHover: true, |
| 54 | clickToClose: true, |
| 55 | maxLength: 200 |
| 56 | }; |
| 57 | public action: any; |
| 58 | public vnfId: any; |
| 59 | public item: any = {}; |
| 60 | |
| 61 | public vnfType: any; |
| 62 | vnfcType: any; |
| 63 | protocol: any; |
| 64 | mode: any = 'NORMAL'; |
| 65 | force: any = 'True'; |
| 66 | ttl: any; |
| 67 | public formattedNameValuePairs = {}; |
| 68 | public requestId = ''; |
| 69 | public enableBrowse: boolean = true; |
| 70 | public enableSpinner: boolean = false; |
| 71 | host: any; |
| 72 | public refNameObj = {}; |
| 73 | |
| 74 | public artifactName; |
| 75 | public type; |
| 76 | public transactions = ''; |
| 77 | public uploadFileName; |
| 78 | |
| 79 | public payload = {}; |
| 80 | public lastvmJson = {}; |
| 81 | public vmPayload = []; |
| 82 | public subPayload = {}; |
| 83 | public vmJson = {}; |
| 84 | public vnfcJson = {}; |
| 85 | public flag = 1; |
| 86 | public oldListName1 = ''; |
| 87 | public actionIdentifiers = {}; |
| 88 | public apiRequest = ''; |
| 89 | public apiResponse = ''; |
| 90 | public statusResponse; |
| 91 | public outputTimeStamp; |
| 92 | public status; |
| 93 | public statusReason; |
Sandeep J | 77ebde8 | 2018-07-20 15:56:31 +0530 | [diff] [blame^] | 94 | public errorResponse; |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 95 | public timer; |
| 96 | public subscribe; |
| 97 | public enableTestButton: boolean = false; |
| 98 | public enableAbort: boolean = false; |
| 99 | public showStatusResponseDiv: boolean = false; |
| 100 | public enablePollButton: boolean = true; |
| 101 | public pollCounter = 0; |
| 102 | public enableCounterDiv: boolean = false; |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 103 | public enableDownload: boolean = false; |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 104 | private userId = localStorage['userId']; |
Sandeep J | 77ebde8 | 2018-07-20 15:56:31 +0530 | [diff] [blame^] | 105 | constructor ( |
| 106 | private location: Location, |
| 107 | private activeRoutes: ActivatedRoute, |
| 108 | private notificationService: NotificationService, |
| 109 | private nService: NotificationsService, |
| 110 | private router: Router, |
| 111 | private paramShareService: ParamShareService, |
| 112 | private mappingEditorService: MappingEditorService, |
| 113 | private httpUtil: HttpUtilService, |
| 114 | private utiltiy: UtilityService, |
| 115 | private ngProgress: NgProgress, |
| 116 | private spinner: NgxSpinnerService |
| 117 | ) { |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 118 | |
| 119 | } |
| 120 | |
| 121 | ngOnInit() { |
| 122 | |
| 123 | |
| 124 | } |
| 125 | |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 126 | |
| 127 | public download() { |
| 128 | if (this.apiRequest) { |
| 129 | var fileName = 'test_' + this.action + '_' + this.actionIdentifiers['vnf-id'] + '_request'; |
| 130 | var theJSON = this.apiRequest; |
| 131 | if (fileName != null || fileName != '') { |
| 132 | var blob = new Blob([theJSON], { |
| 133 | type: 'text/json' |
| 134 | }); |
| 135 | saveAs(blob, fileName); |
| 136 | } |
| 137 | } |
| 138 | else { |
| 139 | this.nService.error('Error', 'Please upload spreadsheet to download the request and response'); |
| 140 | } |
| 141 | |
| 142 | if (this.apiResponse) { |
| 143 | var fileName = 'test_' + this.action + '_' + this.actionIdentifiers['vnf-id'] + '_response'; |
| 144 | var theJSON = this.apiResponse; |
| 145 | if (fileName != null || fileName != '') { |
| 146 | var blob = new Blob([theJSON], { |
| 147 | type: 'text/json' |
| 148 | }); |
| 149 | saveAs(blob, fileName); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | } |
| 154 | |
| 155 | |
| 156 | public abortTest() { |
| 157 | //this.apiResponse = ""; |
| 158 | this.enableBrowse = true; |
| 159 | this.enableTestButton = true; |
| 160 | this.enablePollButton = true; |
sj108s | 9017464 | 2018-03-15 20:26:47 +0530 | [diff] [blame] | 161 | if (this.subscribe && this.subscribe != undefined) this.subscribe.unsubscribe(); |
Kumar, Amaresh (ak583p) | 6c7ccba | 2018-05-09 22:29:45 +0530 | [diff] [blame] | 162 | this.nService.info("Information", "Test has been abandoned and polling stopped"); |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 166 | excelBrowseOption() { |
| 167 | $('#excelInputFile').trigger('click'); |
| 168 | } |
| 169 | |
| 170 | |
| 171 | upload(evt: any) { |
| 172 | /* wire up file reader */ |
| 173 | $('#filesparam').trigger('click'); |
| 174 | const target: DataTransfer = <DataTransfer>(evt.target); |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 175 | this.pollCounter = 0; |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 176 | this.uploadFileName = evt.target.files[0].name; |
| 177 | var fileExtension = this.uploadFileName.substr(this.uploadFileName.lastIndexOf('.') + 1); |
| 178 | |
| 179 | if (target.files.length != 1) { |
| 180 | throw new Error('Cannot upload multiple files on the entry'); |
| 181 | } |
| 182 | if (fileExtension.toUpperCase() === 'XLS' || fileExtension.toUpperCase() === 'XLSX') { |
Sandeep J | 77ebde8 | 2018-07-20 15:56:31 +0530 | [diff] [blame^] | 183 | this.spinner.show(); |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 184 | const reader = new FileReader(); |
| 185 | reader.onload = (e: any) => { |
| 186 | /* read workbook */ |
| 187 | const bstr = e.target.result; |
| 188 | const wb = XLSX.read(bstr, { type: 'binary' }); |
| 189 | /* grab first sheet */ |
| 190 | const wsname = wb.SheetNames[0]; |
| 191 | const ws = wb.Sheets[wsname]; |
| 192 | |
| 193 | /* save data */ |
| 194 | this.requestId = '' |
| 195 | this.enableTestButton = true; |
| 196 | this.enableAbort = true; |
| 197 | this.enablePollButton = true; |
| 198 | |
| 199 | if (this.subscribe && this.subscribe != undefined) { |
| 200 | this.enableCounterDiv = false; |
| 201 | this.subscribe.unsubscribe(); |
| 202 | } |
| 203 | this.apiRequest = ''; |
| 204 | this.apiResponse = ''; |
| 205 | this.showStatusResponseDiv = false; |
| 206 | this.errorResponse = ''; |
| 207 | this.statusResponse = ''; |
sj108s | b694d95 | 2018-03-21 21:25:39 +0530 | [diff] [blame] | 208 | this.enableDownload = true; |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 209 | let arrData = (<AOA>(XLSX.utils.sheet_to_json(ws, { blankrows: false }))); |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 210 | |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 211 | |
| 212 | |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 213 | this.vmPayload = []; |
| 214 | this.subPayload = {}; |
| 215 | this.vmJson = {}; |
| 216 | this.flag = 1; |
| 217 | this.payload = {}; |
| 218 | this.oldListName1 = ''; |
| 219 | this.actionIdentifiers = {}; |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 220 | // Refactor |
| 221 | this.payload = this.processUploadedFile(arrData); |
| 222 | this.uploadedFileResult(); |
sj108s | b694d95 | 2018-03-21 21:25:39 +0530 | [diff] [blame] | 223 | }; |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 224 | |
| 225 | reader.readAsBinaryString(target.files[0]); |
Sandeep J | 77ebde8 | 2018-07-20 15:56:31 +0530 | [diff] [blame^] | 226 | setTimeout(() => { |
| 227 | /** spinner ends after 2.5 seconds */ |
| 228 | this.spinner.hide(); |
| 229 | }, 2500); |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 230 | |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 231 | } |
| 232 | else { |
| 233 | this.nService.error('Error', 'Incorrect spreadsheet uploaded'); |
IBM602-PC0F1E3C\Arundathi | 675e8b8 | 2018-07-16 14:30:26 +0530 | [diff] [blame] | 234 | this.setValuesOnFileUploadFailure(); |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 235 | } |
| 236 | } |
| 237 | |
sj108s | b694d95 | 2018-03-21 21:25:39 +0530 | [diff] [blame] | 238 | processUploadedFile(arrData) { |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 239 | let tempPayload = {}; |
| 240 | for (var i = 0; i < arrData.length; i++) { |
| 241 | var element = arrData[i]; |
| 242 | if (element['TagName'] === 'action') { |
| 243 | this.action = element['Value']; |
| 244 | } |
| 245 | if (element['List Name'] === 'action-identifiers') { |
| 246 | this.vnfId = element['Value']; |
| 247 | var key = element['TagName']; |
| 248 | var value = element['Value']; |
| 249 | if (key && value) { |
| 250 | this.actionIdentifiers[key] = value; |
| 251 | |
| 252 | } |
| 253 | } |
sj108s | b694d95 | 2018-03-21 21:25:39 +0530 | [diff] [blame] | 254 | |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 255 | if (element['List Name'] === 'payload') { |
| 256 | var listName1 = element['List Name_1']; |
| 257 | var listName2 = element['List Name_2']; |
| 258 | var listName3 = element['List Name_3']; |
| 259 | var key = element['TagName']; |
| 260 | var value = element['Value']; |
| 261 | if (listName1) { |
| 262 | if (this.oldListName1 == '' || (listName1 === this.oldListName1)) { |
| 263 | this.constructTestPayload(listName2, listName3, key, value); |
| 264 | tempPayload[listName1] = this.subPayload; |
| 265 | } |
| 266 | else { |
| 267 | this.subPayload = {}; |
| 268 | this.constructTestPayload(listName2, listName3, key, value); |
| 269 | tempPayload[listName1] = this.subPayload; |
| 270 | } |
| 271 | this.oldListName1 = listName1; |
| 272 | } |
| 273 | else { |
| 274 | tempPayload[key] = value; |
| 275 | } |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | return tempPayload; |
| 280 | } |
| 281 | |
sj108s | b694d95 | 2018-03-21 21:25:39 +0530 | [diff] [blame] | 282 | uploadedFileResult() { |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 283 | if (this.action && this.actionIdentifiers['vnf-id']) { |
| 284 | this.nService.success('Success', 'SpreadSheet uploaded successfully'); |
| 285 | } |
| 286 | else { |
IBM602-PC0F1E3C\Arundathi | 675e8b8 | 2018-07-16 14:30:26 +0530 | [diff] [blame] | 287 | this.setValuesOnFileUploadFailure(); |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 288 | this.nService.error("Error", "Please check the contents of the file uploaded") |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | |
| 293 | |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 294 | constructTestPayload(listName2, listName3, key, value) { |
| 295 | if (listName2 == undefined && listName3 == undefined) { |
| 296 | this.subPayload[key] = value; |
| 297 | } |
| 298 | if (listName2) { |
| 299 | |
| 300 | if (!listName3) { |
| 301 | |
| 302 | //vmPayload.push(vmJson) |
| 303 | this.vmJson = {}; |
| 304 | this.vnfcJson = {}; |
| 305 | this.vmJson[key] = value; |
| 306 | this.flag = 0; |
| 307 | } |
| 308 | else { |
| 309 | this.vnfcJson[key] = value; |
| 310 | this.vmJson['vnfc'] = this.vnfcJson; |
| 311 | this.flag = 1; |
| 312 | } |
| 313 | if (this.vmJson) this.lastvmJson = this.vmJson; |
| 314 | if (this.flag == 0) { |
| 315 | this.vmPayload.push(this.lastvmJson); |
| 316 | if (this.vmPayload) this.subPayload['vm'] = this.vmPayload; |
| 317 | } |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | constructRequest() { |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 322 | let timeStamp = new Date().toISOString(); |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 323 | let reqId; |
| 324 | this.requestId = reqId = new Date().getTime().toString(); |
| 325 | let data = { |
| 326 | 'input': { |
| 327 | 'common-header': { |
| 328 | 'timestamp': timeStamp, |
| 329 | 'api-ver': '2.00', |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 330 | 'originator-id': this.userId, |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 331 | 'request-id': this.requestId, |
| 332 | 'sub-request-id': this.requestId, |
| 333 | 'flags': { |
| 334 | 'mode': 'NORMAL', |
| 335 | 'force': 'TRUE', |
| 336 | 'ttl': 3600 |
| 337 | } |
| 338 | }, |
| 339 | 'action': this.action, |
| 340 | 'action-identifiers': this.actionIdentifiers, |
| 341 | 'payload': JSON.stringify(this.payload) |
| 342 | } |
| 343 | }; |
| 344 | |
| 345 | return data; |
| 346 | } |
| 347 | |
| 348 | testVnf() { |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 349 | this.enableBrowse = false; |
| 350 | this.enableTestButton = false; |
| 351 | this.enablePollButton = false; |
| 352 | this.timer = Observable.interval(10000); |
| 353 | this.subscribe = this.timer.subscribe((t) => this.pollTestStatus()); |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 354 | this.ngProgress.start(); |
| 355 | this.apiRequest = JSON.stringify(this.constructRequest()); |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 356 | |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 357 | this.httpUtil.post( |
| 358 | { |
Kumar, Amaresh (ak583p) | 6c7ccba | 2018-05-09 22:29:45 +0530 | [diff] [blame] | 359 | url: environment.testVnf + "?urlAction=" + this.getUrlEndPoint(this.action.toLowerCase()), |
| 360 | data: this.apiRequest |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 361 | }) |
| 362 | .subscribe(resp => { |
| 363 | this.apiResponse = JSON.stringify(resp); |
| 364 | this.enableBrowse = true; |
| 365 | this.enableTestButton = true; |
| 366 | this.ngProgress.done(); |
| 367 | }, |
Kumar, Amaresh (ak583p) | 6c7ccba | 2018-05-09 22:29:45 +0530 | [diff] [blame] | 368 | error => { |
| 369 | this.nService.error('Error', 'Error in connecting to APPC Server'); |
| 370 | this.enableBrowse = true; |
| 371 | this.enableTestButton = true; |
| 372 | this.enablePollButton = true; |
| 373 | this.enableCounterDiv = false; |
| 374 | if (this.subscribe && this.subscribe != undefined) this.subscribe.unsubscribe(); |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 375 | |
Kumar, Amaresh (ak583p) | 6c7ccba | 2018-05-09 22:29:45 +0530 | [diff] [blame] | 376 | }); |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 377 | |
| 378 | setTimeout(() => { |
| 379 | this.ngProgress.done(); |
| 380 | }, 3500); |
| 381 | } |
| 382 | |
| 383 | |
| 384 | pollTestStatus() { |
| 385 | if (this.requestId && this.actionIdentifiers['vnf-id']) { |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 386 | let timeStamp = new Date().toISOString(); |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 387 | let reqId = new Date().getTime().toString(); |
| 388 | let data = { |
| 389 | 'input': { |
| 390 | 'common-header': { |
| 391 | 'timestamp': timeStamp, |
| 392 | 'api-ver': '2.00', |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 393 | 'originator-id': this.userId, |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 394 | 'request-id': reqId, |
| 395 | 'sub-request-id': reqId, |
| 396 | 'flags': { |
| 397 | 'mode': 'NORMAL', |
| 398 | 'force': 'TRUE', |
| 399 | 'ttl': 3600 |
| 400 | } |
| 401 | }, |
| 402 | 'action': 'ActionStatus', |
Kumar, Amaresh (ak583p) | 6c7ccba | 2018-05-09 22:29:45 +0530 | [diff] [blame] | 403 | 'action-identifiers': { |
| 404 | 'vnf-id': this.actionIdentifiers['vnf-id'] |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 405 | }, |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 406 | 'payload': '{"request-id":' + this.requestId + '}' |
| 407 | } |
| 408 | }; |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 409 | this.httpUtil.post( |
| 410 | { |
| 411 | url: environment.checkTestStatus, data: data |
| 412 | |
| 413 | }) |
| 414 | .subscribe(resp => { |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 415 | this.statusResponse = JSON.stringify(resp); |
| 416 | var status = '' |
| 417 | var statusReason = '' |
| 418 | this.enableCounterDiv = true; |
| 419 | this.pollCounter++; |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 420 | if (resp.output) var timeStamp = resp.output['common-header'].timestamp; |
| 421 | if (resp.output.payload) { |
| 422 | var payload = resp.output.payload.replace(/\\/g, "") |
| 423 | try { |
| 424 | payload = JSON.parse(payload) |
| 425 | status = payload['status']; |
| 426 | statusReason = payload['status-reason']; |
| 427 | } |
| 428 | catch (err) { |
| 429 | console.log("error" + err) |
| 430 | } |
| 431 | } |
| 432 | if (timeStamp && status && statusReason) { |
| 433 | this.showStatusResponseDiv = true; |
| 434 | this.outputTimeStamp = timeStamp; |
| 435 | this.status = status; |
| 436 | this.statusReason = statusReason; |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 437 | if (status.toUpperCase() === 'SUCCESS' || status.toUpperCase() === 'SUCCESSFUL') { |
sj108s | 9017464 | 2018-03-15 20:26:47 +0530 | [diff] [blame] | 438 | if (this.subscribe && this.subscribe != undefined) this.subscribe.unsubscribe(); |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 439 | this.enablePollButton = true; |
| 440 | } |
| 441 | if (status.toUpperCase() === 'FAILED') { |
sj108s | 9017464 | 2018-03-15 20:26:47 +0530 | [diff] [blame] | 442 | if (this.subscribe && this.subscribe != undefined) this.subscribe.unsubscribe(); |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 443 | this.enablePollButton = true; |
| 444 | } |
| 445 | } |
| 446 | else { |
| 447 | this.showStatusResponseDiv = false; |
sj108s | b694d95 | 2018-03-21 21:25:39 +0530 | [diff] [blame] | 448 | if (this.subscribe && this.subscribe != undefined) { |
| 449 | this.subscribe.unsubscribe(); |
| 450 | this.enablePollButton = true; |
| 451 | } |
| 452 | |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 453 | } |
| 454 | |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 455 | }, |
Kumar, Amaresh (ak583p) | 6c7ccba | 2018-05-09 22:29:45 +0530 | [diff] [blame] | 456 | error => { |
| 457 | this.statusResponse = null; |
| 458 | this.showStatusResponseDiv = false; |
| 459 | this.errorResponse = 'Error Connecting to APPC server'; |
| 460 | this.enableCounterDiv = false; |
| 461 | if (this.subscribe && this.subscribe != undefined) { |
| 462 | this.subscribe.unsubscribe(); |
| 463 | this.enablePollButton = true; |
| 464 | } |
| 465 | }); |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 466 | } |
| 467 | else { |
| 468 | this.nService.error("Error", "Please enter vnf Id & request Id"); |
| 469 | } |
sj108s | b694d95 | 2018-03-21 21:25:39 +0530 | [diff] [blame] | 470 | |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | getUrlEndPoint(action) { |
| 474 | switch (action) { |
| 475 | case 'configmodify': |
| 476 | return 'config-modify'; |
| 477 | case 'configbackup': |
| 478 | return 'config-backup'; |
| 479 | case 'configrestore': |
| 480 | return 'config-restore'; |
| 481 | case 'healthcheck': |
| 482 | return 'health-check'; |
| 483 | case 'quiescetraffic': |
| 484 | return 'quiesce-traffic'; |
| 485 | case 'resumetraffic': |
| 486 | return 'resume-traffic'; |
| 487 | case 'startapplication': |
| 488 | return 'start-application'; |
| 489 | case 'stopapplication': |
| 490 | return 'stop-application'; |
| 491 | case 'upgradebackout': |
| 492 | return 'upgrade-backout'; |
| 493 | case 'upgradepostcheck': |
| 494 | return 'upgrade-post-check'; |
| 495 | case 'upgradeprecheck': |
| 496 | return 'upgrade-pre-check'; |
| 497 | case 'upgradesoftware': |
| 498 | return 'upgrade-software'; |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 499 | case 'upgradebackup': |
| 500 | return 'upgrade-backup'; |
| 501 | case 'attachvolume': |
| 502 | return 'attach-volume'; |
| 503 | case 'detachvolume': |
| 504 | return 'detach-volume'; |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 505 | default: |
| 506 | return action.toLowerCase(); |
| 507 | } |
| 508 | |
| 509 | } |
| 510 | |
IBM602-PC0F1E3C\Arundathi | 675e8b8 | 2018-07-16 14:30:26 +0530 | [diff] [blame] | 511 | setValuesOnFileUploadFailure() { |
| 512 | this.flag = 1; |
| 513 | this.oldListName1 = ''; |
| 514 | this.vmJson = {}; |
| 515 | this.vnfcJson = {}; |
| 516 | this.subPayload = {}; |
| 517 | this.vmPayload = []; |
| 518 | this.payload = {}; |
| 519 | this.action = ''; |
| 520 | this.actionIdentifiers = {}; |
| 521 | this.apiRequest = ''; |
| 522 | this.apiResponse = ''; |
| 523 | this.enableCounterDiv = false; |
| 524 | this.enableAbort = false; |
| 525 | this.enableTestButton = false; |
| 526 | this.enableDownload = false; |
| 527 | } |
| 528 | |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 529 | } |