| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 1 | /* |
| 2 | Copyright 2020 TATA ELXSI |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the 'License'); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | |
| 16 | Author: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.in), BARATH KUMAR R (barath.r@tataelxsi.co.in) |
| 17 | */ |
| 18 | /** |
| 19 | * @file NS Instance Primitive Component |
| 20 | */ |
| 21 | import { Component, Injector, Input, OnInit } from '@angular/core'; |
| 22 | import { AbstractControl, FormArray, FormBuilder, FormGroup, Validators } from '@angular/forms'; |
| 23 | import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; |
| 24 | import { TranslateService } from '@ngx-translate/core'; |
| 25 | import { NotifierService } from 'angular-notifier'; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 26 | import { APIURLHEADER, ERRORDATA, PRIMITIVEDATA, PRIMITIVETYPES, URLPARAMS } from 'CommonModel'; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 27 | import { DataService } from 'DataService'; |
| 28 | import { environment } from 'environment'; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 29 | import { KDUPRIMITIVELEVEL, NSData, VDUPRIMITIVELEVEL, VNFPROFILE } from 'NSDModel'; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 30 | import { NSPrimitiveParams } from 'NSInstanceModel'; |
| 31 | import { RestService } from 'RestService'; |
| 32 | import { SharedService } from 'SharedService'; |
| 33 | import { isNullOrUndefined } from 'util'; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 34 | import { CONFIGPRIMITIVE, DF, VDUCONFIG, VDUPROFILE, VNFCONFIG, VNFD } from 'VNFDModel'; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * Creating component |
| 38 | * @Component takes NSPrimitiveComponent.html as template url |
| 39 | */ |
| 40 | @Component({ |
| 41 | templateUrl: './NSPrimitiveComponent.html', |
| 42 | styleUrls: ['./NSPrimitiveComponent.scss'] |
| 43 | }) |
| 44 | /** Exporting a class @exports NSPrimitiveComponent */ |
| 45 | export class NSPrimitiveComponent implements OnInit { |
| 46 | /** Form valid on submit trigger @public */ |
| 47 | public submitted: boolean = false; |
| 48 | |
| 49 | /** To inject services @public */ |
| 50 | public injector: Injector; |
| 51 | |
| 52 | /** Instance for active modal service @public */ |
| 53 | public activeModal: NgbActiveModal; |
| 54 | |
| 55 | /** FormGroup instance added to the form @ html @public */ |
| 56 | public primitiveForm: FormGroup; |
| 57 | |
| 58 | /** Primitive params array @public */ |
| 59 | public primitiveParams: FormArray; |
| 60 | |
| 61 | /** Variable set for twoway binding @public */ |
| 62 | public nsdId: string; |
| 63 | |
| 64 | /** Check the loading results @public */ |
| 65 | public isLoadingResults: boolean = false; |
| 66 | |
| 67 | /** Give the message for the loading @public */ |
| 68 | public message: string = 'PLEASEWAIT'; |
| 69 | |
| 70 | /** Contains list of primitive parameter @public */ |
| 71 | public primitiveParameter: {}[] = []; |
| 72 | |
| 73 | /** Input contains component objects @public */ |
| 74 | @Input() public params: URLPARAMS; |
| 75 | |
| 76 | /** Contains list of primitive actions @public */ |
| 77 | public primitiveList: {}[]; |
| 78 | |
| 79 | /** Contains objects that is used to hold types of primitive @public */ |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 80 | public primitiveTypeList: PRIMITIVETYPES[] = []; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 81 | |
| 82 | /** Model value used to hold selected primitive type @public */ |
| 83 | public primitiveType: string; |
| 84 | |
| Barath Kumar R | 6e96d1b | 2020-07-10 12:10:15 +0530 | [diff] [blame] | 85 | /** Contains list of VDU primitive lists @public */ |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 86 | public vduList: VDUPROFILE[]; |
| Barath Kumar R | 6e96d1b | 2020-07-10 12:10:15 +0530 | [diff] [blame] | 87 | |
| Barath Kumar R | 5d75d51 | 2020-09-02 17:00:07 +0530 | [diff] [blame] | 88 | /** Contains list of KDU primitive lists @public */ |
| 89 | public kduList: {}[]; |
| 90 | |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 91 | /** FormBuilder instance added to the formBuilder @private */ |
| 92 | private formBuilder: FormBuilder; |
| 93 | |
| 94 | /** Utilizes rest service for any CRUD operations @private */ |
| 95 | private restService: RestService; |
| 96 | |
| 97 | /** packages data service collections @private */ |
| 98 | private dataService: DataService; |
| 99 | |
| 100 | /** Contains tranlsate instance @private */ |
| 101 | private translateService: TranslateService; |
| 102 | |
| 103 | /** Notifier service to popup notification @private */ |
| 104 | private notifierService: NotifierService; |
| 105 | |
| 106 | /** Contains all methods related to shared @private */ |
| 107 | private sharedService: SharedService; |
| 108 | |
| 109 | /** Contains objects that is used to convert key/value pair @private */ |
| 110 | private objectPrimitiveParams: {} = {}; |
| 111 | |
| 112 | constructor(injector: Injector) { |
| 113 | this.injector = injector; |
| 114 | this.restService = this.injector.get(RestService); |
| 115 | this.dataService = this.injector.get(DataService); |
| 116 | this.translateService = this.injector.get(TranslateService); |
| 117 | this.notifierService = this.injector.get(NotifierService); |
| 118 | this.sharedService = this.injector.get(SharedService); |
| 119 | this.activeModal = this.injector.get(NgbActiveModal); |
| 120 | this.formBuilder = this.injector.get(FormBuilder); |
| Barath Kumar R | 6e96d1b | 2020-07-10 12:10:15 +0530 | [diff] [blame] | 121 | this.primitiveTypeList = [ |
| 122 | { |
| Barath Kumar R | 54d693c | 2020-07-13 20:54:13 +0530 | [diff] [blame] | 123 | title: this.translateService.instant('NSPRIMITIVE'), |
| 124 | value: 'NS_Primitive' |
| 125 | }, |
| 126 | { |
| Barath Kumar R | 6e96d1b | 2020-07-10 12:10:15 +0530 | [diff] [blame] | 127 | title: this.translateService.instant('VNFPRIMITIVE'), |
| 128 | value: 'VNF_Primitive' |
| 129 | }, |
| 130 | { |
| 131 | title: this.translateService.instant('VDUPRIMITIVE'), |
| 132 | value: 'VDU_Primitive' |
| Barath Kumar R | 5d75d51 | 2020-09-02 17:00:07 +0530 | [diff] [blame] | 133 | }, |
| 134 | { |
| 135 | title: this.translateService.instant('KDUPRIMITIVE'), |
| 136 | value: 'KDU_Primitive' |
| Barath Kumar R | 6e96d1b | 2020-07-10 12:10:15 +0530 | [diff] [blame] | 137 | } |
| 138 | ]; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 139 | } |
| 140 | |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 141 | /** convenience getter for easy access to form fields */ |
| 142 | get f(): FormGroup['controls'] { return this.primitiveForm.controls; } |
| 143 | |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 144 | /** |
| 145 | * Lifecyle Hooks the trigger before component is instantiate |
| 146 | */ |
| 147 | public ngOnInit(): void { |
| 148 | /** Setting up initial value for NSD */ |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 149 | this.dataService.currentMessage.subscribe((event: NSData): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 150 | if (event.identifier !== undefined || event.identifier !== '' || event.identifier !== null) { |
| 151 | this.nsdId = event.identifier; |
| 152 | } |
| 153 | }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 154 | this.initializeForm(); |
| 155 | } |
| 156 | |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 157 | /** initialize Forms @public */ |
| 158 | public initializeForm(): void { |
| 159 | this.primitiveForm = this.formBuilder.group({ |
| 160 | primitive: [null, [Validators.required]], |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 161 | member_vnf_index: [null, [Validators.required]], |
| Barath Kumar R | 6e96d1b | 2020-07-10 12:10:15 +0530 | [diff] [blame] | 162 | vdu_id: [null, [Validators.required]], |
| Barath Kumar R | 5d75d51 | 2020-09-02 17:00:07 +0530 | [diff] [blame] | 163 | kdu_name: [null, [Validators.required]], |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 164 | primitive_params: this.formBuilder.array([this.primitiveParamsBuilder()]) |
| 165 | }); |
| 166 | } |
| 167 | |
| 168 | /** Generate primitive params @public */ |
| 169 | public primitiveParamsBuilder(): FormGroup { |
| 170 | return this.formBuilder.group({ |
| 171 | primitive_params_name: [null, [Validators.required]], |
| 172 | primitive_params_value: ['', [Validators.required]] |
| 173 | }); |
| 174 | } |
| 175 | |
| 176 | /** Handle FormArray Controls @public */ |
| 177 | public getControls(): AbstractControl[] { |
| 178 | return (this.getFormControl('primitive_params') as FormArray).controls; |
| 179 | } |
| 180 | |
| 181 | /** Push all primitive params on user's action @public */ |
| 182 | public createPrimitiveParams(): void { |
| 183 | this.primitiveParams = this.getFormControl('primitive_params') as FormArray; |
| 184 | this.primitiveParams.push(this.primitiveParamsBuilder()); |
| 185 | } |
| 186 | |
| 187 | /** Remove primitive params on user's action @public */ |
| 188 | public removePrimitiveParams(index: number): void { |
| 189 | this.primitiveParams.removeAt(index); |
| 190 | } |
| 191 | |
| Barath Kumar R | 5d75d51 | 2020-09-02 17:00:07 +0530 | [diff] [blame] | 192 | /** Execute Primitive @public */ |
| 193 | public execPrimitive(): void { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 194 | this.submitted = true; |
| 195 | this.objectPrimitiveParams = {}; |
| 196 | this.sharedService.cleanForm(this.primitiveForm); |
| 197 | if (this.primitiveForm.invalid) { return; } // Proceed, onces form is valid |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 198 | this.primitiveForm.value.primitive_params.forEach((params: NSPrimitiveParams): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 199 | if (params.primitive_params_name !== null && params.primitive_params_value !== '') { |
| 200 | this.objectPrimitiveParams[params.primitive_params_name] = params.primitive_params_value; |
| 201 | } |
| 202 | }); |
| 203 | //Prepare primitive params |
| 204 | const primitiveParamsPayLoads: {} = { |
| 205 | primitive: this.primitiveForm.value.primitive, |
| 206 | primitive_params: this.objectPrimitiveParams |
| 207 | }; |
| 208 | if (this.primitiveType === 'VNF_Primitive') { |
| 209 | // tslint:disable-next-line: no-string-literal |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 210 | primitiveParamsPayLoads['member_vnf_index'] = this.primitiveForm.value.member_vnf_index; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 211 | } |
| Barath Kumar R | 6e96d1b | 2020-07-10 12:10:15 +0530 | [diff] [blame] | 212 | if (this.primitiveType === 'VDU_Primitive') { |
| 213 | // tslint:disable-next-line: no-string-literal |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 214 | primitiveParamsPayLoads['member_vnf_index'] = this.primitiveForm.value.member_vnf_index; |
| Barath Kumar R | 6e96d1b | 2020-07-10 12:10:15 +0530 | [diff] [blame] | 215 | // tslint:disable-next-line: no-string-literal |
| 216 | primitiveParamsPayLoads['vdu_id'] = this.primitiveForm.value.vdu_id; |
| 217 | } |
| Barath Kumar R | 5d75d51 | 2020-09-02 17:00:07 +0530 | [diff] [blame] | 218 | if (this.primitiveType === 'KDU_Primitive') { |
| 219 | // tslint:disable-next-line: no-string-literal |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 220 | primitiveParamsPayLoads['member_vnf_index'] = this.primitiveForm.value.member_vnf_index; |
| Barath Kumar R | 5d75d51 | 2020-09-02 17:00:07 +0530 | [diff] [blame] | 221 | // tslint:disable-next-line: no-string-literal |
| 222 | primitiveParamsPayLoads['kdu_name'] = this.primitiveForm.value.kdu_name; |
| 223 | } |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 224 | const apiURLHeader: APIURLHEADER = { |
| 225 | url: environment.NSDINSTANCES_URL + '/' + this.nsdId + '/action' |
| 226 | }; |
| 227 | this.isLoadingResults = true; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 228 | this.restService.postResource(apiURLHeader, primitiveParamsPayLoads).subscribe((result: {}): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 229 | this.activeModal.dismiss(); |
| 230 | this.notifierService.notify('success', this.translateService.instant('PAGE.NSPRIMITIVE.EXECUTEDSUCCESSFULLY')); |
| 231 | this.isLoadingResults = false; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 232 | }, (error: ERRORDATA): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 233 | this.isLoadingResults = false; |
| 234 | this.restService.handleError(error, 'post'); |
| 235 | }); |
| 236 | } |
| 237 | /** Primitive type change event @public */ |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 238 | public primitiveTypeChange(data: PRIMITIVETYPES): void { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 239 | this.primitiveList = []; |
| 240 | this.primitiveParameter = []; |
| 241 | this.initializeForm(); |
| 242 | if (data.value === 'NS_Primitive') { |
| Barath Kumar R | 54d693c | 2020-07-13 20:54:13 +0530 | [diff] [blame] | 243 | this.getNSInfo(this.params.name); |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 244 | this.setUpdateValueandValidation('member_vnf_index'); |
| Barath Kumar R | 5d75d51 | 2020-09-02 17:00:07 +0530 | [diff] [blame] | 245 | } |
| 246 | if (data.value === 'VNF_Primitive' || data.value === 'KDU_Primitive' || data.value === 'NS_Primitive') { |
| 247 | this.setUpdateValueandValidation('vdu_id'); |
| 248 | } |
| 249 | if (data.value === 'VDU_Primitive' || data.value === 'VNF_Primitive' || data.value === 'NS_Primitive') { |
| 250 | this.setUpdateValueandValidation('kdu_name'); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 251 | } |
| 252 | } |
| 253 | /** Member index change event */ |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 254 | public indexChange(data: VNFPROFILE, getType?: string): void { |
| Barath Kumar R | 6e96d1b | 2020-07-10 12:10:15 +0530 | [diff] [blame] | 255 | this.getFormControl('vdu_id').setValue(null); |
| Barath Kumar R | 5d75d51 | 2020-09-02 17:00:07 +0530 | [diff] [blame] | 256 | this.getFormControl('kdu_name').setValue(null); |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 257 | if (data['vnfd-id'] !== null) { |
| 258 | this.getVnfdInfo(data['vnfd-id'], getType); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 259 | } else { |
| 260 | this.primitiveList = []; |
| 261 | this.getFormControl('primitive').setValue(null); |
| 262 | this.primitiveParameter = []; |
| 263 | } |
| 264 | } |
| Barath Kumar R | 5d75d51 | 2020-09-02 17:00:07 +0530 | [diff] [blame] | 265 | /** Get VDU/KDU primitive List for the selected event @public */ |
| 266 | public getPrimitiveList(data: {}, selectedType: string): void { |
| 267 | this.primitiveList = data[selectedType + '-configuration']['config-primitive']; |
| Barath Kumar R | 6e96d1b | 2020-07-10 12:10:15 +0530 | [diff] [blame] | 268 | } |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 269 | /** Primivtive change event */ |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 270 | public primitiveChange(data: PRIMITIVEDATA): void { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 271 | this.primitiveParameter = []; |
| 272 | const formArr: FormArray = this.getFormControl('primitive_params') as FormArray; |
| 273 | formArr.controls = []; |
| 274 | this.createPrimitiveParams(); |
| 275 | if (data) { |
| 276 | this.updatePrimitive(data); |
| 277 | } |
| 278 | } |
| Barath Kumar R | 6e96d1b | 2020-07-10 12:10:15 +0530 | [diff] [blame] | 279 | /** Generate vdu section @public */ |
| Barath Kumar R | 1a34b83 | 2021-03-05 11:32:19 +0530 | [diff] [blame^] | 280 | public generateVDUData(vduConfig: VDUCONFIG): VDUPROFILE { |
| Barath Kumar R | 6e96d1b | 2020-07-10 12:10:15 +0530 | [diff] [blame] | 281 | return { |
| Barath Kumar R | 1a34b83 | 2021-03-05 11:32:19 +0530 | [diff] [blame^] | 282 | id: vduConfig.id, |
| 283 | name: vduConfig.id, |
| 284 | 'vdu-configuration': vduConfig |
| Barath Kumar R | 6e96d1b | 2020-07-10 12:10:15 +0530 | [diff] [blame] | 285 | }; |
| 286 | } |
| Barath Kumar R | 5d75d51 | 2020-09-02 17:00:07 +0530 | [diff] [blame] | 287 | /** Generate kdu section @public */ |
| Barath Kumar R | 1a34b83 | 2021-03-05 11:32:19 +0530 | [diff] [blame^] | 288 | public generateKDUData(kduData: KDUPRIMITIVELEVEL, kduConfig: VDUCONFIG): KDUPRIMITIVELEVEL { |
| Barath Kumar R | 5d75d51 | 2020-09-02 17:00:07 +0530 | [diff] [blame] | 289 | return { |
| 290 | name: kduData.name, |
| 291 | 'juju-bundle': kduData['juju-bundle'], |
| Barath Kumar R | 1a34b83 | 2021-03-05 11:32:19 +0530 | [diff] [blame^] | 292 | 'kdu-configuration': kduConfig |
| Barath Kumar R | 5d75d51 | 2020-09-02 17:00:07 +0530 | [diff] [blame] | 293 | }; |
| 294 | } |
| 295 | /** Used to set the validation and value and update the validation and value @public */ |
| 296 | public setUpdateValueandValidation(formName: string): void { |
| 297 | this.getFormControl(formName).setValidators([]); |
| 298 | this.getFormControl(formName).updateValueAndValidity(); |
| 299 | } |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 300 | /** Update primitive value based on parameter */ |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 301 | private updatePrimitive(primitive: PRIMITIVEDATA): void { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 302 | if (primitive.parameter) { |
| 303 | this.primitiveParameter = primitive.parameter; |
| 304 | } else { |
| 305 | this.primitiveParameter = []; |
| 306 | const formArr: AbstractControl[] = this.getControls(); |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 307 | formArr.forEach((formGp: FormGroup): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 308 | formGp.controls.primitive_params_name.setValidators([]); |
| 309 | formGp.controls.primitive_params_name.updateValueAndValidity(); |
| 310 | formGp.controls.primitive_params_value.setValidators([]); |
| 311 | formGp.controls.primitive_params_value.updateValueAndValidity(); |
| 312 | }); |
| 313 | } |
| 314 | } |
| 315 | /** Get primivitive actions from vnfd data */ |
| Barath Kumar R | 6e96d1b | 2020-07-10 12:10:15 +0530 | [diff] [blame] | 316 | private getVnfdInfo(vnfdRef: string, getType?: string): void { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 317 | this.primitiveList = []; |
| 318 | this.primitiveParameter = []; |
| 319 | this.getFormControl('primitive').setValue(null); |
| Barath Kumar R | 86504d2 | 2021-02-19 18:34:44 +0530 | [diff] [blame] | 320 | const apiUrl: string = environment.VNFPACKAGES_URL + '?id=' + vnfdRef; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 321 | this.isLoadingResults = true; |
| Barath Kumar R | 1a34b83 | 2021-03-05 11:32:19 +0530 | [diff] [blame^] | 322 | this.restService.getResource(apiUrl).subscribe((vnfdInfo: VNFD[]): void => { |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 323 | const vnfInstances: VNFD = vnfdInfo[0]; |
| Barath Kumar R | 1a34b83 | 2021-03-05 11:32:19 +0530 | [diff] [blame^] | 324 | if (!isNullOrUndefined(vnfInstances.df)) { |
| Barath Kumar R | 6e96d1b | 2020-07-10 12:10:15 +0530 | [diff] [blame] | 325 | this.getFormControl('vdu_id').setValidators([]); |
| Barath Kumar R | 5d75d51 | 2020-09-02 17:00:07 +0530 | [diff] [blame] | 326 | this.getFormControl('kdu_name').setValidators([]); |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 327 | vnfInstances.df.forEach((df: DF): void => { |
| Barath Kumar R | 1a34b83 | 2021-03-05 11:32:19 +0530 | [diff] [blame^] | 328 | if (df['lcm-operations-configuration'] !== undefined) { |
| 329 | if (df['lcm-operations-configuration']['operate-vnf-op-config'] !== undefined) { |
| 330 | const day12Operation: VDUCONFIG[] = df['lcm-operations-configuration']['operate-vnf-op-config']['day1-2']; |
| 331 | if (day12Operation !== undefined) { |
| 332 | const vnfprimitiveList: VNFCONFIG = day12Operation |
| 333 | .filter((itemData: VNFCONFIG): boolean => itemData.id === vnfInstances.id)[0]; |
| 334 | if (vnfprimitiveList !== undefined) { |
| 335 | this.primitiveList = vnfprimitiveList['config-primitive']; |
| 336 | } |
| 337 | /** VDU Primitive */ |
| 338 | if (getType === 'VDU_Primitive') { |
| 339 | this.kduList = []; |
| 340 | this.vduList = []; |
| 341 | this.primitiveList = []; |
| 342 | df['vdu-profile'].forEach((vduProfile: VDUPROFILE): void => { |
| 343 | day12Operation.forEach((element: VDUCONFIG): void => { |
| 344 | if (element.id === vduProfile.id){ |
| 345 | const vduDataObj: VDUPROFILE = this.generateVDUData(element); |
| 346 | this.vduList.push(vduDataObj); |
| 347 | } |
| 348 | }); |
| 349 | }); |
| 350 | } |
| 351 | /** KDU Primitive */ |
| 352 | if (getType === 'KDU_Primitive') { |
| 353 | this.kduList = []; |
| 354 | this.vduList = []; |
| 355 | this.primitiveList = []; |
| 356 | if (!isNullOrUndefined(vnfInstances.kdu)) { |
| 357 | vnfInstances.kdu.forEach((kduData: KDUPRIMITIVELEVEL): void => { |
| 358 | day12Operation.forEach((element: VDUCONFIG): void => { |
| 359 | if (element.id === kduData.name){ |
| 360 | const kduDataObj: KDUPRIMITIVELEVEL = this.generateKDUData(kduData, element); |
| 361 | this.kduList.push(kduDataObj); |
| 362 | } |
| 363 | }); |
| 364 | }); |
| 365 | } |
| 366 | } |
| 367 | } |
| 368 | } |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 369 | } |
| 370 | }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 371 | } |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 372 | this.isLoadingResults = false; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 373 | }, (error: ERRORDATA): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 374 | this.isLoadingResults = false; |
| 375 | this.restService.handleError(error, 'get'); |
| 376 | }); |
| 377 | } |
| Barath Kumar R | 54d693c | 2020-07-13 20:54:13 +0530 | [diff] [blame] | 378 | /** Get primivitive actions from NSD data */ |
| 379 | private getNSInfo(nsdRef: string): void { |
| 380 | this.primitiveList = []; |
| 381 | this.primitiveParameter = []; |
| 382 | this.getFormControl('primitive').setValue(null); |
| Barath Kumar R | 86504d2 | 2021-02-19 18:34:44 +0530 | [diff] [blame] | 383 | const apiUrl: string = environment.NSDESCRIPTORS_URL + '?id=' + nsdRef; |
| Barath Kumar R | 54d693c | 2020-07-13 20:54:13 +0530 | [diff] [blame] | 384 | this.isLoadingResults = true; |
| 385 | this.restService.getResource(apiUrl) |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 386 | .subscribe((nsdInfo: {}): void => { |
| Barath Kumar R | d3ce0c5 | 2020-08-13 11:44:01 +0530 | [diff] [blame] | 387 | if (!isNullOrUndefined(nsdInfo[0]['ns-configuration'])) { |
| 388 | this.primitiveList = !isNullOrUndefined(nsdInfo[0]['ns-configuration']['config-primitive']) ? |
| Barath Kumar R | 5d75d51 | 2020-09-02 17:00:07 +0530 | [diff] [blame] | 389 | nsdInfo[0]['ns-configuration']['config-primitive'] : []; |
| Barath Kumar R | d3ce0c5 | 2020-08-13 11:44:01 +0530 | [diff] [blame] | 390 | } else { |
| 391 | this.primitiveList = []; |
| 392 | } |
| Barath Kumar R | 54d693c | 2020-07-13 20:54:13 +0530 | [diff] [blame] | 393 | this.isLoadingResults = false; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 394 | }, (error: ERRORDATA): void => { |
| Barath Kumar R | 54d693c | 2020-07-13 20:54:13 +0530 | [diff] [blame] | 395 | this.isLoadingResults = false; |
| 396 | this.restService.handleError(error, 'get'); |
| 397 | }); |
| 398 | } |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 399 | /** Used to get the AbstractControl of controlName passed @private */ |
| 400 | private getFormControl(controlName: string): AbstractControl { |
| 401 | return this.primitiveForm.controls[controlName]; |
| 402 | } |
| 403 | } |