diff options
author | Skip Wonnell <skip@att.com> | 2018-03-01 08:30:15 -0600 |
---|---|---|
committer | Skip Wonnell <skip@att.com> | 2018-03-01 08:33:56 -0600 |
commit | 2c977e2b66ced314a4f51121801f62fe5c3c05e4 (patch) | |
tree | d93b360d7a6502a6aff1f30ba7f96c3e14f8911c /src/app/test | |
parent | 912f105d12fe6f8dc3a2d409938c87016204debe (diff) |
Initial seed code contribution for CDT
Issue-ID: APPC-682
Change-Id: I0331ffce2a430195c29d0d1b2295966f9eb28699
Signed-off-by: Skip Wonnell <skip@att.com>
Diffstat (limited to 'src/app/test')
-rw-r--r-- | src/app/test/test.component.css | 35 | ||||
-rw-r--r-- | src/app/test/test.component.html | 205 | ||||
-rw-r--r-- | src/app/test/test.component.spec.ts | 158 | ||||
-rw-r--r-- | src/app/test/test.component.ts | 533 |
4 files changed, 931 insertions, 0 deletions
diff --git a/src/app/test/test.component.css b/src/app/test/test.component.css new file mode 100644 index 0000000..c1b1169 --- /dev/null +++ b/src/app/test/test.component.css @@ -0,0 +1,35 @@ +/* +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +ECOMP is a trademark and service mark of AT&T Intellectual Property. +============LICENSE_END============================================ +*/ + +.build-button { + padding: 11px; + font-size: 20px; + color: green; + border: 1PX SOLID GREEN; + MARGIN-BOTTOM: 40PX +} + +table.table th, +table.table td { + padding: 0rem; +}
\ No newline at end of file diff --git a/src/app/test/test.component.html b/src/app/test/test.component.html new file mode 100644 index 0000000..ad6ff7f --- /dev/null +++ b/src/app/test/test.component.html @@ -0,0 +1,205 @@ +<!-- +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +ECOMP is a trademark and service mark of AT&T Intellectual Property. +============LICENSE_END============================================ +--> +<simple-notifications [options]="options"></simple-notifications> +<ng-progress [positionUsing]="'marginLeft'" [minimum]="0.15" [maximum]="1" [speed]="200" [showSpinner]="false" [direction]="'leftToRightIncreased'" [color]="'#6ab344'" + [trickleSpeed]="250" [thick]="true" [ease]="'linear'"></ng-progress> + +<div class="card" style=" margin-bottom: 23px;"> + <div class="card-block" style="border-top: 5px solid #6ab344;border-top-right-radius: 7px;border-top-left-radius: 7px;"> + <div class="row"> + <div class="col-lg-3 col-sm-6 col-md-4 col-xs-12"> + <label>Action:</label> + <input class="form-control" type="text" disabled value="{{action}}" /> + </div> + + <!-- <div class="col-lg-3 col-sm-6 col-md-3 col-xs-12"> + <label>Vnf Type:</label> + <input class="form-control" type="text" disabled value="{{vnfType}}" /> + + </div> + <div class="col-lg-3 col-sm-6 col-md-3 col-xs-12"> + <label>Vnfc Type:</label> + <input class="form-control" type="text" disabled value="{{vnfcType}}" /> + + </div>--> + <div class="col-lg-3 col-sm-6 col-md-4 col-xs-12"> + <label>Vnf Id:</label> + <input class="form-control" type="text" [(ngModel)]="this.actionIdentifiers['vnf-id']" /> + + </div> + + <div class="col-lg-3 col-sm-6 col-md-4 col-xs-12" *ngIf="this.actionIdentifiers['vserver-id']"> + <label>Vserver-Id(optional):</label> + <input class="form-control" disabled type="text" [(ngModel)]="this.actionIdentifiers['vserver-id']" /> + + </div> + + <!-- <div class="col-lg-3 col-sm-6 col-md-3 col-xs-12"> + <label>VF-Module-Id(optional):</label> + <input class="form-control" disabled type="text" value="{{this.actionIdentifiers['vmodule-id']}}" /> + + </div>--> + + <div class="col-12"> + <div class="input-group"> + <input id="excelInputFile" #myInput1 hidden class="file" type="file" (change)="upload($event)"> + <input [(ngModel)]="uploadFileName" type="text" class="input-lg" disabled placeholder="Upload SpreadSheet" name="uploadFileName" style="width:80%"> + <button (click)="excelBrowseOption($event)" [disabled]="!enableBrowse" class="browse mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--primary input-lg" + type="button">Upload SpreadSheet + </button> + </div> + </div> + + </div> + </div> +</div> +<br> + +<div class="card"> + + <div class="card-block"> + + <div class="row"> + <div class="col-md-6"> + <span style="margin-left: 5%"><b>REQUEST:</b></span> + </div> + <div class="col-md-6"> + <span style="margin-left: 5%"><b>RESPONSE:</b></span> + </div> + + <div class="col-md-6"> + <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12"> + + <div style="height:200px;width:100%;border:solid 2px grey;overflow:scroll;overflow-x:hidden;overflow-y:scroll;"> + <p style="height:450px;" disabled class="text-center"> + {{apiRequest}} + </p> + </div> + </div> + + </div> + + <div class="col-md-6"> + <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12"> + + <div style="height:200px;width:100%;border:solid 2px grey;overflow:scroll;overflow-x:hidden;overflow-y:scroll;"> + <p style="height:450px;" disabled class="text-center"> + {{apiResponse}} + </p> + </div> + </div> + + </div> + + <div class="col-md-12"> + <div class="row justify-content-center" style="padding-top:0.3cm"> + + <!-- <button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent" type="button" (click)="clearLog()">Abort Test</button> --> + + <button style="margin-left:6%;" [disabled]="!enableTestButton" class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--primary" type="submit" (click)="testVnf()">Execute Test + </button> + <!-- <button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent" type="button" (click)="abortTest()">Abort Test</button> --> + <!--button class="btn btn-primary" type="submit"> Save Revised Name/Value Pair to APPC</button--> + + </div> + + </div> + + </div> + + </div> + + <div style="padding-left:60%;padding-bottom:0.5cm"> + <!-- <a href="javascript:void(0)" style="color:darkblue; text-decoration: double; font-size: 15px;" (click)="download()">Download Raw Request/Response.</a>--> + <button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--primary" type="button" (click)="download()">Download Raw Request/Response + </button> + <button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent" type="button" [disabled]="!enableAbort" (click)="abortTest()">Abort Test + </button> + + </div> +</div> +<br> +<div class="card"> + <div class="card-block"> + + <div class="mdl-dialog__content" style="border:solid 1px grey;overflow:scroll;overflow-x:hidden;overflow-y:hidden;"> + + <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label" style="margin-left: 25%"> + <input placeholder="Request Id" [(ngModel)]="requestId" class="mdl-textfield__input" id="requestId" required name="requestId"> + </div> + <button type="submit" [disabled]="!enablePollButton" class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--primary" (click)=pollTestStatus()>Poll Test Status + </button> + + <div class="col-md-12"> + <span style="margin-left: 18.5%"><b>POLL TEST STATUS RESPONSE</b></span> + </div> + + <div style="margin-left: 18.5%;height:100px;width:60%;border:solid 2px grey;overflow:scroll;overflow-x:hidden;overflow-y:hidden;"> + + <div *ngIf="showStatusResponseDiv"> + <div *ngIf="enableCounterDiv"><b>Poll test no {{pollCounter}}</b></div> + <table> + <thead></thead> + <tbody> + <tr> + <td> + <div class="android-title mdl-layout-title">TimeStamp :</div> + </td> + <td> + <div class="android-title mdl-layout-title">{{outputTimeStamp}}</div> + </td> + </tr> + <tr> + <td> + <div class="android-title mdl-layout-title">Status :</div> + </td> + <td> + <div class="android-title mdl-layout-title">{{status}}</div> + </td> + </tr> + <tr> + <td> + <div class="android-title mdl-layout-title">Status Reason:</div> + </td> + <td> + <div class="android-title mdl-layout-title">{{statusReason}}</div> + </td> + </tr> + </tbody> + </table> + </div> + <div *ngIf="!showStatusResponseDiv"> + <div *ngIf="enableCounterDiv"><b>Poll test no {{pollCounter}}</b></div> + <span>{{statusResponse}}</span> + </div> + + <div *ngIf="errorResponse"> + <p style="height:450px;" disabled class="text-center"> + {{errorResponse}} + </p> + </div> + + </div> + </div> + </div> +</div>
\ No newline at end of file diff --git a/src/app/test/test.component.spec.ts b/src/app/test/test.component.spec.ts new file mode 100644 index 0000000..e869adb --- /dev/null +++ b/src/app/test/test.component.spec.ts @@ -0,0 +1,158 @@ +/* +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +ECOMP is a trademark and service mark of AT&T Intellectual Property. +============LICENSE_END============================================ +*/ + +/* tslint:disable:no-unused-variable */ + +// Modules +import { async, ComponentFixture, TestBed,inject } from '@angular/core/testing'; +import { By } from '@angular/platform-browser'; +import { DebugElement } from '@angular/core'; +import { FormsModule, ReactiveFormsModule } from '@angular/forms'; +import { RouterTestingModule } from '@angular/router/testing'; +import { SimpleNotificationsModule } from 'angular2-notifications'; +import { Http, Response, Headers, RequestOptions, HttpModule } from '@angular/http'; + +// Component +import { TestComponent } from './test.component'; + +// Services +import { NotificationService } from '../shared/services/notification.service'; +import { ParamShareService } from '.././shared/services/paramShare.service'; +import { MappingEditorService } from '../shared/services/mapping-editor.service'; +import { HttpUtilService } from '../shared/services/httpUtil/http-util.service'; +import { UtilityService } from '../shared/services/utilityService/utility.service'; +import { NgProgress } from 'ngx-progressbar'; +import {NgProgressModule} from 'ngx-progressbar'; + +describe( 'TestComponent', () => { + let component: TestComponent; + let fixture: ComponentFixture<TestComponent>; + + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [TestComponent], + imports: [ + FormsModule, + RouterTestingModule, + SimpleNotificationsModule, + HttpModule, + NgProgressModule + ], + providers: [ + NotificationService, + ParamShareService, + MappingEditorService, + HttpUtilService, + UtilityService, + NgProgress + ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(TestComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it( 'should create', () => { + expect(component).toBeTruthy(); + }); + + // it('test', () => { + // expect(2).toEqual(1) + // }); + + + // it('test preparfilename', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => { + // // fixture = TestBed.createComponent(TestComponent); + // // component = fixture.componentInstance; + // mappingEditorService.latestAction=undefined + + // expect(component.prepareFileName()).toBe(undefined); + // })); + + + it('Should have download method', () => { + expect(component.download).toBeDefined(); + }); + + // Test abortTest Method + it('Should have abortTest method', () => { + expect(component.abortTest).toBeDefined(); + }); + + it('Test abortTest Method', () => { + const temp = component.abortTest(); + expect(component.enableBrowse).toBeTruthy(); + expect(component.enableTestButton).toBeTruthy(); + }); + + it('Should have excelBrowseOption method', () => { + expect(component.excelBrowseOption).toBeDefined(); + }); + + it('Should have upload method', () => { + expect(component.upload).toBeDefined(); + }); + + it('Should have constructTestPayload method', () => { + expect(component.constructTestPayload).toBeDefined(); + }); + + it('Should have constructRequest method', () => { + expect(component.constructRequest).toBeDefined(); + }); + + it('Should have testVnf method', () => { + expect(component.testVnf).toBeDefined(); + }); + + it('Should have pollTestStatus method', () => { + expect(component.pollTestStatus).toBeDefined(); + }); + + + // Test getUrlEndPoint Method + it('Should have getUrlEndPoint method', () => { + expect(component.getUrlEndPoint).toBeDefined(); + }); + + it('getUrlEndPoint Should return value', () => { + expect(component.getUrlEndPoint('configmodify')).toEqual('config-modify'); + expect(component.getUrlEndPoint('configbackup')).toEqual('config-backup'); + expect(component.getUrlEndPoint('configrestore')).toEqual('config-restore'); + expect(component.getUrlEndPoint('healthcheck')).toEqual('health-check'); + expect(component.getUrlEndPoint('quiescetraffic')).toEqual('quiesce-traffic'); + expect(component.getUrlEndPoint('resumetraffic')).toEqual('resume-traffic'); + expect(component.getUrlEndPoint('startapplication')).toEqual('start-application'); + expect(component.getUrlEndPoint('stopapplication')).toEqual('stop-application'); + expect(component.getUrlEndPoint('upgradebackout')).toEqual('upgrade-backout'); + expect(component.getUrlEndPoint('upgradepostcheck')).toEqual('upgrade-post-check'); + expect(component.getUrlEndPoint('upgradeprecheck')).toEqual('upgrade-pre-check'); + expect(component.getUrlEndPoint('upgradesoftware')).toEqual('upgrade-software'); + expect(component.getUrlEndPoint('DeFaultCASE')).toEqual('defaultcase'); + }); +})
\ No newline at end of file diff --git a/src/app/test/test.component.ts b/src/app/test/test.component.ts new file mode 100644 index 0000000..1874904 --- /dev/null +++ b/src/app/test/test.component.ts @@ -0,0 +1,533 @@ +/* +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +ECOMP is a trademark and service mark of AT&T Intellectual Property. +============LICENSE_END============================================ +*/ + +import { Component, OnInit } from '@angular/core'; + +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'; +import { HttpUtilService } from '.././shared/services/httpUtil/http-util.service'; +import 'rxjs/add/observable/interval'; +import { Observable } from 'rxjs/Observable'; +import { environment } from '../.././environments/environment'; +import { UtilityService } from '.././shared/services/utilityService/utility.service'; +import 'rxjs/add/operator/map'; +import * as XLSX from 'xlsx'; +import { NgProgress } from 'ngx-progressbar'; + + +let YAML = require('yamljs'); + +type AOA = Array<Array<any>>; +declare var $: any; + +@Component({ selector: 'test', templateUrl: './test.component.html', styleUrls: ['./test.component.css'] }) +export class TestComponent implements OnInit { + public displayParamObjects; + options = { + timeOut: 1000, + showProgressBar: true, + pauseOnHover: true, + clickToClose: true, + maxLength: 200 + }; + public action: any; + public vnfId: any; + public item: any = {}; + + public vnfType: any; + vnfcType: any; + protocol: any; + mode: any = 'NORMAL'; + force: any = 'True'; + ttl: any; + public formattedNameValuePairs = {}; + public requestId = ''; + public enableBrowse: boolean = true; + public enableSpinner: boolean = false; + host: any; + public refNameObj = {}; + + public artifactName; + public type; + public transactions = ''; + public uploadFileName; + + public payload = {}; + public lastvmJson = {}; + public vmPayload = []; + public subPayload = {}; + public vmJson = {}; + public vnfcJson = {}; + public flag = 1; + public oldListName1 = ''; + public actionIdentifiers = {}; + public apiRequest = ''; + public apiResponse = ''; + public statusResponse; + public outputTimeStamp; + public status; + public statusReason; + public errorResponse; + public timer; + public subscribe; + public enableTestButton: boolean = false; + public enableAbort: boolean = false; + public showStatusResponseDiv: boolean = false; + public enablePollButton: boolean = true; + public pollCounter = 0; + public enableCounterDiv: 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) { + + } + + ngOnInit() { + + + } + + prepareFileName(): any { + let fileNameObject: any = this.mappingEditorService.latestAction; + return fileNameObject; + } + + /*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 theJSON = this.apiRequest; + if (fileName != null || fileName != '') { + var blob = new Blob([theJSON], { + type: 'text/json' + }); + saveAs(blob, fileName); + } + } + else { + this.nService.error('Error', 'Please upload spreadsheet to download the request and response'); + } + + if (this.apiResponse) { + var fileName = 'test_' + this.action + '_' + this.actionIdentifiers['vnf-id'] + '_response'; + var theJSON = this.apiResponse; + if (fileName != null || fileName != '') { + var blob = new Blob([theJSON], { + type: 'text/json' + }); + saveAs(blob, fileName); + } + } + + } + + + public abortTest() { + //this.apiResponse = ""; + this.enableBrowse = true; + this.enableTestButton = true; + this.enablePollButton = true; + this.subscribe.unsubscribe(); + + } + + + /*JSONToCSVConvertor(JSONData, fileName, ShowLabel) { + //If JSONData is not an object then JSON.parse will parse the JSON string in an Object + var arrData = typeof JSONData != 'object' ? JSON.parse(JSONData) : JSONData; + + var CSV = ''; + + //This condition will generate the Label/Header + if (ShowLabel) { + var testRow = ""; + for (var index in arrData[0]) { + + CSV += arrData[0][index].name + '\t' + arrData[0][index].value + '\t' + arrData[0][index].source + '\r\n'; + } + } + + if (CSV == '') { + alert("Invalid data"); + return; + } + + //Initialize file format you want csv or xls + var uri = 'data:application/vnd.ms-excel,' + encodeURI(CSV); + + var link = document.createElement("a"); + link.href = uri; + + link.download = fileName + ".xls"; + + //this part will append the anchor tag and remove it after automatic click + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + }*/ + + excelBrowseOption() { + $('#excelInputFile').trigger('click'); + } + + + upload(evt: any) { + /* wire up file reader */ + $('#filesparam').trigger('click'); + const target: DataTransfer = <DataTransfer>(evt.target); + + this.uploadFileName = evt.target.files[0].name; + var fileExtension = this.uploadFileName.substr(this.uploadFileName.lastIndexOf('.') + 1); + + if (target.files.length != 1) { + throw new Error('Cannot upload multiple files on the entry'); + } + if (fileExtension.toUpperCase() === 'XLS' || fileExtension.toUpperCase() === 'XLSX') { + const reader = new FileReader(); + reader.onload = (e: any) => { + /* read workbook */ + const bstr = e.target.result; + const wb = XLSX.read(bstr, { type: 'binary' }); + /* grab first sheet */ + const wsname = wb.SheetNames[0]; + const ws = wb.Sheets[wsname]; + + /* save data */ + this.requestId = '' + this.enableTestButton = true; + this.enableAbort = true; + this.enablePollButton = true; + + if (this.subscribe && this.subscribe != undefined) { + this.enableCounterDiv = false; + this.subscribe.unsubscribe(); + } + this.apiRequest = ''; + this.apiResponse = ''; + this.showStatusResponseDiv = false; + this.errorResponse = ''; + this.statusResponse = ''; + + let arrData = (<AOA>(XLSX.utils.sheet_to_json(ws, { blankrows: false }))); + this.nService.success('Success', 'SpreadSheet uploaded successfully'); + + + console.log('Array data ==' + arrData[0]); + this.vmPayload = []; + this.subPayload = {}; + this.vmJson = {}; + this.flag = 1; + this.payload = {}; + this.oldListName1 = ''; + this.actionIdentifiers = {}; + for (var i = 0; i < arrData.length; i++) { + var element = arrData[i]; + if (element['TagName'] === 'action') { + this.action = element['Value']; + } + if (element['List Name'] === 'action-identifiers') { + this.vnfId = element['Value']; + var key = element['TagName']; + var value = element['Value']; + if (key && value) { + this.actionIdentifiers[key] = value; + + } + } + + if (element['List Name'] === 'payload') { + var listName1 = element['List Name_1']; + var listName2 = element['List Name_2']; + var listName3 = element['List Name_3']; + var key = element['TagName']; + var value = element['Value']; + if (listName1) { + if (this.oldListName1 == '' || (listName1 === this.oldListName1)) { + this.constructTestPayload(listName2, listName3, key, value); + this.payload[listName1] = this.subPayload; + } + else { + this.subPayload = {}; + this.constructTestPayload(listName2, listName3, key, value); + this.payload[listName1] = this.subPayload; + } + this.oldListName1 = listName1; + } + else { + this.payload[key] = value; + } + } + } + + //console.log("VM JSON===" + JSON.stringify(this.vmPayload)) + // console.log('VM payload===' + JSON.stringify(this.payload)); + }; + + reader.readAsBinaryString(target.files[0]); + } + else { + this.nService.error('Error', 'Incorrect spreadsheet uploaded'); + this.flag = 1; + this.oldListName1 = ''; + this.vmJson = {}; + this.vnfcJson = {}; + this.subPayload = {}; + this.vmPayload = []; + this.payload = {}; + this.action = ''; + this.actionIdentifiers = {}; + this.apiRequest = ''; + this.apiResponse = ''; + this.enableCounterDiv = false; + } + } + + constructTestPayload(listName2, listName3, key, value) { + if (listName2 == undefined && listName3 == undefined) { + this.subPayload[key] = value; + } + if (listName2) { + + if (!listName3) { + + //vmPayload.push(vmJson) + this.vmJson = {}; + this.vnfcJson = {}; + this.vmJson[key] = value; + this.flag = 0; + } + else { + this.vnfcJson[key] = value; + this.vmJson['vnfc'] = this.vnfcJson; + this.flag = 1; + } + if (this.vmJson) this.lastvmJson = this.vmJson; + if (this.flag == 0) { + this.vmPayload.push(this.lastvmJson); + if (this.vmPayload) this.subPayload['vm'] = this.vmPayload; + } + } + } + + constructRequest() { + console.log('payload==' + JSON.stringify(this.payload)); + let timeStamp = new Date().toISOString(); + console.log('timestamp==' + timeStamp); + let reqId; + this.requestId = reqId = new Date().getTime().toString(); + let data = { + 'input': { + 'common-header': { + 'timestamp': timeStamp, + 'api-ver': '2.00', + 'originator-id': 'CDT', + 'request-id': this.requestId, + 'sub-request-id': this.requestId, + 'flags': { + 'mode': 'NORMAL', + 'force': 'TRUE', + 'ttl': 3600 + } + }, + 'action': this.action, + 'action-identifiers': this.actionIdentifiers, + 'payload': JSON.stringify(this.payload) + } + }; + + return data; + } + + testVnf() { + //let payload = '{"request-parameters":{"vnf-host-ip-address":"' + this.host + '"},"configuration-parameters":"' + JSON.stringify(this.formattedNameValuePairs) + '"}"'; + //let payload = '{"request-parameters":{"host-ip-address:"' + this.host + '",port-number:"'+port+'"}}'; + + this.enableBrowse = false; + this.enableTestButton = false; + this.enablePollButton = false; + this.timer = Observable.interval(10000); + this.subscribe = this.timer.subscribe((t) => this.pollTestStatus()); + //console.log('full payload==' + JSON.stringify(this.apiRequest)); + this.ngProgress.start(); + this.apiRequest = JSON.stringify(this.constructRequest()); + this.httpUtil.post( + { + url: environment.testVnf + this.getUrlEndPoint(this.action.toLowerCase()), data: this.apiRequest + }) + .subscribe(resp => { + this.apiResponse = JSON.stringify(resp); + this.enableBrowse = true; + this.enableTestButton = true; + this.ngProgress.done(); + }, + error => { + this.nService.error('Error', 'Error in connecting to APPC Server'); + this.enableBrowse = true; + this.enableTestButton = true; + this.enablePollButton = true; + this.enableCounterDiv = false; + this.subscribe.unsubscribe(); + + }); + + setTimeout(() => { + this.ngProgress.done(); + }, 3500); + } + + + pollTestStatus() { + if (this.requestId && this.actionIdentifiers['vnf-id']) { + // console.log("payload==" + JSON.stringify(this.payload)) + let timeStamp = new Date().toISOString(); + // console.log("timestamp==" + timeStamp) + let reqId = new Date().getTime().toString(); + let data = { + 'input': { + 'common-header': { + 'timestamp': timeStamp, + 'api-ver': '2.00', + 'originator-id': 'CDT', + 'request-id': reqId, + 'sub-request-id': reqId, + 'flags': { + 'mode': 'NORMAL', + 'force': 'TRUE', + 'ttl': 3600 + } + }, + 'action': 'ActionStatus', + 'action-identifiers': this.actionIdentifiers, + 'payload': '{"request-id":' + this.requestId + '}' + } + }; + //this.ngProgress.start(); + this.httpUtil.post( + { + url: environment.checkTestStatus, data: data + + }) + .subscribe(resp => { + // console.log('Response==' + JSON.stringify(resp)); + this.statusResponse = JSON.stringify(resp); + var status = '' + var statusReason = '' + this.enableCounterDiv = true; + this.pollCounter++; + //this.statusResponse=JSON.parse(this.statusResponse) + if (resp.output) var timeStamp = resp.output['common-header'].timestamp; + if (resp.output.payload) { + var payload = resp.output.payload.replace(/\\/g, "") + try { + payload = JSON.parse(payload) + status = payload['status']; + statusReason = payload['status-reason']; + } + catch (err) { + console.log("error" + err) + } + } + if (timeStamp && status && statusReason) { + this.showStatusResponseDiv = true; + this.outputTimeStamp = timeStamp; + this.status = status; + this.statusReason = statusReason; + if (status.toUpperCase() === 'SUCCESS') { + this.subscribe.unsubscribe(); + this.enablePollButton = true; + } + if (status.toUpperCase() === 'FAILED') { + this.subscribe.unsubscribe(); + this.enablePollButton = true; + } + } + else { + this.showStatusResponseDiv = false; + } + + // this.ngProgress.done(); + }, + error => { + this.statusResponse = null; + this.showStatusResponseDiv = false; + this.errorResponse = 'Error Connecting to APPC server'; + this.enableCounterDiv = false; + this.subscribe.unsubscribe(); + }); + + } + else { + this.nService.error("Error", "Please enter vnf Id & request Id"); + } + // setTimeout(() => { + // this.ngProgress.done(); + // }, 3500); + } + + 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 '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'; + default: + return action.toLowerCase(); + } + + } + +} |