blob: 64f11594b6dfd4161c689e2403c6df6f692924b0 [file] [log] [blame]
Skip Wonnell2c977e22018-03-01 08:30:15 -06001/*
2============LICENSE_START==========================================
3===================================================================
4Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
Arundathi Patil9d5e8e72018-07-17 15:46:17 +05305
6Copyright (C) 2018 IBM Intellectual Property. All rights reserved.
Skip Wonnell2c977e22018-03-01 08:30:15 -06007===================================================================
Sandeep J3d0d6a32018-07-13 15:10:51 +05308Copyright (C) 2018 IBM.
9===================================================================
Skip Wonnell2c977e22018-03-01 08:30:15 -060010
11Unless otherwise specified, all software contained herein is licensed
12under the Apache License, Version 2.0 (the License);
13you may not use this software except in compliance with the License.
14You may obtain a copy of the License at
15
16 http://www.apache.org/licenses/LICENSE-2.0
17
18Unless required by applicable law or agreed to in writing, software
19distributed under the License is distributed on an "AS IS" BASIS,
20WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21See the License for the specific language governing permissions and
22limitations under the License.
23
Skip Wonnell2c977e22018-03-01 08:30:15 -060024============LICENSE_END============================================
25*/
26
27import { Component, OnInit, ViewChild } from '@angular/core';
28import { saveAs } from 'file-saver';
29import { ParamShareService } from '../../../shared/services/paramShare.service';
30import { MappingEditorService } from '../../../shared/services/mapping-editor.service';
31import { ModalComponent } from '../../../shared/modal/modal.component';
32import { HttpUtilService } from '../../../shared/services/httpUtil/http-util.service';
33import { UtilityService } from '../../../shared/services/utilityService/utility.service';
34import { environment } from '../../../../environments/environment';
35import { NotificationsService } from 'angular2-notifications';
36import { ParameterDefinitionService } from './parameter-definition.service';
37import 'rxjs/add/operator/map';
38import { NgProgress } from 'ngx-progressbar';
Sandeep Jd2917a82018-07-19 16:41:13 +053039import { NgxSpinnerService } from 'ngx-spinner';
Arundathi Patil9d5e8e72018-07-17 15:46:17 +053040import { appConstants } from '../../../../constants/app-constants';
asgaraf56b682019-03-08 19:52:33 +053041import { APIService } from "../../../shared/services/cdt.apicall";
Skip Wonnell2c977e22018-03-01 08:30:15 -060042
Skip Wonnell2c977e22018-03-01 08:30:15 -060043let YAML = require('yamljs');
44
45declare var $: any;
46
47@Component({
48 selector: 'parameter-form',
49 templateUrl: './parameter.component.html',
50 styleUrls: ['../reference-dataform/reference-dataform.component.css'],
51 providers: [ParameterDefinitionService]
52})
53export class ParameterComponent implements OnInit {
asgaraf56b682019-03-08 19:52:33 +053054 clName= "ParameterCompon";
Skip Wonnell2c977e22018-03-01 08:30:15 -060055 public paramForm: any;
56 public actionType: any;
57 public showFilterFields: boolean;
asgaraf56b682019-03-08 19:52:33 +053058
Arundathi Patil9d5e8e72018-07-17 15:46:17 +053059 public filterByFieldvalues = appConstants.filterByFieldvalues;
60 public ruleTypeConfiguaration = appConstants.ruleTypeConfiguaration;
61 public requiredValues: boolean[] = appConstants.requiredValues;
62 public sourceValues = appConstants.sourceValues;
63 public ruleTypeValues = appConstants.ruleTypeValues;
64 public typeValues = appConstants.typeValues;
65 public responseKeyNameValues = appConstants.responseKeyNameValues;
66 public responseKeyValues = appConstants.responseKeyValues;
67 public requestKeyNameValues = appConstants.requestKeyNameValues;
68 public requestKeyValues = appConstants.requestKeyValues;
Skip Wonnell2c977e22018-03-01 08:30:15 -060069 public myKeyFileName = null;
70 public myPdFileName = null;
71 public disposable: any;
72 public confirmation: boolean;
73 public showConfirmation: boolean;
74 public test: boolean;
75 apiToken = localStorage['apiToken'];
76 userId = localStorage['userId'];
77 public initialData: any;
78 public intialData: any;
79 public initialAction: any;
80 public item: any = {};
81 public subscription: any;
82 public Actions = [
Arundathi Patil9d5e8e72018-07-17 15:46:17 +053083 { action: appConstants.Actions.configBackup, value: appConstants.Actions.configBackup },
84 { action: appConstants.Actions.ConfigModify, value: appConstants.Actions.ConfigModify },
85 { action: appConstants.Actions.configRestore, value: appConstants.Actions.configRestore },
86 { action: appConstants.Actions.configure, value: appConstants.Actions.configure },
87 { action: appConstants.Actions.getRunningConfig, value: appConstants.Actions.getRunningConfig },
88 { action: appConstants.Actions.healthCheck, value: appConstants.Actions.healthCheck },
89 { action: appConstants.Actions.startApplication, value: appConstants.Actions.startApplication },
Lukasz Rajewski1fe55d32018-08-28 15:18:35 +020090 { action: appConstants.Actions.stopApplication, value: appConstants.Actions.stopApplication },
Lukasz Rajewskic63fafc2019-03-16 18:18:14 +010091 { action: appConstants.Actions.distributeTraffic, value: appConstants.Actions.distributeTraffic },
92 { action: appConstants.Actions.distributeTrafficCheck, value: appConstants.Actions.distributeTrafficCheck }
Skip Wonnell2c977e22018-03-01 08:30:15 -060093 ];
Arundathi Patil9d5e8e72018-07-17 15:46:17 +053094 public uploadTypes = appConstants.uploadTypes;
Skip Wonnell2c977e22018-03-01 08:30:15 -060095
Arundathi Patil9d5e8e72018-07-17 15:46:17 +053096 options = appConstants.optionsToNotificationComponent;
Skip Wonnell2c977e22018-03-01 08:30:15 -060097 public vnfcTypeData: string = '';
98 public selectedUploadType: string;
99 @ViewChild(ModalComponent) modalComponent: ModalComponent;
100 public title: string;
101 public parameterDefinitionMap: { [index: string]: string; } = {};
102 public parameterNameValues = {};
103 public displayParamObjects;
104 public modelParamDefinitionObjects;
105 public vnfType: any;
106 vnfcType: any;
107 protocol: any;
108 public refNameObj = {};
109 public action;
110 public artifactName;
111 public appDataObject: any;
112 public downloadDataObject: any;
asgaraf56b682019-03-08 19:52:33 +0530113 public artifact_fileName="";
od7427b1ce3d42018-08-23 11:49:12 -0400114 template_id: any;
Skip Wonnell2c977e22018-03-01 08:30:15 -0600115 private selectedActionReference: any;
116
sj108sf27d5542018-04-02 14:46:25 +0530117 constructor(private httpService: HttpUtilService,
asgaraf56b682019-03-08 19:52:33 +0530118 private apiService:APIService,
Skip Wonnell2c977e22018-03-01 08:30:15 -0600119 private parameterDefinitionService: ParameterDefinitionService,
120 private paramShareService: ParamShareService,
121 private mappingEditorService: MappingEditorService,
122 private httpUtil: HttpUtilService,
123 private utilService: UtilityService,
124 private nService: NotificationsService,
Sandeep Jd2917a82018-07-19 16:41:13 +0530125 private ngProgress: NgProgress,
126 private spinner: NgxSpinnerService) {
Skip Wonnell2c977e22018-03-01 08:30:15 -0600127 }
128
129 ngOnInit() {
asgaraf56b682019-03-08 19:52:33 +0530130 var methName= "ngOnInit";
131 this.selectedActionReference = this.mappingEditorService.newObject;
Skip Wonnell2c977e22018-03-01 08:30:15 -0600132 if (this.selectedActionReference && this.selectedActionReference != undefined) {
asgaraf56b682019-03-08 19:52:33 +0530133 this.vnfType = this.selectedActionReference.vnf;
134 this.protocol = this.selectedActionReference.protocol;
135 this.action = this.selectedActionReference.action;
136 if( this.utilService.getTracelvl() > 0 )
137 console.log( this.clName+": "+methName+": vnfType:["+this.vnfType+
138 "] action:["+this.action+"] protocol:["+this.protocol+"]");
139 if(this.selectedActionReference.vnfc) {
140 this.vnfcType = this.selectedActionReference.vnfc;
141 if( this.utilService.getTracelvl() > 0 )
142 console.log( this.clName+": "+methName+": have vnfcType:["+
143 this.vnfcType+"]");
Skip Wonnell2c977e22018-03-01 08:30:15 -0600144 }
Liu700ac8a2020-01-27 10:59:12 +0800145 if( this.action === 'ConfigScaleOut' || this.action === 'ConfigScaleIn'){
asgaraf56b682019-03-08 19:52:33 +0530146 // this.template_id = this.selectedActionReference.templateId;
147 this.template_id = this.mappingEditorService.identifier;
148 }
149 this.artifact_fileName = this.selectedActionReference.pd_artifact;
Skip Wonnell2c977e22018-03-01 08:30:15 -0600150 this.parameterDefinitionService.setValues(this.vnfType, this.vnfcType, this.protocol, this.action, this.artifact_fileName);
151 }
152 else {
153 this.selectedActionReference = {
154 'action': '',
155 'scope': { 'vnf-type': '', 'vnfc-type': '' },
156 'vm': [],
157 'protocol': '',
158 'download-dg-reference': '',
159 'user-name': '',
160 'port-number': '',
161 'artifact-list': [],
162 'deviceTemplate': '',
163 'scopeType': ''
164 };
165 }
asgaraf56b682019-03-08 19:52:33 +0530166 //let path = this.location.path
167 /* this.activeRoutes.url.subscribe(UrlSegment => {
168 this.actionType = UrlSegment[0].path
169 })
170 */
Skip Wonnell2c977e22018-03-01 08:30:15 -0600171 }
172
173 ngAfterViewInit() {
asgaraf56b682019-03-08 19:52:33 +0530174 if( this.mappingEditorService.latestAction) {
Skip Wonnell2c977e22018-03-01 08:30:15 -0600175 this.displayParamObjects = [];
176 this.modelParamDefinitionObjects = [];
asgaraf56b682019-03-08 19:52:33 +0530177 this.displayParamObjects= this.paramShareService.getSessionParamData();
178 // if( this.paramShareService.getSessionParamData() != undefined &&
179 // this.paramShareService.getSessionParamData().length > 0)
180 if( this.displayParamObjects != undefined &&
181 this.displayParamObjects.length > 0 )
182 {
183 this.parameterDefinitionService.populateDataUponSource( this.displayParamObjects);
Skip Wonnell2c977e22018-03-01 08:30:15 -0600184 } else {
asgaraf56b682019-03-08 19:52:33 +0530185 this.getPD();
Skip Wonnell2c977e22018-03-01 08:30:15 -0600186 }
187 } else {
Arundathi Patil9d5e8e72018-07-17 15:46:17 +0530188 this.nService.error(appConstants.errors.error, appConstants.errors["noAction&VNFTypeInRDscreenError"]);
Skip Wonnell2c977e22018-03-01 08:30:15 -0600189 }
190 return this.displayParamObjects;
191 }
192
193
194 public getPD() {
195 let result: any;
asgaraf56b682019-03-08 19:52:33 +0530196 let input=
197 this.utilService.createPayloadForRetrieve( false, this.action, this.vnfType,this.artifact_fileName);
Skip Wonnell2c977e22018-03-01 08:30:15 -0600198 let artifactContent: any;
asgaraf56b682019-03-08 19:52:33 +0530199 this.ngProgress.start();
200 return this.apiService.callGetArtifactsApi(input).subscribe( data => {
201 if( this.utilService.checkResult(data)) {
202 let result: any = JSON.parse(data.output.data.block).artifactInfo[0];
Skip Wonnell2c977e22018-03-01 08:30:15 -0600203 var pdObject = YAML.parse(result['artifact-content']);
204 let fileModel = pdObject['vnf-parameter-list'];
205 this.displayParamObjects = this.parameterDefinitionService.populatePD(fileModel);
206 }
asgaraf56b682019-03-08 19:52:33 +0530207 else {
208 }
209 this.ngProgress.done();
Skip Wonnell2c977e22018-03-01 08:30:15 -0600210 },
211
Arundathi Patil9d5e8e72018-07-17 15:46:17 +0530212 error => this.nService.error(appConstants.errors.error, appConstants.errors.connectionError));
213
Skip Wonnell2c977e22018-03-01 08:30:15 -0600214 }
215
sj108sf50c5162018-04-27 16:34:48 +0530216 public getPDFromSession() {
Arundathi Patil9d5e8e72018-07-17 15:46:17 +0530217
asgaraf56b682019-03-08 19:52:33 +0530218 this.ngProgress.start();
sj108sf50c5162018-04-27 16:34:48 +0530219 return this.httpService.get({
220 url: 'testurl',
asgaraf56b682019-03-08 19:52:33 +0530221 }).subscribe( data => {
222 this.displayParamObjects = this.paramShareService.getSessionParamData();
223 this.ngProgress.done();
sj108sf50c5162018-04-27 16:34:48 +0530224 },
asgaraf56b682019-03-08 19:52:33 +0530225 error => {
226 this.displayParamObjects = this.paramShareService.getSessionParamData();
227 this.ngProgress.done();
228 });
sj108sf50c5162018-04-27 16:34:48 +0530229 }
230
Skip Wonnell2c977e22018-03-01 08:30:15 -0600231 selectedNavItem(item: any) {
232 this.item = item;
233 }
234
235 //========================== End of selectedNavItem() Method============================================
236 browsePdFile() {
237 $('#inputFile1').trigger('click');
238 }
239
240 //========================== End of browsePdFile() Method============================================
241 browseKeyFile() {
242 $('#inputFile2').trigger('click');
243
244 }
245
246 //========================== End of browseKeyFile() Method============================================
247
248
249 //========================== End of appendSlashes() Method============================================
250
251
252 //========================== End of prepareFileName() Method============================================
253 ngOnDestroy() {
254 this.parameterDefinitionService.destroy(this.displayParamObjects);
255 }
256
257 //========================== End of ngOnDestroy() Method============================================
258
Skip Wonnell2c977e22018-03-01 08:30:15 -0600259 public showUpload() {
260 this.selectedUploadType = this.uploadTypes[0].value;
261 };
262
263 //========================== End of showUpload() Method============================================
264 //This is called when the user selects new files from the upload button
265 public fileChange(input, uploadType) {
266 if (input.files && input.files[0]) {
Sandeep Jd2917a82018-07-19 16:41:13 +0530267 this.spinner.show();
Skip Wonnell2c977e22018-03-01 08:30:15 -0600268 // Create the file reader
269 let reader = new FileReader();
270 this.readFile(input.files[0], reader, (result) => {
asgaraf56b682019-03-08 19:52:33 +0530271 if ('keyfile' === uploadType) {
272 this.myKeyFileName = input.files[0].name;
273 this.displayParamObjects = this.parameterDefinitionService.processKeyFile(this.myKeyFileName, result);
274 }
Skip Wonnell2c977e22018-03-01 08:30:15 -0600275 if ('pdfile' === uploadType) {
276 this.myPdFileName = input.files[0].name;
277 this.displayParamObjects = this.parameterDefinitionService.processPDfile(this.myPdFileName, result);
278 }
279 });
Sandeep Jd2917a82018-07-19 16:41:13 +0530280 setTimeout(() => {
281 /** spinner ends after 3.5 seconds */
282 this.spinner.hide();
283 }, 3500);
Skip Wonnell2c977e22018-03-01 08:30:15 -0600284 }
285 }
286
287 //========================== End of fileChange() Method============================================
288 public readFile(file, reader, callback) {
289 // Set a callback funtion to fire after the file is fully loaded
290 reader.onload = () => {
291 // callback with the results
292 callback(reader.result);
293 };
Skip Wonnell2c977e22018-03-01 08:30:15 -0600294 // Read the file
295 reader.readAsText(file, 'UTF-8');
296 }
297
298 //========================== End of readFile() Method============================================
299 fileChangeEvent(fileInput: any) {
300 let obj: any = fileInput.target.files;
301 }
302
asgaraf56b682019-03-08 19:52:33 +0530303 sourceChanged( data, obj) {
Skip Wonnell2c977e22018-03-01 08:30:15 -0600304 if (data == 'A&AI') {
Arundathi Patil9d5e8e72018-07-17 15:46:17 +0530305 obj.ruleTypeValues = appConstants.ruleTypeValues;
Skip Wonnell2c977e22018-03-01 08:30:15 -0600306 for (let x = 0; x < 5; x++) {
307 obj['response-keys'][x]['key-name'] = null;
308 obj['response-keys'][x]['key-value'] = null;
309 }
310 } else if (data == 'Manual') {
311 obj.ruleTypeValues = [null];
312 obj['rule-type'] = null;
313 obj.showFilterFields = false;
314 for (let x = 0; x < 5; x++) {
315 obj['response-keys'][x]['key-name'] = null;
316 obj['response-keys'][x]['key-value'] = null;
317 }
318 }
319 else {
320 obj.ruleTypeValues = [null];
321 }
322 }
323
324 //========================== End of sourceChanged() Method============================================
asgaraf56b682019-03-08 19:52:33 +0530325 ruleTypeChanged( data, obj) {
Skip Wonnell2c977e22018-03-01 08:30:15 -0600326 if (data == null || data == undefined || data == 'null') {
327 obj.showFilterFields = false;
328 obj['rule-type'] = null;
329 for (let x = 0; x < 5; x++) {
330 obj['response-keys'][x]['key-name'] = null;
331 obj['response-keys'][x]['key-value'] = null;
332 }
333 } else {
334 let sourceObject = this.ruleTypeConfiguaration[data];
335 if (data == 'vm-name-list' || data == 'vnfc-name-list' || data == 'vnfc-oam-ipv4-address-list') {
336 this.showFilterFields = false;
337 obj.showFilterFields = true;
338 this.filetrByFieldChanged(obj['response-keys'][3]['key-value'], obj);
339 } else {
340 obj.showFilterFields = false;
341 obj['response-keys'][3]['key-name'] = null;
342 obj['response-keys'][3]['key-value'] = null;
343 obj['response-keys'][4]['key-name'] = null;
344 obj['response-keys'][4]['key-value'] = null;
345 }
346 for (let x = 0; x < sourceObject.length; x++) {
347 obj['response-keys'][x]['key-name'] = sourceObject[x]['key-name'];
asgaraf56b682019-03-08 19:52:33 +0530348 obj['response-keys'][x]['key-value'] = sourceObject[x]['key-value'];
Skip Wonnell2c977e22018-03-01 08:30:15 -0600349 }
350 }
351
352 }
353
354 //========================== End of ruleTypeChanged() Method============================================
355 filetrByFieldChanged(data, obj) {
356 if (data == null || data == undefined || data == 'null') {
357 obj.enableFilterByValue = false;
358 obj['response-keys'][4]['key-value'] = null;
359 } else {
360 obj.enableFilterByValue = true;
361 }
362
363 }
364
365
Arundathi Patil9d5e8e72018-07-17 15:46:17 +0530366}