2 ============LICENSE_START==========================================
3 ===================================================================
4 Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
5 ===================================================================
7 Unless otherwise specified, all software contained herein is licensed
8 under the Apache License, Version 2.0 (the License);
9 you may not use this software except in compliance with the License.
10 You may obtain a copy of the License at
12 http://www.apache.org/licenses/LICENSE-2.0
14 Unless required by applicable law or agreed to in writing, software
15 distributed under the License is distributed on an "AS IS" BASIS,
16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 See the License for the specific language governing permissions and
18 limitations under the License.
19 ============LICENSE_END============================================
22 import * as XLSX from 'xlsx';
23 import * as _ from 'underscore';
24 import { ActivatedRoute, Router } from '@angular/router';
25 import { Component, OnInit, ViewChild } from '@angular/core';
26 import { BuildDesignComponent } from '../build-artifacts.component';
27 import { HttpUtilService } from '../../../shared/services/httpUtil/http-util.service';
28 import { Location } from '@angular/common';
29 import { MappingEditorService } from '../../..//shared/services/mapping-editor.service';
30 import { ModalComponent } from '../../../shared/modal/modal.component';
31 import { NgProgress } from 'ngx-progressbar';
32 import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
33 import { NotificationService } from '../../../shared/services/notification.service';
34 import { NotificationsService } from 'angular2-notifications';
35 import { ParamShareService } from '../../..//shared/services/paramShare.service';
36 import { environment } from '../../../../environments/environment';
37 import { saveAs } from 'file-saver';
39 type AOA = Array<Array<any>>;
42 selector: 'reference-dataform',
43 templateUrl: './reference-dataform.component.html',
44 styleUrls: ['./reference-dataform.component.css']
46 export class ReferenceDataformComponent implements OnInit {
47 @ViewChild(ModalComponent) modalComponent: ModalComponent;
48 public showUploadStatus: boolean = false;
49 public fileUploaded: boolean = false;
50 public uploadedData: any;
51 public statusMsg: string;
52 public uploadStatus: boolean = false;
53 public isCollapsedContent: boolean = true;
54 public vnfcCollLength: number = 0;
55 public vfncCollection = [];
57 public actionType: any;
58 numberTest: RegExp = /^[^.a-z]+$/;
59 public numberOfVmTest: boolean = true;
60 public tempAllData = [];
61 disableGrpNotationValue: boolean;
62 public noRefData = false;
63 public disableRetrieve = false;
64 public getRefStatus = false;
65 public uploadStatusError: boolean;
66 public showUploadErrorStatus: boolean;
67 public noData: string;
69 public appData = { reference: {}, template: { templateData: {}, nameValueData: {} }, pd: {} };
70 public downloadData = {
72 template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' },
73 pd: { pdData: '', pdFileName: '' }
76 public uploadFileName: any;
77 public addVmClickedFlag: boolean = false;
78 public getExcelUploadStatus: boolean = false;
79 public uploadedDataArray: any;
80 public actionFlag = false;
83 nonConfigureAction: any;
86 public actionLevels = [
91 identifierDrpValues: any = [];
92 //settings for the notifications.
95 showProgressBar: true,
100 //initializing this object to contain all the parameters to be captured
101 public referenceDataObject = {
103 'action-level': 'vnf',
104 scope: { 'vnf-type': '', 'vnfc-type': '' },
107 'device-protocol': '',
112 public refernceScopeObj = { sourceType: '', from: '', to: '' };
113 public actions = ['', 'Configure', 'ConfigModify', 'ConfigBackup', 'ConfigRestore', 'GetRunningConfig', 'HealthCheck', 'StartApplication', 'StopApplication', 'QuiesceTraffic', 'ResumeTraffic', 'UpgradeBackout', 'UpgradeBackup', 'UpgradePostCheck', 'UpgradePreCheck', 'UpgradeSoftware', 'OpenStack Actions', 'ConfigScaleOut'];
114 public groupAnotationValue = ['', 'Pair'];
115 public groupAnotationType = ['', 'first-vnfc-name', 'fixed-value', 'relative-value'];
116 public deviceProtocols = ['', 'ANSIBLE', 'CHEF', 'NETCONF-XML', 'REST', 'CLI', 'RESTCONF'];
117 public deviceTemplates = ['', 'Y', 'N'];
118 public sourceTypeColl = ['', 'vnfType', 'vnfcType'];
119 public ipAddressBoolean = ['', 'Y', 'N'];
120 public Sample: any = {
121 'vnfc-instance': '1',
122 'vnfc-function-code': '',
123 'ipaddress-v4-oam-vip': '',
124 'group-notation-type': '',
125 'group-notation-value': ''
127 hideModal: boolean = false;
129 public uploadTypes = [{
130 value: 'Reference Data',
131 display: 'Sample Json Param File'
134 value: 'Mapping Data',
135 display: 'Sample Json Param File'
138 public selectedUploadType: string = this.uploadTypes[0].value;
139 public vnfcTypeData: string = '';
140 public title: string;
141 public allowAction: boolean = true;
142 public actionExist: boolean = false;
143 public disableVnftype: boolean = false;
144 public otherActions: boolean = false;
145 public actionHealthCheck: boolean = false;
146 public actionChanged: boolean = false;
147 public initialAction: string = '';
148 public noCacheData: boolean;
149 public updateParams: any;
150 public vnfParams: any;
151 public firstArrayElement = [];
152 public remUploadedDataArray = [];
153 isConfigScaleOut = false
155 constructor(private buildDesignComponent: BuildDesignComponent, private httpUtils: HttpUtilService, private route: Router, private location: Location, private activeRoutes: ActivatedRoute, private notificationService: NotificationService,
156 private paramShareService: ParamShareService, private mappingEditorService: MappingEditorService, private modalService: NgbModal, private nService: NotificationsService, private ngProgress: NgProgress) {
161 let path = this.location.path;
162 this.title = 'Reference Data';
163 this.referenceDataObject = {
165 'action-level': 'vnf',
166 scope: { 'vnf-type': '', 'vnfc-type': '' },
169 'device-protocol': '',
174 this.updateParams = sessionStorage.getItem('updateParams');
175 let cacheData = this.mappingEditorService.referenceNameObjects;
176 if (cacheData != undefined && cacheData != null && cacheData.length > 0) {
177 this.tempAllData = cacheData;
178 // console.log("latest action")
179 // console.log(this.mappingEditorService.latestAction)
180 if (this.mappingEditorService.latestAction != undefined) {
181 this.referenceDataObject = this.mappingEditorService.latestAction;
182 this.toggleIdentifier(this.referenceDataObject.action);
183 //this.referenceDataObject['template-id-list'] = this.mappingEditorService.identifier
184 //use these commented objects to be used in template and pd pages
185 //this.templateIdentifier = this.mappingEditorService.identifier
186 this.refernceScopeObj.sourceType = this.referenceDataObject['scopeType'];
187 this.oldAction = this.referenceDataObject.action;
188 this.populateExistinAction(this.referenceDataObject.action);
190 } else if (this.updateParams != 'undefined') {
193 var appData = this.mappingEditorService.appDataObject;
194 if (appData != null || appData != undefined) this.appData = appData;
195 var downloadData = this.mappingEditorService.downloadDataObject;
196 if (downloadData != null || downloadData != undefined) this.downloadData = downloadData;
197 this.vnfParams = JSON.parse(sessionStorage.getItem('vnfParams'));
198 if (this.vnfParams && this.vnfParams.vnfType) {
199 this.referenceDataObject['scope']['vnf-type'] = this.vnfParams.vnfType;
201 if (this.vnfParams && this.vnfParams.vnfcType) {
202 this.referenceDataObject['scope']['vnfc-type'] = this.vnfParams.vnfcType;
204 this.uploadedDataArray = [];
205 this.remUploadedDataArray = [];
206 this.firstArrayElement = [];
207 this.uploadFileName = '';
208 this.templateIdentifier = this.mappingEditorService.identifier
209 //this.tempAllData = [];
211 toggleIdentifier(data) {
212 if (data == 'ConfigScaleOut') {
213 this.isConfigScaleOut = true
216 this.isConfigScaleOut = false
220 //to retrive the data from appc and assign it to the vaiables, if no data display the message reterived from the API
223 let payload = JSON.parse(sessionStorage.getItem('updateParams'));
224 payload['userID'] = localStorage['userId'];
225 payload = JSON.stringify(payload);
229 'request-id': localStorage['apiToken'],
230 'action': 'getArtifact',
235 this.ngProgress.start();
236 this.httpUtils.post({
237 url: environment.getDesigns,
239 }).subscribe(resp => {
240 if (resp.output.data.block != undefined) {
241 this.nService.success('Status', 'data fetched ');
242 let artifactInfo = JSON.parse(resp.output.data.block).artifactInfo[0];
243 let reference_data = JSON.parse(artifactInfo['artifact-content'])['reference_data'][0];
244 this.referenceDataObject = reference_data;
245 // console.log('reference data obj==' + JSON.stringify(this.referenceDataObject));
246 this.refernceScopeObj.sourceType = this.referenceDataObject['scopeType'];
247 this.mappingEditorService.getReferenceList().push(JSON.parse(artifactInfo['artifact-content']));
248 this.tempAllData = JSON.parse(artifactInfo['artifact-content'])['reference_data'];
249 this.oldAction = this.referenceDataObject.action;
250 if (this.referenceDataObject.action === 'OpenStack Actions') {
251 this.deviceProtocols = ['', 'OpenStack'];
252 this.buildDesignComponent.tabs = [
255 name: 'Reference Data',
260 this.buildDesignComponent.tabs = [
262 name: 'Reference Data',
266 url: 'templates/myTemplates',
268 name: 'Parameter Definition',
269 url: 'parameterDefinitions/create'
276 // console.log('tempalldata===' + JSON.stringify(this.tempAllData));
278 this.nService.success('Status', 'Sorry !!! I dont have any artifact Named : ' + (JSON.parse(payload))['artifact-name']);
280 this.ngProgress.done();
284 this.nService.warn('status', 'error while reteriving artifact');
287 this.ngProgress.done();
291 //reinitializing the required values
293 let referenceObject = this.prepareReferenceObject();
294 this.mappingEditorService.changeNavAppData(this.appData);
295 this.mappingEditorService.changeNavDownloadData(this.downloadData);
296 this.uploadedDataArray = [];
297 this.remUploadedDataArray = [];
298 this.firstArrayElement = [];
299 this.uploadFileName = '';
302 numberValidation(event: any) {
303 // // console.log(this.numberTest.test(event));
304 if (this.numberTest.test(event) && event != 0) {
305 this.numberOfVmTest = true;
308 this.numberOfVmTest = false;
312 updateSessionValues(event: any, type: string) {
313 if (type === 'action') {
314 sessionStorage.setItem('action', event);
316 if (type === 'vnfType') {
317 sessionStorage.setItem('vnfType', event);
321 addVnfcData(vmNumber: number) {
323 'vnfc-instance': this.referenceDataObject.vm[vmNumber].vnfc.length + 1,
324 'vnfc-type': this.vnfcTypeData,
325 'vnfc-function-code': '',
326 'ipaddress-v4-oam-vip': '',
327 'group-notation-type': '',
328 'group-notation-value': ''
330 this.referenceDataObject.vm[vmNumber].vnfc.push(newObj);
333 //to remove the VM's created by the user
334 removeFeature(vmNumber: any, index: any,templateId) {
335 if(this.referenceDataObject.action == "Configure"){
336 this.referenceDataObject.vm.splice(vmNumber, 1);
337 this.referenceDataObject.vm.forEach((obj,arrIndex)=>{
338 if(arrIndex>=vmNumber){
339 obj["vm-instance"] = obj["vm-instance"]-1
342 console.log(this.referenceDataObject.vm)
344 let data = this.referenceDataObject.vm.filter(obj=>{
345 return obj['template-id'] == templateId;
347 this.referenceDataObject.vm.splice(data[index]['vm-instance'], 1);
348 this.referenceDataObject.vm.forEach((obj,arrIndex)=>{
350 obj["vm-instance"] = arrIndex+1
356 //add new VM's to the configure
359 var vnfcObj = JSON.parse(JSON.stringify(this.Sample));
360 let mberOFVm = Number(this.refernceScopeObj.from);
361 let arrlength = this.referenceDataObject.vm.length;
362 mberOFVm = arrlength + mberOFVm;
363 for (var i = (arrlength); i < mberOFVm; i++) {
364 if (this.referenceDataObject.action == 'ConfigScaleOut') {
365 arr.push({ 'template-id': this.templateIdentifier, 'vm-instance': (i + 1), vnfc: [Object.assign({}, this.Sample)] });
367 arr.push({ 'vm-instance': (i + 1), vnfc: [Object.assign({}, this.Sample)] });
370 //this.referenceDataObject.vm.splice(arrlength, 0, ...arr);
371 this.referenceDataObject.vm = this.referenceDataObject.vm.concat(arr); //splice(arrlength, 0, ...arr);
374 //Reference object to create reference data
375 prepareReferenceObject(isSaving?:any){
376 let scopeName = this. resetParamsOnVnfcType();
377 let extension = this.decideExtension();
378 this.prepareArtifactList(scopeName,extension);
380 if (this.referenceDataObject.action === 'OpenStack Actions') {
381 this.referenceDataObject['template'] = 'N';
382 this.referenceDataObject['artifact-list'] = [];
384 //ditaching the object from the form and processing pfurther
385 let newObj = $.extend(true, {}, this.referenceDataObject);
386 let action = this.referenceDataObject.action;
387 //preparing Obj for save/download
388 newObj = this.deleteVmsforNonActions(newObj,action)
389 this.pushOrReplaceTempData(newObj,action);
390 this. addAllActionObj(newObj,scopeName);
392 //saving data to service
393 this.mappingEditorService.getReferenceList().push(JSON.parse(JSON.stringify(this.referenceDataObject)));
394 this.buildDesignComponent.updateAccessUpdatePages(this.referenceDataObject.action, this.mappingEditorService.getReferenceList());
395 this.mappingEditorService.changeNav(this.tempAllData);
396 //on action change or template identifier change reset the form by restting values of Reference data object
397 this.resetVmsForScaleout(this.currentAction)
398 return { totlaRefDtaa: this.tempAllData, scopeName: scopeName };
401 public checkIfelementExistsInArray(element, array) {
402 //// console.log("Element==" + element)
403 var result: boolean = false;
405 array.forEach(function (item) {
406 // // console.log("Item==" + item)
407 if (element === item) {
408 // console.log('Element==' + element + 'Item==' + item);
417 /* // console.log("This uploaded array==" + JSON.stringify(this.uploadedDataArray))
418 // // console.log("This template data before==" + JSON.stringify(this.tempAllData))
419 if (this.uploadedDataArray && this.uploadedDataArray != undefined && this.uploadedDataArray.length!=0) {
420 /* for (var i = 0; i < this.uploadedDataArray.length; i++) {
421 var action = this.uploadedDataArray[i][0];
422 for (var j = 0; j < this.tempAllData.length; j++) {
423 if (action === this.tempAllData[j].action) {
424 this.tempAllData.splice(j);
425 // console.log("This template data===" + this.tempAllData[j]);
429 if (this.tempAllData && this.tempAllData != undefined) {
430 for (var i = 0; i < this.tempAllData.length; i++) {
431 // alert(this.checkIfelementExistsInArray(this.tempAllData[i].action,this.actions))
432 var result = this.checkIfelementExistsInArray(this.tempAllData[i].action, this.actions);
433 if (this.tempAllData[i].action === "AllAction") result = true;
435 // console.log("Removing VM action==" + this.tempAllData[i].action)
436 this.tempAllData.splice(i, 1);
442 // // console.log("This template data after==" + JSON.stringify(this.tempAllData))
443 /* wire up file reader */
444 const target: DataTransfer = <DataTransfer>(evt.target);
445 //// console.log("filename========" + evt.target.files[0].name)
446 this.uploadFileName = evt.target.files[0].name;
447 var fileExtension = this.uploadFileName.substr(this.uploadFileName.lastIndexOf('.') + 1);
448 if (target.files.length != 1) {
449 throw new Error('Cannot upload multiple files on the entry');
451 if (fileExtension.toUpperCase() === 'XLS' || fileExtension.toUpperCase() === 'XLSX') {
452 const reader = new FileReader();
453 reader.onload = (e: any) => {
455 const bstr = e.target.result;
456 // // console.log("print 1---" + bstr);
457 const wb = XLSX.read(bstr, { type: 'binary' });
458 // // console.log("print 2---" + JSON.stringify(wb));
459 /* grab first sheet */
460 const wsname = wb.SheetNames[0];
461 // // console.log("Name:---" + wsname);
462 const ws = wb.Sheets[wsname];
466 let arrData = (<AOA>(XLSX.utils.sheet_to_json(ws, { header: 1 })));
467 //// console.log("row======" + (XLSX.utils.sheet_to_json(ws, { header: 1 })).toString())
468 // // console.log("Array data---" + JSON.stringify(arrData));
469 this.uploadedDataArray = arrData;
470 this.firstArrayElement = arrData[0];
471 var remUploadedDataArray = arrData;
472 remUploadedDataArray.shift();
473 this.remUploadedDataArray = remUploadedDataArray;
474 if (arrData != null) {
475 this.getExcelUploadStatus = true;
476 this.nService.success('Success', 'Vm capabilities data uploaded successfully');
480 this.nService.success('Error', 'Empty Vm capabilities file uploaded');
483 reader.readAsBinaryString(target.files[0]);
484 // console.log('TARGET files---' + JSON.stringify(evt.target));
487 this.nService.error('Error', 'Incorrect VM capabilities file uploaded');
492 addVmCapabilitiesData() {
493 for (var i = 0; i < this.uploadedDataArray.length; i++) {
494 var vnfcFuncCodeArray = [];
495 var data = this.uploadedDataArray[i];
496 for (var j = 1; j < data.length; j++) {
497 // // console.log("Data " +j +" is "+ JSON.stringify(data[j]))
498 if (data[j] != undefined) {
499 if (data[j].toUpperCase() === 'Y') {
500 vnfcFuncCodeArray.push(this.firstArrayElement[j]);
501 //vnfcFuncCodeArray.push({name:this.firstArrayElement[j]});
505 var action = this.uploadedDataArray[i][0];
506 if (action && action != undefined) {
509 'action-level': 'vm',
511 'vnf-type': this.referenceDataObject['scope']['vnf-type'], //need to confirm what should be this value
514 'vnfc-function-code-list': vnfcFuncCodeArray,
516 'device-protocol': 'OS'
519 this.tempAllData.push(json);
526 save(form: any, isValid: boolean) {
527 if (this.referenceDataObject.action === '') {
528 this.nService.error('Error', 'Select a valid Action');
531 if (this.referenceDataObject['device-protocol'] === '') {
532 this.nService.error('Error', 'Select a valid Device protocol');
537 let referenceObject = this.prepareReferenceObject();
538 let theJSON = JSON.stringify({ 'reference_data': this.tempAllData }, null, '\t');
539 let uri = 'data:application/json;charset=UTF-8,' + encodeURIComponent(theJSON);
540 this.downloadData.reference = theJSON;
541 this.validateTempAllData();
542 var blob = new Blob([theJSON], {
545 let fileName = 'reference_AllAction_' + referenceObject.scopeName + '_' + '0.0.1V.json';
546 saveAs(blob, fileName);
547 var templateData = JSON.stringify(this.downloadData.template.templateData);
548 var nameValueData = JSON.stringify(this.downloadData.template.nameValueData);
549 var pdData = this.downloadData.pd.pdData;
550 if (templateData != '{}' && templateData != null && templateData != undefined) this.downloadTemplate();
551 if (nameValueData != '{}' && nameValueData != null && nameValueData != undefined) this.downloadNameValue();
552 if (pdData != '' && pdData != null && pdData != undefined) this.downloadPd();
557 var fileName = this.downloadData.template.templateFileName;
558 var theJSON = this.downloadData.template.templateData;
559 if (fileName != null || fileName != '') {
560 var fileExtensionArr = fileName.split('.');
561 var blob = new Blob([theJSON], {
562 type: 'text/' + fileExtensionArr[1]
564 saveAs(blob, fileName);
568 downloadNameValue() {
569 var fileName = this.downloadData.template.nameValueFileName;
570 var theJSON = this.downloadData.template.nameValueData;
571 var blob = new Blob([theJSON], {
575 saveAs(blob, fileName);
579 let fileName = this.downloadData.pd.pdFileName;
580 let theJSON = this.downloadData.pd.pdData;
581 var blob = new Blob([theJSON], {
585 saveAs(blob, fileName);
588 saveToAppc(valid, form,event) {
589 if (this.referenceDataObject.action === '') {
590 this.nService.error('Error', 'Select a valid Action');
593 if (this.referenceDataObject['device-protocol'] === '') {
594 this.nService.error('Error', 'Select a valid Device protocol');
599 form._submitted = true;
602 let referenceObject = this.prepareReferenceObject(true);
603 this.validateTempAllData();
604 let theJSON = JSON.stringify(this.tempAllData, null, '\t');
605 let fileName = 'reference_AllAction_' + referenceObject.scopeName + '_' + '0.0.1V.json';
606 this.uploadArtifact(JSON.stringify({ reference_data: this.tempAllData }), this.tempAllData[this.tempAllData.length - 1], fileName);
607 var templateData = JSON.stringify(this.appData.template.templateData);
608 var nameValueData = JSON.stringify(this.appData.template.nameValueData);
609 var pdData = JSON.stringify(this.appData.pd);
610 if (templateData != '{}' && templateData != null && templateData != undefined) this.saveTemp();
611 if (nameValueData != '{}' && nameValueData != null && nameValueData != undefined) this.saveNameValue();
612 if (pdData != '{}' && pdData != null && pdData != undefined) this.savePd();
613 if (this.actionChanged) {
614 this.referenceDataObject.action = this.currentAction;
615 this.populateExistinAction(this.referenceDataObject.action);
616 this.actionChanged = false;
621 this.nService.warn('status', 'unable to save the artifact');
625 validateTempAllData() {
626 if (this.tempAllData) {
627 var updatedData = [];
628 this.tempAllData.forEach(data => {
630 updatedData.push(data);
633 this.tempAllData = updatedData;
637 appendSlashes(artifactData) {
638 return artifactData.replace(/"/g, '\\"');
641 uploadArtifact(artifactData, dataJson, fileName) {
643 let slashedPayload = this.appendSlashes(artifactData);
644 let newPyaload = '{"userID": "' + localStorage['userId'] + '","vnf-type" : "' + dataJson['scope']['vnf-type'] + '","action" : "AllAction","artifact-name" : "' + fileName + '","artifact-type" : "APPC-CONFIG","artifact-version" : "0.1","artifact-contents" :" ' + slashedPayload + '"}';
648 'request-id': localStorage['apiToken'],
649 'action': 'uploadArtifact',
650 'payload': newPyaload,
654 this.ngProgress.start();
655 this.httpUtils.post({
656 url: environment.getDesigns,
658 }).subscribe((resp) => {
659 if (resp != null && resp.output.status.code == '400') {
660 window.scrollTo(0, 0);
661 this.nService.success('Status', 'successfully uploaded the Reference Data');
663 this.nService.warn('Status', 'Error while saving Reference Data');
665 this.uploadStatusError = false;
666 this.getRefStatus = false;
667 this.ngProgress.done();
669 this.nService.error('Status', 'Error Connecting to the APPC Network');
670 window.scrollTo(0, 0);
672 this.appData.reference = payload;
674 this.ngProgress.done();
679 if (sessionStorage.getItem('updateParams') != 'undefined') {
681 this.noCacheData = false;
683 this.noCacheData = true;
687 cloneMessage(servermessage) {
689 for (var key in servermessage) {
690 if (servermessage.hasOwnProperty(key)) //ensure not adding inherited props
691 clone[key] = servermessage[key];
696 public showUpload() {
697 this.selectedUploadType = this.uploadTypes[0].value;
700 public fileChange(input) {
701 this.fileName = input.target.files[0].name.replace(/C:\\fakepath\\/i, '');
702 this.fileUploaded = true;
703 this.disableRetrieve = true;
704 if (input.target.files && input.target.files[0]) {
705 // Create the file reader
706 let reader = new FileReader();
707 this.readFile(input.target.files[0], reader, (result) => {
708 // After the callback fires do:
709 if ('Reference Data' === this.selectedUploadType) {
712 let jsonObject = (JSON.parse(result))['reference_data'];
713 this.uploadedData = JSON.parse(JSON.stringify(jsonObject));
714 this.tempAllData = JSON.parse(JSON.stringify(jsonObject));
715 this.notificationService.notifySuccessMessage('Reference Data file successfully uploaded..');
716 if (jsonObject instanceof Array) {
717 this.referenceDataObject = jsonObject[0];
718 jsonObject.forEach(obj => {
719 this.selectedActions.push(obj.action);
722 this.referenceDataObject = jsonObject;
723 this.selectedActions.push(jsonObject.action);
725 if (this.referenceDataObject.action === 'OpenStack Actions') {
726 this.deviceProtocols = ['', 'OpenStack'];
727 this.buildDesignComponent.tabs = [
730 name: 'Reference Data',
735 this.buildDesignComponent.tabs = [
737 name: 'Reference Data',
741 url: 'templates/myTemplates',
743 name: 'Parameter Definition',
744 url: 'parameterDefinitions/create'
751 if (this.referenceDataObject.template == null) {
752 this.referenceDataObject.template = 'Y';
754 if (this.referenceDataObject['action-level'] == null) {
755 this.referenceDataObject['action-level'] = 'VNF';
758 this.nService.error('Error', 'Incorrect file format');
761 this.hideModal = true;
764 this.notificationService.notifyErrorMessage('Failed to read file..');
769 public readFile(file, reader, callback) {
770 // Set a callback funtion to fire after the file is fully loaded
771 reader.onload = () => {
772 // callback with the results
773 callback(reader.result);
775 this.notificationService.notifySuccessMessage('Uploading File ' + file.name + ':' + file.type + ':' + file.size);
777 reader.readAsText(file, 'UTF-8');
780 fileChangeEvent(fileInput: any) {
781 let obj: any = fileInput.target.files;
786 'vnfc-instance': '1',
787 'vnfc-function-code': '',
788 'ipaddress-v4-oam-vip': '',
789 'group-notation-type': '',
790 'group-notation-value': ''
794 setVmInstance(index) {
795 this.referenceDataObject.vm[index]['vm-instance'] = index + 1;
798 setVnfcType(str: String) {
799 this.Sample['vnfc-type'] = str;
802 getChange(value: String) {
803 if (value === 'vnfType') {
804 this.referenceDataObject.scope['vnfc-type'] = '';
809 this.referenceDataObject['action-level'] = 'vnf';
810 this.referenceDataObject.template = 'Y';
811 this.referenceDataObject['device-protocol'] = '';
812 this.referenceDataObject['user-name'] = '';
813 this.referenceDataObject['port-number'] = '';
814 this.refernceScopeObj.sourceType = '';
815 this.Sample['vnfc-type'] = '';
818 populateExistinAction(data) {
819 let existAction = this.tempAllData.findIndex(obj => {
820 return obj.action == data;
822 if (existAction > -1) {
823 let obj = $.extend(true, {}, this.tempAllData[existAction]);
824 this.referenceDataObject = obj;
825 this.referenceDataObject.scope['vnf-type'] = obj['scope']['vnf-type'];
826 this.referenceDataObject.scope['vnfc-type'] = obj['scope']['vnfc-type'];
827 this.referenceDataObject['device-protocol'] = obj['device-protocol'];
828 this.refernceScopeObj['sourceType'] = obj['scopeType'];
831 this.referenceDataObject.action = data;
833 //# iof healthCeck change deviceprotocol drp vaues
834 if (data == 'HealthCheck') {
835 this.deviceProtocols = ['', 'ANSIBLE', 'CHEF', 'REST'];
836 this.actionHealthCheck = true;
837 } else if (data == 'UpgradeBackout' || data == 'ResumeTraffic' || data == 'QuiesceTraffic' || data == 'UpgradeBackup' || data == 'UpgradePostCheck' || data == 'UpgradePreCheck' || data == 'UpgradeSoftware' || data == 'ConfigBackup' || data == 'ConfigRestore' || data == 'StartApplication' || data == 'StopApplication' || data == 'GetRunningConfig') {
838 this.deviceProtocols = ['', 'CHEF', 'ANSIBLE'];
839 } else if (data == 'OpenStack Actions') {
840 this.deviceProtocols = ['', 'OpenStack'];
841 } else if (data == 'ConfigScaleOut') {
842 this.deviceProtocols = ['', 'CHEF', 'ANSIBLE', 'NETCONF-XML','RESTCONF'];
845 this.deviceProtocols = ['', 'ANSIBLE', 'CHEF', 'NETCONF-XML', 'RESTCONF', 'CLI'];
846 this.actionHealthCheck = false;
850 //Modal pop up for action change with values entered.
851 actionChange(data, content, userForm) {
852 // this.actionChanged = true;
853 this.disableGrpNotationValue = false
857 if ((userForm.valid) && this.oldAction != '' && this.oldAction != undefined) {
858 this.actionChanged = true;
859 this.modalService.open(content).result.then(res => {
861 this.currentAction = this.referenceDataObject.action;
862 this.referenceDataObject.action = this.oldAction;
863 $('#saveToAppc').click();//make sure the save all is done before the tempall obj is saved form the API
864 this.toggleIdentifier(data)
865 this.oldAction = this.currentAction;// this.referenceDataObject.action + '';
866 this.referenceDataObject.action = this.currentAction
868 this.populateExistinAction(data);
869 if (this.oldAction === 'OpenStack Actions') {
871 this.uploadedDataArray = [];
872 this.remUploadedDataArray = [];
873 this.firstArrayElement = [];
874 this.uploadFileName = '';
875 //this.tempAllData = [];
879 this.toggleIdentifier(data)
880 this.currentAction = this.referenceDataObject.action;
881 this.populateExistinAction(data);
882 this.oldAction = this.referenceDataObject.action + '';
887 this.actionChanged = true;
888 this.oldAction = this.referenceDataObject.action + '';
889 this.populateExistinAction(data);
890 this.resetVmsForScaleout(data);
891 this.toggleIdentifier(data)
894 if (data == 'ConfigScaleOut') {
895 this.groupAnotationType = ['', 'first-vnfc-name', 'fixed-value', 'relative-value', 'existing-group-name'];
898 if (data == 'OpenStack Actions') {
899 this.buildDesignComponent.tabs = [
902 name: 'Reference Data',
907 this.buildDesignComponent.tabs = [
909 name: 'Reference Data',
913 url: 'templates/myTemplates',
915 name: 'Parameter Definition',
916 url: 'parameterDefinitions/create'
923 if (data == 'Configure' || data == 'ConfigModify') {
924 this.nonConfigureAction = false;
926 this.nonConfigureAction = true;
929 // For the issue with multiple template changes
930 // idChange(data, content, userForm) {
931 // if (data == null) {
934 // if ((userForm.valid) && this.oldAction != '' && this.oldAction != undefined) {
935 // let referenceObject = this.prepareReferenceObject();
936 // this.actionChanged = true;
937 // if(this.templateIdentifier)
939 // this.modalService.open(content).result.then(res => {
940 // if (res == 'yes') {
941 // this.validateTempAllData();
942 // let theJSON = JSON.stringify(this.tempAllData, null, '\t');
943 // let fileName = 'reference_AllAction_' + referenceObject.scopeName + '_' + '0.0.1V.json';
944 // this.uploadArtifact(JSON.stringify({ reference_data: this.tempAllData }), this.tempAllData[this.tempAllData.length - 1], fileName);
945 // var templateData = JSON.stringify(this.appData.template.templateData);
946 // var nameValueData = JSON.stringify(this.appData.template.nameValueData);
947 // var pdData = JSON.stringify(this.appData.pd);
948 // if (templateData != '{}' && templateData != null && templateData != undefined) this.saveTemp();
949 // if (nameValueData != '{}' && nameValueData != null && nameValueData != undefined) this.saveNameValue();
950 // if (pdData != '{}' && pdData != null && pdData != undefined) this.savePd();
951 // this.clearTemplateCache();
952 // this.clearPdCache();
955 // this.clearTemplateCache();
956 // this.clearPdCache();
965 // get the value and save the userid and persist it.
966 this.mappingEditorService.setTemplateMappingDataFromStore(undefined);
967 localStorage['paramsContent'] = '{}';
968 this.mappingEditorService.setParamContent(undefined);
969 this.paramShareService.setSessionParamData(undefined);
970 this.appData = { reference: {}, template: { templateData: {}, nameValueData: {} }, pd: {} };
971 this.downloadData = {
973 template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' },
974 pd: { pdData: '', pdFileName: '' }
978 // needed for the the clearing template cache.
980 // // get the value and save the userid and persist it.
981 // this.clearTemplateCache();
982 // this.clearPdCache();
983 // this.appData = { reference: {}, template: { templateData: {}, nameValueData: {} }, pd: {} };
984 // this.downloadData = {
986 // template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' },
987 // pd: { pdData: '', pdFileName: '' }
991 // clearTemplateCache()
993 // this.mappingEditorService.setTemplateMappingDataFromStore(undefined);
994 // localStorage['paramsContent'] = '{}';
998 // this.mappingEditorService.setParamContent(undefined);
999 // this.paramShareService.setSessionParamData(undefined);
1006 { url: environment.getDesigns, data: this.appData.template.templateData })
1007 .subscribe(resp => {
1008 if (resp.output.status.code === '400' && resp.output.status.message === 'success') {
1009 this.nService.success('Status', 'Successfully uploaded the Template Data');
1011 if (resp.output.status.code === '401') {
1012 this.nService.warn('Status', 'Error in saving the Template to Appc');
1016 (err) => this.nService.error('Status', 'Error Connecting to the APPC Network'));
1024 url: environment.getDesigns, data: this.appData.template.nameValueData
1026 .subscribe(resp => {
1027 if (resp.output.status.code === '400' && resp.output.status.message === 'success') {
1028 this.nService.success('Status', 'Successfully uploaded the Name Value Pairs');
1030 if (resp.output.status.code === '401') {
1031 this.nService.warn('Status', 'Error in saving the Name value pairs to Appc');
1035 this.nService.error('Status', 'Error Connecting to the APPC Network');
1045 url: environment.getDesigns, data: this.appData.pd
1047 .subscribe(resp => {
1048 if (resp.output.status.code === '400' && resp.output.status.message === 'success') {
1049 this.nService.success('Status', 'Successfully uploaded PD file');
1051 if (resp.output.status.code === '401') {
1052 this.nService.warn('Status', 'Error in saving the PD to Appc');
1056 this.nService.error('Status', 'Error Connecting to the APPC Network');
1061 openModel(toShow: any, message: any, title: any) {
1062 this.modalComponent.isShow = toShow;
1063 this.modalComponent.message = message;
1064 this.modalComponent.title = title;
1068 $('#inputFile').trigger('click');
1071 excelBrowseOption() {
1072 $('#excelInputFile').trigger('click');
1076 $('#identifierModal').modal();
1080 if (!(this.referenceDataObject['template-id-list'])) {
1081 this.referenceDataObject['template-id-list'] = [];
1083 if(!(this.referenceDataObject['template-id-list'].indexOf(this.templateId.trim())>-1)){
1084 this.referenceDataObject['template-id-list'].push(this.templateId.trim());
1089 this.referenceDataObject.vm = [];
1093 // this.referenceDataObject.vm = this.referenceDataObject.vm;
1096 resetGroupNotation() {
1097 if (this.Sample['group-notation-type'] == "existing-group-name") {
1098 this.Sample['group-notation-value'] = ""
1100 this.disableGrpNotationValue = true
1102 this.disableGrpNotationValue = false
1106 resetVmsForScaleout(action){
1107 //reset currentform vms based on action
1108 if (action == "ConfigScaleOut") {
1109 let ConfigScaleOutIndex = this.tempAllData.findIndex(obj => {
1110 return obj['action'] ==action
1112 if (ConfigScaleOutIndex > -1) {
1113 this.referenceDataObject.vm = this.tempAllData[ConfigScaleOutIndex].vm
1115 if(this.actionChanged ){
1116 this.referenceDataObject.vm = []
1123 resetParamsOnVnfcType(){
1125 //if only vnf is there
1126 if (this.referenceDataObject.scope['vnfc-type'] == '' || this.referenceDataObject.scope['vnfc-type'] == null || this.referenceDataObject.scope['vnfc-type'] == 'null') {
1127 scopeName = this.referenceDataObject.scope['vnf-type'];
1128 this.referenceDataObject.scope['vnfc-type'] = '';
1129 this.referenceDataObject['action-level'] = 'vnf';
1130 this.referenceDataObject['scopeType'] = 'vnf-type';
1132 //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
1134 scopeName = this.referenceDataObject.scope['vnfc-type'];
1135 if (this.referenceDataObject.action == 'Configure' || this.referenceDataObject.action == 'ConfigModify') {
1136 this.referenceDataObject['action-level'] = 'vnfc';
1137 this.referenceDataObject['scopeType'] = 'vnfc-type';
1139 this.referenceDataObject['action-level'] = 'vnf';
1140 this.referenceDataObject['scopeType'] = 'vnf-type';
1143 //replacing / with _ and removing spaces in the scopeName
1145 scopeName = scopeName.replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '');
1150 //marking the extension based on the device-protocol selected by the user
1151 let extension = 'json';
1152 if (this.referenceDataObject['device-protocol'] == 'ANSIBLE' || this.referenceDataObject['device-protocol'] == 'CHEF' || this.referenceDataObject['device-protocol'] == 'CLI') {
1154 } else if (this.referenceDataObject['device-protocol'] == 'NETCONF-XML' || this.referenceDataObject['device-protocol'] == 'REST') {
1159 prepareArtifactList(scopeName,extension){
1160 this.referenceDataObject['artifact-list'] = [];
1162 //preparing the artifact list array file names along with extension
1163 let config_template_fileName = this.referenceDataObject.action + '_' + scopeName + '_' + '0.0.1V.' + extension;
1164 let pd_fileName = this.referenceDataObject.action + '_' + scopeName + '_' + '0.0.1V.yaml';
1165 let reference_fileName = this.referenceDataObject.action + '_' + scopeName + '_' + '0.0.1V.json';
1167 let configTemplate = {
1168 'artifact-name': 'template_' + config_template_fileName,
1169 'artifact-type': 'config_template'
1173 'artifact-name': 'pd_' + pd_fileName,
1174 'artifact-type': 'parameter_definitions'
1176 if (this.referenceDataObject.action != 'ConfigScaleOut') {
1178 this.referenceDataObject['artifact-list'].push(configTemplate,
1183 let identifiers = this.referenceDataObject['template-id-list'];
1185 for (var x = 0; x < identifiers.length; x++) {
1186 //for replacing spaces and "/" with "_"
1187 identifiers[x]=identifiers[x].replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '');
1188 pd_fileName = this.referenceDataObject.action + '_' + scopeName + '_' + '0.0.1V_' + identifiers[x] + '.yaml';
1189 config_template_fileName = this.referenceDataObject.action + '_' + scopeName + '_' + '0.0.1V_' + identifiers[x] + '.' + extension;
1192 'artifact-name': 'template_' + config_template_fileName,
1193 'artifact-type': 'config_template'
1196 'artifact-name': 'pd_' + pd_fileName,
1197 'artifact-type': 'parameter_definitions'
1199 this.referenceDataObject['artifact-list'].push(configTemplate,
1207 deleteVmsforNonActions(newObj,action){
1208 let configureObject = (action == 'Configure');
1209 let ConfigScaleOut = (action == 'ConfigScaleOut');
1210 //delete VM's if selected action is not configure.
1211 if (!ConfigScaleOut && !configureObject && this.tempAllData.length != 0) {
1214 if (ConfigScaleOut) {
1219 //this.tempAllData.push(newObj);
1221 if (ConfigScaleOut) {
1223 delete newObj['template-id-list'];
1228 pushOrReplaceTempData(newObj,action){
1230 let actionObjIndex = this.tempAllData.findIndex(obj => {
1231 return obj['action'] == action;
1233 if (newObj.action != 'HealthCheck') {
1234 delete newObj['url'];
1237 if (actionObjIndex > -1) {
1238 this.tempAllData[actionObjIndex] = newObj;
1239 this.mappingEditorService.saveLatestAction(this.tempAllData[actionObjIndex]);
1240 this.mappingEditorService.saveLatestIdentifier(this.templateIdentifier);
1242 if (newObj.action != '') {
1243 this.tempAllData.push(newObj);
1244 this.mappingEditorService.saveLatestAction(newObj);
1245 this.mappingEditorService.saveLatestIdentifier(this.templateIdentifier);
1251 addAllActionObj(newObj,scopeName){
1253 //Creating all action block to allow mulitple actions at once
1255 action: 'AllAction',
1256 'action-level': 'vnf',
1257 scope: newObj.scope,
1259 'artifact-name': 'reference_AllAction' + '_' + scopeName + '_' + '0.0.1V.json',
1260 'artifact-type': 'reference_template'
1263 let allActionIndex = this.tempAllData.findIndex(obj => {
1264 return obj['action'] == 'AllAction';
1266 if (allActionIndex > -1) {
1267 this.tempAllData[allActionIndex] = allAction;
1269 this.tempAllData.push(allAction);
1274 if (this.uploadedDataArray && this.uploadedDataArray != undefined && this.uploadedDataArray.length != 0) {
1276 if (this.tempAllData && this.tempAllData != undefined) {
1277 for (var i = 0; i < this.tempAllData.length; i++) {
1278 // alert(this.checkIfelementExistsInArray(this.tempAllData[i].action,this.actions))
1281 if (this.tempAllData[i].action === 'AllAction') {
1285 result = this.checkIfelementExistsInArray(this.tempAllData[i].action, this.actions);
1288 // console.log('Removing VM action==' + this.tempAllData[i].action);
1289 this.tempAllData.splice(i, 1);
1295 this.addVmCapabilitiesData();