2 ============LICENSE_START==========================================
3 ===================================================================
4 Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
5 ===================================================================
6 Copyright (C) 2018 IBM.
7 ===================================================================
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
13 http://www.apache.org/licenses/LICENSE-2.0
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.
20 ============LICENSE_END============================================
23 import * as XLSX from 'xlsx';
24 import * as _ from 'underscore';
25 import { ActivatedRoute, Router } from '@angular/router';
26 import { Component, OnInit, ViewChild } from '@angular/core';
27 import { BuildDesignComponent } from '../build-artifacts.component';
28 import { HttpUtilService } from '../../../shared/services/httpUtil/http-util.service';
29 import { Location } from '@angular/common';
30 import { MappingEditorService } from '../../..//shared/services/mapping-editor.service';
31 import { ModalComponent } from '../../../shared/modal/modal.component';
32 import { NgProgress } from 'ngx-progressbar';
33 import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
34 import { NotificationService } from '../../../shared/services/notification.service';
35 import { NotificationsService } from 'angular2-notifications';
36 import { ParamShareService } from '../../..//shared/services/paramShare.service';
37 import { environment } from '../../../../environments/environment';
38 import { saveAs } from 'file-saver';
39 import { UtilityService } from '../../../shared/services/utilityService/utility.service';
40 import { appConstants } from '../../../../constants/app-constants';
42 type AOA = Array<Array<any>>;
43 const REFERENCE_DATA:string= "reference_data";
45 selector: 'reference-dataform',
46 templateUrl: './reference-dataform.component.html',
47 styleUrls: ['./reference-dataform.component.css']
49 export class ReferenceDataformComponent implements OnInit {
50 @ViewChild(ModalComponent) modalComponent: ModalComponent;
51 public showUploadStatus: boolean = false;
52 public fileUploaded: boolean = false;
53 public uploadedData: any;
54 public statusMsg: string;
55 public uploadStatus: boolean = false;
56 public isCollapsedContent: boolean = true;
57 public vnfcCollLength: number = 0;
58 public vfncCollection = [];
60 public actionType: any;
61 numberTest: RegExp = /^[^.a-z]+$/;
62 public numberOfVmTest: boolean = true;
63 public tempAllData = [];
64 disableGrpNotationValue: boolean;
65 public noRefData = false;
66 public disableRetrieve = false;
67 public getRefStatus = false;
68 public uploadStatusError: boolean;
69 public showUploadErrorStatus: boolean;
70 public noData: string;
72 public appData = { reference: {}, template: { templateData: {}, nameValueData: {} }, pd: {} };
73 public downloadData = {
75 template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' },
76 pd: { pdData: '', pdFileName: '' }
79 public uploadFileName: any;
80 public addVmClickedFlag: boolean = false;
81 public getExcelUploadStatus: boolean = false;
82 public uploadedDataArray: any;
83 public actionFlag = false;
86 nonConfigureAction: any;
89 public actionLevels = [
92 oldtemplateIdentifier: any
94 identifierDrpValues: any = [];
95 //settings for the notifications.
98 showProgressBar: true,
103 //initializing this object to contain all the parameters to be captured
104 public referenceDataObject = {
106 'action-level': 'vnf',
107 scope: { 'vnf-type': '', 'vnfc-type': '' },
110 'device-protocol': '',
115 public refernceScopeObj = { sourceType: '', from: '', to: '' };
116 public actions = [ appConstants.Actions.blank,
117 appConstants.Actions.configure,
118 appConstants.Actions.ConfigModify,
119 appConstants.Actions.configBackup,
120 appConstants.Actions.configRestore,
121 appConstants.Actions.getRunningConfig,
122 appConstants.Actions.healthCheck,
123 appConstants.Actions.startApplication,
124 appConstants.Actions.stopApplication,
125 appConstants.Actions.quiesceTraffic,
126 appConstants.Actions.resumeTraffic,
127 appConstants.Actions.upgradeBackout,
128 appConstants.Actions.upgradeBackup,
129 appConstants.Actions.upgradePostCheck,
130 appConstants.Actions.upgradePreCheck,
131 appConstants.Actions.upgradeSoftware,
132 appConstants.Actions.openStackActions,
133 appConstants.Actions.configScaleOut
135 public groupAnotationValue = [appConstants.groupAnotationValue.blank, appConstants.groupAnotationValue.pair];
136 public groupAnotationType = [appConstants.groupAnotationType.blank, appConstants.groupAnotationType.firstVnfcName, appConstants.groupAnotationType.fixedValue, appConstants.groupAnotationType.relativeValue];
137 public deviceProtocols = [appConstants.DeviceProtocols.blank, appConstants.DeviceProtocols.ansible, appConstants.DeviceProtocols.chef, appConstants.DeviceProtocols.netconfXML, appConstants.DeviceProtocols.rest, appConstants.DeviceProtocols.cli, appConstants.DeviceProtocols.restConf];
138 public deviceTemplates = [appConstants.deviceTemplates.blank, appConstants.deviceTemplates.y, appConstants.deviceTemplates.n];
139 public sourceTypeColl = [appConstants.sourceTypeColl.blank, appConstants.sourceTypeColl.vnfType, appConstants.sourceTypeColl.vnfcType];
140 public ipAddressBoolean = ['', 'Y', 'N'];
141 public Sample: any = {
142 'vnfc-instance': '1',
143 'vnfc-function-code': '',
144 'ipaddress-v4-oam-vip': '',
145 'group-notation-type': '',
146 'group-notation-value': ''
148 hideModal: boolean = false;
150 public uploadTypes = [{
151 value: 'Reference Data',
152 display: 'Sample Json Param File'
155 value: 'Mapping Data',
156 display: 'Sample Json Param File'
159 public selectedUploadType: string = this.uploadTypes[0].value;
160 public vnfcTypeData: string = '';
161 public title: string;
162 public allowAction: boolean = true;
163 public actionExist: boolean = false;
164 public disableVnftype: boolean = false;
165 public otherActions: boolean = false;
166 public actionHealthCheck: boolean = false;
167 public actionChanged: boolean = false;
168 public initialAction: string = '';
169 public noCacheData: boolean;
170 public updateParams: any;
171 public vnfParams: any;
172 public firstArrayElement = [];
173 public remUploadedDataArray = [];
174 isConfigScaleOut = false
175 configScaleOutExist: boolean
176 public versionNoForApiCall: any= "0.0.1"
178 private buildDesignComponent: BuildDesignComponent,
179 private httpUtils: HttpUtilService,
180 private route: Router,
181 private location: Location,
182 private activeRoutes: ActivatedRoute,
183 private notificationService: NotificationService,
184 private paramShareService: ParamShareService,
185 private mappingEditorService: MappingEditorService,
186 private modalService: NgbModal,
187 private nService: NotificationsService,
188 private ngProgress: NgProgress,
189 private utilityService: UtilityService) {
195 let path = this.location.path;
196 this.title = 'Reference Data';
197 this.referenceDataObject = {
199 'action-level': 'vnf',
200 scope: { 'vnf-type': '', 'vnfc-type': '' },
203 'device-protocol': '',
208 this.updateParams = sessionStorage.getItem('updateParams');
209 let cacheData = this.mappingEditorService.referenceNameObjects;
210 if (cacheData != undefined && cacheData != null && cacheData.length > 0) {
211 this.tempAllData = cacheData;
212 if (this.mappingEditorService.latestAction != undefined) {
213 this.referenceDataObject = this.mappingEditorService.latestAction;
214 this.toggleIdentifier(this.referenceDataObject.action);
215 this.refernceScopeObj.sourceType = this.referenceDataObject['scopeType'];
216 this.oldAction = this.referenceDataObject.action;
217 this.populateExistinAction(this.referenceDataObject.action);
219 } else if (this.updateParams != 'undefined') {
222 var appData = this.mappingEditorService.appDataObject;
223 if (appData != null || appData != undefined) this.appData = appData;
224 var downloadData = this.mappingEditorService.downloadDataObject;
225 if (downloadData != null || downloadData != undefined) this.downloadData = downloadData;
226 this.vnfParams = JSON.parse(sessionStorage.getItem('vnfParams'));
227 if (this.vnfParams && this.vnfParams.vnfType) {
228 this.referenceDataObject['scope']['vnf-type'] = this.vnfParams.vnfType;
230 if (this.vnfParams && this.vnfParams.vnfcType) {
231 this.referenceDataObject['scope']['vnfc-type'] = this.vnfParams.vnfcType;
233 this.uploadedDataArray = [];
234 this.remUploadedDataArray = [];
235 this.firstArrayElement = [];
236 this.uploadFileName = '';
237 this.templateIdentifier = this.mappingEditorService.identifier
238 // Enable or Block Template and PD Tabs
239 this.buildDesignComponent.getRefData(this.referenceDataObject);
240 this.configDrp(this.referenceDataObject.action)
242 toggleIdentifier(data) {
243 if (data == 'ConfigScaleOut') {
244 this.isConfigScaleOut = true
247 this.isConfigScaleOut = false
251 //to retrive the data from appc and assign it to the vaiables, if no data display the message reterived from the API
254 let data = this.utilityService.createPayloadForRetrieve(true, '', '', '');
255 this.ngProgress.start();
256 this.httpUtils.post({
257 url: environment.getDesigns,
259 }).subscribe(resp => {
260 if (resp.output.data.block != undefined) {
261 this.nService.success(appConstants.notifications.titles.status, appConstants.messages.datafetched);
262 let artifactInfo = JSON.parse(resp.output.data.block).artifactInfo[0];
263 let reference_data = JSON.parse(artifactInfo['artifact-content'])['reference_data'][0];
264 this.referenceDataObject = reference_data;
265 this.toggleIdentifier(this.referenceDataObject.action);
266 if (this.referenceDataObject.action == appConstants.Actions.configScaleOut) {
267 this.groupAnotationType = [appConstants.groupAnotationType.blank, appConstants.groupAnotationType.firstVnfcName, appConstants.groupAnotationType.fixedValue, appConstants.groupAnotationType.relativeValue, appConstants.groupAnotationType.existingGroupName];
270 // Enable or Block Template and PD Tabs
271 this.buildDesignComponent.getRefData(this.referenceDataObject);
272 this.refernceScopeObj.sourceType = this.referenceDataObject['scopeType'];
273 this.mappingEditorService.getReferenceList().push(JSON.parse(artifactInfo['artifact-content']));
274 this.tempAllData = JSON.parse(artifactInfo['artifact-content'])['reference_data'];
275 this.oldAction = this.referenceDataObject.action;
276 if (this.referenceDataObject.action === appConstants.Actions.openStackActions) {
277 this.deviceProtocols = [appConstants.DeviceProtocols.blank, appConstants.DeviceProtocols.openStack];
278 this.buildDesignComponent.tabs = [
281 name: 'Reference Data',
286 this.buildDesignComponent.tabs = [
288 name: 'Reference Data',
292 url: 'templates/myTemplates',
294 name: 'Parameter Definition',
295 url: 'parameterDefinitions/create'
302 this.getArtifactsOpenStack();
304 this.nService.success('Status', 'Sorry !!! I dont have any artifact Named : ' + (JSON.parse(sessionStorage.getItem('updateParams')))['artifact-name']);
306 this.ngProgress.done();
310 this.nService.warn('status', 'error while reteriving artifact');
313 this.ngProgress.done();
317 //reinitializing the required values
319 let referenceObject = this.prepareReferenceObject();
320 this.mappingEditorService.changeNavAppData(this.appData);
321 this.mappingEditorService.changeNavDownloadData(this.downloadData);
322 this.uploadedDataArray = [];
323 this.remUploadedDataArray = [];
324 this.firstArrayElement = [];
325 this.uploadFileName = '';
328 numberValidation(event: any) {
329 if (this.numberTest.test(event) && event != 0) {
330 this.numberOfVmTest = true;
333 this.numberOfVmTest = false;
337 updateSessionValues(event: any, type: string) {
338 if (type === 'action') {
339 sessionStorage.setItem('action', event);
341 if (type === 'vnfType') {
342 sessionStorage.setItem('vnfType', event);
346 addVnfcData(vmNumber: number) {
348 'vnfc-instance': this.referenceDataObject.vm[vmNumber].vnfc.length + 1,
349 'vnfc-type': this.vnfcTypeData,
350 'vnfc-function-code': '',
351 'ipaddress-v4-oam-vip': '',
352 'group-notation-type': '',
353 'group-notation-value': ''
355 this.referenceDataObject.vm[vmNumber].vnfc.push(newObj);
358 //to remove the VM's created by the user
359 removeFeature(vmNumber: any, index: any, templateId) {
360 if (this.referenceDataObject.action == "Configure") {
361 this.referenceDataObject.vm.splice(vmNumber, 1);
362 this.referenceDataObject.vm.forEach((obj, arrIndex) => {
363 if (arrIndex >= vmNumber) {
364 obj["vm-instance"] = obj["vm-instance"] - 1
368 let data = this.referenceDataObject.vm.filter(obj => {
369 return obj['template-id'] == templateId;
372 let vmIndex = this.findVmindex(data, vmNumber, templateId)
373 this.referenceDataObject.vm.splice(vmIndex, 1);
375 this.referenceDataObject.vm.forEach((obj, arrIndex) => {
376 if (obj['template-id'] == templateId) {
378 obj["vm-instance"] = index + 1
386 findVmindex(data, vmNumber, templateId) {
387 return this.referenceDataObject.vm.findIndex(obj => {
388 let x = obj['vm-instance'] == (vmNumber + 1) && templateId == obj['template-id']//true
394 //add new VM's to the configure
397 let mberOFVm = Number(this.refernceScopeObj.from);
398 if (this.referenceDataObject.action == 'ConfigScaleOut') {
399 let existingVmsLength = this.referenceDataObject.vm.filter(obj => {
400 return obj['template-id'] == this.templateIdentifier
402 mberOFVm = existingVmsLength + mberOFVm;
404 for (var i = (existingVmsLength); i < mberOFVm; i++) {
406 this.referenceDataObject.vm.push({ 'template-id': this.templateIdentifier, 'vm-instance': (existingVmsLength + index + 1), vnfc: [Object.assign({}, this.Sample)] });
411 let arrlength = this.referenceDataObject.vm.length;
412 mberOFVm = arrlength + mberOFVm;
413 for (var i = (arrlength); i < mberOFVm; i++) {
414 if (this.referenceDataObject.action == 'ConfigScaleOut') {
415 this.referenceDataObject.vm.push({ 'template-id': this.templateIdentifier, 'vm-instance': (i + 1), vnfc: [Object.assign({}, this.Sample)] });
417 this.referenceDataObject.vm.push({ 'vm-instance': (i + 1), vnfc: [Object.assign({}, this.Sample)] });
423 //Reference object to create reference data
424 prepareReferenceObject(isSaving?: any) {
425 let scopeName = this.resetParamsOnVnfcType();
426 let extension = this.decideExtension(this.referenceDataObject);
427 this.prepareArtifactList(scopeName, extension);
428 if (this.referenceDataObject.action === 'OpenStack Actions') {
429 this.referenceDataObject['template'] = 'N';
430 this.referenceDataObject['artifact-list'] = [];
431 this.referenceDataObject['firstRowVmSpreadSheet']=this.firstArrayElement;
433 //detaching the object from the form and processing further
434 let newObj = $.extend(true, {}, this.referenceDataObject);
435 let action = this.referenceDataObject.action;
436 newObj = this.deleteVmsforNonActions(newObj, action)
437 this.pushOrReplaceTempData(newObj, action);
438 this.addAllActionObj(newObj, scopeName);
440 //saving data to service
441 this.mappingEditorService.getReferenceList().push(JSON.parse(JSON.stringify(this.referenceDataObject)));
442 this.buildDesignComponent.updateAccessUpdatePages(this.referenceDataObject.action, this.mappingEditorService.getReferenceList());
443 this.mappingEditorService.changeNav(this.tempAllData);
444 //on action change or template identifier change reset the form by restting values of Reference data object
445 this.resetVmsForScaleout(this.currentAction)
446 return { totlaRefDtaa: this.tempAllData, scopeName: scopeName };
449 public checkIfelementExistsInArray(element, array) {
450 //// console.log("Element==" + element)
451 var result: boolean = false;
453 array.forEach(function (item) {
454 // // console.log("Item==" + item)
455 if (element === item) {
456 // console.log('Element==' + element + 'Item==' + item);
465 /* wire up file reader */
466 const target: DataTransfer = <DataTransfer>(evt.target);
467 //// console.log("filename========" + evt.target.files[0].name)
468 this.uploadFileName = evt.target.files[0].name;
469 var fileExtension = this.uploadFileName.substr(this.uploadFileName.lastIndexOf('.') + 1);
470 if (target.files.length != 1) {
471 throw new Error(appConstants.errors.multipleFileUploadError);
473 if (fileExtension.toUpperCase() === 'XLS' || fileExtension.toUpperCase() === 'XLSX') {
474 const reader = new FileReader();
475 reader.onload = (e: any) => {
477 const bstr = e.target.result;
478 // // console.log("print 1---" + bstr);
479 const wb = XLSX.read(bstr, { type: 'binary' });
480 // // console.log("print 2---" + JSON.stringify(wb));
481 /* grab first sheet */
482 const wsname = wb.SheetNames[0];
483 // // console.log("Name:---" + wsname);
484 const ws = wb.Sheets[wsname];
488 let arrData = (<AOA>(XLSX.utils.sheet_to_json(ws, { header: 1 })));
489 this.uploadedDataArray = arrData;
490 this.firstArrayElement = arrData[0];
491 var remUploadedDataArray = arrData;
492 remUploadedDataArray.shift();
493 this.remUploadedDataArray = remUploadedDataArray;
494 if (arrData != null) {
495 this.getExcelUploadStatus = true;
496 this.nService.success(appConstants.notifications.titles.success, appConstants.messages.vmDataUploadSuccess);
500 this.nService.success(appConstants.notifications.titles.error, appConstants.messages.emptyVmUpload);
503 reader.readAsBinaryString(target.files[0]);
506 this.nService.error(appConstants.notifications.titles.error, appConstants.messages.incorrectVmUpload);
511 addVmCapabilitiesData() {
512 for (var i = 0; i < this.uploadedDataArray.length; i++) {
513 var vnfcFuncCodeArray = [];
514 var data = this.uploadedDataArray[i];
515 for (var j = 1; j < data.length; j++) {
516 if (data[j] != undefined) {
517 if (data[j].toUpperCase() === 'Y') {
518 vnfcFuncCodeArray.push(this.firstArrayElement[j]);
522 var action = this.uploadedDataArray[i][0];
523 if (action && action != undefined) {
526 'action-level': 'vm',
528 'vnf-type': this.referenceDataObject['scope']['vnf-type'], //need to confirm what should be this value
531 'vnfc-function-code-list': vnfcFuncCodeArray,
533 'device-protocol': 'OS'
536 this.tempAllData.push(json);
543 save(form: any, isValid: boolean) {
544 if (this.referenceDataObject.action === '') {
545 this.nService.error(appConstants.notifications.titles.error, appConstants.errors.noActionError);
548 if (this.referenceDataObject['device-protocol'] === '') {
549 this.nService.error(appConstants.notifications.titles.error, appConstants.errors.noDeviceProtocolError);
554 let referenceObject = this.prepareReferenceObject();
555 let theJSON = JSON.stringify({ 'reference_data': this.tempAllData }, null, '\t');
556 let uri = 'data:application/json;charset=UTF-8,' + encodeURIComponent(theJSON);
557 this.downloadData.reference = theJSON;
558 this.validateTempAllData();
559 var blob = new Blob([theJSON], {
562 let fileName = 'reference_AllAction_' + referenceObject.scopeName + '_' + '0.0.1V.json';
563 this.downloadFile(blob, fileName, 100)
564 var templateData = JSON.stringify(this.downloadData.template.templateData);
565 var nameValueData = JSON.stringify(this.downloadData.template.nameValueData);
566 var pdData = this.downloadData.pd.pdData;
567 if (templateData != '{}' && templateData != null && templateData != undefined) this.downloadTemplate();
568 if (nameValueData != '{}' && nameValueData != null && nameValueData != undefined) this.downloadNameValue();
569 if (pdData != '' && pdData != null && pdData != undefined) this.downloadPd();
572 downloadFile(blob, fileName, delay) {
574 saveAs(blob, fileName);
579 var fileName = this.downloadData.template.templateFileName;
580 var theJSON = this.downloadData.template.templateData;
581 if (fileName != null || fileName != '') {
582 var fileExtensionArr = fileName.split('.');
583 var blob = new Blob([theJSON], {
584 type: 'text/' + fileExtensionArr[1]
586 this.downloadFile(blob, fileName, 130)
590 downloadNameValue() {
591 var fileName = this.downloadData.template.nameValueFileName;
592 var theJSON = this.downloadData.template.nameValueData;
593 var blob = new Blob([theJSON], {
597 this.downloadFile(blob, fileName, 160)
601 let fileName = this.downloadData.pd.pdFileName;
602 let theJSON = this.downloadData.pd.pdData;
603 var blob = new Blob([theJSON], {
607 this.downloadFile(blob, fileName, 180)
610 saveToAppc(valid, form, event) {
611 if (this.referenceDataObject.action === '') {
612 this.nService.error(appConstants.notifications.titles.error, appConstants.errors.noActionError);
615 if (this.referenceDataObject['device-protocol'] === '') {
616 this.nService.error(appConstants.notifications.titles.error, appConstants.errors.noDeviceProtocolError);
621 form._submitted = true;
624 let referenceObject = this.prepareReferenceObject(true);
625 this.validateTempAllData();
626 let theJSON = JSON.stringify(this.tempAllData, null, '\t');
627 let fileName = 'reference_AllAction_' + referenceObject.scopeName + '_' + '0.0.1V.json';
628 this.uploadArtifact(JSON.stringify({ reference_data: this.tempAllData }), this.tempAllData[this.tempAllData.length - 1], fileName);
629 var templateData = JSON.stringify(this.appData.template.templateData);
630 var nameValueData = JSON.stringify(this.appData.template.nameValueData);
631 var pdData = JSON.stringify(this.appData.pd);
632 if (templateData != '{}' && templateData != null && templateData != undefined) this.saveTemp();
633 if (nameValueData != '{}' && nameValueData != null && nameValueData != undefined) this.saveNameValue();
634 if (pdData != '{}' && pdData != null && pdData != undefined) this.savePd();
635 if (this.actionChanged) {
637 if (this.currentAction) {
638 this.referenceDataObject.action = this.currentAction;
641 this.populateExistinAction(this.referenceDataObject.action);
642 this.actionChanged = false;
647 this.nService.warn(appConstants.notifications.titles.status, appConstants.messages.artifactSaveError);
651 validateTempAllData() {
652 if (this.tempAllData) {
653 var updatedData = [];
654 this.tempAllData.forEach(data => {
656 updatedData.push(data);
659 this.tempAllData = updatedData;
663 appendSlashes(artifactData) {
664 return artifactData.replace(/"/g, '\\"');
667 uploadArtifact(artifactData, dataJson, fileName) {
669 let slashedPayload = this.appendSlashes(artifactData);
670 let payload = this.utilityService.createPayLoadForSave(REFERENCE_DATA, dataJson['scope']['vnf-type'], "AllAction", fileName, this.versionNoForApiCall, slashedPayload);
671 this.ngProgress.start();
672 this.httpUtils.post({
673 url: environment.getDesigns,
675 }).subscribe((resp) => {
676 if (resp != null && resp.output.status.code == appConstants.errorCode["400"]) {
677 window.scrollTo(0, 0);
678 this.nService.success(appConstants.notifications.titles.status, appConstants.messages.referenceDataUplaodSuccess);
680 this.nService.warn(appConstants.notifications.titles.status, appConstants.messages.referenceDataUplaodFailure);
682 this.uploadStatusError = false;
683 this.getRefStatus = false;
684 this.ngProgress.done();
686 this.nService.error(appConstants.notifications.titles.status, appConstants.errors.connectionError);
687 window.scrollTo(0, 0);
689 this.appData.reference = payload;
691 this.ngProgress.done();
696 if (sessionStorage.getItem('updateParams') != 'undefined') {
698 this.noCacheData = false;
700 this.noCacheData = true;
704 cloneMessage(servermessage) {
706 for (var key in servermessage) {
707 if (servermessage.hasOwnProperty(key)) //ensure not adding inherited props
708 clone[key] = servermessage[key];
713 public showUpload() {
714 this.selectedUploadType = this.uploadTypes[0].value;
717 public fileChange(input) {
718 this.fileName = input.target.files[0].name.replace(/C:\\fakepath\\/i, '');
719 this.fileUploaded = true;
720 this.disableRetrieve = true;
721 if (input.target.files && input.target.files[0]) {
722 // Create the file reader
723 let reader = new FileReader();
724 this.readFile(input.target.files[0], reader, (result) => {
725 // After the callback fires do:
726 if ('Reference Data' === this.selectedUploadType) {
729 let jsonObject = (JSON.parse(result))['reference_data'];
730 this.uploadedData = JSON.parse(JSON.stringify(jsonObject));
731 this.tempAllData = JSON.parse(JSON.stringify(jsonObject));
732 this.notificationService.notifySuccessMessage('Reference Data file successfully uploaded..');
733 if (jsonObject instanceof Array) {
734 this.referenceDataObject = jsonObject[0];
735 jsonObject.forEach(obj => {
736 this.selectedActions.push(obj.action);
739 this.referenceDataObject = jsonObject;
741 this.selectedActions.push(jsonObject.action);
743 this.toggleIdentifier(this.referenceDataObject.action)
744 this.configDrp(this.referenceDataObject.action)
745 if (this.referenceDataObject.action === 'OpenStack Actions') {
746 this.deviceProtocols = ['', 'OpenStack'];
747 this.buildDesignComponent.tabs = [
750 name: 'Reference Data',
755 this.buildDesignComponent.tabs = [
757 name: 'Reference Data',
761 url: 'templates/myTemplates',
763 name: 'Parameter Definition',
764 url: 'parameterDefinitions/create'
771 this.getArtifactsOpenStack();
772 if (this.referenceDataObject.template == null) {
773 this.referenceDataObject.template = 'Y';
775 if (this.referenceDataObject['action-level'] == null) {
776 this.referenceDataObject['action-level'] = 'VNF';
778 // Enable or Block Template and PD Tabs
779 this.buildDesignComponent.getRefData(this.referenceDataObject);
781 this.nService.error(appConstants.notifications.titles.error, appConstants.messages.incorrectFileFormat);
784 this.hideModal = true;
787 this.notificationService.notifyErrorMessage('Failed to read file..');
791 public readFile(file, reader, callback) {
792 // Set a callback funtion to fire after the file is fully loaded
793 reader.onload = () => {
794 // callback with the results
795 callback(reader.result);
797 this.notificationService.notifySuccessMessage('Uploading File ' + file.name + ':' + file.type + ':' + file.size);
799 reader.readAsText(file, 'UTF-8');
802 fileChangeEvent(fileInput: any) {
803 let obj: any = fileInput.target.files;
808 'vnfc-instance': '1',
809 'vnfc-function-code': '',
810 'ipaddress-v4-oam-vip': '',
811 'group-notation-type': '',
812 'group-notation-value': ''
816 setVmInstance(index) {
817 this.referenceDataObject.vm[index]['vm-instance'] = index + 1;
820 setVnfcType(str: String) {
821 this.Sample['vnfc-type'] = str;
824 getChange(value: String) {
825 if (value === 'vnfType') {
826 this.referenceDataObject.scope['vnfc-type'] = '';
831 this.referenceDataObject['action-level'] = 'vnf';
832 this.referenceDataObject.template = 'Y';
833 this.referenceDataObject['device-protocol'] = '';
834 this.referenceDataObject['user-name'] = '';
835 this.referenceDataObject['port-number'] = '';
836 this.refernceScopeObj.sourceType = '';
837 this.Sample['vnfc-type'] = '';
840 populateExistinAction(data) {
841 let existAction = this.tempAllData.findIndex(obj => {
842 return obj.action == data;
844 if (existAction > -1) {
845 let obj = $.extend(true, {}, this.tempAllData[existAction]);
846 this.referenceDataObject = obj;
847 this.referenceDataObject.scope['vnf-type'] = obj['scope']['vnf-type'];
848 this.referenceDataObject.scope['vnfc-type-list'] = obj['scope']['vnfc-type-list'];
849 this.referenceDataObject['device-protocol'] = obj['device-protocol'];
850 this.refernceScopeObj['sourceType'] = obj['scopeType'];
853 this.referenceDataObject.action = data;
855 //# iof healthCeck change deviceprotocol drp vaues
858 this.deviceProtocols = ['', 'ANSIBLE', 'CHEF', 'REST'];
859 this.actionHealthCheck = true;
861 case 'UpgradeBackout':
862 case 'ResumeTraffic':
863 case 'QuiesceTraffic':
864 case 'UpgradeBackup':
865 case 'UpgradePostCheck':
866 case 'UpgradePreCheck':
867 case 'UpgradeSoftware':
868 case 'ConfigRestore':
869 case 'StartApplication':
870 case 'StopApplication':
871 case 'GetRunningConfig':
873 this.deviceProtocols = ['', 'CHEF', 'ANSIBLE'];
875 case 'OpenStack Actions':
876 this.deviceProtocols = ['', 'OpenStack'];
878 case 'ConfigScaleOut':
879 this.deviceProtocols = ['', 'CHEF', 'ANSIBLE', 'NETCONF-XML', 'RESTCONF'];
882 this.deviceProtocols = ['', 'ANSIBLE', 'CHEF', 'NETCONF-XML', 'RESTCONF', 'CLI'];
883 this.actionHealthCheck = false;
887 //Modal pop up for action change with values entered.
888 actionChange(data, content, userForm) {
889 this.disableGrpNotationValue = false
893 if ((userForm.valid) && this.oldAction != '' && this.oldAction != undefined) {
894 this.actionChanged = true;
895 this.modalService.open(content, { backdrop: 'static', keyboard: false }).result.then(res => {
897 this.currentAction = this.referenceDataObject.action;
898 this.referenceDataObject.action = this.oldAction;
899 $('#saveToAppc').click();//make sure the save all is done before the tempall obj is saved form the API
900 this.toggleIdentifier(data)
901 this.oldAction = this.currentAction;// this.referenceDataObject.action + '';
902 this.referenceDataObject.action = this.currentAction
904 this.populateExistinAction(data);
905 if (this.oldAction === 'OpenStack Actions') {
907 this.uploadedDataArray = [];
908 this.remUploadedDataArray = [];
909 this.firstArrayElement = [];
910 this.uploadFileName = '';
911 //this.tempAllData = [];
914 this.refernceScopeObj.from = '';
915 this.getArtifactsOpenStack()
917 this.toggleIdentifier(data)
918 this.currentAction = this.referenceDataObject.action;
919 this.populateExistinAction(data);
920 this.resetVmsForScaleout(data);
921 this.oldAction = this.referenceDataObject.action + '';
924 this.refernceScopeObj.from = '';
927 // Enable or Block Template and PD Tabs
928 if (this.currentAction == 'ConfigScaleOut' && this.templateIdentifier) {
929 let referenceDataObjectTemp = this.referenceDataObject;
930 referenceDataObjectTemp['template-id'] = this.templateIdentifier;
931 this.buildDesignComponent.getRefData(referenceDataObjectTemp);
933 this.buildDesignComponent.getRefData(this.referenceDataObject);
937 this.actionChanged = true;
938 this.currentAction = this.referenceDataObject.action;
939 this.oldAction = this.referenceDataObject.action + '';
940 this.populateExistinAction(data);
941 this.resetVmsForScaleout(data);
942 this.toggleIdentifier(data);
944 // Enable or Block Template and PD Tabs
945 if (this.currentAction == 'ConfigScaleOut' && this.templateIdentifier) {
946 let referenceDataObjectTemp = this.referenceDataObject;
947 referenceDataObjectTemp['template-id'] = this.templateIdentifier;
948 this.buildDesignComponent.getRefData(referenceDataObjectTemp);
950 this.buildDesignComponent.getRefData(this.referenceDataObject);
957 if (data == 'ConfigScaleOut') {
958 this.groupAnotationType = ['', 'first-vnfc-name', 'fixed-value', 'relative-value', 'existing-group-name'];
960 this.groupAnotationType = ['', 'first-vnfc-name', 'fixed-value', 'relative-value'];
962 if (data == 'OpenStack Actions') {
963 this.buildDesignComponent.tabs = [
966 name: 'Reference Data',
971 this.buildDesignComponent.tabs = [
973 name: 'Reference Data',
977 url: 'templates/myTemplates',
979 name: 'Parameter Definition',
980 url: 'parameterDefinitions/create'
987 if (data == 'Configure' || data == 'ConfigModify') {
988 this.nonConfigureAction = false;
990 this.nonConfigureAction = true;
994 deviceProtocolChange() {
995 // Enable or Block Template and PD Tabs
996 this.buildDesignComponent.getRefData(this.referenceDataObject)
999 // For the issue with multiple template changes
1000 idChange(data, content, userForm) {
1004 // Enable or Block Template and PD Tabs
1005 let referenceDataObjectTemp = this.referenceDataObject;
1006 referenceDataObjectTemp['template-id'] = data;
1007 this.buildDesignComponent.getRefData(referenceDataObjectTemp);
1009 if ((userForm.valid) && this.oldtemplateIdentifier != '' && this.oldtemplateIdentifier != undefined) {
1010 this.currentAction = "ConfigScaleOut"
1011 this.oldtemplateIdentifier = this.templateIdentifier
1012 let referenceObject = this.prepareReferenceObject();
1013 this.actionChanged = true;
1014 if (this.templateIdentifier) {
1015 this.modalService.open(content).result.then(res => {
1017 this.validateTempAllData();
1018 let theJSON = JSON.stringify(this.tempAllData, null, '\t');
1019 let fileName = 'reference_AllAction_' + referenceObject.scopeName + '_' + '0.0.1V.json';
1020 this.uploadArtifact(JSON.stringify({ reference_data: this.tempAllData }), this.tempAllData[this.tempAllData.length - 1], fileName);
1021 var templateData = JSON.stringify(this.appData.template.templateData);
1022 var nameValueData = JSON.stringify(this.appData.template.nameValueData);
1023 var pdData = JSON.stringify(this.appData.pd);
1024 if (templateData != '{}' && templateData != null && templateData != undefined) this.saveTemp();
1025 if (nameValueData != '{}' && nameValueData != null && nameValueData != undefined) this.saveNameValue();
1026 if (pdData != '{}' && pdData != null && pdData != undefined) this.savePd();
1028 this.clearVnfcData()
1029 this.refernceScopeObj.from = '';
1033 this.refernceScopeObj.from = '';
1041 // get the value and save the userid and persist it.
1042 this.clearTemplateCache();
1043 this.clearPdCache();
1044 this.appData = { reference: {}, template: { templateData: {}, nameValueData: {} }, pd: {} };
1045 this.downloadData = {
1047 template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' },
1048 pd: { pdData: '', pdFileName: '' }
1052 clearTemplateCache() {
1053 this.mappingEditorService.setTemplateMappingDataFromStore(undefined);
1054 localStorage['paramsContent'] = '{}';
1057 this.mappingEditorService.setParamContent(undefined);
1058 this.paramShareService.setSessionParamData(undefined);
1065 { url: environment.getDesigns, data: this.appData.template.templateData })
1066 .subscribe(resp => {
1067 if (resp.output.status.code === '400' && resp.output.status.message === 'success') {
1068 this.nService.success('Status', 'Successfully uploaded the Template Data');
1070 if (resp.output.status.code === '401') {
1071 this.nService.warn('Status', 'Error in saving the Template to Appc');
1075 (err) => this.nService.error('Status', 'Error Connecting to the APPC Network'));
1083 url: environment.getDesigns, data: this.appData.template.nameValueData
1085 .subscribe(resp => {
1086 if (resp.output.status.code === '400' && resp.output.status.message === 'success') {
1087 this.nService.success('Status', 'Successfully uploaded the Name Value Pairs');
1089 if (resp.output.status.code === '401') {
1090 this.nService.warn('Status', 'Error in saving the Name value pairs to Appc');
1094 this.nService.error('Status', 'Error Connecting to the APPC Network');
1104 url: environment.getDesigns, data: this.appData.pd
1106 .subscribe(resp => {
1107 if (resp.output.status.code === '400' && resp.output.status.message === 'success') {
1108 this.nService.success('Status', 'Successfully uploaded PD file');
1110 if (resp.output.status.code === '401') {
1111 this.nService.warn('Status', 'Error in saving the PD to Appc');
1115 this.nService.error('Status', 'Error Connecting to the APPC Network');
1120 openModel(toShow: any, message: any, title: any) {
1121 this.modalComponent.isShow = toShow;
1122 this.modalComponent.message = message;
1123 this.modalComponent.title = title;
1127 $('#inputFile').trigger('click');
1130 excelBrowseOption() {
1131 $('#excelInputFile').trigger('click');
1135 $('#identifierModal').modal();
1139 if (!(this.referenceDataObject['template-id-list'])) {
1140 this.referenceDataObject['template-id-list'] = [];
1142 if (!(this.referenceDataObject['template-id-list'].indexOf(this.templateId.trim()) > -1)) {
1143 this.referenceDataObject['template-id-list'].push(this.templateId.trim());
1148 this.referenceDataObject.vm = [];
1152 // this.referenceDataObject.vm = this.referenceDataObject.vm;
1155 resetGroupNotation() {
1156 if (this.Sample['group-notation-type'] == "existing-group-name") {
1157 this.Sample['group-notation-value'] = ""
1158 this.disableGrpNotationValue = true
1160 this.disableGrpNotationValue = false
1164 resetVmsForScaleout(action) {
1165 //reset currentform vms based on action
1166 if (action == "ConfigScaleOut" || action == "Configure") {
1167 let ConfigScaleOutIndex = this.tempAllData.findIndex(obj => {
1168 return obj['action'] == action
1170 if (ConfigScaleOutIndex > -1) {
1171 this.referenceDataObject.vm = this.tempAllData[ConfigScaleOutIndex].vm
1173 if (this.actionChanged) {
1174 this.referenceDataObject.vm = []
1180 resetParamsOnVnfcType() {
1182 //if only vnf is there
1183 if (this.referenceDataObject.scope['vnfc-type'] == '' || this.referenceDataObject.scope['vnfc-type'] == null || this.referenceDataObject.scope['vnfc-type'] == 'null') {
1184 scopeName = this.referenceDataObject.scope['vnf-type'];
1185 this.referenceDataObject.scope['vnfc-type'] = '';
1186 this.referenceDataObject['action-level'] = 'vnf';
1187 this.referenceDataObject['scopeType'] = 'vnf-type';
1189 //if VNFC is entered set action level & Scope type to VNFC for configure and configure modify, and default the values to vnf and vnf type for all other actions
1191 scopeName = this.referenceDataObject.scope['vnfc-type'];
1192 if (this.referenceDataObject.action == 'Configure' || this.referenceDataObject.action == 'ConfigModify') {
1193 this.referenceDataObject['action-level'] = 'vnfc';
1194 this.referenceDataObject['scopeType'] = 'vnfc-type';
1196 this.referenceDataObject['action-level'] = 'vnf';
1197 this.referenceDataObject['scopeType'] = 'vnf-type';
1200 //replacing / with _ and removing spaces in the scopeName
1202 scopeName = scopeName.replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '');
1206 decideExtension(obj) {
1207 //marking the extension based on the device-protocol selected by the user
1208 let extension = '.json';
1209 switch (obj['device-protocol']) {
1213 extension = '.json';
1222 prepareArtifactList(scopeName, extension) {
1223 this.referenceDataObject['artifact-list'] = [];
1224 //preparing the artifact list array file names along with extension
1225 let config_template_fileName = this.referenceDataObject.action + '_' + scopeName + '_' + '0.0.1V.' + extension;
1226 let pd_fileName = this.referenceDataObject.action + '_' + scopeName + '_' + '0.0.1V.yaml';
1227 let reference_fileName = this.referenceDataObject.action + '_' + scopeName + '_' + '0.0.1V.json';
1228 let configTemplate = {
1229 'artifact-name': 'template_' + config_template_fileName,
1230 'artifact-type': 'config_template'
1233 'artifact-name': 'pd_' + pd_fileName,
1234 'artifact-type': 'parameter_definitions'
1236 if (this.referenceDataObject.action != 'ConfigScaleOut') {
1237 this.referenceDataObject['artifact-list'].push(configTemplate,
1241 let identifiers = this.referenceDataObject['template-id-list'];
1243 for (var x = 0; x < identifiers.length; x++) {
1244 //for replacing spaces and "/" with "_"
1245 identifiers[x] = identifiers[x].replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '');
1246 pd_fileName = this.referenceDataObject.action + '_' + scopeName + '_' + '0.0.1V_' + identifiers[x] + '.yaml';
1247 config_template_fileName = this.referenceDataObject.action + '_' + scopeName + '_' + '0.0.1V_' + identifiers[x] + '.' + extension;
1250 'artifact-name': 'template_' + config_template_fileName,
1251 'artifact-type': 'config_template'
1254 'artifact-name': 'pd_' + pd_fileName,
1255 'artifact-type': 'parameter_definitions'
1257 this.referenceDataObject['artifact-list'].push(configTemplate,
1265 deleteVmsforNonActions(newObj, action) {
1266 let configureObject = (action == 'Configure');
1267 let ConfigScaleOut = (action == 'ConfigScaleOut');
1268 //delete VM's if selected action is not configure.
1269 if (!ConfigScaleOut && !configureObject && this.tempAllData.length != 0) {
1270 if (ConfigScaleOut) {
1275 if (ConfigScaleOut) {
1277 delete newObj['template-id-list'];
1282 pushOrReplaceTempData(newObj, action) {
1283 let actionObjIndex = this.tempAllData.findIndex(obj => {
1284 return obj['action'] == action;
1286 if (newObj.action != 'HealthCheck') {
1287 delete newObj['url'];
1290 if (actionObjIndex > -1) {
1291 this.tempAllData[actionObjIndex] = newObj;
1292 this.mappingEditorService.saveLatestAction(this.tempAllData[actionObjIndex]);
1293 if (newObj.action == "ConfigScaleOut") {
1294 this.mappingEditorService.saveLatestIdentifier(this.templateIdentifier);
1297 this.templateIdentifier = ('')
1298 this.mappingEditorService.saveLatestIdentifier(this.templateIdentifier)
1301 if (newObj.action != '') {
1302 this.tempAllData.push(newObj);
1303 this.mappingEditorService.saveLatestAction(newObj);
1304 if (newObj.action == "ConfigScaleOut") {
1305 this.mappingEditorService.saveLatestIdentifier(this.templateIdentifier);
1308 this.templateIdentifier = ('')
1309 this.mappingEditorService.saveLatestIdentifier(this.templateIdentifier)
1316 addAllActionObj(newObj, scopeName) {
1317 //Creating all action block to allow mulitple actions at once
1319 action: 'AllAction',
1320 'action-level': 'vnf',
1321 scope: newObj.scope,
1323 'artifact-name': 'reference_AllAction' + '_' + scopeName + '_' + '0.0.1V.json',
1324 'artifact-type': 'reference_template'
1327 let allActionIndex = this.tempAllData.findIndex(obj => {
1328 return obj['action'] == 'AllAction';
1330 if (allActionIndex > -1) {
1331 this.tempAllData[allActionIndex] = allAction;
1333 this.tempAllData.push(allAction);
1338 if (this.uploadedDataArray && this.uploadedDataArray != undefined && this.uploadedDataArray.length != 0) {
1339 if (this.tempAllData && this.tempAllData != undefined) {
1340 for (var i = 0; i < this.tempAllData.length; i++) {
1342 if (this.tempAllData[i].action === 'AllAction') {
1346 result = this.checkIfelementExistsInArray(this.tempAllData[i].action, this.actions);
1349 this.tempAllData.splice(i, 1);
1355 this.addVmCapabilitiesData();
1359 trackByFn(index, item) {
1362 getArtifactsOpenStack() {
1364 var vnfcFunctionCodeArrayList = [];
1365 var vnfcSetArray=[];
1366 for (var i = 0; i < this.tempAllData.length; i++) {
1367 if (!this.checkIfelementExistsInArray(this.tempAllData[i].action, this.actions) && (this.tempAllData[i].action != 'AllAction')) {
1368 var vnfcFunctionCodeArray = this.tempAllData[i]["vnfc-function-code-list"]
1369 vnfcFunctionCodeArrayList.push([this.tempAllData[i].action].concat(this.tempAllData[i]["vnfc-function-code-list"]))
1371 if(this.tempAllData[i].action==='OpenStack Actions')
1373 vnfcSetArray=this.tempAllData[i]['firstRowVmSpreadSheet']
1379 let vnfcSetArrayLen = vnfcSetArray.length;
1381 for (let i = 0; i < vnfcFunctionCodeArrayList.length; i++) {
1382 let element = vnfcFunctionCodeArrayList[i];
1383 for (let j = 1; j < element.length; j++) {
1384 for (let k = j; k < vnfcSetArrayLen; k++) {
1385 if (element[j] === vnfcSetArray[k]) {
1389 element.splice(j, 0, '');
1395 this.firstArrayElement = vnfcSetArray;
1396 this.remUploadedDataArray = vnfcFunctionCodeArrayList;