X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=src%2Fapp%2Finstances%2Fns-primitive%2FNSPrimitiveComponent.ts;h=d5cf56559af022aa7625c5578e3800eb6f9f0f16;hb=1db2e54394d3400d264e07e15e288f46f33eff65;hp=02269d37cab604393b0ed2f1e9edcfa21e6b2cfe;hpb=3b4814aa2d3dec621dadb52f058ba95a3dc3a86a;p=osm%2FNG-UI.git diff --git a/src/app/instances/ns-primitive/NSPrimitiveComponent.ts b/src/app/instances/ns-primitive/NSPrimitiveComponent.ts index 02269d3..d5cf565 100644 --- a/src/app/instances/ns-primitive/NSPrimitiveComponent.ts +++ b/src/app/instances/ns-primitive/NSPrimitiveComponent.ts @@ -26,7 +26,7 @@ import { NotifierService } from 'angular-notifier'; import { APIURLHEADER, ERRORDATA, URLPARAMS } from 'CommonModel'; import { DataService } from 'DataService'; import { environment } from 'environment'; -import { NSData } from 'NSDModel'; +import { KDUPRIMITIVELEVEL, NSData, VDUPRIMITIVELEVEL } from 'NSDModel'; import { NSPrimitiveParams } from 'NSInstanceModel'; import { RestService } from 'RestService'; import { SharedService } from 'SharedService'; @@ -81,6 +81,12 @@ export class NSPrimitiveComponent implements OnInit { /** Model value used to hold selected primitive type @public */ public primitiveType: string; + /** Contains list of VDU primitive lists @public */ + public vduList: {}[]; + + /** Contains list of KDU primitive lists @public */ + public kduList: {}[]; + /** FormBuilder instance added to the formBuilder @private */ private formBuilder: FormBuilder; @@ -111,8 +117,24 @@ export class NSPrimitiveComponent implements OnInit { this.sharedService = this.injector.get(SharedService); this.activeModal = this.injector.get(NgbActiveModal); this.formBuilder = this.injector.get(FormBuilder); - this.primitiveTypeList = [{ title: this.translateService.instant('VNFPRIMITIVE'), value: 'VNF_Primitive' }]; - this.primitiveType = 'VNF_Primitive'; + this.primitiveTypeList = [ + { + title: this.translateService.instant('NSPRIMITIVE'), + value: 'NS_Primitive' + }, + { + title: this.translateService.instant('VNFPRIMITIVE'), + value: 'VNF_Primitive' + }, + { + title: this.translateService.instant('VDUPRIMITIVE'), + value: 'VDU_Primitive' + }, + { + title: this.translateService.instant('KDUPRIMITIVE'), + value: 'KDU_Primitive' + } + ]; } /** @@ -125,9 +147,6 @@ export class NSPrimitiveComponent implements OnInit { this.nsdId = event.identifier; } }); - if (!isNullOrUndefined(this.params.nsConfig)) { - this.primitiveTypeList.push({ title: this.translateService.instant('NSPRIMITIVE'), value: 'NS_Primitive' }); - } this.initializeForm(); } @@ -139,6 +158,8 @@ export class NSPrimitiveComponent implements OnInit { this.primitiveForm = this.formBuilder.group({ primitive: [null, [Validators.required]], vnf_member_index: [null, [Validators.required]], + vdu_id: [null, [Validators.required]], + kdu_name: [null, [Validators.required]], primitive_params: this.formBuilder.array([this.primitiveParamsBuilder()]) }); } @@ -167,8 +188,8 @@ export class NSPrimitiveComponent implements OnInit { this.primitiveParams.removeAt(index); } - /** Execute NS Primitive @public */ - public execNSPrimitive(): void { + /** Execute Primitive @public */ + public execPrimitive(): void { this.submitted = true; this.objectPrimitiveParams = {}; this.sharedService.cleanForm(this.primitiveForm); @@ -187,6 +208,18 @@ export class NSPrimitiveComponent implements OnInit { // tslint:disable-next-line: no-string-literal primitiveParamsPayLoads['vnf_member_index'] = this.primitiveForm.value.vnf_member_index; } + if (this.primitiveType === 'VDU_Primitive') { + // tslint:disable-next-line: no-string-literal + primitiveParamsPayLoads['vnf_member_index'] = this.primitiveForm.value.vnf_member_index; + // tslint:disable-next-line: no-string-literal + primitiveParamsPayLoads['vdu_id'] = this.primitiveForm.value.vdu_id; + } + if (this.primitiveType === 'KDU_Primitive') { + // tslint:disable-next-line: no-string-literal + primitiveParamsPayLoads['vnf_member_index'] = this.primitiveForm.value.vnf_member_index; + // tslint:disable-next-line: no-string-literal + primitiveParamsPayLoads['kdu_name'] = this.primitiveForm.value.kdu_name; + } const apiURLHeader: APIURLHEADER = { url: environment.NSDINSTANCES_URL + '/' + this.nsdId + '/action' }; @@ -206,21 +239,32 @@ export class NSPrimitiveComponent implements OnInit { this.primitiveParameter = []; this.initializeForm(); if (data.value === 'NS_Primitive') { - this.primitiveList = !isNullOrUndefined(this.params.nsConfig['config-primitive']) ? - this.params.nsConfig['config-primitive'] : []; - this.getFormControl('vnf_member_index').setValidators([]); + this.getNSInfo(this.params.name); + this.setUpdateValueandValidation('vnf_member_index'); + } + if (data.value === 'VNF_Primitive' || data.value === 'KDU_Primitive' || data.value === 'NS_Primitive') { + this.setUpdateValueandValidation('vdu_id'); + } + if (data.value === 'VDU_Primitive' || data.value === 'VNF_Primitive' || data.value === 'NS_Primitive') { + this.setUpdateValueandValidation('kdu_name'); } } /** Member index change event */ - public indexChange(data: {}): void { + public indexChange(data: {}, getType?: string): void { + this.getFormControl('vdu_id').setValue(null); + this.getFormControl('kdu_name').setValue(null); if (data) { - this.getVnfdInfo(data['vnfd-id-ref']); + this.getVnfdInfo(data['vnfd-id-ref'], getType); } else { this.primitiveList = []; this.getFormControl('primitive').setValue(null); this.primitiveParameter = []; } } + /** Get VDU/KDU primitive List for the selected event @public */ + public getPrimitiveList(data: {}, selectedType: string): void { + this.primitiveList = data[selectedType + '-configuration']['config-primitive']; + } /** Primivtive change event */ public primitiveChange(data: { parameter: {}[] }): void { this.primitiveParameter = []; @@ -231,6 +275,27 @@ export class NSPrimitiveComponent implements OnInit { this.updatePrimitive(data); } } + /** Generate vdu section @public */ + public generateVDUData(vduData: VDUPRIMITIVELEVEL): VDUPRIMITIVELEVEL { + return { + id: vduData.id, + name: vduData.name, + 'vdu-configuration': vduData['vdu-configuration'] + }; + } + /** Generate kdu section @public */ + public generateKDUData(kduData: KDUPRIMITIVELEVEL): KDUPRIMITIVELEVEL { + return { + name: kduData.name, + 'juju-bundle': kduData['juju-bundle'], + 'kdu-configuration': kduData['kdu-configuration'] + }; + } + /** Used to set the validation and value and update the validation and value @public */ + public setUpdateValueandValidation(formName: string): void { + this.getFormControl(formName).setValidators([]); + this.getFormControl(formName).updateValueAndValidity(); + } /** Update primitive value based on parameter */ private updatePrimitive(primitive: { parameter: {}[] }): void { if (primitive.parameter) { @@ -247,7 +312,7 @@ export class NSPrimitiveComponent implements OnInit { } } /** Get primivitive actions from vnfd data */ - private getVnfdInfo(vnfdRef: string): void { + private getVnfdInfo(vnfdRef: string, getType?: string): void { this.primitiveList = []; this.primitiveParameter = []; this.getFormControl('primitive').setValue(null); @@ -255,9 +320,58 @@ export class NSPrimitiveComponent implements OnInit { this.isLoadingResults = true; this.restService.getResource(apiUrl) .subscribe((vnfdInfo: {}) => { - if (vnfdInfo[0]['vnf-configuration']) { + if (vnfdInfo[0]['vnf-configuration'] !== undefined && vnfdInfo[0]['vnf-configuration']) { + this.getFormControl('vdu_id').setValidators([]); + this.getFormControl('kdu_name').setValidators([]); this.primitiveList = vnfdInfo[0]['vnf-configuration']['config-primitive']; } + if (getType === 'VDU_Primitive') { + this.kduList = []; + this.vduList = []; + this.primitiveList = []; + if (!isNullOrUndefined(vnfdInfo[0].vdu)) { + vnfdInfo[0].vdu.forEach((vduData: VDUPRIMITIVELEVEL) => { + if (vduData['vdu-configuration']) { + const vduDataObj: VDUPRIMITIVELEVEL = this.generateVDUData(vduData); + this.vduList.push(vduDataObj); + } + }); + } + } + if (getType === 'KDU_Primitive') { + this.kduList = []; + this.vduList = []; + this.primitiveList = []; + if (!isNullOrUndefined(vnfdInfo[0].kdu)) { + vnfdInfo[0].kdu.forEach((kduData: KDUPRIMITIVELEVEL) => { + if (kduData['kdu-configuration']) { + const kduDataObj: KDUPRIMITIVELEVEL = this.generateKDUData(kduData); + this.kduList.push(kduDataObj); + } + }); + } + } + this.isLoadingResults = false; + }, (error: ERRORDATA) => { + this.isLoadingResults = false; + this.restService.handleError(error, 'get'); + }); + } + /** Get primivitive actions from NSD data */ + private getNSInfo(nsdRef: string): void { + this.primitiveList = []; + this.primitiveParameter = []; + this.getFormControl('primitive').setValue(null); + const apiUrl: string = environment.NSDESCRIPTORS_URL + '?short-name=' + nsdRef; + this.isLoadingResults = true; + this.restService.getResource(apiUrl) + .subscribe((nsdInfo: {}) => { + if (!isNullOrUndefined(nsdInfo[0]['ns-configuration'])) { + this.primitiveList = !isNullOrUndefined(nsdInfo[0]['ns-configuration']['config-primitive']) ? + nsdInfo[0]['ns-configuration']['config-primitive'] : []; + } else { + this.primitiveList = []; + } this.isLoadingResults = false; }, (error: ERRORDATA) => { this.isLoadingResults = false;