diff options
Diffstat (limited to 'src/app/test/test.component.ts')
-rw-r--r-- | src/app/test/test.component.ts | 234 |
1 files changed, 173 insertions, 61 deletions
diff --git a/src/app/test/test.component.ts b/src/app/test/test.component.ts index f3f6a94..347bde6 100644 --- a/src/app/test/test.component.ts +++ b/src/app/test/test.component.ts @@ -25,6 +25,7 @@ import { NgxSpinnerService } from 'ngx-spinner'; import { saveAs } from 'file-saver'; import { Location } from '@angular/common'; import { ActivatedRoute, Router } from '@angular/router'; +import { NotificationService } from '.././shared/services/notification.service'; import { ParamShareService } from '.././shared/services/paramShare.service'; import { MappingEditorService } from '.././shared/services/mapping-editor.service'; import { NotificationsService } from 'angular2-notifications'; @@ -61,7 +62,7 @@ export class TestComponent implements OnInit { vnfcType: any; protocol: any; mode: any = 'NORMAL'; - force: any = 'True'; + public force = 'TRUE'; ttl: any; public formattedNameValuePairs = {}; public requestId = ''; @@ -87,10 +88,11 @@ export class TestComponent implements OnInit { public apiRequest = ''; public apiResponse = ''; public statusResponse; + public appcTimestampResponse; public outputTimeStamp; public status; public statusReason; - public errorResponse; + public errorResponse; public timer; public subscribe; public enableTestButton: boolean = false; @@ -101,30 +103,39 @@ export class TestComponent implements OnInit { public enableCounterDiv: boolean = false; public enableDownload: boolean = false; private userId = localStorage['userId']; - constructor ( - private location: Location, - private activeRoutes: ActivatedRoute, - private nService: NotificationsService, - private router: Router, - private paramShareService: ParamShareService, - private mappingEditorService: MappingEditorService, - private httpUtil: HttpUtilService, - private utiltiy: UtilityService, - private ngProgress: NgProgress, - private spinner: NgxSpinnerService - ) { + timeStampInt: number; + AppcTimeStampInt: number; + AppcTimeDiff: number; + isAppcTimestampReceived: boolean = false; + + 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, + private utiltiy: UtilityService, private ngProgress: NgProgress, private spinner: NgxSpinnerService) { } ngOnInit() { + let timeStampI = new Date(); + console.log("ngOnInit: local timeStamp:[" + timeStampI + "]"); + let timeStampS = timeStampI.toISOString(); + console.log("ngOnInit: local ISO timestamp:[" + timeStampS + "]"); + //.. send HTTP request to APPC + this.getAppcTimestamp(); + } - } + /*public download() { + let stringData: any; + stringData = JSON.stringify(this.paramShareService.getSessionParamData()); + let paramsKeyValueFromEditor: JSON; + paramsKeyValueFromEditor = JSON.parse(stringData); + let fileName = 'param_' + this.action + '_' + this.type + '_' + "0.0.1" + 'V'; + this.JSONToCSVConvertor([paramsKeyValueFromEditor], fileName, true); + }*/ public download() { if (this.apiRequest) { - var fileName = 'test_' + this.action + '_' + this.actionIdentifiers['vnf-id'] + '_request'; + var fileName = 'test_' + this.action + '_' + this.actionIdentifiers['vnf-id'] + '_request.json'; var theJSON = this.apiRequest; if (fileName != null || fileName != '') { var blob = new Blob([theJSON], { @@ -138,7 +149,7 @@ export class TestComponent implements OnInit { } if (this.apiResponse) { - var fileName = 'test_' + this.action + '_' + this.actionIdentifiers['vnf-id'] + '_response'; + var fileName = 'test_' + this.action + '_' + this.actionIdentifiers['vnf-id'] + '_response.json'; var theJSON = this.apiResponse; if (fileName != null || fileName != '') { var blob = new Blob([theJSON], { @@ -157,6 +168,7 @@ export class TestComponent implements OnInit { this.enableTestButton = true; this.enablePollButton = true; if (this.subscribe && this.subscribe != undefined) this.subscribe.unsubscribe(); + this.apiResponse="Test has been abandoned and polling stopped"; this.nService.info("Information", "Test has been abandoned and polling stopped"); } @@ -290,7 +302,7 @@ export class TestComponent implements OnInit { constructTestPayload(listName2, listName3, key, value) { - if (listName2 == undefined && listName3 == undefined) { + if ((listName2 == undefined || listName2 == '') && (listName3 == undefined || listName3 == '')) { this.subPayload[key] = value; } if (listName2) { @@ -305,7 +317,7 @@ export class TestComponent implements OnInit { } else { this.vnfcJson[key] = value; - this.vmJson['vnfc'] = this.vnfcJson; + this.vmJson['vnfc'] = [this.vnfcJson]; this.flag = 1; } if (this.vmJson) this.lastvmJson = this.vmJson; @@ -317,7 +329,22 @@ export class TestComponent implements OnInit { } constructRequest() { - let timeStamp = new Date().toISOString(); + this.timeStampInt = Date.now(); //.. milliseconds + let timeStamp; + console.log("constructRequest: isAppcTimestampReceived:" + + (this.isAppcTimestampReceived ? "true" : "false")); + if (this.isAppcTimestampReceived) { + console.log("constructRequest: AppcTimeDiff:[" + this.AppcTimeDiff + "]"); + this.timeStampInt += this.AppcTimeDiff; + timeStamp = new Date(this.timeStampInt).toISOString(); + console.log("constructRequest: got timeStamp from APPC:[" + timeStamp + "]"); + } + else { //.. still not received + console.log('constructRequest: Appc Timestamp is not ready (use local)'); + this.timeStampInt -= 100000; + timeStamp = new Date(this.timeStampInt).toISOString(); + }; + console.log('constructRequest: timeStamp:[' + timeStamp + ']'); let reqId; this.requestId = reqId = new Date().getTime().toString(); let data = { @@ -330,7 +357,7 @@ export class TestComponent implements OnInit { 'sub-request-id': this.requestId, 'flags': { 'mode': 'NORMAL', - 'force': 'TRUE', + 'force': this.force.toString().toUpperCase(), 'ttl': 3600 } }, @@ -339,6 +366,15 @@ export class TestComponent implements OnInit { 'payload': JSON.stringify(this.payload) } }; + if (this.action == 'Unlock') { + let payload = JSON.parse(data.input['payload']); + data.input['common-header']['request-id'] = payload['request-id']; + data.input['common-header']['sub-request-id'] = payload['request-id']; + } + + if(this.action == 'Unlock' || this.action == 'Lock' || this.action == 'CheckLock') { + delete data.input['payload']; + } return data; } @@ -348,13 +384,20 @@ export class TestComponent implements OnInit { this.enableTestButton = false; this.enablePollButton = false; this.timer = Observable.interval(10000); - this.subscribe = this.timer.subscribe((t) => this.pollTestStatus()); + if(this.action == 'Unlock' || this.action == 'Lock' || this.action == 'CheckLock') { + this.enablePollButton = true; + this.enableBrowse = true; + this.enableTestButton = true; + this.requestId = ''; + } else { + this.subscribe = this.timer.subscribe((t) => this.pollTestStatus()); + } this.ngProgress.start(); this.apiRequest = JSON.stringify(this.constructRequest()); this.httpUtil.post( { - url: environment.testVnf + "?urlAction=" + this.getUrlEndPoint(this.action.toLowerCase()), + url: environment.testVnf + "?urlAction=" + this.getUrlEndPoint(this.action), data: this.apiRequest }) .subscribe(resp => { @@ -365,10 +408,11 @@ export class TestComponent implements OnInit { }, error => { this.nService.error('Error', 'Error in connecting to APPC Server'); - this.enableBrowse = true; + // this.enableBrowse = true; this.enableTestButton = true; this.enablePollButton = true; this.enableCounterDiv = false; + this.enableBrowse = true; if (this.subscribe && this.subscribe != undefined) this.subscribe.unsubscribe(); }); @@ -378,10 +422,98 @@ export class TestComponent implements OnInit { }, 3500); } + getAppcTimestamp() { + this.timeStampInt = Date.now(); //.. milliseconds + console.log("getAppcTimestamp: timeStampInt:[" + this.timeStampInt + "]"); + let timeStampP = new Date(this.timeStampInt).toISOString(); + console.log("getAppcTimestamp: from int timestamp:[" + timeStampP + "]"); + this.isAppcTimestampReceived = false; + let reqId = new Date().getTime().toString(); + try { + let data = { + 'input': { + 'design-request': { + 'request-id': reqId, + 'action': 'getAppcTimestampUTC', + 'payload': '{}' + } + } + }; + console.log('getAppcTimestamp: sending httpUtil.post...'); + this.httpUtil.post( + { + url: environment.getDesigns, data: data + }) + .subscribe(resp => { + this.appcTimestampResponse = resp; + // this.appcTimestampResponse = JSON.stringify(resp); + console.log('appcTimestampResponse:[' + resp + ']'); + this.parseAppcTimestamp(this.appcTimestampResponse); + }); + } + catch (e) { + this.nService.warn('status', + 'Error while retrieving APPC Timestamp(using local by default)!'); + } + } + + parseAppcTimestamp(tstampStr: string) { + //.. parse the response to get timestamp as milliseconds + // input format: YYYY-MM-DDTHH:mm:ss.sssZ (24 chars) + var rexp = + new RegExp(/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})\.(\d{3})Z/); + var mresult = rexp.exec(tstampStr); + if (mresult[0]) { + console.log("parseAppcTimestamp: response format is OK..."); + var aYearS = mresult[1]; + var aYear = parseInt(aYearS, 10); + var aMonS = mresult[2]; + var aMon = parseInt(aMonS, 10) - 1; + var aDayS = mresult[3]; + var aDay = parseInt(aDayS, 10); + var aHrS = mresult[4]; + var aHr = parseInt(aHrS, 10); + var aMntS = mresult[5]; + var aMnt = parseInt(aMntS, 10); + var aSecS = mresult[6]; + var aSec = parseInt(aSecS, 10); + var aMsecS = mresult[7]; + var aMsec = parseInt(aMsecS, 10); + this.AppcTimeStampInt = + Date.UTC(aYear, aMon, aDay, aHr, aMnt, aSec, aMsec); + console.log( + "parseAppcTimestamp: AppcTimeStampInt:[" + this.AppcTimeStampInt + "]"); + let timeStampP = new Date(this.AppcTimeStampInt).toISOString(); + console.log("parseAppcTimestamp: from int timestamp:[" + timeStampP + "]"); + //.. AppcTimeDiff - time difference in milliseconds + this.AppcTimeDiff = this.AppcTimeStampInt - this.timeStampInt; + console.log("parseAppcTimestamp: AppcTimeDiff:[" + this.AppcTimeDiff + "]"); + this.isAppcTimestampReceived = true; + } + else { + throw new Error( + 'The received APPC Timestamp is not matching expected format: YYYY-MM-DDTHH:mm:ss.sssZ !'); + } + } pollTestStatus() { if (this.requestId && this.actionIdentifiers['vnf-id']) { - let timeStamp = new Date().toISOString(); + // console.log("payload==" + JSON.stringify(this.payload)) + this.timeStampInt = Date.now(); //.. milliseconds + let timeStamp; + console.log("pollTestStatus: isAppcTimestampReceived:" + + (this.isAppcTimestampReceived ? "true" : "false")); + if (this.isAppcTimestampReceived) { + this.timeStampInt += this.AppcTimeDiff; + timeStamp = new Date(this.timeStampInt).toISOString(); + console.log("pollTestStatus: got timeStamp from APPC:[" + timeStamp + "]"); + } + else { //.. still not received + console.log('pollTestStatus: Appc Timestamp is not ready (use local)'); + this.timeStampInt -= 100000; + timeStamp = new Date(this.timeStampInt).toISOString(); + }; + console.log("pollTestStatus: timestamp:[" + timeStamp + "]"); let reqId = new Date().getTime().toString(); let data = { 'input': { @@ -393,7 +525,7 @@ export class TestComponent implements OnInit { 'sub-request-id': reqId, 'flags': { 'mode': 'NORMAL', - 'force': 'TRUE', + 'force': this.force.toString().toUpperCase(), 'ttl': 3600 } }, @@ -435,10 +567,14 @@ export class TestComponent implements OnInit { if (status.toUpperCase() === 'SUCCESS' || status.toUpperCase() === 'SUCCESSFUL') { if (this.subscribe && this.subscribe != undefined) this.subscribe.unsubscribe(); this.enablePollButton = true; + this.enableBrowse = true; + this.enableTestButton = true; } if (status.toUpperCase() === 'FAILED') { if (this.subscribe && this.subscribe != undefined) this.subscribe.unsubscribe(); this.enablePollButton = true; + this.enableBrowse = true; + this.enableTestButton = true; } } else { @@ -456,11 +592,14 @@ export class TestComponent implements OnInit { this.showStatusResponseDiv = false; this.errorResponse = 'Error Connecting to APPC server'; this.enableCounterDiv = false; + this.enableBrowse = true; + this.enableTestButton = true; if (this.subscribe && this.subscribe != undefined) { this.subscribe.unsubscribe(); this.enablePollButton = true; } }); + } else { this.nService.error("Error", "Please enter vnf Id & request Id"); @@ -469,43 +608,16 @@ export class TestComponent implements OnInit { } getUrlEndPoint(action) { - switch (action) { - case 'configmodify': - return 'config-modify'; - case 'configbackup': - return 'config-backup'; - case 'configrestore': - return 'config-restore'; - case 'healthcheck': - return 'health-check'; - case 'quiescetraffic': - return 'quiesce-traffic'; - case 'resumetraffic': - return 'resume-traffic'; - case 'distributetraffic': - return 'distribute-traffic'; - case 'startapplication': - return 'start-application'; - case 'stopapplication': - return 'stop-application'; - case 'upgradebackout': - return 'upgrade-backout'; - case 'upgradepostcheck': - return 'upgrade-post-check'; - case 'upgradeprecheck': - return 'upgrade-pre-check'; - case 'upgradesoftware': - return 'upgrade-software'; - case 'upgradebackup': - return 'upgrade-backup'; - case 'attachvolume': - return 'attach-volume'; - case 'detachvolume': - return 'detach-volume'; - default: - return action.toLowerCase(); + let charArray = action.split(''); + let url = ''; + for (let i = 0; i < charArray.length; i++) { + if (charArray[i] == charArray[i].toUpperCase() && i != 0) { + url = url + '-'; + } + url = url + charArray[i]; } + return url.toLowerCase(); } setValuesOnFileUploadFailure() { |