blob: 347bde6353697490f651947f43730203db0890ca [file] [log] [blame]
Skip Wonnell2c977e22018-03-01 08:30:15 -06001/*
2============LICENSE_START==========================================
3===================================================================
4Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
5===================================================================
Sandeep J77ebde82018-07-20 15:56:31 +05306Copyright (C) 2018 IBM.
7===================================================================
Skip Wonnell2c977e22018-03-01 08:30:15 -06008Unless otherwise specified, all software contained herein is licensed
9under the Apache License, Version 2.0 (the License);
10you may not use this software except in compliance with the License.
11You may obtain a copy of the License at
12
13 http://www.apache.org/licenses/LICENSE-2.0
14
15Unless required by applicable law or agreed to in writing, software
16distributed under the License is distributed on an "AS IS" BASIS,
17WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18See the License for the specific language governing permissions and
19limitations under the License.
Skip Wonnell2c977e22018-03-01 08:30:15 -060020============LICENSE_END============================================
21*/
22
23import { Component, OnInit } from '@angular/core';
Sandeep J77ebde82018-07-20 15:56:31 +053024import { NgxSpinnerService } from 'ngx-spinner';
Skip Wonnell2c977e22018-03-01 08:30:15 -060025import { saveAs } from 'file-saver';
26import { Location } from '@angular/common';
27import { ActivatedRoute, Router } from '@angular/router';
asgaraf56b682019-03-08 19:52:33 +053028import { NotificationService } from '.././shared/services/notification.service';
Skip Wonnell2c977e22018-03-01 08:30:15 -060029import { ParamShareService } from '.././shared/services/paramShare.service';
30import { MappingEditorService } from '.././shared/services/mapping-editor.service';
31import { NotificationsService } from 'angular2-notifications';
32import { HttpUtilService } from '.././shared/services/httpUtil/http-util.service';
33import 'rxjs/add/observable/interval';
34import { Observable } from 'rxjs/Observable';
35import { environment } from '../.././environments/environment';
36import { UtilityService } from '.././shared/services/utilityService/utility.service';
37import 'rxjs/add/operator/map';
38import * as XLSX from 'xlsx';
39import { NgProgress } from 'ngx-progressbar';
40
41
42let YAML = require('yamljs');
43
44type AOA = Array<Array<any>>;
45declare var $: any;
46
47@Component({ selector: 'test', templateUrl: './test.component.html', styleUrls: ['./test.component.css'] })
48export 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';
asgaraf56b682019-03-08 19:52:33 +053065 public force = 'TRUE';
Skip Wonnell2c977e22018-03-01 08:30:15 -060066 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;
asgaraf56b682019-03-08 19:52:33 +053091 public appcTimestampResponse;
Skip Wonnell2c977e22018-03-01 08:30:15 -060092 public outputTimeStamp;
93 public status;
94 public statusReason;
asgaraf56b682019-03-08 19:52:33 +053095 public errorResponse;
Skip Wonnell2c977e22018-03-01 08:30:15 -060096 public timer;
97 public subscribe;
98 public enableTestButton: boolean = false;
99 public enableAbort: boolean = false;
100 public showStatusResponseDiv: boolean = false;
101 public enablePollButton: boolean = true;
102 public pollCounter = 0;
103 public enableCounterDiv: boolean = false;
sj108sf1e61ce2018-03-13 20:29:58 +0530104 public enableDownload: boolean = false;
Mohamed Asgar Samiulla(ma926a)d7dffc22018-04-02 19:00:49 +0530105 private userId = localStorage['userId'];
asgaraf56b682019-03-08 19:52:33 +0530106 timeStampInt: number;
107 AppcTimeStampInt: number;
108 AppcTimeDiff: number;
109 isAppcTimestampReceived: boolean = false;
110
111 constructor (private location: Location, private activeRoutes: ActivatedRoute, private notificationService: NotificationService, private nService: NotificationsService, private router: Router, private paramShareService: ParamShareService, private mappingEditorService: MappingEditorService, private httpUtil: HttpUtilService,
112 private utiltiy: UtilityService, private ngProgress: NgProgress, private spinner: NgxSpinnerService) {
Skip Wonnell2c977e22018-03-01 08:30:15 -0600113
114 }
115
116 ngOnInit() {
asgaraf56b682019-03-08 19:52:33 +0530117 let timeStampI = new Date();
118 console.log("ngOnInit: local timeStamp:[" + timeStampI + "]");
119 let timeStampS = timeStampI.toISOString();
120 console.log("ngOnInit: local ISO timestamp:[" + timeStampS + "]");
121 //.. send HTTP request to APPC
122 this.getAppcTimestamp();
Skip Wonnell2c977e22018-03-01 08:30:15 -0600123 }
124
Skip Wonnell2c977e22018-03-01 08:30:15 -0600125
asgaraf56b682019-03-08 19:52:33 +0530126 /*public download() {
127 let stringData: any;
128 stringData = JSON.stringify(this.paramShareService.getSessionParamData());
129 let paramsKeyValueFromEditor: JSON;
130 paramsKeyValueFromEditor = JSON.parse(stringData);
131 let fileName = 'param_' + this.action + '_' + this.type + '_' + "0.0.1" + 'V';
132 this.JSONToCSVConvertor([paramsKeyValueFromEditor], fileName, true);
133
134 }*/
135
Skip Wonnell2c977e22018-03-01 08:30:15 -0600136 public download() {
137 if (this.apiRequest) {
asgaraf56b682019-03-08 19:52:33 +0530138 var fileName = 'test_' + this.action + '_' + this.actionIdentifiers['vnf-id'] + '_request.json';
Skip Wonnell2c977e22018-03-01 08:30:15 -0600139 var theJSON = this.apiRequest;
140 if (fileName != null || fileName != '') {
141 var blob = new Blob([theJSON], {
142 type: 'text/json'
143 });
144 saveAs(blob, fileName);
145 }
146 }
147 else {
148 this.nService.error('Error', 'Please upload spreadsheet to download the request and response');
149 }
150
151 if (this.apiResponse) {
asgaraf56b682019-03-08 19:52:33 +0530152 var fileName = 'test_' + this.action + '_' + this.actionIdentifiers['vnf-id'] + '_response.json';
Skip Wonnell2c977e22018-03-01 08:30:15 -0600153 var theJSON = this.apiResponse;
154 if (fileName != null || fileName != '') {
155 var blob = new Blob([theJSON], {
156 type: 'text/json'
157 });
158 saveAs(blob, fileName);
159 }
160 }
161
162 }
163
164
165 public abortTest() {
166 //this.apiResponse = "";
167 this.enableBrowse = true;
168 this.enableTestButton = true;
169 this.enablePollButton = true;
sj108s90174642018-03-15 20:26:47 +0530170 if (this.subscribe && this.subscribe != undefined) this.subscribe.unsubscribe();
asgaraf56b682019-03-08 19:52:33 +0530171 this.apiResponse="Test has been abandoned and polling stopped";
Kumar, Amaresh (ak583p)6c7ccba2018-05-09 22:29:45 +0530172 this.nService.info("Information", "Test has been abandoned and polling stopped");
Skip Wonnell2c977e22018-03-01 08:30:15 -0600173 }
174
175
Skip Wonnell2c977e22018-03-01 08:30:15 -0600176 excelBrowseOption() {
177 $('#excelInputFile').trigger('click');
178 }
179
180
181 upload(evt: any) {
182 /* wire up file reader */
183 $('#filesparam').trigger('click');
184 const target: DataTransfer = <DataTransfer>(evt.target);
sj108sf1e61ce2018-03-13 20:29:58 +0530185 this.pollCounter = 0;
Skip Wonnell2c977e22018-03-01 08:30:15 -0600186 this.uploadFileName = evt.target.files[0].name;
187 var fileExtension = this.uploadFileName.substr(this.uploadFileName.lastIndexOf('.') + 1);
188
189 if (target.files.length != 1) {
190 throw new Error('Cannot upload multiple files on the entry');
191 }
192 if (fileExtension.toUpperCase() === 'XLS' || fileExtension.toUpperCase() === 'XLSX') {
Sandeep J77ebde82018-07-20 15:56:31 +0530193 this.spinner.show();
Skip Wonnell2c977e22018-03-01 08:30:15 -0600194 const reader = new FileReader();
195 reader.onload = (e: any) => {
196 /* read workbook */
197 const bstr = e.target.result;
198 const wb = XLSX.read(bstr, { type: 'binary' });
199 /* grab first sheet */
200 const wsname = wb.SheetNames[0];
201 const ws = wb.Sheets[wsname];
202
203 /* save data */
204 this.requestId = ''
205 this.enableTestButton = true;
206 this.enableAbort = true;
207 this.enablePollButton = true;
208
209 if (this.subscribe && this.subscribe != undefined) {
210 this.enableCounterDiv = false;
211 this.subscribe.unsubscribe();
212 }
213 this.apiRequest = '';
214 this.apiResponse = '';
215 this.showStatusResponseDiv = false;
216 this.errorResponse = '';
217 this.statusResponse = '';
sj108sb694d952018-03-21 21:25:39 +0530218 this.enableDownload = true;
Skip Wonnell2c977e22018-03-01 08:30:15 -0600219 let arrData = (<AOA>(XLSX.utils.sheet_to_json(ws, { blankrows: false })));
sj108sf1e61ce2018-03-13 20:29:58 +0530220
Skip Wonnell2c977e22018-03-01 08:30:15 -0600221
222
Skip Wonnell2c977e22018-03-01 08:30:15 -0600223 this.vmPayload = [];
224 this.subPayload = {};
225 this.vmJson = {};
226 this.flag = 1;
227 this.payload = {};
228 this.oldListName1 = '';
229 this.actionIdentifiers = {};
sj108sf1e61ce2018-03-13 20:29:58 +0530230 // Refactor
231 this.payload = this.processUploadedFile(arrData);
232 this.uploadedFileResult();
sj108sb694d952018-03-21 21:25:39 +0530233 };
Skip Wonnell2c977e22018-03-01 08:30:15 -0600234
235 reader.readAsBinaryString(target.files[0]);
Sandeep J77ebde82018-07-20 15:56:31 +0530236 setTimeout(() => {
237 /** spinner ends after 2.5 seconds */
238 this.spinner.hide();
239 }, 2500);
sj108sf1e61ce2018-03-13 20:29:58 +0530240
Skip Wonnell2c977e22018-03-01 08:30:15 -0600241 }
242 else {
243 this.nService.error('Error', 'Incorrect spreadsheet uploaded');
IBM602-PC0F1E3C\Arundathi675e8b82018-07-16 14:30:26 +0530244 this.setValuesOnFileUploadFailure();
Skip Wonnell2c977e22018-03-01 08:30:15 -0600245 }
246 }
247
sj108sb694d952018-03-21 21:25:39 +0530248 processUploadedFile(arrData) {
sj108sf1e61ce2018-03-13 20:29:58 +0530249 let tempPayload = {};
250 for (var i = 0; i < arrData.length; i++) {
251 var element = arrData[i];
252 if (element['TagName'] === 'action') {
253 this.action = element['Value'];
254 }
255 if (element['List Name'] === 'action-identifiers') {
256 this.vnfId = element['Value'];
257 var key = element['TagName'];
258 var value = element['Value'];
259 if (key && value) {
260 this.actionIdentifiers[key] = value;
261
262 }
263 }
sj108sb694d952018-03-21 21:25:39 +0530264
sj108sf1e61ce2018-03-13 20:29:58 +0530265 if (element['List Name'] === 'payload') {
266 var listName1 = element['List Name_1'];
267 var listName2 = element['List Name_2'];
268 var listName3 = element['List Name_3'];
269 var key = element['TagName'];
270 var value = element['Value'];
271 if (listName1) {
272 if (this.oldListName1 == '' || (listName1 === this.oldListName1)) {
273 this.constructTestPayload(listName2, listName3, key, value);
274 tempPayload[listName1] = this.subPayload;
275 }
276 else {
277 this.subPayload = {};
278 this.constructTestPayload(listName2, listName3, key, value);
279 tempPayload[listName1] = this.subPayload;
280 }
281 this.oldListName1 = listName1;
282 }
283 else {
284 tempPayload[key] = value;
285 }
286 }
287 }
288
289 return tempPayload;
290 }
291
sj108sb694d952018-03-21 21:25:39 +0530292 uploadedFileResult() {
sj108sf1e61ce2018-03-13 20:29:58 +0530293 if (this.action && this.actionIdentifiers['vnf-id']) {
294 this.nService.success('Success', 'SpreadSheet uploaded successfully');
295 }
296 else {
IBM602-PC0F1E3C\Arundathi675e8b82018-07-16 14:30:26 +0530297 this.setValuesOnFileUploadFailure();
sj108sf1e61ce2018-03-13 20:29:58 +0530298 this.nService.error("Error", "Please check the contents of the file uploaded")
299 }
300 }
301
302
303
Skip Wonnell2c977e22018-03-01 08:30:15 -0600304 constructTestPayload(listName2, listName3, key, value) {
asgaraf56b682019-03-08 19:52:33 +0530305 if ((listName2 == undefined || listName2 == '') && (listName3 == undefined || listName3 == '')) {
Skip Wonnell2c977e22018-03-01 08:30:15 -0600306 this.subPayload[key] = value;
307 }
308 if (listName2) {
309
310 if (!listName3) {
311
312 //vmPayload.push(vmJson)
313 this.vmJson = {};
314 this.vnfcJson = {};
315 this.vmJson[key] = value;
316 this.flag = 0;
317 }
318 else {
319 this.vnfcJson[key] = value;
asgaraf56b682019-03-08 19:52:33 +0530320 this.vmJson['vnfc'] = [this.vnfcJson];
Skip Wonnell2c977e22018-03-01 08:30:15 -0600321 this.flag = 1;
322 }
323 if (this.vmJson) this.lastvmJson = this.vmJson;
324 if (this.flag == 0) {
325 this.vmPayload.push(this.lastvmJson);
326 if (this.vmPayload) this.subPayload['vm'] = this.vmPayload;
327 }
328 }
329 }
330
331 constructRequest() {
asgaraf56b682019-03-08 19:52:33 +0530332 this.timeStampInt = Date.now(); //.. milliseconds
333 let timeStamp;
334 console.log("constructRequest: isAppcTimestampReceived:" +
335 (this.isAppcTimestampReceived ? "true" : "false"));
336 if (this.isAppcTimestampReceived) {
337 console.log("constructRequest: AppcTimeDiff:[" + this.AppcTimeDiff + "]");
338 this.timeStampInt += this.AppcTimeDiff;
339 timeStamp = new Date(this.timeStampInt).toISOString();
340 console.log("constructRequest: got timeStamp from APPC:[" + timeStamp + "]");
341 }
342 else { //.. still not received
343 console.log('constructRequest: Appc Timestamp is not ready (use local)');
344 this.timeStampInt -= 100000;
345 timeStamp = new Date(this.timeStampInt).toISOString();
346 };
347 console.log('constructRequest: timeStamp:[' + timeStamp + ']');
Skip Wonnell2c977e22018-03-01 08:30:15 -0600348 let reqId;
349 this.requestId = reqId = new Date().getTime().toString();
350 let data = {
351 'input': {
352 'common-header': {
353 'timestamp': timeStamp,
354 'api-ver': '2.00',
Mohamed Asgar Samiulla(ma926a)d7dffc22018-04-02 19:00:49 +0530355 'originator-id': this.userId,
Skip Wonnell2c977e22018-03-01 08:30:15 -0600356 'request-id': this.requestId,
357 'sub-request-id': this.requestId,
358 'flags': {
359 'mode': 'NORMAL',
asgaraf56b682019-03-08 19:52:33 +0530360 'force': this.force.toString().toUpperCase(),
Skip Wonnell2c977e22018-03-01 08:30:15 -0600361 'ttl': 3600
362 }
363 },
364 'action': this.action,
365 'action-identifiers': this.actionIdentifiers,
366 'payload': JSON.stringify(this.payload)
367 }
368 };
asgaraf56b682019-03-08 19:52:33 +0530369 if (this.action == 'Unlock') {
370 let payload = JSON.parse(data.input['payload']);
371 data.input['common-header']['request-id'] = payload['request-id'];
372 data.input['common-header']['sub-request-id'] = payload['request-id'];
373 }
374
375 if(this.action == 'Unlock' || this.action == 'Lock' || this.action == 'CheckLock') {
376 delete data.input['payload'];
377 }
Skip Wonnell2c977e22018-03-01 08:30:15 -0600378
379 return data;
380 }
381
382 testVnf() {
Skip Wonnell2c977e22018-03-01 08:30:15 -0600383 this.enableBrowse = false;
384 this.enableTestButton = false;
385 this.enablePollButton = false;
386 this.timer = Observable.interval(10000);
asgaraf56b682019-03-08 19:52:33 +0530387 if(this.action == 'Unlock' || this.action == 'Lock' || this.action == 'CheckLock') {
388 this.enablePollButton = true;
389 this.enableBrowse = true;
390 this.enableTestButton = true;
391 this.requestId = '';
392 } else {
393 this.subscribe = this.timer.subscribe((t) => this.pollTestStatus());
394 }
Skip Wonnell2c977e22018-03-01 08:30:15 -0600395 this.ngProgress.start();
396 this.apiRequest = JSON.stringify(this.constructRequest());
Mohamed Asgar Samiulla(ma926a)d7dffc22018-04-02 19:00:49 +0530397
Skip Wonnell2c977e22018-03-01 08:30:15 -0600398 this.httpUtil.post(
399 {
asgaraf56b682019-03-08 19:52:33 +0530400 url: environment.testVnf + "?urlAction=" + this.getUrlEndPoint(this.action),
Kumar, Amaresh (ak583p)6c7ccba2018-05-09 22:29:45 +0530401 data: this.apiRequest
Skip Wonnell2c977e22018-03-01 08:30:15 -0600402 })
403 .subscribe(resp => {
404 this.apiResponse = JSON.stringify(resp);
405 this.enableBrowse = true;
406 this.enableTestButton = true;
407 this.ngProgress.done();
408 },
Kumar, Amaresh (ak583p)6c7ccba2018-05-09 22:29:45 +0530409 error => {
410 this.nService.error('Error', 'Error in connecting to APPC Server');
asgaraf56b682019-03-08 19:52:33 +0530411 // this.enableBrowse = true;
Kumar, Amaresh (ak583p)6c7ccba2018-05-09 22:29:45 +0530412 this.enableTestButton = true;
413 this.enablePollButton = true;
414 this.enableCounterDiv = false;
asgaraf56b682019-03-08 19:52:33 +0530415 this.enableBrowse = true;
Kumar, Amaresh (ak583p)6c7ccba2018-05-09 22:29:45 +0530416 if (this.subscribe && this.subscribe != undefined) this.subscribe.unsubscribe();
Skip Wonnell2c977e22018-03-01 08:30:15 -0600417
Kumar, Amaresh (ak583p)6c7ccba2018-05-09 22:29:45 +0530418 });
Skip Wonnell2c977e22018-03-01 08:30:15 -0600419
420 setTimeout(() => {
421 this.ngProgress.done();
422 }, 3500);
423 }
424
asgaraf56b682019-03-08 19:52:33 +0530425 getAppcTimestamp() {
426 this.timeStampInt = Date.now(); //.. milliseconds
427 console.log("getAppcTimestamp: timeStampInt:[" + this.timeStampInt + "]");
428 let timeStampP = new Date(this.timeStampInt).toISOString();
429 console.log("getAppcTimestamp: from int timestamp:[" + timeStampP + "]");
430 this.isAppcTimestampReceived = false;
431 let reqId = new Date().getTime().toString();
432 try {
433 let data = {
434 'input': {
435 'design-request': {
436 'request-id': reqId,
437 'action': 'getAppcTimestampUTC',
438 'payload': '{}'
439 }
440 }
441 };
442 console.log('getAppcTimestamp: sending httpUtil.post...');
443 this.httpUtil.post(
444 {
445 url: environment.getDesigns, data: data
446 })
447 .subscribe(resp => {
448 this.appcTimestampResponse = resp;
449 // this.appcTimestampResponse = JSON.stringify(resp);
450 console.log('appcTimestampResponse:[' + resp + ']');
451 this.parseAppcTimestamp(this.appcTimestampResponse);
452 });
453 }
454 catch (e) {
455 this.nService.warn('status',
456 'Error while retrieving APPC Timestamp(using local by default)!');
457 }
458 }
459
460 parseAppcTimestamp(tstampStr: string) {
461 //.. parse the response to get timestamp as milliseconds
462 // input format: YYYY-MM-DDTHH:mm:ss.sssZ (24 chars)
463 var rexp =
464 new RegExp(/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})\.(\d{3})Z/);
465 var mresult = rexp.exec(tstampStr);
466 if (mresult[0]) {
467 console.log("parseAppcTimestamp: response format is OK...");
468 var aYearS = mresult[1];
469 var aYear = parseInt(aYearS, 10);
470 var aMonS = mresult[2];
471 var aMon = parseInt(aMonS, 10) - 1;
472 var aDayS = mresult[3];
473 var aDay = parseInt(aDayS, 10);
474 var aHrS = mresult[4];
475 var aHr = parseInt(aHrS, 10);
476 var aMntS = mresult[5];
477 var aMnt = parseInt(aMntS, 10);
478 var aSecS = mresult[6];
479 var aSec = parseInt(aSecS, 10);
480 var aMsecS = mresult[7];
481 var aMsec = parseInt(aMsecS, 10);
482 this.AppcTimeStampInt =
483 Date.UTC(aYear, aMon, aDay, aHr, aMnt, aSec, aMsec);
484 console.log(
485 "parseAppcTimestamp: AppcTimeStampInt:[" + this.AppcTimeStampInt + "]");
486 let timeStampP = new Date(this.AppcTimeStampInt).toISOString();
487 console.log("parseAppcTimestamp: from int timestamp:[" + timeStampP + "]");
488 //.. AppcTimeDiff - time difference in milliseconds
489 this.AppcTimeDiff = this.AppcTimeStampInt - this.timeStampInt;
490 console.log("parseAppcTimestamp: AppcTimeDiff:[" + this.AppcTimeDiff + "]");
491 this.isAppcTimestampReceived = true;
492 }
493 else {
494 throw new Error(
495 'The received APPC Timestamp is not matching expected format: YYYY-MM-DDTHH:mm:ss.sssZ !');
496 }
497 }
Skip Wonnell2c977e22018-03-01 08:30:15 -0600498
499 pollTestStatus() {
500 if (this.requestId && this.actionIdentifiers['vnf-id']) {
asgaraf56b682019-03-08 19:52:33 +0530501 // console.log("payload==" + JSON.stringify(this.payload))
502 this.timeStampInt = Date.now(); //.. milliseconds
503 let timeStamp;
504 console.log("pollTestStatus: isAppcTimestampReceived:" +
505 (this.isAppcTimestampReceived ? "true" : "false"));
506 if (this.isAppcTimestampReceived) {
507 this.timeStampInt += this.AppcTimeDiff;
508 timeStamp = new Date(this.timeStampInt).toISOString();
509 console.log("pollTestStatus: got timeStamp from APPC:[" + timeStamp + "]");
510 }
511 else { //.. still not received
512 console.log('pollTestStatus: Appc Timestamp is not ready (use local)');
513 this.timeStampInt -= 100000;
514 timeStamp = new Date(this.timeStampInt).toISOString();
515 };
516 console.log("pollTestStatus: timestamp:[" + timeStamp + "]");
Skip Wonnell2c977e22018-03-01 08:30:15 -0600517 let reqId = new Date().getTime().toString();
518 let data = {
519 'input': {
520 'common-header': {
521 'timestamp': timeStamp,
522 'api-ver': '2.00',
Mohamed Asgar Samiulla(ma926a)d7dffc22018-04-02 19:00:49 +0530523 'originator-id': this.userId,
Skip Wonnell2c977e22018-03-01 08:30:15 -0600524 'request-id': reqId,
525 'sub-request-id': reqId,
526 'flags': {
527 'mode': 'NORMAL',
asgaraf56b682019-03-08 19:52:33 +0530528 'force': this.force.toString().toUpperCase(),
Skip Wonnell2c977e22018-03-01 08:30:15 -0600529 'ttl': 3600
530 }
531 },
532 'action': 'ActionStatus',
Kumar, Amaresh (ak583p)6c7ccba2018-05-09 22:29:45 +0530533 'action-identifiers': {
534 'vnf-id': this.actionIdentifiers['vnf-id']
Mohamed Asgar Samiulla(ma926a)d7dffc22018-04-02 19:00:49 +0530535 },
Skip Wonnell2c977e22018-03-01 08:30:15 -0600536 'payload': '{"request-id":' + this.requestId + '}'
537 }
538 };
Skip Wonnell2c977e22018-03-01 08:30:15 -0600539 this.httpUtil.post(
540 {
541 url: environment.checkTestStatus, data: data
542
543 })
544 .subscribe(resp => {
Skip Wonnell2c977e22018-03-01 08:30:15 -0600545 this.statusResponse = JSON.stringify(resp);
546 var status = ''
547 var statusReason = ''
548 this.enableCounterDiv = true;
549 this.pollCounter++;
Skip Wonnell2c977e22018-03-01 08:30:15 -0600550 if (resp.output) var timeStamp = resp.output['common-header'].timestamp;
551 if (resp.output.payload) {
552 var payload = resp.output.payload.replace(/\\/g, "")
553 try {
554 payload = JSON.parse(payload)
555 status = payload['status'];
556 statusReason = payload['status-reason'];
557 }
558 catch (err) {
559 console.log("error" + err)
560 }
561 }
562 if (timeStamp && status && statusReason) {
563 this.showStatusResponseDiv = true;
564 this.outputTimeStamp = timeStamp;
565 this.status = status;
566 this.statusReason = statusReason;
sj108sf1e61ce2018-03-13 20:29:58 +0530567 if (status.toUpperCase() === 'SUCCESS' || status.toUpperCase() === 'SUCCESSFUL') {
sj108s90174642018-03-15 20:26:47 +0530568 if (this.subscribe && this.subscribe != undefined) this.subscribe.unsubscribe();
Skip Wonnell2c977e22018-03-01 08:30:15 -0600569 this.enablePollButton = true;
asgaraf56b682019-03-08 19:52:33 +0530570 this.enableBrowse = true;
571 this.enableTestButton = true;
Skip Wonnell2c977e22018-03-01 08:30:15 -0600572 }
573 if (status.toUpperCase() === 'FAILED') {
sj108s90174642018-03-15 20:26:47 +0530574 if (this.subscribe && this.subscribe != undefined) this.subscribe.unsubscribe();
Skip Wonnell2c977e22018-03-01 08:30:15 -0600575 this.enablePollButton = true;
asgaraf56b682019-03-08 19:52:33 +0530576 this.enableBrowse = true;
577 this.enableTestButton = true;
Skip Wonnell2c977e22018-03-01 08:30:15 -0600578 }
579 }
580 else {
581 this.showStatusResponseDiv = false;
sj108sb694d952018-03-21 21:25:39 +0530582 if (this.subscribe && this.subscribe != undefined) {
583 this.subscribe.unsubscribe();
584 this.enablePollButton = true;
585 }
586
Skip Wonnell2c977e22018-03-01 08:30:15 -0600587 }
588
Skip Wonnell2c977e22018-03-01 08:30:15 -0600589 },
Kumar, Amaresh (ak583p)6c7ccba2018-05-09 22:29:45 +0530590 error => {
591 this.statusResponse = null;
592 this.showStatusResponseDiv = false;
593 this.errorResponse = 'Error Connecting to APPC server';
594 this.enableCounterDiv = false;
asgaraf56b682019-03-08 19:52:33 +0530595 this.enableBrowse = true;
596 this.enableTestButton = true;
Kumar, Amaresh (ak583p)6c7ccba2018-05-09 22:29:45 +0530597 if (this.subscribe && this.subscribe != undefined) {
598 this.subscribe.unsubscribe();
599 this.enablePollButton = true;
600 }
601 });
asgaraf56b682019-03-08 19:52:33 +0530602
Skip Wonnell2c977e22018-03-01 08:30:15 -0600603 }
604 else {
605 this.nService.error("Error", "Please enter vnf Id & request Id");
606 }
sj108sb694d952018-03-21 21:25:39 +0530607
Skip Wonnell2c977e22018-03-01 08:30:15 -0600608 }
609
610 getUrlEndPoint(action) {
asgaraf56b682019-03-08 19:52:33 +0530611 let charArray = action.split('');
612 let url = '';
613 for (let i = 0; i < charArray.length; i++) {
614 if (charArray[i] == charArray[i].toUpperCase() && i != 0) {
615 url = url + '-';
616 }
617 url = url + charArray[i];
Skip Wonnell2c977e22018-03-01 08:30:15 -0600618 }
619
asgaraf56b682019-03-08 19:52:33 +0530620 return url.toLowerCase();
Skip Wonnell2c977e22018-03-01 08:30:15 -0600621 }
622
IBM602-PC0F1E3C\Arundathi675e8b82018-07-16 14:30:26 +0530623 setValuesOnFileUploadFailure() {
624 this.flag = 1;
625 this.oldListName1 = '';
626 this.vmJson = {};
627 this.vnfcJson = {};
628 this.subPayload = {};
629 this.vmPayload = [];
630 this.payload = {};
631 this.action = '';
632 this.actionIdentifiers = {};
633 this.apiRequest = '';
634 this.apiResponse = '';
635 this.enableCounterDiv = false;
636 this.enableAbort = false;
637 this.enableTestButton = false;
638 this.enableDownload = false;
639 }
640
Skip Wonnell2c977e22018-03-01 08:30:15 -0600641}