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.distributeTraffic,
141 appConstants.Actions.upgradeBackout,
142 appConstants.Actions.upgradeBackup,
143 appConstants.Actions.upgradePostCheck,
144 appConstants.Actions.upgradePreCheck,
145 appConstants.Actions.upgradeSoftware,
146 appConstants.Actions.openStackActions,
147 appConstants.Actions.configScaleOut
149 public groupAnotationValue = [appConstants.groupAnotationValue.blank, appConstants.groupAnotationValue.pair];
150 public groupAnotationType = [appConstants.groupAnotationType.blank, appConstants.groupAnotationType.firstVnfcName, appConstants.groupAnotationType.fixedValue, appConstants.groupAnotationType.relativeValue];
151 public deviceProtocols = [appConstants.DeviceProtocols.blank, appConstants.DeviceProtocols.ansible, appConstants.DeviceProtocols.chef, appConstants.DeviceProtocols.netconfXML, appConstants.DeviceProtocols.rest, appConstants.DeviceProtocols.cli, appConstants.DeviceProtocols.restConf];
152 public deviceTemplates = [appConstants.deviceTemplates.blank, appConstants.deviceTemplates.y, appConstants.deviceTemplates.n];
153 public sourceTypeColl = [appConstants.sourceTypeColl.blank, appConstants.sourceTypeColl.vnfType, appConstants.sourceTypeColl.vnfcType];
154 public ipAddressBoolean = ['', 'Y', 'N'];
155 public Sample: any = {
156 'vnfc-instance': '1',
157 'vnfc-function-code': '',
158 'ipaddress-v4-oam-vip': '',
159 'group-notation-type': '',
160 'group-notation-value': ''
162 hideModal: boolean = false;
164 public uploadTypes = [{
165 value: 'Reference Data',
166 display: 'Sample Json Param File'
169 value: 'Mapping Data',
170 display: 'Sample Json Param File'
173 public selectedUploadType: string = this.uploadTypes[0].value;
174 public vnfcTypeData: string = '';
175 public title: string;
176 public allowAction: boolean = true;
177 public actionExist: boolean = false;
178 public disableVnftype: boolean = false;
179 public otherActions: boolean = false;
180 public actionHealthCheck: boolean = false;
181 public actionChanged: boolean = false;
182 public initialAction: string = '';
183 public noCacheData: boolean;
184 public updateParams: any;
185 public vnfParams: any;
186 public firstArrayElement = [];
187 public remUploadedDataArray = [];
188 isConfigScaleOut = false
189 isConfigureAction = false;
190 configScaleOutExist: boolean = true;
191 displayVnfc = 'false';
193 isVnfcTypeList: boolean = true;
194 public actionList = {
195 "ConfigScaleOut": "ConfigScaleOut",
196 "Configure": "Configure"
198 public versionNoForApiCall = "0.0.1";
199 private displayVMBlock: boolean = true;
202 private buildDesignComponent: BuildDesignComponent,
203 private httpUtils: HttpUtilService,
204 private route: Router,
205 private location: Location,
206 private activeRoutes: ActivatedRoute,
207 private notificationService: NotificationService,
208 private paramShareService: ParamShareService,
209 private mappingEditorService: MappingEditorService,
210 private modalService: NgbModal,
211 private nService: NotificationsService,
212 private ngProgress: NgProgress,
213 private utilityService: UtilityService,
214 private dialogService: DialogService,
215 private referenceDataFormUtil: ReferenceDataFormUtil) {
216 console.log(this.classNm + ": new: start.");
220 let methName = "ngOnInit";
221 if (this.utilityService.getTracelvl() > 0)
222 console.log(this.classNm + ": " + methName + ": start.");
223 this.displayVnfc = sessionStorage.getItem("vnfcSelectionFlag");
224 if (this.configScaleOutExist) {
225 this.actions = ['', 'Configure', 'ConfigModify', 'ConfigBackup', 'ConfigRestore', 'GetRunningConfig', 'HealthCheck', 'StartApplication', 'StopApplication', 'QuiesceTraffic', 'ResumeTraffic', 'DistributeTraffic', 'UpgradeBackout', 'UpgradeBackup', 'UpgradePostCheck', 'UpgradePreCheck', 'UpgradeSoftware', 'OpenStack Actions', 'ConfigScaleOut'];
227 this.actions = ['', 'Configure', 'ConfigModify', 'ConfigBackup', 'ConfigRestore', 'GetRunningConfig', 'HealthCheck', 'StartApplication', 'StopApplication', 'QuiesceTraffic', 'ResumeTraffic', 'DistributeTraffic', 'UpgradeBackout', 'UpgradeBackup', 'UpgradePostCheck', 'UpgradePreCheck', 'UpgradeSoftware', 'OpenStack Actions'];
230 let path = this.location.path;
231 this.title = 'Reference Data';
232 this.referenceDataObject = {
234 'action-level': 'vnf',
235 scope: { 'vnf-type': '', 'vnfc-type-list': [] },
238 'device-protocol': '',
243 this.updateParams = sessionStorage.getItem('updateParams');
244 let cacheData = this.mappingEditorService.referenceNameObjects;
245 if (cacheData != undefined && cacheData != null && cacheData.length > 0) {
246 if (this.utilityService.getTracelvl() > 0)
247 console.log(this.classNm + ": ngOnInit: have cacheData.");
248 this.tempAllData = cacheData;
249 if (this.mappingEditorService.latestAction != undefined) {
250 this.referenceDataObject = this.mappingEditorService.latestAction;
251 this.toggleIdentifier(this.referenceDataObject.action);
252 this.refernceScopeObj.sourceType = this.referenceDataObject['scopeType'];
253 this.oldAction = this.referenceDataObject.action;
254 this.populateExistinAction(this.referenceDataObject.action);
255 this.displayHideVnfc();
257 } else if (this.updateParams != 'undefined') {
260 var appData = this.mappingEditorService.appDataObject;
261 if (appData != null || appData != undefined) this.appData = appData;
262 var downloadData = this.mappingEditorService.downloadDataObject;
263 if (downloadData != null || downloadData != undefined) this.downloadData = downloadData;
264 if (sessionStorage.getItem('vnfParams')) {
265 this.vnfParams = JSON.parse(sessionStorage.getItem('vnfParams'));
267 if (this.vnfParams && this.vnfParams.vnfType) {
268 if (this.utilityService.getTracelvl() > 0)
269 console.log(this.classNm + ": " + methName + ": vnfParams.vnfType:[" +
270 this.vnfParams.vnfType + "]");
271 this.referenceDataObject['scope']['vnf-type'] = this.vnfParams.vnfType;
273 if (this.vnfParams && this.vnfParams.vnfcType) {
274 if (this.utilityService.getTracelvl() > 0)
275 console.log(this.classNm + ": " + methName + ": vnfParams.vnfcType:[" +
276 this.vnfParams.vnfcType + "]");
277 this.referenceDataObject['scope']['vnfc-type'] = this.vnfParams.vnfcType;
279 this.uploadedDataArray = [];
280 this.remUploadedDataArray = [];
281 this.firstArrayElement = [];
282 this.uploadFileName = '';
283 this.templateIdentifier = this.mappingEditorService.identifier
284 this.oldVnfcIdentifier = this.vnfcIdentifier;
285 if (this.utilityService.getTracelvl() > 1)
286 console.log(this.classNm + ": " + methName + ": displayVnfc:[" +
287 this.displayVnfc + "]");
288 if (this.utilityService.getTracelvl() > 1)
289 console.log(this.classNm + ": " + methName + ": templateIdentifier:[" +
290 this.templateIdentifier + "]");
291 // Enable or Block Template and PD Tabs
292 this.buildDesignComponent.getRefData(
293 { ...this.referenceDataObject, displayVnfc: this.displayVnfc },
294 { reqField: this.templateIdentifier });
295 //.. configure some drop-downs
296 this.configDrp(this.referenceDataObject.action)
297 if (this.utilityService.getTracelvl() > 0)
298 console.log(this.classNm + ": " + methName + ": finish.");
301 toggleIdentifier(data) {
302 if (data == 'ConfigScaleOut') {
303 this.isConfigScaleOut = true
306 this.isConfigScaleOut = false
310 //to retrive the data from appc and assign it to the vaiables, if no data display the message reterived from the API
312 if (this.utilityService.getTracelvl() > 0)
313 console.log(this.classNm + ": getArtifact: start.");
315 let data = this.utilityService.createPayloadForRetrieve(true, '', '', '');
316 this.ngProgress.start();
317 this.httpUtils.post({
318 url: environment.getDesigns,
320 }).subscribe(resp => {
321 if (this.utilityService.getTracelvl() > 1)
322 console.log(this.classNm + ": getArtifact: got response ...");
323 if (resp.output.data.block != undefined) {
324 if (this.utilityService.getTracelvl() > 1)
325 console.log(this.classNm +
326 ": getArtifact: output.data.block not empty.");
327 this.nService.success(appConstants.notifications.titles.status, appConstants.messages.datafetched);
328 let artifactInfo = JSON.parse(resp.output.data.block).artifactInfo[0];
329 let reference_data = JSON.parse(artifactInfo['artifact-content'])['reference_data'][0];
330 this.referenceDataObject = reference_data;
331 this.toggleIdentifier(this.referenceDataObject.action);
332 if (this.referenceDataObject.action == appConstants.Actions.configScaleOut) {
333 this.groupAnotationType = [appConstants.groupAnotationType.blank, appConstants.groupAnotationType.firstVnfcName, appConstants.groupAnotationType.fixedValue, appConstants.groupAnotationType.relativeValue, appConstants.groupAnotationType.existingGroupName];
335 //chck vnfc or vnfcTypeList
336 this.displayHideVnfc();
337 // Enable or Block Template and PD Tabs
338 this.buildDesignComponent.getRefData(
339 { ...this.referenceDataObject, displayVnfc: this.displayVnfc });
340 this.refernceScopeObj.sourceType = this.referenceDataObject['scopeType'];
341 this.mappingEditorService.getReferenceList().push(JSON.parse(artifactInfo['artifact-content']));
342 this.tempAllData = JSON.parse(artifactInfo['artifact-content'])['reference_data'];
343 this.oldAction = this.referenceDataObject.action;
344 this.oldVnfcIdentifier = this.vnfcIdentifier;
345 if (this.referenceDataObject.action === appConstants.Actions.openStackActions) {
346 this.deviceProtocols = [appConstants.DeviceProtocols.blank, appConstants.DeviceProtocols.openStack];
347 this.buildDesignComponent.tabs = [
349 name: 'Reference Data',
354 this.buildDesignComponent.tabs = [
356 name: 'Reference Data',
360 url: 'templates/myTemplates',
362 name: 'Parameter Definition',
363 url: 'parameterDefinitions/create'
370 this.getArtifactsOpenStack();
372 this.nService.success('Status', 'Sorry !!! I dont have any artifact Named : ' + (JSON.parse(sessionStorage.getItem('updateParams')))['artifact-name']);
374 this.ngProgress.done();
378 this.nService.warn('status', 'error while reteriving artifact');
381 this.ngProgress.done();
386 if (this.utilityService.getTracelvl() > 0)
387 console.log(this.classNm + ": displayHideVnfc: start...");
388 if (this.utilityService.getTracelvl() > 1) {
389 if (this.referenceDataObject.scope['vnfc-type-list']) {
390 console.log(this.classNm +
391 ": displayHideVnfc: refDataObj.scope.vnfc-type-list.length=" +
392 this.referenceDataObject.scope['vnfc-type-list'].length);
394 console.log(this.classNm +
395 ": displayHideVnfc: refDataObj.scope.vnfc-type-list not defined");
397 console.log(this.classNm + ": displayHideVnfc: scope.vnfc-type:[" +
398 this.referenceDataObject.scope['vnfc-type'] + "]");
400 if (this.referenceDataObject.scope['vnfc-type-list'] == undefined && (this.referenceDataObject.scope['vnfc-type'] != undefined || this.referenceDataObject.scope['vnfc-type'] != "")) {
401 this.isVnfcType = true
402 this.displayVnfc = 'true'
403 this.isVnfcTypeList = false
405 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'] == "")) {
406 this.isVnfcType = false
407 this.displayVnfc = 'true'
408 this.isVnfcTypeList = true
409 if (!this.mappingEditorService.newObject.vnfc) {
410 this.vnfcIdentifier = this.referenceDataObject.scope['vnfc-type-list'][0];
411 // this.mappingEditorService.newObject.vnfc = this.vnfcIdentifier;
412 // this.referenceDataObject['vnfcIdentifier'] = this.vnfcIdentifier;
415 this.vnfcIdentifier = this.mappingEditorService.newObject.vnfc;
417 if (this.utilityService.getTracelvl() > 0)
418 console.log(this.classNm + ": displayHideVnfc: vnfcIdentifier:[" +
419 this.vnfcIdentifier + "]");
421 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) {
422 if (this.displayVnfc == 'true') {
423 this.isVnfcType = false
424 this.displayVnfc = 'true'
425 this.isVnfcTypeList = true
427 this.isVnfcType = false
428 this.displayVnfc = 'false'
429 this.isVnfcTypeList = false
432 if (this.referenceDataObject.scope['vnfc-type-list'] == undefined && this.referenceDataObject.scope['vnfc-type'] == '') {
433 this.isVnfcType = false
434 this.displayVnfc = 'false'
435 this.isVnfcTypeList = false
437 if (this.utilityService.getTracelvl() > 1)
438 console.log(this.classNm + ": displayHideVnfc: finish. isVnfcType:[" +
439 this.isVnfcType + " displayVnfc:[" + this.displayVnfc + "] isVnfcTypeList:[" +
440 this.isVnfcTypeList + "]");
443 //reinitializing the required values
445 if (this.utilityService.getTracelvl() > 0)
446 console.log(this.classNm + ": ngOnDestroy: start:" +
447 " vnfcIdentifier:[" + this.vnfcIdentifier + "]");
448 let referenceObject = this.prepareReferenceObject();
449 this.mappingEditorService.changeNavAppData(this.appData);
450 this.mappingEditorService.changeNavDownloadData(this.downloadData);
451 this.uploadedDataArray = [];
452 this.remUploadedDataArray = [];
453 this.firstArrayElement = [];
454 this.uploadFileName = '';
457 numberValidation(event: any) {
458 if (this.numberTest.test(event) && event != 0) {
459 this.numberOfVmTest = true;
462 this.numberOfVmTest = false;
465 // update my vnf pop up session values
466 updateSessionValues(event: any, type: string) {
467 if (this.utilityService.getTracelvl() > 0)
468 console.log(this.classNm + ": updateSessionValues: type:[" + type + "]");
469 if (type === 'action') {
470 sessionStorage.setItem('action', event);
472 if (type === 'vnfType') {
473 sessionStorage.setItem('vnfType', event);
477 addVnfcData(vmNumber: number) {
479 'vnfc-instance': this.referenceDataObject.vm[vmNumber].vnfc.length + 1,
480 'vnfc-type': this.vnfcTypeData,
481 'vnfc-function-code': '',
482 'ipaddress-v4-oam-vip': '',
483 'group-notation-type': '',
484 'group-notation-value': ''
486 this.referenceDataObject.vm[vmNumber].vnfc.push(newObj);
489 //validating the vnf and vnfc data in the pop up
490 validateVnfcName(name) {
491 if (this.utilityService.getTracelvl() > 0)
492 console.log(this.classNm + ": validateVnfcName: start: name:[" + name + "]");
493 if (!name.trim() || name.length < 1) {
494 this.errorMessage = '';
496 } else if (name.startsWith(' ') || name.endsWith(' ')) {
497 this.errorMessage = 'Leading and trailing spaces are not allowed';
499 } else if (name.includes(' ')) {
500 this.errorMessage = 'More than one space is not allowed in VNFC Type';
502 } else if (name.length > 50) {
503 this.errorMessage = 'VNFC Type should be of minimum one character and maximum 50 character';
506 this.invalid = false;
507 this.errorMessage = '';
511 //to remove the VM's created by the user
512 removeFeature(vmNumber: any, index: any, templateId) {
513 if (this.referenceDataObject.action == "Configure") {
514 this.referenceDataObject.vm.splice(vmNumber, 1);
515 this.referenceDataObject.vm.forEach((obj, arrIndex) => {
516 if (arrIndex >= vmNumber) {
517 obj["vm-instance"] = obj["vm-instance"] - 1
521 let data = this.referenceDataObject.vm.filter(obj => {
522 return obj['template-id'] == templateId;
525 let vmIndex = this.findVmindex(data, vmNumber, templateId)
526 this.referenceDataObject.vm.splice(vmIndex, 1);
528 this.referenceDataObject.vm.forEach((obj, arrIndex) => {
529 if (obj['template-id'] == templateId) {
531 obj["vm-instance"] = index + 1
539 findVmindex(data, vmNumber, templateId) {
540 return this.referenceDataObject.vm.findIndex(obj => {
541 let x = obj['vm-instance'] == (vmNumber + 1) && templateId == obj['template-id']//true
547 //add new VM's to the configure
550 let mberOFVm = Number(this.refernceScopeObj.from);
551 if (this.referenceDataObject.action == 'ConfigScaleOut') {
552 let existingVmsLength = this.referenceDataObject.vm.filter(obj => {
553 return obj['template-id'] == this.templateIdentifier
555 mberOFVm = existingVmsLength + mberOFVm;
557 for (var i = (existingVmsLength); i < mberOFVm; i++) {
559 this.referenceDataObject.vm.push({ 'template-id': this.templateIdentifier, 'vm-instance': (existingVmsLength + index + 1), vnfc: [Object.assign({}, this.Sample)] });
564 let arrlength = this.referenceDataObject.vm.length;
565 mberOFVm = arrlength + mberOFVm;
566 for (var i = (arrlength); i < mberOFVm; i++) {
567 if (this.referenceDataObject.action == 'ConfigScaleOut') {
568 this.referenceDataObject.vm.push({ 'template-id': this.templateIdentifier, 'vm-instance': (i + 1), vnfc: [Object.assign({}, this.Sample)] });
570 this.referenceDataObject.vm.push({ 'vm-instance': (i + 1), vnfc: [Object.assign({}, this.Sample)] });
576 //Reference object to create reference data
577 prepareReferenceObject(isSaving?: any) {
578 if (this.utilityService.getTracelvl() > 0)
579 console.log(this.classNm + ": prepareReferenceObject: start.");
580 let scopeName = this.resetParamsOnVnfcType();
581 let extension = this.decideExtension(this.referenceDataObject);
582 this.prepareArtifactList(scopeName, extension);
583 if (this.referenceDataObject.action === 'OpenStack Actions') {
584 this.referenceDataObject['template'] = 'N';
585 this.referenceDataObject['artifact-list'] = [];
586 this.referenceDataObject['firstRowVmSpreadSheet'] = this.firstArrayElement;
588 //detaching the object from the form and processing further
589 let newObj = $.extend(true, {}, this.referenceDataObject);
590 let action = this.referenceDataObject.action;
591 newObj = this.deleteVmsforNonActions(newObj, action)
592 this.pushOrReplaceTempData(newObj, action);
593 this.addAllActionObj(newObj, scopeName);
595 //saving data to service
596 this.mappingEditorService.getReferenceList().push(JSON.parse(JSON.stringify(this.referenceDataObject)));
597 this.buildDesignComponent.updateAccessUpdatePages(this.referenceDataObject.action, this.mappingEditorService.getReferenceList());
598 this.mappingEditorService.changeNav(this.tempAllData);
599 //on action change or template identifier change reset the form by restting values of Reference data object
600 this.resetVmsForScaleout(this.currentAction)
601 return { totlaRefDtaa: this.tempAllData, scopeName: scopeName };
604 public checkIfelementExistsInArray(element, array) {
605 //// console.log("Element==" + element)
606 var result: boolean = false;
608 array.forEach(function (item) {
609 // // console.log("Item==" + item)
610 if (element === item) {
611 // console.log('Element==' + element + 'Item==' + item);
620 if (this.utilityService.getTracelvl() > 0)
621 console.log(this.classNm + ": upload: start.");
622 /* wire up file reader */
623 const target: DataTransfer = <DataTransfer>(evt.target);
624 this.uploadFileName = evt.target.files[0].name;
625 var fileExtension = this.uploadFileName.substr(this.uploadFileName.lastIndexOf('.') + 1);
626 if (target.files.length != 1) {
627 console.log(this.classNm + ": upload: Error: got no file !");
628 throw new Error(appConstants.errors.multipleFileUploadError);
630 console.log(this.classNm + ": upload: filename:[" + evt.target.files[0].name + "]");
631 if (fileExtension.toUpperCase() === 'XLS' || fileExtension.toUpperCase() === 'XLSX') {
632 const reader = new FileReader();
633 reader.onload = (e: any) => {
635 const bstr = e.target.result;
636 // // console.log("print 1---" + bstr);
637 const wb = XLSX.read(bstr, { type: 'binary' });
638 // // console.log("print 2---" + JSON.stringify(wb));
639 /* grab first sheet */
640 const wsname = wb.SheetNames[0];
641 // // console.log("Name:---" + wsname);
642 const ws = wb.Sheets[wsname];
646 let arrData = (<AOA>(XLSX.utils.sheet_to_json(ws, { header: 1 })));
647 this.uploadedDataArray = arrData;
648 this.firstArrayElement = arrData[0];
649 var remUploadedDataArray = arrData;
650 remUploadedDataArray.shift();
651 this.remUploadedDataArray = remUploadedDataArray;
652 if (arrData != null) {
653 this.getExcelUploadStatus = true;
654 this.nService.success(appConstants.notifications.titles.success, appConstants.messages.vmDataUploadSuccess);
658 this.nService.success(appConstants.notifications.titles.error, appConstants.messages.emptyVmUpload);
661 reader.readAsBinaryString(target.files[0]);
664 this.nService.error(appConstants.notifications.titles.error, appConstants.messages.incorrectVmUpload);
669 addVmCapabilitiesData() {
670 if (this.utilityService.getTracelvl() > 0)
671 console.log(this.classNm + ": addVmCapabilitiesData: start.");
672 for (var i = 0; i < this.uploadedDataArray.length; i++) {
673 var vnfcFuncCodeArray = [];
674 var data = this.uploadedDataArray[i];
675 for (var j = 1; j < data.length; j++) {
676 if (data[j] != undefined) {
677 if (data[j].toUpperCase() === 'Y') {
678 vnfcFuncCodeArray.push(this.firstArrayElement[j]);
682 var action = this.uploadedDataArray[i][0];
683 if (action && action != undefined) {
686 'action-level': 'vm',
688 'vnf-type': this.referenceDataObject['scope']['vnf-type'], //need to confirm what should be this value
691 'vnfc-function-code-list': vnfcFuncCodeArray,
693 'device-protocol': 'OS'
696 this.tempAllData.push(json);
703 save(form: any, isValid: boolean) {
704 if (this.utilityService.getTracelvl() > 0)
705 console.log(this.classNm + ": save: start: referenceDataObject.action:[" +
706 this.referenceDataObject.action + "]");
707 if (this.referenceDataObject.action === '') {
708 this.nService.error(appConstants.notifications.titles.error, appConstants.errors.noActionError);
711 if (this.referenceDataObject['device-protocol'] === '') {
712 this.nService.error(appConstants.notifications.titles.error, appConstants.errors.noDeviceProtocolError);
717 let referenceObject = this.prepareReferenceObject();
718 let theJSON = JSON.stringify({ 'reference_data': this.tempAllData }, null, '\t');
719 let uri = 'data:application/json;charset=UTF-8,' + encodeURIComponent(theJSON);
720 this.downloadData.reference = theJSON;
721 this.validateTempAllData();
722 var blob = new Blob([theJSON], {
725 let fileName = 'reference_AllAction_' + referenceObject.scopeName + '_' + '0.0.1V.json';
726 this.downloadFile(blob, fileName, 100)
727 var templateData = JSON.stringify(this.downloadData.template.templateData);
728 var nameValueData = JSON.stringify(this.downloadData.template.nameValueData);
729 var pdData = this.downloadData.pd.pdData;
730 if (templateData != '{}' && templateData != null && templateData != undefined) this.downloadTemplate();
731 if (nameValueData != '{}' && nameValueData != null && nameValueData != undefined) this.downloadNameValue();
732 if (pdData != '' && pdData != null && pdData != undefined) this.downloadPd();
735 downloadFile(blob, fileName, delay) {
736 if (this.utilityService.getTracelvl() > 0)
737 console.log(this.classNm + ": downloadFile: start.");
739 saveAs(blob, fileName);
744 if (this.utilityService.getTracelvl() > 0)
745 console.log(this.classNm + ": downloadTemplate: start.");
746 var fileName = this.downloadData.template.templateFileName;
747 console.log(this.classNm + ": downloadTemplate: fileName:[" + fileName + "]");
748 var theJSON = this.downloadData.template.templateData;
749 if (fileName != null || fileName != '') {
750 var fileExtensionArr = fileName.split('.');
751 var blob = new Blob([theJSON], {
752 type: 'text/' + fileExtensionArr[1]
754 this.downloadFile(blob, fileName, 130)
758 downloadNameValue() {
759 var fileName = this.downloadData.template.nameValueFileName;
760 var theJSON = this.downloadData.template.nameValueData;
761 var blob = new Blob([theJSON], {
765 this.downloadFile(blob, fileName, 160)
769 let fileName = this.downloadData.pd.pdFileName;
770 let theJSON = this.downloadData.pd.pdData;
771 var blob = new Blob([theJSON], {
775 this.downloadFile(blob, fileName, 180)
778 // save the values to the cache, on action change without download
779 validateDataAndSaveToAppc(valid, form, event) {
780 if (this.utilityService.getTracelvl() > 0)
781 console.log(this.classNm + ": validateDataAndSaveToAppc: start: valid:" + valid);
782 // will show error message
783 this.showValidationErrors(this.referenceDataObject);
785 form._submitted = true;
787 let referenceObject = this.prepareReferenceObject(true);
788 let removedKeysArray = []
789 this.tempAllData.forEach((data, index) => {
791 removedKeysArray.push(JSON.parse(JSON.stringify(this.deleteUnwantedKeys(data))))
794 this.tempAllData = removedKeysArray;
796 this.validateTempAllData();
798 if (this.actionChanged) {
800 if (this.currentAction) {
801 this.referenceDataObject.action = this.currentAction;
804 this.populateExistinAction(this.referenceDataObject.action);
805 this.actionChanged = false;
810 this.nService.warn('status', 'unable to save the artifact');
814 //this method saves reference, template, param and PD data to APPC
816 if (this.utilityService.getTracelvl() > 0)
817 console.log(this.classNm + ": saveToAppc: start: vnf-type:[" +
818 this.referenceDataObject.scope['vnf-type'] + "]");
819 let theJSON = JSON.stringify(this.tempAllData);
820 if (this.utilityService.getTracelvl() > 0)
821 console.log(this.classNm + ": saveToAppc: tempAllData:[" + theJSON + "]");
822 let fileName = 'reference_AllAction_' + this.referenceDataObject.scope['vnf-type'].replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '') + '_' + '0.0.1V.json';
823 this.saveReferenceDataToAppc(
824 JSON.stringify({ reference_data: this.tempAllData }), this.referenceDataObject.scope['vnf-type'], fileName);
826 var templateData = JSON.stringify(this.appData.template.templateData);
827 var nameValueData = JSON.stringify(this.appData.template.nameValueData);
828 var pdData = JSON.stringify(this.appData.pd);
829 if (templateData != '{}' && templateData != null && templateData != undefined) this.referenceDataFormUtil.handleApiData(this.appData.template.templateData, 'template data');
830 if (nameValueData != '{}' && nameValueData != null && nameValueData != undefined) this.referenceDataFormUtil.handleApiData(this.appData.template.nameValueData, 'name value pairs');
831 if (pdData != '{}' && pdData != null && pdData != undefined) this.referenceDataFormUtil.handleApiData(this.appData.pd, 'PD file');
834 // valaidation of template data
835 validateTempAllData() {
836 if (this.utilityService.getTracelvl() > 0)
837 console.log(this.classNm + ": validateTempAllData: start.");
838 if (this.tempAllData) {
839 var updatedData = [];
840 this.tempAllData.forEach(data => {
842 updatedData.push(data);
845 this.tempAllData = updatedData;
849 //.. prepare and send the data to the API.
850 saveReferenceDataToAppc(artifactData, vnf_type, fileName) {
851 if (this.utilityService.getTracelvl() > 0)
852 console.log(this.classNm + ": saveReferenceDataToAppc: start: vnf_type:[" +
855 let slashedPayload = this.referenceDataFormUtil.appendSlashes(artifactData);
856 let payload = this.utilityService.createPayLoadForSave("reference_data", vnf_type, "AllAction", fileName, this.versionNoForApiCall, slashedPayload);
857 this.ngProgress.start();
858 this.httpUtils.post({
859 url: environment.getDesigns,
861 }).subscribe((resp) => {
862 if (resp != null && resp.output.status.code == '400') {
863 window.scrollTo(0, 0);
864 this.nService.success('Status', 'successfully uploaded the Reference Data');
866 this.nService.warn('Status', 'Error while saving Reference Data');
868 this.uploadStatusError = false;
869 this.getRefStatus = false;
870 this.ngProgress.done();
872 this.nService.error('Status', 'Error Connecting to the APPC Network');
873 window.scrollTo(0, 0);
875 this.appData.reference = payload;
877 this.ngProgress.done();
882 console.log(this.classNm + ": retriveFromAppc: start.");
883 if (sessionStorage.getItem('updateParams') != 'undefined') {
885 this.noCacheData = false;
887 this.noCacheData = true;
891 cloneMessage(servermessage) {
893 for (var key in servermessage) {
894 if (servermessage.hasOwnProperty(key)) //ensure not adding inherited props
895 clone[key] = servermessage[key];
900 public showUpload() {
901 this.selectedUploadType = this.uploadTypes[0].value;
904 public fileChange(input) {
905 if (this.utilityService.getTracelvl() > 0)
906 console.log(this.classNm + ": fileChange: start.");
907 this.fileName = input.target.files[0].name.replace(/C:\\fakepath\\/i, '');
908 this.fileUploaded = true;
909 this.disableRetrieve = true;
910 if (input.target.files && input.target.files[0]) {
911 // Create the file reader
912 let reader = new FileReader();
913 this.readFile(input.target.files[0], reader, (result) => {
914 // After the callback fires do:
915 if ('Reference Data' === this.selectedUploadType) {
918 let jsonObject = (JSON.parse(result))['reference_data'];
919 this.uploadedData = JSON.parse(JSON.stringify(jsonObject));
920 //check for legacy artifact and do not allow it
921 for (let i = 0; i < this.uploadedData.length; i++) {
922 obj = this.uploadedData[i];
923 if (obj.scope['vnfc-type'] != undefined && obj.scope['vnfc-type'] != '') {
924 this.nService.error('Error', 'The legacy reference artifact not supported');
928 this.displayVnfc = 'false';
929 this.isVnfcType = false;
930 this.isVnfcTypeList = false;
931 for (let i = 0; i < this.uploadedData.length; i++) {
932 obj = this.uploadedData[i];
933 if (obj.scope['vnfc-type-list'] && obj.scope['vnfc-type-list'].length > 0) {
934 this.displayVnfc = 'true';
935 this.isVnfcTypeList = true;
936 this.vnfcIdentifier = obj.scope['vnfc-type-list'][0];
939 this.oldAction = obj.action;
940 this.tempAllData = JSON.parse(JSON.stringify(jsonObject));
941 if (this.utilityService.getTracelvl() > 0)
942 console.log(this.classNm + ": fileChange: read & parsed.");
943 this.notificationService.notifySuccessMessage('Reference Data file successfully uploaded..');
944 if (jsonObject instanceof Array) {
945 this.referenceDataObject = jsonObject[0];
946 jsonObject.forEach(obj => {
947 this.selectedActions.push(obj.action);
950 this.referenceDataObject = jsonObject;
952 this.selectedActions.push(jsonObject.action);
954 if (this.utilityService.getTracelvl() > 0)
955 console.log(this.classNm + ": fileChange: " +
956 "referenceDataObject.action:[" +
957 this.referenceDataObject.action + "]");
958 this.toggleIdentifier(this.referenceDataObject.action)
959 this.configDrp(this.referenceDataObject.action)
960 if (this.referenceDataObject.action === 'OpenStack Actions') {
961 this.deviceProtocols = ['', 'OpenStack'];
962 this.buildDesignComponent.tabs = [
965 name: 'Reference Data',
970 this.buildDesignComponent.tabs = [
972 name: 'Reference Data',
976 url: 'templates/myTemplates',
978 name: 'Parameter Definition',
979 url: 'parameterDefinitions/create'
986 this.getArtifactsOpenStack();
987 if (this.referenceDataObject.template == null) {
988 this.referenceDataObject.template = 'Y';
990 if (this.referenceDataObject['action-level'] == null) {
991 this.referenceDataObject['action-level'] = 'VNF';
993 if (this.utilityService.getTracelvl() > 0)
994 console.log(this.classNm + ": fileChange: displayVnfc:[" +
995 this.displayVnfc + "]");
996 // Enable or Block Template and PD Tabs
997 this.buildDesignComponent.getRefData(
998 { ...this.referenceDataObject, displayVnfc: this.displayVnfc });
1000 this.nService.error(appConstants.notifications.titles.error, appConstants.messages.incorrectFileFormat);
1003 this.hideModal = true;
1006 if (this.utilityService.getTracelvl() > 0)
1007 console.log(this.classNm + ": fileChange: Error: Failed to read file!");
1008 this.notificationService.notifyErrorMessage('Failed to read file..');
1012 public readFile(file, reader, callback) {
1013 console.log(this.classNm + ": readFile: start.");
1014 // Set a callback funtion to fire after the file is fully loaded
1015 reader.onload = () => {
1016 // callback with the results
1017 callback(reader.result);
1019 this.notificationService.notifySuccessMessage('Uploading File ' + file.name + ':' + file.type + ':' + file.size);
1021 reader.readAsText(file, 'UTF-8');
1024 fileChangeEvent(fileInput: any) {
1025 let obj: any = fileInput.target.files;
1029 console.log(this.classNm + ": clearVnfcData: start.");
1031 'vnfc-instance': '1',
1032 'vnfc-function-code': '',
1033 'ipaddress-v4-oam-vip': '',
1034 'group-notation-type': '',
1035 'group-notation-value': ''
1039 setVmInstance(index) {
1040 this.referenceDataObject.vm[index]['vm-instance'] = index + 1;
1043 // setVnfcType(str: String) {
1044 // this.Sample['vnfc-type'] = str;
1047 // getChange(value: String) {
1048 // if (value === 'vnfType') {
1049 // this.referenceDataObject.scope['vnfc-type'] = '';
1054 if (this.utilityService.getTracelvl() > 0)
1055 console.log(this.classNm + ": resetForm: start.");
1056 this.referenceDataObject['action-level'] = 'vnf';
1057 this.referenceDataObject.template = 'Y';
1058 this.referenceDataObject['device-protocol'] = '';
1059 this.referenceDataObject['user-name'] = '';
1060 this.referenceDataObject['port-number'] = '';
1061 this.refernceScopeObj.sourceType = '';
1062 this.Sample['vnfc-type'] = '';
1065 // this method gets called with the action as parameter and the respective action details are fetched and assigned to the current page
1066 populateExistinAction(data) {
1067 if (this.utilityService.getTracelvl() > 0)
1068 console.log(this.classNm + ": populateExistinAction: start.");
1069 let existAction = this.tempAllData.findIndex(obj => {
1070 return obj.action == data;
1072 if (existAction > -1) {
1073 let obj = $.extend(true, {}, this.tempAllData[existAction]);
1074 this.referenceDataObject = obj;
1075 this.referenceDataObject.scope['vnf-type'] = obj['scope']['vnf-type'];
1076 this.referenceDataObject.scope['vnfc-type-list'] = obj['scope']['vnfc-type-list'];
1077 this.referenceDataObject['device-protocol'] = obj['device-protocol'];
1078 this.refernceScopeObj['sourceType'] = obj['scopeType'];
1079 if (obj['scope']['vnfc-type-list'] != undefined && obj['scope']['vnfc-type-list'].length > 0) {
1080 this.referenceDataObject['vnfcIdentifier'] = obj['scope']['vnfc-type-list'][0];
1083 if (this.utilityService.getTracelvl() > 0)
1084 console.log(this.classNm + ": populateExistinAction: action not found");
1086 this.referenceDataObject.action = data;
1088 //# iof healthCeck change deviceprotocol drp vaues
1091 this.deviceProtocols = ['', 'ANSIBLE', 'CHEF', 'REST'];
1092 this.actionHealthCheck = true;
1094 case 'UpgradeBackout':
1095 case 'ResumeTraffic':
1096 case 'QuiesceTraffic':
1097 case 'DistributeTraffic':
1098 case 'UpgradeBackup':
1099 case 'UpgradePostCheck':
1100 case 'UpgradePreCheck':
1101 case 'UpgradeSoftware':
1102 case 'ConfigRestore':
1103 case 'StartApplication':
1104 case 'StopApplication':
1105 case 'ConfigBackup':
1106 this.deviceProtocols = ['', 'CHEF', 'ANSIBLE'];
1108 case 'OpenStack Actions':
1109 this.deviceProtocols = ['', 'OpenStack'];
1111 case 'ConfigScaleOut':
1112 this.deviceProtocols = ['', 'CHEF', 'ANSIBLE', 'NETCONF-XML', 'RESTCONF'];
1114 case 'GetRunningConfig':
1115 this.deviceProtocols = ['', 'CHEF', 'ANSIBLE', 'NETCONF-XML', 'RESTCONF', 'CLI', 'REST'];
1118 this.deviceProtocols = ['', 'ANSIBLE', 'CHEF', 'NETCONF-XML', 'RESTCONF', 'CLI'];
1119 this.actionHealthCheck = false;
1123 //Modal pop up for action change with values entered.
1124 actionChange(data, userForm) {
1125 var methName = "actionChange";
1126 if (this.utilityService.getTracelvl() > 0)
1127 console.log(this.classNm + ": " + methName + ": start: data:[" + data + "]" +
1128 " userForm.valid:[" + userForm.valid + "]");
1129 this.disableGrpNotationValue = false
1131 console.log(this.classNm + ": " + methName + ": data == null");
1134 if ((userForm.valid) && this.oldAction != '' && this.oldAction != undefined) {
1135 this.actionChanged = true;
1136 console.log(this.classNm + ": " + methName +
1137 ": userForm valid and oldAction defined");
1138 // Calling common Confirmation Modal
1139 let disposable = this.dialogService.addDialog(ConfirmComponent)
1140 .subscribe((isConfirmed) => {
1141 //We get dialog result
1142 console.log(this.classNm + ": " + methName + ": isConfirmed:[" +
1145 // User clicked on Yes
1146 this.currentAction = this.referenceDataObject.action;
1147 console.log(this.classNm + ": " + methName +
1148 ": clicked on Yes: currentAction:[" + this.currentAction +
1149 "] oldAction:[" + this.oldAction + "]");
1150 this.referenceDataObject.action = this.oldAction;
1151 $('#saveToAppc').click();//make sure the save all is done before the tempall obj is saved form the API
1152 this.toggleIdentifier(data)
1153 this.oldAction = this.currentAction;// this.referenceDataObject.action + '';
1154 this.referenceDataObject.action = this.currentAction;
1155 this.populateExistinAction(data);
1156 if (this.oldAction === 'OpenStack Actions') {
1158 this.uploadedDataArray = [];
1159 this.remUploadedDataArray = [];
1160 this.firstArrayElement = [];
1161 this.uploadFileName = '';
1162 //this.tempAllData = [];
1165 this.refernceScopeObj.from = '';
1166 this.getArtifactsOpenStack();
1168 // Clears VNFC Information data on action change
1169 this.clearVnfcData()
1170 this.resetVmsForScaleout(data);
1173 // User clicked on No
1174 this.toggleIdentifier(data)
1175 this.currentAction = this.referenceDataObject.action;
1176 console.log(this.classNm + ": " + methName +
1177 ": clicked on No: currentAction:[" + this.currentAction + "]");
1178 this.populateExistinAction(data);
1179 this.resetVmsForScaleout(data);
1180 this.oldAction = this.referenceDataObject.action + '';
1182 this.clearVnfcData()
1183 this.refernceScopeObj.from = '';
1186 if (this.referenceDataObject.action === 'Configure' || this.referenceDataObject.action === 'ConfigModify' || this.referenceDataObject.action === 'DistributeTraffic') {
1187 this.isConfigureAction = true;
1189 this.isConfigureAction = false;
1190 delete this.mappingEditorService.newObject['vnfc'];
1193 // Enable or Block Template and PD Tabs
1194 if (this.currentAction == 'ConfigScaleOut' && this.templateIdentifier && this.templateIdentifier != '') {
1195 // let referenceDataObjectTemp = this.referenceDataObject;
1196 // referenceDataObjectTemp['template-id'] = this.templateIdentifier;
1197 // this.buildDesignComponent.getRefData(referenceDataObjectTemp);
1198 this.buildDesignComponent.getRefData({ ...this.referenceDataObject, displayVnfc: this.displayVnfc }, { reqField: this.templateIdentifier });
1201 this.buildDesignComponent.getRefData({ ...this.referenceDataObject, displayVnfc: this.displayVnfc });
1205 console.log(this.classNm + ": " + methName +
1206 ": userForm Not valid or oldAction not defined");
1207 this.actionChanged = true;
1208 this.currentAction = this.referenceDataObject.action;
1209 this.oldAction = this.referenceDataObject.action + '';
1210 this.populateExistinAction(data);
1211 this.resetVmsForScaleout(data);
1212 this.toggleIdentifier(data);
1214 // Enable or Block Template and PD Tabs
1215 if (this.currentAction == 'ConfigScaleOut' && this.templateIdentifier) {
1216 // let referenceDataObjectTemp = this.referenceDataObject;
1217 // referenceDataObjectTemp['template-id'] = this.templateIdentifier;
1218 // this.buildDesignComponent.getRefData(referenceDataObjectTemp);
1219 this.buildDesignComponent.getRefData({ ...this.referenceDataObject, displayVnfc: this.displayVnfc }, { reqField: this.templateIdentifier });
1221 this.buildDesignComponent.getRefData({ ...this.referenceDataObject, displayVnfc: this.displayVnfc });
1224 this.configDrp(data)
1228 console.log(this.classNm + ": configDrp: start: data:[" + data + "]");
1229 if (data == 'ConfigScaleOut') {
1230 this.groupAnotationType = ['', 'first-vnfc-name', 'fixed-value', 'relative-value', 'existing-group-name'];
1232 this.groupAnotationType = ['', 'first-vnfc-name', 'fixed-value', 'relative-value'];
1234 if (data == 'OpenStack Actions') {
1235 this.buildDesignComponent.tabs = [
1238 name: 'Reference Data',
1243 this.buildDesignComponent.tabs = [
1245 name: 'Reference Data',
1249 url: 'templates/myTemplates',
1251 name: 'Parameter Definition',
1252 url: 'parameterDefinitions/create'
1259 if (data == 'Configure' || data == 'ConfigModify' || data == 'DistributeTraffic') {
1260 this.nonConfigureAction = false;
1262 this.nonConfigureAction = true;
1266 deviceProtocolChange() {
1267 console.log(this.classNm + ": deviceProtocolChange: start.");
1268 if (this.referenceDataObject['device-protocol'] == 'REST') {
1271 delete this.referenceDataObject['context-url']
1273 // Enable or Block Template and PD Tabs
1274 this.buildDesignComponent.getRefData(
1275 { ...this.referenceDataObject, displayVnfc: this.displayVnfc },
1276 { reqField: this.templateIdentifier });
1279 // used to call or trigger save object on template Identifier changes
1280 idChange(data, userForm) {
1281 console.log(this.classNm + ": idChange: start: data:[" + data + "]");
1285 // Enable or Block Template and PD Tabs
1286 // let referenceDataObjectTemp = this.referenceDataObject;
1287 // referenceDataObjectTemp['template-id'] = data;
1288 // this.buildDesignComponent.getRefData(referenceDataObjectTemp);
1289 this.buildDesignComponent.getRefData(
1290 { ...this.referenceDataObject, displayVnfc: this.displayVnfc },
1291 { reqField: data });
1293 if ((userForm.valid)) {
1294 this.currentAction = "ConfigScaleOut"
1295 this.oldtemplateIdentifier = this.templateIdentifier
1296 let referenceObject = this.prepareReferenceObject();
1297 this.actionChanged = true;
1298 if (this.templateIdentifier) {
1299 // Calling common Confirmation Modal
1300 let disposable = this.dialogService.addDialog(ConfirmComponent)
1301 .subscribe((isConfirmed) => {
1302 //We get dialog result
1304 // User clicked on Yes
1305 this.validateTempAllData();
1308 this.clearVnfcData();
1309 this.refernceScopeObj.from = '';
1312 // User clicked on No
1314 this.refernceScopeObj.from = '';
1319 this.oldtemplateIdentifier = this.templateIdentifier;
1323 // used to call or trigger save object on multiple VNFC's changes
1324 vnfcChanged(data, userForm) {
1325 console.log(this.classNm + ": vnfcChanged: new vnfcIdentifier:[" + data + "]");
1326 console.log(this.classNm + ": vnfcChanged: oldVnfcIdentifier:[" +
1327 this.oldVnfcIdentifier + "]");
1328 console.log(this.classNm + ": vnfcChanged: scope.vnfc-type:[" +
1329 this.referenceDataObject.scope['vnfc-type'] + "]");
1330 this.vnfcIdentifier = data;
1335 //.. populate VNFC Type in Sample field
1336 this.setVnfcTypeInSample(this.vnfcIdentifier);
1337 // Enable or Block Template and PD Tabs
1338 let referenceDataObjectTemp = this.referenceDataObject;
1339 referenceDataObjectTemp['vnfcIdentifier'] = data;
1340 console.log(this.classNm +
1341 ": vnfcChanged: displayVnfc:[" + this.displayVnfc + "]");
1342 this.buildDesignComponent.getRefData(
1343 { ...this.referenceDataObject, displayVnfc: this.displayVnfc },
1344 { reqField: data });
1345 console.log(this.classNm +
1346 ": vnfcChanged: userForm.valid:[" + userForm.valid + "]");
1347 if ((userForm.valid) && this.oldVnfcIdentifier != '' && this.oldVnfcIdentifier != undefined) {
1348 this.currentAction = this.referenceDataObject.action
1349 this.oldVnfcIdentifier = this.vnfcIdentifier
1350 let referenceObject = this.prepareReferenceObject();
1351 this.actionChanged = true;
1352 if (this.vnfcIdentifier) {
1353 // Calling common Confirmation Modal
1354 let disposable = this.dialogService.addDialog(ConfirmComponent)
1355 .subscribe((isConfirmed) => {
1356 //We get dialog result
1358 // User clicked on Yes
1359 this.validateTempAllData();
1362 this.clearVnfcData()
1363 this.refernceScopeObj.from = '';
1366 // User clicked on No
1368 this.refernceScopeObj.from = '';
1374 this.oldVnfcIdentifier = this.vnfcIdentifier
1380 console.log(this.classNm + ": clearCache: start.");
1381 // get the value and save the userid and persist it.
1382 this.clearTemplateCache();
1383 this.clearPdCache();
1384 this.appData = { reference: {}, template: { templateData: {}, nameValueData: {} }, pd: {} };
1385 this.downloadData = {
1387 template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' },
1388 pd: { pdData: '', pdFileName: '' }
1392 clearTemplateCache() {
1393 this.mappingEditorService.setTemplateMappingDataFromStore(undefined);
1394 localStorage['paramsContent'] = '{}';
1397 this.mappingEditorService.setParamContent(undefined);
1398 this.paramShareService.setSessionParamData(undefined);
1402 console.log(this.classNm + ": saveTemp: start.");
1406 { url: environment.getDesigns, data: this.appData.template.templateData })
1407 .subscribe(resp => {
1408 if (resp.output.status.code === '400' && resp.output.status.message === 'success') {
1409 this.nService.success('Status', 'Successfully uploaded the Template Data');
1411 if (resp.output.status.code === '401') {
1412 this.nService.warn('Status', 'Error in saving the Template to Appc');
1416 (err) => this.nService.error('Status', 'Error Connecting to the APPC Network'));
1420 console.log(this.classNm + ": saveNameValue: start.");
1425 url: environment.getDesigns, data: this.appData.template.nameValueData
1427 .subscribe(resp => {
1428 if (resp.output.status.code === '400' && resp.output.status.message === 'success') {
1429 this.nService.success('Status', 'Successfully uploaded the Name Value Pairs');
1431 if (resp.output.status.code === '401') {
1432 this.nService.warn('Status', 'Error in saving the Name value pairs to Appc');
1436 this.nService.error('Status', 'Error Connecting to the APPC Network');
1446 url: environment.getDesigns, data: this.appData.pd
1448 .subscribe(resp => {
1449 if (resp.output.status.code === '400' && resp.output.status.message === 'success') {
1450 this.nService.success('Status', 'Successfully uploaded PD file');
1452 if (resp.output.status.code === '401') {
1453 this.nService.warn('Status', 'Error in saving the PD to Appc');
1457 this.nService.error('Status', 'Error Connecting to the APPC Network');
1462 openModel(toShow: any, message: any, title: any) {
1463 console.log(this.classNm + ": openModel: start: title:[" + title + "]");
1464 this.modalComponent.isShow = toShow;
1465 this.modalComponent.message = message;
1466 this.modalComponent.title = title;
1470 $('#inputFile').trigger('click');
1473 excelBrowseOption() {
1474 $('#excelInputFile').trigger('click');
1478 $('#identifierModal').modal();
1482 if (!(this.referenceDataObject['template-id-list'])) {
1483 this.referenceDataObject['template-id-list'] = [];
1485 if (!(this.referenceDataObject['template-id-list'].indexOf(this.templateId.trim()) > -1)) {
1486 this.referenceDataObject['template-id-list'].push(this.templateId.trim());
1488 // Changing value to blank otherwise it will show previous value in text box of popup
1489 this.templateId = '';
1492 // adds the vnfc to the vnfc dropdown list
1494 var newVnfcTypeV = this.newVnfcType.trim();
1495 console.log(this.classNm +
1496 ": addVnfc: start: newVnfcTypeV:[" + newVnfcTypeV + "]");
1497 if (!(this.referenceDataObject.scope['vnfc-type-list'])) {
1498 this.referenceDataObject.scope['vnfc-type-list'] = [];
1499 // this.vnfcIdentifier = newVnfcTypeV;
1500 } else if (this.referenceDataObject.scope['vnfc-type-list'].length == 0) {
1501 // this.vnfcIdentifier = newVnfcTypeV;
1503 this.vnfcIdentifier = newVnfcTypeV;
1504 console.log(this.classNm +
1505 ": addVnfc: vnfcIdentifier:[" + this.vnfcIdentifier + "]");
1506 if (!(this.referenceDataObject.scope['vnfc-type-list'].indexOf(newVnfcTypeV) > -1)) {
1507 this.referenceDataObject.scope['vnfc-type-list'].push(newVnfcTypeV);
1509 this.tempAllData.forEach(obj => {
1510 if (obj.action == "Configure" || obj.action == "ConfigModify" || obj.action == "DistributeTraffic") {
1511 obj.scope['vnfc-type-list'] = this.referenceDataObject.scope['vnfc-type-list']
1513 this.resetArtifactList(obj);
1515 console.log(this.classNm + ": addVnfc: scope vnfc-type:[" +
1516 this.referenceDataObject.scope['vnfc-type'] + "]");
1517 this.setVnfcTypeInSample(newVnfcTypeV);
1518 // Changing newVnfcType value to blank otherwise it will show previous value in text box of popup
1519 this.newVnfcType = ''
1523 console.log(this.classNm + ": resetVms: start.");
1524 this.referenceDataObject.vm = [];
1528 // this.referenceDataObject.vm = this.referenceDataObject.vm;
1531 resetGroupNotation() {
1532 if (this.Sample['group-notation-type'] == "existing-group-name") {
1533 this.Sample['group-notation-value'] = ""
1534 this.disableGrpNotationValue = true
1536 this.disableGrpNotationValue = false
1540 resetVmsForScaleout(action) {
1541 //reset currentform vms based on action
1542 if (action == "ConfigScaleOut" || action == "Configure") {
1543 let ConfigScaleOutIndex = this.tempAllData.findIndex(obj => {
1544 return obj['action'] == action
1546 if (ConfigScaleOutIndex > -1) {
1547 this.referenceDataObject.vm = this.tempAllData[ConfigScaleOutIndex].vm
1549 if (this.actionChanged) {
1550 this.referenceDataObject.vm = []
1556 resetParamsOnVnfcType() {
1557 console.log(this.classNm + ": resetParamsOnVnfcType: start:\n " +
1558 "ref.DataObject.scope vnfc-type:[" +
1559 this.referenceDataObject.scope['vnfc-type'] + "]");
1561 //if only vnf is there
1562 if (this.referenceDataObject.scope['vnfc-type'] == '' || this.referenceDataObject.scope['vnfc-type'] == null || this.referenceDataObject.scope['vnfc-type'] == 'null') {
1563 scopeName = this.referenceDataObject.scope['vnf-type'];
1564 this.referenceDataObject.scope['vnfc-type'] = '';
1565 this.referenceDataObject['action-level'] = 'vnf';
1566 this.referenceDataObject['scopeType'] = 'vnf-type';
1568 //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
1570 scopeName = this.referenceDataObject.scope['vnfc-type'];
1571 if (this.referenceDataObject.action == 'Configure' || this.referenceDataObject.action == 'ConfigModify' || this.referenceDataObject.action == 'DistributeTraffic') {
1572 this.referenceDataObject['action-level'] = 'vnfc';
1573 this.referenceDataObject['scopeType'] = 'vnfc-type';
1575 this.referenceDataObject['action-level'] = 'vnf';
1576 this.referenceDataObject['scopeType'] = 'vnf-type';
1579 //replacing / with _ and removing spaces in the scopeName
1581 scopeName = scopeName.replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '');
1583 console.log(this.classNm + ": resetParamsOnVnfcType: return scopeName:[" +
1588 decideExtension(obj) {
1589 //marking the extension based on the device-protocol selected by the user
1590 let extension = '.json';
1591 switch (obj['device-protocol']) {
1595 extension = '.json';
1604 prepareArtifactList(scopeName, extension) {
1605 console.log(this.classNm + ": prepareArtifactList: start: scopeName:[" +
1606 scopeName + "] extension:[" + extension + "]");
1607 this.referenceDataObject['artifact-list'] = [];
1608 //preparing the artifact list array file names along with extension
1609 let config_template_fileName = this.referenceDataObject.action + '_' + scopeName + '_' + '0.0.1V' + extension;
1610 let pd_fileName = this.referenceDataObject.action + '_' + scopeName + '_' + '0.0.1V.yaml';
1611 let reference_fileName = this.referenceDataObject.action + '_' + scopeName + '_' + '0.0.1V.json';
1612 let configTemplate = {
1613 'artifact-name': 'template_' + config_template_fileName,
1614 'artifact-type': 'config_template'
1617 'artifact-name': 'pd_' + pd_fileName,
1618 'artifact-type': 'parameter_definitions'
1620 if (this.referenceDataObject.action != 'ConfigScaleOut') {
1621 this.referenceDataObject['artifact-list'].push(configTemplate,
1625 let identifiers = this.referenceDataObject['template-id-list'];
1627 for (var x = 0; x < identifiers.length; x++) {
1628 //for replacing spaces and "/" with "_"
1629 identifiers[x] = identifiers[x].replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '');
1630 pd_fileName = this.referenceDataObject.action + '_' + scopeName + '_' + '0.0.1V_' + identifiers[x] + '.yaml';
1631 config_template_fileName = this.referenceDataObject.action + '_' + scopeName + '_' + '0.0.1V_' + identifiers[x] + extension;
1634 'artifact-name': 'template_' + config_template_fileName,
1635 'artifact-type': 'config_template'
1638 'artifact-name': 'pd_' + pd_fileName,
1639 'artifact-type': 'parameter_definitions'
1641 this.referenceDataObject['artifact-list'].push(configTemplate,
1649 deleteVmsforNonActions(newObj, action) {
1650 let configureObject = (action == 'Configure');
1651 let ConfigScaleOut = (action == 'ConfigScaleOut');
1652 //delete VM's if selected action is not configure.
1653 if (!ConfigScaleOut && !configureObject && this.tempAllData.length != 0) {
1654 if (ConfigScaleOut) {
1659 if (ConfigScaleOut) {
1661 delete newObj['template-id-list'];
1666 pushOrReplaceTempData(newObj, action) {
1667 console.log(this.classNm + ": pushOrReplaceTempData: start: action:[" +
1668 action + "]\n newObj.scope vnfc-type:[" + newObj.scope['vnfc-type'] + "]");
1669 if (newObj.scope['vnfc-type'] == undefined ||
1670 newObj.scope['vnfc-type'] == null ||
1671 newObj.scope['vnfc-type'].length < 1) {
1672 console.log(this.classNm + ": pushOrReplaceTempData: scope vnfc-type" +
1673 " is empty.\n vnfcIdentifier:[" + this.vnfcIdentifier + "]");
1674 if (this.vnfcIdentifier != null && this.vnfcIdentifier != undefined &&
1675 this.vnfcIdentifier.length > 0) {
1676 newObj.scope['vnfc-type'] = this.vnfcIdentifier;
1679 let actionObjIndex = this.tempAllData.findIndex(obj => {
1680 return obj['action'] == action;
1682 if (newObj.action != 'HealthCheck') {
1683 delete newObj['url'];
1686 if (actionObjIndex > -1) {
1687 this.tempAllData[actionObjIndex] = newObj;
1688 this.mappingEditorService.saveLatestAction(this.tempAllData[actionObjIndex]);
1689 if (newObj.action == "ConfigScaleOut") {
1690 this.mappingEditorService.saveLatestIdentifier(this.templateIdentifier);
1693 this.templateIdentifier = ('')
1694 this.mappingEditorService.saveLatestIdentifier(this.templateIdentifier)
1697 if (newObj.action != '') {
1698 this.tempAllData.push(newObj);
1699 this.mappingEditorService.saveLatestAction(newObj);
1700 if (newObj.action == "ConfigScaleOut") {
1701 this.mappingEditorService.saveLatestIdentifier(this.templateIdentifier);
1704 this.templateIdentifier = ('')
1705 this.mappingEditorService.saveLatestIdentifier(this.templateIdentifier)
1712 // removes the unwanted keys added in the artifact for vnfc level actions
1713 deleteUnwantedKeys(newObj) {
1714 console.log(this.classNm + ": deleteUnwantedKeys: start.");
1715 newObj = JSON.parse(JSON.stringify(newObj))
1716 delete newObj['template-id']
1717 delete newObj['vnfcIdentifier']
1718 if (newObj.action != "ConfigScaleOut") {
1719 delete newObj['template-id-list']
1721 if (newObj.action != 'HealthCheck') {
1722 delete newObj['url'];
1724 if (newObj.action != "Configure" && newObj.action != "ConfigModify" && newObj.action != "DistributeTraffic") {
1725 newObj.scope['vnfc-type-list'] = [];
1730 addAllActionObj(newObj, scopeName) {
1731 if (this.utilityService.getTracelvl() > 0)
1732 console.log(this.classNm + ": addAllActionObj: start.");
1733 //Creating all action block to allow mulitple actions at once
1735 action: 'AllAction',
1736 'action-level': 'vnf',
1737 scope: newObj.scope,
1739 'artifact-name': 'reference_AllAction' + '_' + scopeName + '_' + '0.0.1V.json',
1740 'artifact-type': 'reference_template'
1743 let allActionIndex = this.tempAllData.findIndex(obj => {
1744 return obj['action'] == 'AllAction';
1746 if (allActionIndex > -1) {
1747 this.tempAllData[allActionIndex] = allAction;
1749 this.tempAllData.push(allAction);
1754 if (this.utilityService.getTracelvl() > 0)
1755 console.log(this.classNm + ": resetTempData: start.");
1756 if (this.uploadedDataArray && this.uploadedDataArray != undefined && this.uploadedDataArray.length != 0) {
1757 if (this.tempAllData && this.tempAllData != undefined) {
1758 for (var i = 0; i < this.tempAllData.length; i++) {
1760 if (this.tempAllData[i].action === 'AllAction') {
1764 result = this.checkIfelementExistsInArray(this.tempAllData[i].action, this.actions);
1767 this.tempAllData.splice(i, 1);
1773 this.addVmCapabilitiesData();
1777 trackByFn(index, item) {
1781 getArtifactsOpenStack() {
1782 console.log(this.classNm + ": getArtifactsOpenStack: start: " +
1783 "tempAllData length=" + this.tempAllData.length);
1785 var vnfcFunctionCodeArrayList = [];
1786 var vnfcSetArray = [];
1787 for (var i = 0; i < this.tempAllData.length; i++) {
1788 if (!this.checkIfelementExistsInArray(this.tempAllData[i].action, this.actions) && (this.tempAllData[i].action != 'AllAction')) {
1789 var vnfcFunctionCodeArray = this.tempAllData[i]["vnfc-function-code-list"]
1790 vnfcFunctionCodeArrayList.push([this.tempAllData[i].action].concat(this.tempAllData[i]["vnfc-function-code-list"]))
1792 if (this.tempAllData[i].action === 'OpenStack Actions') {
1793 vnfcSetArray = this.tempAllData[i]['firstRowVmSpreadSheet']
1796 console.log(this.classNm + ": getArtifactsOpenStack: vnfcSetArray length=" +
1797 vnfcSetArray.length);
1799 let vnfcSetArrayLen = vnfcSetArray.length;
1801 for (let i = 0; i < vnfcFunctionCodeArrayList.length; i++) {
1802 let element = vnfcFunctionCodeArrayList[i];
1803 for (let j = 1; j < element.length; j++) {
1804 for (let k = j; k < vnfcSetArrayLen; k++) {
1805 if (element[j] === vnfcSetArray[k]) {
1809 element.splice(j, 0, '');
1815 this.firstArrayElement = vnfcSetArray;
1816 this.remUploadedDataArray = vnfcFunctionCodeArrayList;
1821 * Handles the display of VM block based on the action change
1823 handleVMBlockDisplay() {
1824 switch (this.referenceDataObject.action) {
1825 case this.actionList.ConfigScaleOut:
1826 case this.actionList.Configure:
1829 this.displayVMBlock = true;
1832 this.displayVMBlock = false;
1836 //.. check VNFC Type equality in Upper Selection vs entered in Sample field
1837 checkVnfcTypeEqual(vnfctp: string) {
1838 var methName = "checkVnfcTypeEqual";
1839 console.log(this.classNm + ": " + methName + ": vnfctp:[" + vnfctp + "]");
1840 console.log(this.classNm + ": " + methName + ": vnfcIdentifier:[" +
1841 this.vnfcIdentifier + "]");
1842 console.log(this.classNm + ": " + methName + ": Sample[vnfc-type]:[" +
1843 this.Sample['vnfc-type'] + "]");
1844 if (vnfctp != null && vnfctp.length > 0) {
1845 if (this.vnfcIdentifier != null && this.vnfcIdentifier.length > 0) {
1847 this.classNm + ": " + methName + ": compare non empty VNFC Types...");
1848 if (vnfctp != this.vnfcIdentifier) {
1849 console.log(this.classNm + ": " + methName + ": Non-match WARNING !");
1850 //.. display in pop-up
1851 this.nService.warn('WARNING',
1852 "The specified VNFC Types don't match." +
1853 " Can cause discrepancy in the artifacts.", this.options);
1855 console.log(this.classNm + ": checkVnfcTypeEqual: VNFC Types're equal.");
1861 //.. populating VNFC Type in Sample fields
1862 setVnfcTypeInSample(vnfctp: string) {
1863 // if( this.utilityService.getTracelvl() > 0 )
1864 console.log(this.classNm + ": setVnfcTypeInSample: vnfctp:[" + vnfctp + "]");
1865 this.Sample['vnfc-type'] = vnfctp;
1868 // Common method to show validation errors
1869 private showValidationErrors(referenceDataObject) {
1870 if (this.referenceDataObject.action === '') {
1871 this.nService.error('Error', 'Select a valid Action');
1874 if (this.referenceDataObject['device-protocol'] === '') {
1875 this.nService.error('Error', 'Select a valid Device protocol');
1879 if (referenceDataObject.action === 'ConfigScaleOut' && !this.templateIdentifier) {
1880 this.nService.error('Error', 'Select a valid Template Identifier');
1884 resetArtifactList(obj) {
1885 console.log(this.classNm + ": resetArtifactList: start...");
1886 let vnfcTypeList = obj.scope['vnfc-type-list'];
1887 let vnf = this.referenceDataObject.scope['vnf-type']
1889 let config_template_fileName
1894 obj['artifact-list'] = [];
1895 for (var x = 0; x < vnfcTypeList.length; x++) {
1896 let extension = this.referenceDataFormUtil.decideExtension(obj)
1897 //for replacing spaces and "/" with "_"
1898 let type = vnfcTypeList[x].replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '');
1899 pd_fileName = this.referenceDataObject.action + '_' + vnf.replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '') + '_' + type + '_' + '0.0.1V.yaml';
1900 config_template_fileName = this.referenceDataObject.action + '_' + vnf.replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '') + '_' + type + '_' + '0.0.1V' + extension;
1901 param_fileName = this.referenceDataObject.action + '_' + vnf.replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '') + '_' + type + '_' + '0.0.1V.json';
1903 'artifact-name': 'template_' + config_template_fileName,
1904 'artifact-type': 'config_template'
1907 'artifact-name': 'pd_' + pd_fileName,
1908 'artifact-type': 'parameter_definitions'
1911 'artifact-name': 'param_' + param_fileName,
1912 'artifact-type': 'param_values'
1915 this.referenceDataObject['artifact-list'].push(configTemplate,
1916 pdTemplate, paramValue
1918 obj['artifact-list'].push(configTemplate,
1919 pdTemplate, paramValue