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 { ReferenceDataFormUtil } from './reference-dataform.util';
40 import { UtilityService } from '../../../shared/services/utilityService/utility.service';
41 import { appConstants } from '../../../../constants/app-constants';
42 // Common Confirm Modal
43 import { DialogService } from 'ng2-bootstrap-modal';
44 import { ConfirmComponent } from "../../../shared/confirmModal/confirm.component";
47 type AOA = Array<Array<any>>;
48 const REFERENCE_DATA:string= "reference_data";
51 selector: 'reference-dataform',
52 templateUrl: './reference-dataform.component.html',
53 styleUrls: ['./reference-dataform.component.css'],
54 providers: [ReferenceDataFormUtil]
56 export class ReferenceDataformComponent implements OnInit {
57 public classNm= "ReferenceDataformCompon";
58 @ViewChild(ModalComponent) modalComponent: ModalComponent;
59 public showUploadStatus: boolean = false;
60 public fileUploaded: boolean = false;
61 public uploadedData: any;
62 public statusMsg: string;
63 public uploadStatus: boolean = false;
64 public isCollapsedContent: boolean = true;
65 public vnfcCollLength: number = 0;
66 public vfncCollection = [];
68 public actionType: any;
69 numberTest: RegExp = /^[^.a-z]+$/;
70 public numberOfVmTest: boolean = true;
71 public tempAllData = [];
72 disableGrpNotationValue: boolean;
73 public noRefData = false;
74 public disableRetrieve = false;
75 public getRefStatus = false;
76 public uploadStatusError: boolean;
77 public showUploadErrorStatus: boolean;
78 public noData: string;
80 public appData = { reference: {}, template: { templateData: {}, nameValueData: {} }, pd: {} };
81 public downloadData = {
83 template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' },
84 pd: { pdData: '', pdFileName: '' }
90 oldVnfcIdentifier: any;
91 public uploadFileName: any;
92 public addVmClickedFlag: boolean = false;
93 public getExcelUploadStatus: boolean = false;
94 public uploadedDataArray: any;
95 public actionFlag = false;
98 nonConfigureAction: any;
102 public actionLevels = [
105 oldtemplateIdentifier: any
107 identifierDrpValues: any = [];
108 //settings for the notifications.
111 showProgressBar: true,
116 //initializing this object to contain all the parameters to be captured
117 public referenceDataObject = {
119 'action-level': 'vnf',
120 scope: { 'vnf-type': '', 'vnfc-type-list': [] },
123 'device-protocol': '',
128 public refernceScopeObj = { sourceType: '', from: '', to: '' };
129 public actions = [ appConstants.Actions.blank,
130 appConstants.Actions.configure,
131 appConstants.Actions.ConfigModify,
132 appConstants.Actions.configBackup,
133 appConstants.Actions.configRestore,
134 appConstants.Actions.getRunningConfig,
135 appConstants.Actions.healthCheck,
136 appConstants.Actions.startApplication,
137 appConstants.Actions.stopApplication,
138 appConstants.Actions.quiesceTraffic,
139 appConstants.Actions.resumeTraffic,
140 appConstants.Actions.upgradeBackout,
141 appConstants.Actions.upgradeBackup,
142 appConstants.Actions.upgradePostCheck,
143 appConstants.Actions.upgradePreCheck,
144 appConstants.Actions.upgradeSoftware,
145 appConstants.Actions.openStackActions,
146 appConstants.Actions.configScaleOut
148 public groupAnotationValue = [appConstants.groupAnotationValue.blank, appConstants.groupAnotationValue.pair];
149 public groupAnotationType = [appConstants.groupAnotationType.blank, appConstants.groupAnotationType.firstVnfcName, appConstants.groupAnotationType.fixedValue, appConstants.groupAnotationType.relativeValue];
150 public deviceProtocols = [appConstants.DeviceProtocols.blank, appConstants.DeviceProtocols.ansible, appConstants.DeviceProtocols.chef, appConstants.DeviceProtocols.netconfXML, appConstants.DeviceProtocols.rest, appConstants.DeviceProtocols.cli, appConstants.DeviceProtocols.restConf];
151 public deviceTemplates = [appConstants.deviceTemplates.blank, appConstants.deviceTemplates.y, appConstants.deviceTemplates.n];
152 public sourceTypeColl = [appConstants.sourceTypeColl.blank, appConstants.sourceTypeColl.vnfType, appConstants.sourceTypeColl.vnfcType];
153 public ipAddressBoolean = ['', 'Y', 'N'];
154 public Sample: any = {
155 'vnfc-instance': '1',
156 'vnfc-function-code': '',
157 'ipaddress-v4-oam-vip': '',
158 'group-notation-type': '',
159 'group-notation-value': ''
161 hideModal: boolean = false;
163 public uploadTypes = [{
164 value: 'Reference Data',
165 display: 'Sample Json Param File'
168 value: 'Mapping Data',
169 display: 'Sample Json Param File'
172 public selectedUploadType: string = this.uploadTypes[0].value;
173 public vnfcTypeData: string = '';
174 public title: string;
175 public allowAction: boolean = true;
176 public actionExist: boolean = false;
177 public disableVnftype: boolean = false;
178 public otherActions: boolean = false;
179 public actionHealthCheck: boolean = false;
180 public actionChanged: boolean = false;
181 public initialAction: string = '';
182 public noCacheData: boolean;
183 public updateParams: any;
184 public vnfParams: any;
185 public firstArrayElement = [];
186 public remUploadedDataArray = [];
187 isConfigScaleOut = false
188 isConfigOrConfigModify = false;
189 configScaleOutExist: boolean = true;
190 displayVnfc = 'false';
192 isVnfcTypeList: boolean = true;
193 public actionList = {
194 "ConfigScaleOut": "ConfigScaleOut",
195 "Configure": "Configure"
197 public versionNoForApiCall = "0.0.1";
198 private displayVMBlock: boolean = true;
201 private buildDesignComponent: BuildDesignComponent,
202 private httpUtils: HttpUtilService,
203 private route: Router,
204 private location: Location,
205 private activeRoutes: ActivatedRoute,
206 private notificationService: NotificationService,
207 private paramShareService: ParamShareService,
208 private mappingEditorService: MappingEditorService,
209 private modalService: NgbModal,
210 private nService: NotificationsService,
211 private ngProgress: NgProgress,
212 private utilityService: UtilityService,
213 private dialogService: DialogService,
214 private referenceDataFormUtil: ReferenceDataFormUtil )
216 console.log( this.classNm+": new: start.");
220 if( this.utilityService.getTracelvl() > 0 )
221 console.log( this.classNm+": ngOnInit: start.");
222 this.displayVnfc = sessionStorage.getItem("vnfcSelectionFlag");
223 if (this.configScaleOutExist) {
224 this.actions = ['', 'Configure', 'ConfigModify', 'ConfigBackup', 'ConfigRestore', 'GetRunningConfig', 'HealthCheck', 'StartApplication', 'StopApplication', 'QuiesceTraffic', 'ResumeTraffic', 'UpgradeBackout', 'UpgradeBackup', 'UpgradePostCheck', 'UpgradePreCheck', 'UpgradeSoftware', 'OpenStack Actions', 'ConfigScaleOut'];
226 this.actions = ['', 'Configure', 'ConfigModify', 'ConfigBackup', 'ConfigRestore', 'GetRunningConfig', 'HealthCheck', 'StartApplication', 'StopApplication', 'QuiesceTraffic', 'ResumeTraffic', 'UpgradeBackout', 'UpgradeBackup', 'UpgradePostCheck', 'UpgradePreCheck', 'UpgradeSoftware', 'OpenStack Actions'];
229 let path = this.location.path;
230 this.title = 'Reference Data';
231 this.referenceDataObject = {
233 'action-level': 'vnf',
234 scope: { 'vnf-type': '', 'vnfc-type-list': [] },
237 'device-protocol': '',
242 this.updateParams = sessionStorage.getItem('updateParams');
243 let cacheData = this.mappingEditorService.referenceNameObjects;
244 if (cacheData != undefined && cacheData != null && cacheData.length > 0) {
245 this.tempAllData = cacheData;
246 if (this.mappingEditorService.latestAction != undefined) {
247 this.referenceDataObject = this.mappingEditorService.latestAction;
248 this.toggleIdentifier(this.referenceDataObject.action);
249 this.refernceScopeObj.sourceType = this.referenceDataObject['scopeType'];
250 this.oldAction = this.referenceDataObject.action;
251 this.populateExistinAction(this.referenceDataObject.action);
252 this.displayHideVnfc();
254 } else if (this.updateParams != 'undefined') {
257 var appData = this.mappingEditorService.appDataObject;
258 if (appData != null || appData != undefined) this.appData = appData;
259 var downloadData = this.mappingEditorService.downloadDataObject;
260 if (downloadData != null || downloadData != undefined) this.downloadData = downloadData;
261 if (sessionStorage.getItem('vnfParams')) {
262 this.vnfParams = JSON.parse(sessionStorage.getItem('vnfParams'));
264 if( this.vnfParams && this.vnfParams.vnfType) {
265 if( this.utilityService.getTracelvl() > 0 )
266 console.log( this.classNm+": ngOnInit: vnfParams.vnfType:["+
267 this.vnfParams.vnfType+"]");
268 this.referenceDataObject['scope']['vnf-type']= this.vnfParams.vnfType;
270 if( this.vnfParams && this.vnfParams.vnfcType) {
271 if( this.utilityService.getTracelvl() > 0 )
272 console.log( this.classNm+": ngOnInit: vnfParams.vnfcType:["+
273 this.vnfParams.vnfcType+"]");
274 this.referenceDataObject['scope']['vnfc-type']= this.vnfParams.vnfcType;
276 this.uploadedDataArray = [];
277 this.remUploadedDataArray = [];
278 this.firstArrayElement = [];
279 this.uploadFileName = '';
280 this.templateIdentifier = this.mappingEditorService.identifier
281 this.oldVnfcIdentifier = this.vnfcIdentifier;
282 if( this.utilityService.getTracelvl() > 1 )
283 console.log( this.classNm+": ngOnInit: displayVnfc:["+this.displayVnfc+"]");
284 if( this.utilityService.getTracelvl() > 1 )
285 console.log( this.classNm+": ngOnInit: templateIdentifier:["+
286 this.templateIdentifier+"]");
287 // Enable or Block Template and PD Tabs
288 this.buildDesignComponent.getRefData(
289 { ...this.referenceDataObject, displayVnfc: this.displayVnfc },
290 { reqField: this.templateIdentifier });
291 this.configDrp(this.referenceDataObject.action)
294 toggleIdentifier(data) {
295 if (data == 'ConfigScaleOut') {
296 this.isConfigScaleOut = true
299 this.isConfigScaleOut = false
303 //to retrive the data from appc and assign it to the vaiables, if no data display the message reterived from the API
305 if( this.utilityService.getTracelvl() > 0 )
306 console.log( this.classNm+": getArtifact: start.");
308 let data = this.utilityService.createPayloadForRetrieve(true, '', '', '');
309 this.ngProgress.start();
310 this.httpUtils.post({
311 url: environment.getDesigns,
313 }).subscribe(resp => {
314 if( this.utilityService.getTracelvl() > 1 )
315 console.log( this.classNm+": getArtifact: got response ...");
316 if (resp.output.data.block != undefined) {
317 if( this.utilityService.getTracelvl() > 1 )
318 console.log( this.classNm+
319 ": getArtifact: output.data.block not empty.");
320 this.nService.success(appConstants.notifications.titles.status, appConstants.messages.datafetched);
321 let artifactInfo = JSON.parse(resp.output.data.block).artifactInfo[0];
322 let reference_data = JSON.parse(artifactInfo['artifact-content'])['reference_data'][0];
323 this.referenceDataObject = reference_data;
324 this.toggleIdentifier(this.referenceDataObject.action);
325 if (this.referenceDataObject.action == appConstants.Actions.configScaleOut) {
326 this.groupAnotationType = [appConstants.groupAnotationType.blank, appConstants.groupAnotationType.firstVnfcName, appConstants.groupAnotationType.fixedValue, appConstants.groupAnotationType.relativeValue, appConstants.groupAnotationType.existingGroupName];
328 //chck vnfc or vnfcTypeList
329 this.displayHideVnfc();
330 // Enable or Block Template and PD Tabs
331 this.buildDesignComponent.getRefData(
332 {...this.referenceDataObject, displayVnfc: this.displayVnfc } );
333 this.refernceScopeObj.sourceType = this.referenceDataObject['scopeType'];
334 this.mappingEditorService.getReferenceList().push(JSON.parse(artifactInfo['artifact-content']));
335 this.tempAllData = JSON.parse(artifactInfo['artifact-content'])['reference_data'];
336 this.oldAction = this.referenceDataObject.action;
337 this.oldVnfcIdentifier = this.vnfcIdentifier;
338 if (this.referenceDataObject.action === appConstants.Actions.openStackActions) {
339 this.deviceProtocols = [appConstants.DeviceProtocols.blank, appConstants.DeviceProtocols.openStack];
340 this.buildDesignComponent.tabs = [
342 name: 'Reference Data',
347 this.buildDesignComponent.tabs = [
349 name: 'Reference Data',
353 url: 'templates/myTemplates',
355 name: 'Parameter Definition',
356 url: 'parameterDefinitions/create'
363 this.getArtifactsOpenStack();
365 this.nService.success('Status', 'Sorry !!! I dont have any artifact Named : ' + (JSON.parse(sessionStorage.getItem('updateParams')))['artifact-name']);
367 this.ngProgress.done();
371 this.nService.warn('status', 'error while reteriving artifact');
374 this.ngProgress.done();
379 if( this.utilityService.getTracelvl() > 0 )
380 console.log(this.classNm+": displayHideVnfc: start...");
381 if( this.utilityService.getTracelvl() > 1 ) {
382 if( this.referenceDataObject.scope['vnfc-type-list'] ) {
383 console.log( this.classNm+
384 ": displayHideVnfc: refDataObj.scope.vnfc-type-list.length="+
385 this.referenceDataObject.scope['vnfc-type-list'].length );
387 console.log( this.classNm+
388 ": displayHideVnfc: refDataObj.scope.vnfc-type-list not defined");
390 console.log( this.classNm+": displayHideVnfc: scope.vnfc-type:["+
391 this.referenceDataObject.scope['vnfc-type']+"]");
393 if (this.referenceDataObject.scope['vnfc-type-list'] == undefined && (this.referenceDataObject.scope['vnfc-type'] != undefined || this.referenceDataObject.scope['vnfc-type'] != "")) {
394 this.isVnfcType = true
395 this.displayVnfc = 'true'
396 this.isVnfcTypeList = false
398 if (this.referenceDataObject.scope['vnfc-type-list'] != undefined && this.referenceDataObject.scope['vnfc-type-list'].length != 0 && (this.referenceDataObject.scope['vnfc-type'] == undefined || this.referenceDataObject.scope['vnfc-type'] == "")) {
399 this.isVnfcType = false
400 this.displayVnfc = 'true'
401 this.isVnfcTypeList = true
402 if(!this.mappingEditorService.newObject.vnfc) {
403 this.vnfcIdentifier = this.referenceDataObject.scope['vnfc-type-list'][0];
404 // this.mappingEditorService.newObject.vnfc = this.vnfcIdentifier;
405 // this.referenceDataObject['vnfcIdentifier'] = this.vnfcIdentifier;
408 this.vnfcIdentifier = this.mappingEditorService.newObject.vnfc;
410 if( this.utilityService.getTracelvl() > 0 )
411 console.log(this.classNm+": displayHideVnfc: vnfcIdentifier:["+
412 this.vnfcIdentifier+"]");
414 if (this.referenceDataObject.scope['vnfc-type-list'] != undefined && this.referenceDataObject.scope['vnfc-type-list'].length == 0 && this.referenceDataObject.scope['vnfc-type'] != undefined && this.referenceDataObject.scope['vnfc-type'].length == 0) {
415 if(this.displayVnfc == 'true') {
416 this.isVnfcType = false
417 this.displayVnfc = 'true'
418 this.isVnfcTypeList = true
420 this.isVnfcType = false
421 this.displayVnfc = 'false'
422 this.isVnfcTypeList = false
425 if (this.referenceDataObject.scope['vnfc-type-list'] == undefined && this.referenceDataObject.scope['vnfc-type'] == '') {
426 this.isVnfcType = false
427 this.displayVnfc = 'false'
428 this.isVnfcTypeList = false
430 if( this.utilityService.getTracelvl() > 1 )
431 console.log(this.classNm+": displayHideVnfc: finish. isVnfcType:["+
432 this.isVnfcType+" displayVnfc:["+this.displayVnfc+"] isVnfcTypeList:["+
433 this.isVnfcTypeList+"]");
436 //reinitializing the required values
438 if( this.utilityService.getTracelvl() > 0 )
439 console.log( this.classNm+": ngOnDestroy: start:"+
440 " vnfcIdentifier:["+this.vnfcIdentifier+"]");
441 let referenceObject = this.prepareReferenceObject();
442 this.mappingEditorService.changeNavAppData(this.appData);
443 this.mappingEditorService.changeNavDownloadData(this.downloadData);
444 this.uploadedDataArray = [];
445 this.remUploadedDataArray = [];
446 this.firstArrayElement = [];
447 this.uploadFileName = '';
450 numberValidation(event: any) {
451 if (this.numberTest.test(event) && event != 0) {
452 this.numberOfVmTest = true;
455 this.numberOfVmTest = false;
458 // update my vnf pop up session values
459 updateSessionValues(event: any, type: string) {
460 if (type === 'action') {
461 sessionStorage.setItem('action', event);
463 if (type === 'vnfType') {
464 sessionStorage.setItem('vnfType', event);
468 addVnfcData(vmNumber: number) {
470 'vnfc-instance': this.referenceDataObject.vm[vmNumber].vnfc.length + 1,
471 'vnfc-type': this.vnfcTypeData,
472 'vnfc-function-code': '',
473 'ipaddress-v4-oam-vip': '',
474 'group-notation-type': '',
475 'group-notation-value': ''
477 this.referenceDataObject.vm[vmNumber].vnfc.push(newObj);
480 //validating the vnf and vnfc data in the pop up
481 validateVnfcName(name) {
482 if( this.utilityService.getTracelvl() > 0 )
483 console.log( this.classNm+": validateVnfcName: start: name:["+name+"]");
484 if (!name.trim() || name.length < 1) {
485 this.errorMessage = '';
487 } else if (name.startsWith(' ') || name.endsWith(' ')) {
488 this.errorMessage = 'Leading and trailing spaces are not allowed';
490 } else if (name.includes(' ')) {
491 this.errorMessage = 'More than one space is not allowed in VNFC Type';
493 } else if (name.length > 50) {
494 this.errorMessage = 'VNFC Type should be of minimum one character and maximum 50 character';
497 this.invalid = false;
498 this.errorMessage = '';
502 //to remove the VM's created by the user
503 removeFeature(vmNumber: any, index: any, templateId) {
504 if (this.referenceDataObject.action == "Configure") {
505 this.referenceDataObject.vm.splice(vmNumber, 1);
506 this.referenceDataObject.vm.forEach((obj, arrIndex) => {
507 if (arrIndex >= vmNumber) {
508 obj["vm-instance"] = obj["vm-instance"] - 1
512 let data = this.referenceDataObject.vm.filter(obj => {
513 return obj['template-id'] == templateId;
516 let vmIndex = this.findVmindex(data, vmNumber, templateId)
517 this.referenceDataObject.vm.splice(vmIndex, 1);
519 this.referenceDataObject.vm.forEach((obj, arrIndex) => {
520 if (obj['template-id'] == templateId) {
522 obj["vm-instance"] = index + 1
530 findVmindex(data, vmNumber, templateId) {
531 return this.referenceDataObject.vm.findIndex(obj => {
532 let x = obj['vm-instance'] == (vmNumber + 1) && templateId == obj['template-id']//true
538 //add new VM's to the configure
541 let mberOFVm = Number(this.refernceScopeObj.from);
542 if (this.referenceDataObject.action == 'ConfigScaleOut') {
543 let existingVmsLength = this.referenceDataObject.vm.filter(obj => {
544 return obj['template-id'] == this.templateIdentifier
546 mberOFVm = existingVmsLength + mberOFVm;
548 for (var i = (existingVmsLength); i < mberOFVm; i++) {
550 this.referenceDataObject.vm.push({ 'template-id': this.templateIdentifier, 'vm-instance': (existingVmsLength + index + 1), vnfc: [Object.assign({}, this.Sample)] });
555 let arrlength = this.referenceDataObject.vm.length;
556 mberOFVm = arrlength + mberOFVm;
557 for (var i = (arrlength); i < mberOFVm; i++) {
558 if (this.referenceDataObject.action == 'ConfigScaleOut') {
559 this.referenceDataObject.vm.push({ 'template-id': this.templateIdentifier, 'vm-instance': (i + 1), vnfc: [Object.assign({}, this.Sample)] });
561 this.referenceDataObject.vm.push({ 'vm-instance': (i + 1), vnfc: [Object.assign({}, this.Sample)] });
567 //Reference object to create reference data
568 prepareReferenceObject(isSaving?: any) {
569 if( this.utilityService.getTracelvl() > 0 )
570 console.log( this.classNm+": prepareReferenceObject: start.");
571 let scopeName = this.resetParamsOnVnfcType();
572 let extension = this.decideExtension(this.referenceDataObject);
573 this.prepareArtifactList(scopeName, extension);
574 if (this.referenceDataObject.action === 'OpenStack Actions') {
575 this.referenceDataObject['template'] = 'N';
576 this.referenceDataObject['artifact-list'] = [];
577 this.referenceDataObject['firstRowVmSpreadSheet']=this.firstArrayElement;
579 //detaching the object from the form and processing further
580 let newObj = $.extend(true, {}, this.referenceDataObject);
581 let action = this.referenceDataObject.action;
582 newObj = this.deleteVmsforNonActions(newObj, action)
583 this.pushOrReplaceTempData(newObj, action);
584 this.addAllActionObj(newObj, scopeName);
586 //saving data to service
587 this.mappingEditorService.getReferenceList().push(JSON.parse(JSON.stringify(this.referenceDataObject)));
588 this.buildDesignComponent.updateAccessUpdatePages(this.referenceDataObject.action, this.mappingEditorService.getReferenceList());
589 this.mappingEditorService.changeNav(this.tempAllData);
590 //on action change or template identifier change reset the form by restting values of Reference data object
591 this.resetVmsForScaleout(this.currentAction)
592 return { totlaRefDtaa: this.tempAllData, scopeName: scopeName };
595 public checkIfelementExistsInArray(element, array) {
596 //// console.log("Element==" + element)
597 var result: boolean = false;
599 array.forEach(function (item) {
600 // // console.log("Item==" + item)
601 if (element === item) {
602 // console.log('Element==' + element + 'Item==' + item);
611 if( this.utilityService.getTracelvl() > 0 )
612 console.log( this.classNm+": upload: start.");
613 /* wire up file reader */
614 const target: DataTransfer = <DataTransfer>(evt.target);
615 this.uploadFileName = evt.target.files[0].name;
616 var fileExtension = this.uploadFileName.substr(this.uploadFileName.lastIndexOf('.') + 1);
617 if (target.files.length != 1) {
618 console.log( this.classNm+": upload: Error: got no file !");
619 throw new Error(appConstants.errors.multipleFileUploadError);
621 console.log( this.classNm+": upload: filename:["+evt.target.files[0].name+"]");
622 if (fileExtension.toUpperCase() === 'XLS' || fileExtension.toUpperCase() === 'XLSX') {
623 const reader = new FileReader();
624 reader.onload = (e: any) => {
626 const bstr = e.target.result;
627 // // console.log("print 1---" + bstr);
628 const wb = XLSX.read(bstr, { type: 'binary' });
629 // // console.log("print 2---" + JSON.stringify(wb));
630 /* grab first sheet */
631 const wsname = wb.SheetNames[0];
632 // // console.log("Name:---" + wsname);
633 const ws = wb.Sheets[wsname];
637 let arrData = (<AOA>(XLSX.utils.sheet_to_json(ws, { header: 1 })));
638 this.uploadedDataArray = arrData;
639 this.firstArrayElement = arrData[0];
640 var remUploadedDataArray = arrData;
641 remUploadedDataArray.shift();
642 this.remUploadedDataArray = remUploadedDataArray;
643 if (arrData != null) {
644 this.getExcelUploadStatus = true;
645 this.nService.success(appConstants.notifications.titles.success, appConstants.messages.vmDataUploadSuccess);
649 this.nService.success(appConstants.notifications.titles.error, appConstants.messages.emptyVmUpload);
652 reader.readAsBinaryString(target.files[0]);
655 this.nService.error(appConstants.notifications.titles.error, appConstants.messages.incorrectVmUpload);
660 addVmCapabilitiesData() {
661 if( this.utilityService.getTracelvl() > 0 )
662 console.log( this.classNm+": addVmCapabilitiesData: start.");
663 for (var i = 0; i < this.uploadedDataArray.length; i++) {
664 var vnfcFuncCodeArray = [];
665 var data = this.uploadedDataArray[i];
666 for (var j = 1; j < data.length; j++) {
667 if (data[j] != undefined) {
668 if (data[j].toUpperCase() === 'Y') {
669 vnfcFuncCodeArray.push(this.firstArrayElement[j]);
673 var action = this.uploadedDataArray[i][0];
674 if (action && action != undefined) {
677 'action-level': 'vm',
679 'vnf-type': this.referenceDataObject['scope']['vnf-type'], //need to confirm what should be this value
682 'vnfc-function-code-list': vnfcFuncCodeArray,
684 'device-protocol': 'OS'
687 this.tempAllData.push(json);
694 save(form: any, isValid: boolean) {
695 if( this.utilityService.getTracelvl() > 0 )
696 console.log( this.classNm+": save: start: referenceDataObject.action:["+
697 this.referenceDataObject.action+"]");
698 if (this.referenceDataObject.action === '') {
699 this.nService.error(appConstants.notifications.titles.error, appConstants.errors.noActionError);
702 if (this.referenceDataObject['device-protocol'] === '') {
703 this.nService.error(appConstants.notifications.titles.error, appConstants.errors.noDeviceProtocolError);
708 let referenceObject = this.prepareReferenceObject();
709 let theJSON = JSON.stringify({ 'reference_data': this.tempAllData }, null, '\t');
710 let uri = 'data:application/json;charset=UTF-8,' + encodeURIComponent(theJSON);
711 this.downloadData.reference = theJSON;
712 this.validateTempAllData();
713 var blob = new Blob([theJSON], {
716 let fileName = 'reference_AllAction_' + referenceObject.scopeName + '_' + '0.0.1V.json';
717 this.downloadFile(blob, fileName, 100)
718 var templateData = JSON.stringify(this.downloadData.template.templateData);
719 var nameValueData = JSON.stringify(this.downloadData.template.nameValueData);
720 var pdData = this.downloadData.pd.pdData;
721 if (templateData != '{}' && templateData != null && templateData != undefined) this.downloadTemplate();
722 if (nameValueData != '{}' && nameValueData != null && nameValueData != undefined) this.downloadNameValue();
723 if (pdData != '' && pdData != null && pdData != undefined) this.downloadPd();
726 downloadFile(blob, fileName, delay) {
727 if( this.utilityService.getTracelvl() > 0 )
728 console.log( this.classNm+": downloadFile: start.");
730 saveAs(blob, fileName);
735 if( this.utilityService.getTracelvl() > 0 )
736 console.log( this.classNm+": downloadTemplate: start.");
737 var fileName = this.downloadData.template.templateFileName;
738 console.log( this.classNm+": downloadTemplate: fileName:["+fileName+"]");
739 var theJSON = this.downloadData.template.templateData;
740 if (fileName != null || fileName != '') {
741 var fileExtensionArr = fileName.split('.');
742 var blob = new Blob([theJSON], {
743 type: 'text/' + fileExtensionArr[1]
745 this.downloadFile(blob, fileName, 130)
749 downloadNameValue() {
750 var fileName = this.downloadData.template.nameValueFileName;
751 var theJSON = this.downloadData.template.nameValueData;
752 var blob = new Blob([theJSON], {
756 this.downloadFile(blob, fileName, 160)
760 let fileName = this.downloadData.pd.pdFileName;
761 let theJSON = this.downloadData.pd.pdData;
762 var blob = new Blob([theJSON], {
766 this.downloadFile(blob, fileName, 180)
769 // save the values to the cache, on action change without download
770 validateDataAndSaveToAppc( valid, form, event) {
771 if( this.utilityService.getTracelvl() > 0 )
772 console.log( this.classNm+": validateDataAndSaveToAppc: start: valid:"+valid);
773 // will show error message
774 this.showValidationErrors(this.referenceDataObject);
776 form._submitted = true;
778 let referenceObject = this.prepareReferenceObject(true);
779 let removedKeysArray = []
780 this.tempAllData.forEach((data, index) => {
782 removedKeysArray.push(JSON.parse(JSON.stringify(this.deleteUnwantedKeys(data))))
785 this.tempAllData = removedKeysArray;
787 this.validateTempAllData();
789 if (this.actionChanged) {
791 if (this.currentAction) {
792 this.referenceDataObject.action = this.currentAction;
795 this.populateExistinAction(this.referenceDataObject.action);
796 this.actionChanged = false;
801 this.nService.warn('status', 'unable to save the artifact');
805 //this method saves reference, template, param and PD data to APPC
807 if( this.utilityService.getTracelvl() > 0 )
808 console.log( this.classNm+": saveToAppc: start: vnf-type:["+
809 this.referenceDataObject.scope['vnf-type']+"]");
810 let theJSON = JSON.stringify(this.tempAllData, null, '\t');
811 let fileName = 'reference_AllAction_' + this.referenceDataObject.scope['vnf-type'].replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '') + '_' + '0.0.1V.json';
812 this.saveReferenceDataToAppc(
813 JSON.stringify({ reference_data: this.tempAllData }), this.referenceDataObject.scope['vnf-type'], fileName);
815 var templateData = JSON.stringify(this.appData.template.templateData);
816 var nameValueData = JSON.stringify(this.appData.template.nameValueData);
817 var pdData = JSON.stringify(this.appData.pd);
818 if (templateData != '{}' && templateData != null && templateData != undefined) this.referenceDataFormUtil.handleApiData(this.appData.template.templateData, 'template data');
819 if (nameValueData != '{}' && nameValueData != null && nameValueData != undefined) this.referenceDataFormUtil.handleApiData(this.appData.template.nameValueData, 'name value pairs');
820 if (pdData != '{}' && pdData != null && pdData != undefined) this.referenceDataFormUtil.handleApiData(this.appData.pd, 'PD file');
823 // valaidation of template data
824 validateTempAllData() {
825 if( this.utilityService.getTracelvl() > 0 )
826 console.log( this.classNm+": validateTempAllData: start.");
827 if (this.tempAllData) {
828 var updatedData = [];
829 this.tempAllData.forEach(data => {
831 updatedData.push(data);
834 this.tempAllData = updatedData;
838 //.. prepare and send the data to the API.
839 saveReferenceDataToAppc(artifactData, vnf_type, fileName) {
840 if( this.utilityService.getTracelvl() > 0 )
841 console.log( this.classNm+": saveReferenceDataToAppc: start: vnf_type:["+
844 let slashedPayload = this.referenceDataFormUtil.appendSlashes(artifactData);
845 let payload = this.utilityService.createPayLoadForSave("reference_data", vnf_type, "AllAction", fileName, this.versionNoForApiCall, slashedPayload);
846 this.ngProgress.start();
847 this.httpUtils.post({
848 url: environment.getDesigns,
850 }).subscribe((resp) => {
851 if (resp != null && resp.output.status.code == '400') {
852 window.scrollTo(0, 0);
853 this.nService.success('Status', 'successfully uploaded the Reference Data');
855 this.nService.warn('Status', 'Error while saving Reference Data');
857 this.uploadStatusError = false;
858 this.getRefStatus = false;
859 this.ngProgress.done();
861 this.nService.error('Status', 'Error Connecting to the APPC Network');
862 window.scrollTo(0, 0);
864 this.appData.reference = payload;
866 this.ngProgress.done();
871 console.log( this.classNm+": retriveFromAppc: start.");
872 if (sessionStorage.getItem('updateParams') != 'undefined') {
874 this.noCacheData = false;
876 this.noCacheData = true;
880 cloneMessage(servermessage) {
882 for (var key in servermessage) {
883 if (servermessage.hasOwnProperty(key)) //ensure not adding inherited props
884 clone[key] = servermessage[key];
889 public showUpload() {
890 this.selectedUploadType = this.uploadTypes[0].value;
893 public fileChange(input) {
894 if( this.utilityService.getTracelvl() > 0 )
895 console.log( this.classNm+": fileChange: start.");
896 this.fileName = input.target.files[0].name.replace(/C:\\fakepath\\/i, '');
897 this.fileUploaded = true;
898 this.disableRetrieve = true;
899 if (input.target.files && input.target.files[0]) {
900 // Create the file reader
901 let reader = new FileReader();
902 this.readFile(input.target.files[0], reader, (result) => {
903 // After the callback fires do:
904 if ('Reference Data' === this.selectedUploadType) {
907 let jsonObject = (JSON.parse(result))['reference_data'];
908 this.uploadedData = JSON.parse(JSON.stringify(jsonObject));
909 //check for legacy artifact and do not allow it
910 for (let i = 0; i < this.uploadedData.length; i++) {
911 obj = this.uploadedData[i];
912 if (obj.scope['vnfc-type'] != undefined && obj.scope['vnfc-type'] != '') {
913 this.nService.error('Error', 'The legacy reference artifact not supported');
917 this.displayVnfc = 'false';
918 this.isVnfcType = false;
919 this.isVnfcTypeList = false;
920 for (let i = 0; i < this.uploadedData.length; i++) {
921 obj = this.uploadedData[i];
922 if (obj.scope['vnfc-type-list'] && obj.scope['vnfc-type-list'].length > 0) {
923 this.displayVnfc = 'true';
924 this.isVnfcTypeList = true;
925 this.vnfcIdentifier = obj.scope['vnfc-type-list'][0];
928 this.oldAction=obj.action;
929 this.tempAllData = JSON.parse(JSON.stringify(jsonObject));
930 if( this.utilityService.getTracelvl() > 0 )
931 console.log( this.classNm+": fileChange: read & parsed.");
932 this.notificationService.notifySuccessMessage('Reference Data file successfully uploaded..');
933 if (jsonObject instanceof Array) {
934 this.referenceDataObject = jsonObject[0];
935 jsonObject.forEach(obj => {
936 this.selectedActions.push(obj.action);
939 this.referenceDataObject = jsonObject;
941 this.selectedActions.push(jsonObject.action);
943 if( this.utilityService.getTracelvl() > 0 )
944 console.log( this.classNm+": fileChange: "+
945 "referenceDataObject.action:["+
946 this.referenceDataObject.action+"]");
947 this.toggleIdentifier(this.referenceDataObject.action)
948 this.configDrp(this.referenceDataObject.action)
949 if (this.referenceDataObject.action === 'OpenStack Actions') {
950 this.deviceProtocols = ['', 'OpenStack'];
951 this.buildDesignComponent.tabs = [
954 name: 'Reference Data',
959 this.buildDesignComponent.tabs = [
961 name: 'Reference Data',
965 url: 'templates/myTemplates',
967 name: 'Parameter Definition',
968 url: 'parameterDefinitions/create'
975 this.getArtifactsOpenStack();
976 if (this.referenceDataObject.template == null) {
977 this.referenceDataObject.template = 'Y';
979 if (this.referenceDataObject['action-level'] == null) {
980 this.referenceDataObject['action-level'] = 'VNF';
982 if( this.utilityService.getTracelvl() > 0 )
983 console.log( this.classNm+": fileChange: displayVnfc:["+
984 this.displayVnfc+"]");
985 // Enable or Block Template and PD Tabs
986 this.buildDesignComponent.getRefData(
987 { ...this.referenceDataObject, displayVnfc: this.displayVnfc });
989 this.nService.error(appConstants.notifications.titles.error, appConstants.messages.incorrectFileFormat);
992 this.hideModal = true;
995 if( this.utilityService.getTracelvl() > 0 )
996 console.log( this.classNm+": fileChange: Error: Failed to read file!");
997 this.notificationService.notifyErrorMessage('Failed to read file..');
1001 public readFile(file, reader, callback) {
1002 console.log( this.classNm+": readFile: start.");
1003 // Set a callback funtion to fire after the file is fully loaded
1004 reader.onload = () => {
1005 // callback with the results
1006 callback(reader.result);
1008 this.notificationService.notifySuccessMessage('Uploading File ' + file.name + ':' + file.type + ':' + file.size);
1010 reader.readAsText(file, 'UTF-8');
1013 fileChangeEvent(fileInput: any) {
1014 let obj: any = fileInput.target.files;
1018 console.log( this.classNm+": clearVnfcData: start.");
1020 'vnfc-instance': '1',
1021 'vnfc-function-code': '',
1022 'ipaddress-v4-oam-vip': '',
1023 'group-notation-type': '',
1024 'group-notation-value': ''
1028 setVmInstance(index) {
1029 this.referenceDataObject.vm[index]['vm-instance'] = index + 1;
1032 // setVnfcType(str: String) {
1033 // this.Sample['vnfc-type'] = str;
1036 // getChange(value: String) {
1037 // if (value === 'vnfType') {
1038 // this.referenceDataObject.scope['vnfc-type'] = '';
1043 console.log( this.classNm+": resetForm: start.");
1044 this.referenceDataObject['action-level'] = 'vnf';
1045 this.referenceDataObject.template = 'Y';
1046 this.referenceDataObject['device-protocol'] = '';
1047 this.referenceDataObject['user-name'] = '';
1048 this.referenceDataObject['port-number'] = '';
1049 this.refernceScopeObj.sourceType = '';
1050 this.Sample['vnfc-type'] = '';
1053 // this method gets called with the action as parameter and the respective action details are fetched and assigned to the current page
1054 populateExistinAction(data) {
1055 console.log( this.classNm+": populateExistinAction: start.");
1056 let existAction = this.tempAllData.findIndex(obj => {
1057 return obj.action == data;
1059 if (existAction > -1) {
1060 let obj = $.extend(true, {}, this.tempAllData[existAction]);
1061 this.referenceDataObject = obj;
1062 this.referenceDataObject.scope['vnf-type'] = obj['scope']['vnf-type'];
1063 this.referenceDataObject.scope['vnfc-type-list'] = obj['scope']['vnfc-type-list'];
1064 this.referenceDataObject['device-protocol'] = obj['device-protocol'];
1065 this.refernceScopeObj['sourceType'] = obj['scopeType'];
1066 if(obj['scope']['vnfc-type-list'] != undefined && obj['scope']['vnfc-type-list'].length >0) {
1067 this.referenceDataObject['vnfcIdentifier'] = obj['scope']['vnfc-type-list'][0];
1070 console.log( this.classNm+": populateExistinAction: action not found");
1072 this.referenceDataObject.action = data;
1074 //# iof healthCeck change deviceprotocol drp vaues
1077 this.deviceProtocols = ['', 'ANSIBLE', 'CHEF', 'REST'];
1078 this.actionHealthCheck = true;
1080 case 'UpgradeBackout':
1081 case 'ResumeTraffic':
1082 case 'QuiesceTraffic':
1083 case 'UpgradeBackup':
1084 case 'UpgradePostCheck':
1085 case 'UpgradePreCheck':
1086 case 'UpgradeSoftware':
1087 case 'ConfigRestore':
1088 case 'StartApplication':
1089 case 'StopApplication':
1090 case 'ConfigBackup':
1091 this.deviceProtocols = ['', 'CHEF', 'ANSIBLE'];
1093 case 'OpenStack Actions':
1094 this.deviceProtocols = ['', 'OpenStack'];
1096 case 'ConfigScaleOut':
1097 this.deviceProtocols = ['', 'CHEF', 'ANSIBLE', 'NETCONF-XML', 'RESTCONF'];
1099 case 'GetRunningConfig':
1100 this.deviceProtocols = ['', 'CHEF', 'ANSIBLE', 'NETCONF-XML', 'RESTCONF', 'CLI', 'REST'];
1103 this.deviceProtocols = ['', 'ANSIBLE', 'CHEF', 'NETCONF-XML', 'RESTCONF', 'CLI'];
1104 this.actionHealthCheck = false;
1108 //Modal pop up for action change with values entered.
1109 actionChange(data, userForm) {
1110 var methName= "actionChange";
1111 console.log( this.classNm+": "+methName+": start: data:["+data+"]");
1112 this.disableGrpNotationValue = false
1114 console.log( this.classNm+": "+methName+": data == null");
1117 if ((userForm.valid) && this.oldAction != '' && this.oldAction != undefined) {
1118 this.actionChanged = true;
1119 console.log( this.classNm+": "+methName+
1120 ": userForm valid and oldAction defined");
1121 // Calling common Confirmation Modal
1122 let disposable = this.dialogService.addDialog(ConfirmComponent)
1123 .subscribe((isConfirmed)=>{
1124 //We get dialog result
1125 console.log( this.classNm+": "+methName+": isConfirmed:["+
1128 // User clicked on Yes
1129 this.currentAction = this.referenceDataObject.action;
1130 console.log( this.classNm+": "+methName+
1131 ": clicked on Yes: currentAction:["+this.currentAction+
1132 "] oldAction:["+this.oldAction+"]");
1133 this.referenceDataObject.action = this.oldAction;
1134 $('#saveToAppc').click();//make sure the save all is done before the tempall obj is saved form the API
1135 this.toggleIdentifier(data)
1136 this.oldAction = this.currentAction;// this.referenceDataObject.action + '';
1137 this.referenceDataObject.action = this.currentAction;
1138 this.populateExistinAction(data);
1139 if (this.oldAction === 'OpenStack Actions') {
1141 this.uploadedDataArray = [];
1142 this.remUploadedDataArray = [];
1143 this.firstArrayElement = [];
1144 this.uploadFileName = '';
1145 //this.tempAllData = [];
1148 this.refernceScopeObj.from = '';
1149 this.getArtifactsOpenStack();
1151 // Clears VNFC Information data on action change
1152 this.clearVnfcData()
1153 this.resetVmsForScaleout(data);
1156 // User clicked on No
1157 this.toggleIdentifier(data)
1158 this.currentAction = this.referenceDataObject.action;
1159 console.log( this.classNm+": "+methName+
1160 ": clicked on No: currentAction:["+this.currentAction+"]");
1161 this.populateExistinAction(data);
1162 this.resetVmsForScaleout(data);
1163 this.oldAction = this.referenceDataObject.action + '';
1165 this.clearVnfcData()
1166 this.refernceScopeObj.from = '';
1169 if (this.referenceDataObject.action === 'Configure' || this.referenceDataObject.action === 'ConfigModify') {
1170 this.isConfigOrConfigModify = true;
1172 this.isConfigOrConfigModify = false;
1173 delete this.mappingEditorService.newObject['vnfc'];
1176 // Enable or Block Template and PD Tabs
1177 if (this.currentAction == 'ConfigScaleOut' && this.templateIdentifier && this.templateIdentifier != '') {
1178 // let referenceDataObjectTemp = this.referenceDataObject;
1179 // referenceDataObjectTemp['template-id'] = this.templateIdentifier;
1180 // this.buildDesignComponent.getRefData(referenceDataObjectTemp);
1181 this.buildDesignComponent.getRefData({ ...this.referenceDataObject, displayVnfc: this.displayVnfc }, { reqField: this.templateIdentifier });
1184 this.buildDesignComponent.getRefData({ ...this.referenceDataObject, displayVnfc: this.displayVnfc });
1188 console.log( this.classNm+": "+methName+
1189 ": userForm Not valid or oldAction not defined");
1190 this.actionChanged = true;
1191 this.currentAction = this.referenceDataObject.action;
1192 this.oldAction = this.referenceDataObject.action + '';
1193 this.populateExistinAction(data);
1194 this.resetVmsForScaleout(data);
1195 this.toggleIdentifier(data);
1197 // Enable or Block Template and PD Tabs
1198 if (this.currentAction == 'ConfigScaleOut' && this.templateIdentifier) {
1199 // let referenceDataObjectTemp = this.referenceDataObject;
1200 // referenceDataObjectTemp['template-id'] = this.templateIdentifier;
1201 // this.buildDesignComponent.getRefData(referenceDataObjectTemp);
1202 this.buildDesignComponent.getRefData({ ...this.referenceDataObject, displayVnfc: this.displayVnfc }, { reqField: this.templateIdentifier });
1204 this.buildDesignComponent.getRefData({ ...this.referenceDataObject, displayVnfc: this.displayVnfc });
1207 this.configDrp(data)
1211 console.log( this.classNm+": configDrp: start: data:["+data+"]");
1212 if (data == 'ConfigScaleOut') {
1213 this.groupAnotationType = ['', 'first-vnfc-name', 'fixed-value', 'relative-value', 'existing-group-name'];
1215 this.groupAnotationType = ['', 'first-vnfc-name', 'fixed-value', 'relative-value'];
1217 if (data == 'OpenStack Actions') {
1218 this.buildDesignComponent.tabs = [
1221 name: 'Reference Data',
1226 this.buildDesignComponent.tabs = [
1228 name: 'Reference Data',
1232 url: 'templates/myTemplates',
1234 name: 'Parameter Definition',
1235 url: 'parameterDefinitions/create'
1242 if (data == 'Configure' || data == 'ConfigModify') {
1243 this.nonConfigureAction = false;
1245 this.nonConfigureAction = true;
1249 deviceProtocolChange() {
1250 console.log( this.classNm+": deviceProtocolChange: start.");
1251 if (this.referenceDataObject['device-protocol'] == 'REST') {
1254 delete this.referenceDataObject['context-url']
1256 // Enable or Block Template and PD Tabs
1257 this.buildDesignComponent.getRefData(
1258 {...this.referenceDataObject,displayVnfc: this.displayVnfc },
1259 {reqField: this.templateIdentifier});
1262 // used to call or trigger save object on template Identifier changes
1263 idChange(data, userForm) {
1264 console.log( this.classNm+": idChange: start: data:["+data+"]");
1268 // Enable or Block Template and PD Tabs
1269 // let referenceDataObjectTemp = this.referenceDataObject;
1270 // referenceDataObjectTemp['template-id'] = data;
1271 // this.buildDesignComponent.getRefData(referenceDataObjectTemp);
1272 this.buildDesignComponent.getRefData(
1273 {...this.referenceDataObject, displayVnfc: this.displayVnfc },
1274 { reqField: data });
1276 if ((userForm.valid)) {
1277 this.currentAction = "ConfigScaleOut"
1278 this.oldtemplateIdentifier = this.templateIdentifier
1279 let referenceObject = this.prepareReferenceObject();
1280 this.actionChanged = true;
1281 if (this.templateIdentifier) {
1282 // Calling common Confirmation Modal
1283 let disposable = this.dialogService.addDialog(ConfirmComponent)
1284 .subscribe((isConfirmed)=>{
1285 //We get dialog result
1287 // User clicked on Yes
1288 this.validateTempAllData();
1291 this.clearVnfcData();
1292 this.refernceScopeObj.from = '';
1295 // User clicked on No
1297 this.refernceScopeObj.from = '';
1302 this.oldtemplateIdentifier = this.templateIdentifier;
1306 // used to call or trigger save object on multiple VNFC's changes
1307 vnfcChanged( data, userForm) {
1308 console.log( this.classNm+": vnfcChanged: new vnfcIdentifier:["+data+"]");
1309 console.log( this.classNm+": vnfcChanged: oldVnfcIdentifier:["+
1310 this.oldVnfcIdentifier+"]");
1311 console.log(this.classNm+": vnfcChanged: scope.vnfc-type:["+
1312 this.referenceDataObject.scope['vnfc-type']+"]");
1313 this.vnfcIdentifier = data;
1318 //.. populate VNFC Type in Sample field
1319 this.setVnfcTypeInSample( this.vnfcIdentifier );
1320 // Enable or Block Template and PD Tabs
1321 let referenceDataObjectTemp = this.referenceDataObject;
1322 referenceDataObjectTemp['vnfcIdentifier'] = data;
1323 console.log( this.classNm+
1324 ": vnfcChanged: displayVnfc:["+this.displayVnfc+"]");
1325 this.buildDesignComponent.getRefData(
1326 {...this.referenceDataObject, displayVnfc: this.displayVnfc },
1327 { reqField: data });
1328 console.log( this.classNm+
1329 ": vnfcChanged: userForm.valid:["+userForm.valid+"]");
1330 if ((userForm.valid) && this.oldVnfcIdentifier != '' && this.oldVnfcIdentifier != undefined) {
1331 this.currentAction = this.referenceDataObject.action
1332 this.oldVnfcIdentifier = this.vnfcIdentifier
1333 let referenceObject = this.prepareReferenceObject();
1334 this.actionChanged = true;
1335 if (this.vnfcIdentifier) {
1336 // Calling common Confirmation Modal
1337 let disposable = this.dialogService.addDialog(ConfirmComponent)
1338 .subscribe((isConfirmed)=>{
1339 //We get dialog result
1341 // User clicked on Yes
1342 this.validateTempAllData();
1345 this.clearVnfcData()
1346 this.refernceScopeObj.from = '';
1349 // User clicked on No
1351 this.refernceScopeObj.from = '';
1357 this.oldVnfcIdentifier = this.vnfcIdentifier
1363 console.log( this.classNm+": clearCache: start.");
1364 // get the value and save the userid and persist it.
1365 this.clearTemplateCache();
1366 this.clearPdCache();
1367 this.appData = { reference: {}, template: { templateData: {}, nameValueData: {} }, pd: {} };
1368 this.downloadData = {
1370 template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' },
1371 pd: { pdData: '', pdFileName: '' }
1375 clearTemplateCache() {
1376 this.mappingEditorService.setTemplateMappingDataFromStore(undefined);
1377 localStorage['paramsContent'] = '{}';
1380 this.mappingEditorService.setParamContent(undefined);
1381 this.paramShareService.setSessionParamData(undefined);
1385 console.log( this.classNm+": saveTemp: start.");
1389 { url: environment.getDesigns, data: this.appData.template.templateData })
1390 .subscribe(resp => {
1391 if (resp.output.status.code === '400' && resp.output.status.message === 'success') {
1392 this.nService.success('Status', 'Successfully uploaded the Template Data');
1394 if (resp.output.status.code === '401') {
1395 this.nService.warn('Status', 'Error in saving the Template to Appc');
1399 (err) => this.nService.error('Status', 'Error Connecting to the APPC Network'));
1403 console.log( this.classNm+": saveNameValue: start.");
1408 url: environment.getDesigns, data: this.appData.template.nameValueData
1410 .subscribe(resp => {
1411 if (resp.output.status.code === '400' && resp.output.status.message === 'success') {
1412 this.nService.success('Status', 'Successfully uploaded the Name Value Pairs');
1414 if (resp.output.status.code === '401') {
1415 this.nService.warn('Status', 'Error in saving the Name value pairs to Appc');
1419 this.nService.error('Status', 'Error Connecting to the APPC Network');
1429 url: environment.getDesigns, data: this.appData.pd
1431 .subscribe(resp => {
1432 if (resp.output.status.code === '400' && resp.output.status.message === 'success') {
1433 this.nService.success('Status', 'Successfully uploaded PD file');
1435 if (resp.output.status.code === '401') {
1436 this.nService.warn('Status', 'Error in saving the PD to Appc');
1440 this.nService.error('Status', 'Error Connecting to the APPC Network');
1445 openModel(toShow: any, message: any, title: any) {
1446 console.log( this.classNm+": openModel: start: title:["+title+"]");
1447 this.modalComponent.isShow = toShow;
1448 this.modalComponent.message = message;
1449 this.modalComponent.title = title;
1453 $('#inputFile').trigger('click');
1456 excelBrowseOption() {
1457 $('#excelInputFile').trigger('click');
1461 $('#identifierModal').modal();
1465 if (!(this.referenceDataObject['template-id-list'])) {
1466 this.referenceDataObject['template-id-list'] = [];
1468 if (!(this.referenceDataObject['template-id-list'].indexOf(this.templateId.trim()) > -1)) {
1469 this.referenceDataObject['template-id-list'].push(this.templateId.trim());
1471 // Changing value to blank otherwise it will show previous value in text box of popup
1472 this.templateId = '';
1475 // adds the vnfc to the vnfc dropdown list
1477 var newVnfcTypeV= this.newVnfcType.trim();
1478 console.log(this.classNm+
1479 ": addVnfc: start: newVnfcTypeV:["+newVnfcTypeV+"]");
1480 if (!(this.referenceDataObject.scope['vnfc-type-list'])) {
1481 this.referenceDataObject.scope['vnfc-type-list'] = [];
1482 // this.vnfcIdentifier = newVnfcTypeV;
1483 } else if (this.referenceDataObject.scope['vnfc-type-list'].length == 0){
1484 // this.vnfcIdentifier = newVnfcTypeV;
1486 this.vnfcIdentifier = newVnfcTypeV;
1487 console.log(this.classNm+
1488 ": addVnfc: vnfcIdentifier:["+this.vnfcIdentifier+"]");
1489 if (!(this.referenceDataObject.scope['vnfc-type-list'].indexOf(newVnfcTypeV) > -1)) {
1490 this.referenceDataObject.scope['vnfc-type-list'].push(newVnfcTypeV);
1492 this.tempAllData.forEach(obj => {
1493 if (obj.action == "Configure" || obj.action == "ConfigModify") {
1494 obj.scope['vnfc-type-list'] = this.referenceDataObject.scope['vnfc-type-list']
1496 this.resetArtifactList(obj);
1498 console.log(this.classNm+": addVnfc: scope vnfc-type:["+
1499 this.referenceDataObject.scope['vnfc-type']+"]");
1500 this.setVnfcTypeInSample( newVnfcTypeV );
1501 // Changing newVnfcType value to blank otherwise it will show previous value in text box of popup
1502 this.newVnfcType = ''
1506 console.log( this.classNm+": resetVms: start.");
1507 this.referenceDataObject.vm = [];
1511 // this.referenceDataObject.vm = this.referenceDataObject.vm;
1514 resetGroupNotation() {
1515 if (this.Sample['group-notation-type'] == "existing-group-name") {
1516 this.Sample['group-notation-value'] = ""
1517 this.disableGrpNotationValue = true
1519 this.disableGrpNotationValue = false
1523 resetVmsForScaleout(action) {
1524 //reset currentform vms based on action
1525 if (action == "ConfigScaleOut" || action == "Configure") {
1526 let ConfigScaleOutIndex = this.tempAllData.findIndex(obj => {
1527 return obj['action'] == action
1529 if (ConfigScaleOutIndex > -1) {
1530 this.referenceDataObject.vm = this.tempAllData[ConfigScaleOutIndex].vm
1532 if (this.actionChanged) {
1533 this.referenceDataObject.vm = []
1539 resetParamsOnVnfcType() {
1540 console.log( this.classNm+": resetParamsOnVnfcType: start:\n "+
1541 "ref.DataObject.scope vnfc-type:["+
1542 this.referenceDataObject.scope['vnfc-type']+"]");
1544 //if only vnf is there
1545 if (this.referenceDataObject.scope['vnfc-type'] == '' || this.referenceDataObject.scope['vnfc-type'] == null || this.referenceDataObject.scope['vnfc-type'] == 'null') {
1546 scopeName = this.referenceDataObject.scope['vnf-type'];
1547 this.referenceDataObject.scope['vnfc-type'] = '';
1548 this.referenceDataObject['action-level'] = 'vnf';
1549 this.referenceDataObject['scopeType'] = 'vnf-type';
1551 //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
1553 scopeName = this.referenceDataObject.scope['vnfc-type'];
1554 if (this.referenceDataObject.action == 'Configure' || this.referenceDataObject.action == 'ConfigModify') {
1555 this.referenceDataObject['action-level'] = 'vnfc';
1556 this.referenceDataObject['scopeType'] = 'vnfc-type';
1558 this.referenceDataObject['action-level'] = 'vnf';
1559 this.referenceDataObject['scopeType'] = 'vnf-type';
1562 //replacing / with _ and removing spaces in the scopeName
1564 scopeName = scopeName.replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '');
1566 console.log( this.classNm+": resetParamsOnVnfcType: return scopeName:["+
1571 decideExtension(obj) {
1572 //marking the extension based on the device-protocol selected by the user
1573 let extension = '.json';
1574 switch (obj['device-protocol']) {
1578 extension = '.json';
1587 prepareArtifactList(scopeName, extension) {
1588 console.log( this.classNm+": prepareArtifactList: start: scopeName:["+
1589 scopeName+"] extension:["+extension+"]");
1590 this.referenceDataObject['artifact-list'] = [];
1591 //preparing the artifact list array file names along with extension
1592 let config_template_fileName = this.referenceDataObject.action + '_' + scopeName + '_' + '0.0.1V.' + extension;
1593 let pd_fileName = this.referenceDataObject.action + '_' + scopeName + '_' + '0.0.1V.yaml';
1594 let reference_fileName = this.referenceDataObject.action + '_' + scopeName + '_' + '0.0.1V.json';
1595 let configTemplate = {
1596 'artifact-name': 'template_' + config_template_fileName,
1597 'artifact-type': 'config_template'
1600 'artifact-name': 'pd_' + pd_fileName,
1601 'artifact-type': 'parameter_definitions'
1603 if (this.referenceDataObject.action != 'ConfigScaleOut') {
1604 this.referenceDataObject['artifact-list'].push(configTemplate,
1608 let identifiers = this.referenceDataObject['template-id-list'];
1610 for (var x = 0; x < identifiers.length; x++) {
1611 //for replacing spaces and "/" with "_"
1612 identifiers[x] = identifiers[x].replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '');
1613 pd_fileName = this.referenceDataObject.action + '_' + scopeName + '_' + '0.0.1V_' + identifiers[x] + '.yaml';
1614 config_template_fileName = this.referenceDataObject.action + '_' + scopeName + '_' + '0.0.1V_' + identifiers[x] + '.' + extension;
1617 'artifact-name': 'template_' + config_template_fileName,
1618 'artifact-type': 'config_template'
1621 'artifact-name': 'pd_' + pd_fileName,
1622 'artifact-type': 'parameter_definitions'
1624 this.referenceDataObject['artifact-list'].push(configTemplate,
1632 deleteVmsforNonActions(newObj, action) {
1633 let configureObject = (action == 'Configure');
1634 let ConfigScaleOut = (action == 'ConfigScaleOut');
1635 //delete VM's if selected action is not configure.
1636 if (!ConfigScaleOut && !configureObject && this.tempAllData.length != 0) {
1637 if (ConfigScaleOut) {
1642 if (ConfigScaleOut) {
1644 delete newObj['template-id-list'];
1649 pushOrReplaceTempData(newObj, action) {
1650 console.log( this.classNm+": pushOrReplaceTempData: start: action:["+
1651 action+"]\n newObj.scope vnfc-type:["+newObj.scope['vnfc-type']+"]");
1652 if( newObj.scope['vnfc-type'] == undefined ||
1653 newObj.scope['vnfc-type'] == null ||
1654 newObj.scope['vnfc-type'].length < 1 )
1656 console.log( this.classNm+": pushOrReplaceTempData: scope vnfc-type"+
1657 " is empty.\n vnfcIdentifier:["+this.vnfcIdentifier+"]");
1658 if( this.vnfcIdentifier != null && this.vnfcIdentifier != undefined &&
1659 this.vnfcIdentifier.length > 0 )
1661 newObj.scope['vnfc-type']= this.vnfcIdentifier;
1664 let actionObjIndex = this.tempAllData.findIndex(obj => {
1665 return obj['action'] == action;
1667 if (newObj.action != 'HealthCheck') {
1668 delete newObj['url'];
1671 if (actionObjIndex > -1) {
1672 this.tempAllData[actionObjIndex] = newObj;
1673 this.mappingEditorService.saveLatestAction(this.tempAllData[actionObjIndex]);
1674 if (newObj.action == "ConfigScaleOut") {
1675 this.mappingEditorService.saveLatestIdentifier(this.templateIdentifier);
1678 this.templateIdentifier = ('')
1679 this.mappingEditorService.saveLatestIdentifier(this.templateIdentifier)
1682 if (newObj.action != '') {
1683 this.tempAllData.push(newObj);
1684 this.mappingEditorService.saveLatestAction(newObj);
1685 if (newObj.action == "ConfigScaleOut") {
1686 this.mappingEditorService.saveLatestIdentifier(this.templateIdentifier);
1689 this.templateIdentifier = ('')
1690 this.mappingEditorService.saveLatestIdentifier(this.templateIdentifier)
1697 // removes the unwanted keys added in the artifact for vnfc level actions
1698 deleteUnwantedKeys(newObj) {
1699 console.log( this.classNm+": deleteUnwantedKeys: start.");
1700 newObj = JSON.parse(JSON.stringify(newObj))
1701 delete newObj['template-id']
1702 delete newObj['vnfcIdentifier']
1703 if (newObj.action != "ConfigScaleOut") {
1704 delete newObj['template-id-list']
1706 if (newObj.action != 'HealthCheck') {
1707 delete newObj['url'];
1709 if (newObj.action != "Configure" && newObj.action != "ConfigModify") {
1710 newObj.scope['vnfc-type-list'] = [];
1715 addAllActionObj(newObj, scopeName) {
1716 console.log( this.classNm+": addAllActionObj: start.");
1717 //Creating all action block to allow mulitple actions at once
1719 action: 'AllAction',
1720 'action-level': 'vnf',
1721 scope: newObj.scope,
1723 'artifact-name': 'reference_AllAction' + '_' + scopeName + '_' + '0.0.1V.json',
1724 'artifact-type': 'reference_template'
1727 let allActionIndex = this.tempAllData.findIndex(obj => {
1728 return obj['action'] == 'AllAction';
1730 if (allActionIndex > -1) {
1731 this.tempAllData[allActionIndex] = allAction;
1733 this.tempAllData.push(allAction);
1738 console.log( this.classNm+": resetTempData: start.");
1739 if (this.uploadedDataArray && this.uploadedDataArray != undefined && this.uploadedDataArray.length != 0) {
1740 if (this.tempAllData && this.tempAllData != undefined) {
1741 for (var i = 0; i < this.tempAllData.length; i++) {
1743 if (this.tempAllData[i].action === 'AllAction') {
1747 result = this.checkIfelementExistsInArray(this.tempAllData[i].action, this.actions);
1750 this.tempAllData.splice(i, 1);
1756 this.addVmCapabilitiesData();
1760 trackByFn(index, item) {
1764 getArtifactsOpenStack() {
1765 console.log( this.classNm+": getArtifactsOpenStack: start: "+
1766 "tempAllData length="+this.tempAllData.length );
1768 var vnfcFunctionCodeArrayList = [];
1769 var vnfcSetArray=[];
1770 for (var i = 0; i < this.tempAllData.length; i++) {
1771 if (!this.checkIfelementExistsInArray(this.tempAllData[i].action, this.actions) && (this.tempAllData[i].action != 'AllAction')) {
1772 var vnfcFunctionCodeArray = this.tempAllData[i]["vnfc-function-code-list"]
1773 vnfcFunctionCodeArrayList.push([this.tempAllData[i].action].concat(this.tempAllData[i]["vnfc-function-code-list"]))
1775 if(this.tempAllData[i].action==='OpenStack Actions')
1777 vnfcSetArray=this.tempAllData[i]['firstRowVmSpreadSheet']
1780 console.log( this.classNm+": getArtifactsOpenStack: vnfcSetArray length="+
1781 vnfcSetArray.length );
1784 let vnfcSetArrayLen = vnfcSetArray.length;
1786 for (let i = 0; i < vnfcFunctionCodeArrayList.length; i++) {
1787 let element = vnfcFunctionCodeArrayList[i];
1788 for (let j = 1; j < element.length; j++) {
1789 for (let k = j; k < vnfcSetArrayLen; k++) {
1790 if (element[j] === vnfcSetArray[k]) {
1794 element.splice(j, 0, '');
1800 this.firstArrayElement = vnfcSetArray;
1801 this.remUploadedDataArray = vnfcFunctionCodeArrayList;
1806 * Handles the display of VM block based on the action change
1808 handleVMBlockDisplay() {
1809 switch (this.referenceDataObject.action) {
1810 case this.actionList.ConfigScaleOut:
1811 case this.actionList.Configure:
1814 this.displayVMBlock = true;
1817 this.displayVMBlock = false;
1821 //.. check VNFC Type equality in Upper Selection vs entered in Sample field
1822 checkVnfcTypeEqual( vnfctp: string ) {
1823 var methName= "checkVnfcTypeEqual";
1824 console.log(this.classNm+": "+methName+": vnfctp:["+vnfctp+"]");
1825 console.log( this.classNm+": "+methName+": vnfcIdentifier:["+
1826 this.vnfcIdentifier+"]");
1827 console.log( this.classNm+": "+methName+": Sample[vnfc-type]:["+
1828 this.Sample['vnfc-type']+"]");
1829 if( vnfctp != null && vnfctp.length > 0 ) {
1830 if( this.vnfcIdentifier != null && this.vnfcIdentifier.length > 0 ) {
1832 this.classNm+": "+methName+": compare non empty VNFC Types...");
1833 if( vnfctp != this.vnfcIdentifier ) {
1834 console.log( this.classNm+": "+methName+": Non-match WARNING !");
1835 //.. display in pop-up
1836 this.nService.warn( 'WARNING',
1837 "The specified VNFC Types don't match."+
1838 " Can cause discrepancy in the artifacts.", this.options );
1840 console.log(this.classNm+": checkVnfcTypeEqual: VNFC Types're equal.");
1846 //.. populating VNFC Type in Sample fields
1847 setVnfcTypeInSample( vnfctp: string ) {
1848 // if( this.utilityService.getTracelvl() > 0 )
1849 console.log( this.classNm+": setVnfcTypeInSample: vnfctp:["+vnfctp+"]");
1850 this.Sample['vnfc-type']= vnfctp;
1853 // Common method to show validation errors
1854 private showValidationErrors(referenceDataObject) {
1855 if (this.referenceDataObject.action === '') {
1856 this.nService.error('Error', 'Select a valid Action');
1859 if (this.referenceDataObject['device-protocol'] === '') {
1860 this.nService.error('Error', 'Select a valid Device protocol');
1864 if (referenceDataObject.action === 'ConfigScaleOut' && !this.templateIdentifier) {
1865 this.nService.error('Error', 'Select a valid Template Identifier');
1869 resetArtifactList( obj) {
1870 console.log( this.classNm+": resetArtifactList: start...");
1871 let vnfcTypeList = obj.scope['vnfc-type-list'];
1872 let vnf = this.referenceDataObject.scope['vnf-type']
1874 let config_template_fileName
1879 obj['artifact-list'] = [];
1880 for (var x = 0; x < vnfcTypeList.length; x++) {
1881 let extension = this.referenceDataFormUtil.decideExtension(obj)
1882 //for replacing spaces and "/" with "_"
1883 let type = vnfcTypeList[x].replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '');
1884 pd_fileName = this.referenceDataObject.action + '_' + vnf.replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '') + '_' + type + '_' + '0.0.1V.yaml';
1885 config_template_fileName = this.referenceDataObject.action + '_' + vnf.replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '') + '_' + type + '_' + '0.0.1V' + extension;
1886 param_fileName = this.referenceDataObject.action + '_' + vnf.replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '') + '_' + type + '_' + '0.0.1V.json';
1888 'artifact-name': 'template_' + config_template_fileName,
1889 'artifact-type': 'config_template'
1892 'artifact-name': 'pd_' + pd_fileName,
1893 'artifact-type': 'parameter_definitions'
1896 'artifact-name': 'param_' + param_fileName,
1897 'artifact-type': 'param_values'
1900 this.referenceDataObject['artifact-list'].push(configTemplate,
1901 pdTemplate, paramValue
1903 obj['artifact-list'].push(configTemplate,
1904 pdTemplate, paramValue