X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=src%2Fapp%2Futilities%2Fns-update%2FNsUpdateComponent.ts;h=d5eb44371dbd2830a7de34e4a0f41fc325f8ba97;hb=e478d7eaa9ac0636c14f62450364729519ef8f8e;hp=b33bfc445edf0b01515f4ae9ed60757a0aa85a86;hpb=0a34dfa32165036b380ec6ac493469b34007df0a;p=osm%2FNG-UI.git diff --git a/src/app/utilities/ns-update/NsUpdateComponent.ts b/src/app/utilities/ns-update/NsUpdateComponent.ts index b33bfc4..d5eb443 100644 --- a/src/app/utilities/ns-update/NsUpdateComponent.ts +++ b/src/app/utilities/ns-update/NsUpdateComponent.ts @@ -18,7 +18,6 @@ /** * @file Ns Update Component */ -import { isNullOrUndefined } from 'util'; import { HttpHeaders } from '@angular/common/http'; import { Component, Injector, Input, OnInit } from '@angular/core'; import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms'; @@ -29,9 +28,10 @@ import { APIURLHEADER, CONFIGCONSTANT, ERRORDATA, MODALCLOSERESPONSEDATA, URLPAR import { environment } from 'environment'; import { NSUPDATE, TERMINATEVNF } from 'NSInstanceModel'; import { RestService } from 'RestService'; +import { isNullOrUndefined } from 'SharedService'; import { SharedService } from 'SharedService'; import { VNFD } from 'VNFDModel'; -import { VNFInstanceDetails } from 'VNFInstanceModel'; +import { InstanceData, VDUDETAIL, VDUR, VNFInstanceDetails } from 'VNFInstanceModel'; import { WarningComponent } from 'WarningComponent'; /** @@ -66,6 +66,8 @@ export class NsUpdateComponent implements OnInit { public memberIndexValue: string; /** Form Check vnfdId Section @public */ public vnfdIdShow: boolean = false; + /** Form Check vduId Section @public */ + public vduIdShow: boolean = false; /** Contains MemberVNFIndex values @public */ public memberVnfIndex: {}[] = []; /** Contains MemberVNFIndex content @public */ @@ -84,6 +86,10 @@ export class NsUpdateComponent implements OnInit { public instanceId: string; /** Selected VNFInstanceId @public */ public selectedvnfId: string = ''; + /** Items for vduId & countIndex @public */ + public vdu: {}[]; + /** Contains vduId @public */ + public vduId: {}; /** Input contains component objects @private */ @Input() private params: URLPARAMS; /** FormBuilder instance added to the formBuilder @private */ @@ -117,6 +123,10 @@ export class NsUpdateComponent implements OnInit { { title: this.translateService.instant('REMOVEVNF'), value: 'REMOVE_VNF' + }, + { + title: this.translateService.instant('VERTICALSCALE'), + value: 'VERTICAL_SCALE' } ]; } @@ -140,36 +150,43 @@ export class NsUpdateComponent implements OnInit { this.nsUpdateForm = this.formBuilder.group({ updateType: [null, [Validators.required]], memberVnfIndex: [null, [Validators.required]], - vnfdId: [null, [Validators.required]] + vnfdId: [null, [Validators.required]], + vduId: [null, [Validators.required]], + countIndex: [null, [Validators.required]] }); } /** Getting MemberVnfIndex using NSDescriptor API @public */ public getMemberVnfIndex(): void { + this.isLoadingResults = true; const vnfInstanceData: {}[] = []; this.restService.getResource(environment.VNFINSTANCES_URL).subscribe((vnfInstancesData: VNFInstanceDetails[]): void => { vnfInstancesData.forEach((vnfData: VNFInstanceDetails): void => { + const vnfdRef: string = 'vnfd-ref'; + const memberIndex: string = 'member-vnf-index-ref'; + const nsrId: string = 'nsr-id-ref'; + const vnfId: string = 'vnfd-id'; const vnfDataObj: {} = { - VNFD: vnfData['vnfd-ref'], + // eslint-disable-next-line security/detect-object-injection + VNFD: vnfData[vnfdRef], VNFInstanceId: vnfData._id, - MemberIndex: vnfData['member-vnf-index-ref'], - NS: vnfData['nsr-id-ref'], - VNFID: vnfData['vnfd-id'] + // eslint-disable-next-line security/detect-object-injection + MemberIndex: vnfData[memberIndex], + // eslint-disable-next-line security/detect-object-injection + NS: vnfData[nsrId], + // eslint-disable-next-line security/detect-object-injection + VNFID: vnfData[vnfId] }; vnfInstanceData.push(vnfDataObj); }); const nsId: string = 'NS'; // eslint-disable-next-line security/detect-object-injection this.nsIdFilteredData = vnfInstanceData.filter((vnfdData: {}[]): boolean => vnfdData[nsId] === this.params.id); - this.nsIdFilteredData.forEach((resVNF: {}[]): void => { - const memberIndex: string = 'MemberIndex'; - const vnfinstanceID: string = 'VNFInstanceId'; + this.nsIdFilteredData.forEach((resVNF: InstanceData): void => { const assignMemberIndex: {} = { - // eslint-disable-next-line security/detect-object-injection - id: resVNF[memberIndex], - // eslint-disable-next-line security/detect-object-injection - vnfinstanceId: resVNF[vnfinstanceID] + id: resVNF.MemberIndex, + vnfinstanceId: resVNF.VNFInstanceId }; this.memberVnfIndex.push(assignMemberIndex); }); @@ -187,10 +204,11 @@ export class NsUpdateComponent implements OnInit { */ public getSelectedVNF(id: string): void { this.instanceId = id; + this.getVdu(this.instanceId); let memberIndexFilteredData: {}[] = []; const memberIndex: string = 'MemberIndex'; memberIndexFilteredData = this.nsIdFilteredData.filter((vnfdData: {}[]): boolean => - // eslint-disable-next-line security/detect-object-injection + // eslint-disable-next-line security/detect-object-injection vnfdData[memberIndex] === this.memberIndexValue); const vnfId: string = 'VNFID'; const selectedvnfId: string = 'VNFD'; @@ -203,13 +221,52 @@ export class NsUpdateComponent implements OnInit { } } + /** Getting vdu-id & count-index from API */ + public getVdu(id: string): void { + const vnfInstanceData: {}[] = []; + this.getFormControl('vduId').setValue(null); + this.getFormControl('countIndex').setValue(null); + if (!isNullOrUndefined(id)) { + this.restService.getResource(environment.VNFINSTANCES_URL + '/' + id). + subscribe((vnfInstanceDetail: VNFInstanceDetails): void => { + this.instanceId = id; + this.selectedvnfId = vnfInstanceDetail['vnfd-ref']; + if (!isNullOrUndefined(vnfInstanceDetail.vdur)) { + vnfInstanceDetail.vdur.forEach((vdu: VDUR): void => { + const vnfInstanceDataObj: {} = + { + 'count-index': vdu['count-index'], + VDU: vdu['vdu-id-ref'] + + }; + vnfInstanceData.push(vnfInstanceDataObj); + }); + this.vdu = vnfInstanceData; + this.vduId = this.vdu.filter((vdu: VDUDETAIL, index: number, self: {}[]): {} => + index === self.findIndex((t: VDUDETAIL): {} => ( + t.VDU === vdu.VDU + )) + ); + } + }, (error: ERRORDATA): void => { + this.restService.handleError(error, 'get'); + this.isLoadingResults = false; + }); + } + } + /** Trigger NsUpdate on submit */ public triggerNsUpdate(): void { this.submitted = true; this.sharedService.cleanForm(this.nsUpdateForm); if (this.nsUpdateForm.invalid) { return; } // Proceed, onces form is valid this.vnfdId = this.nsUpdateForm.value.vnfdId; - this.checkUpdateType(); + if (this.terminateVnf === 'VERTICAL_SCALE') { + this.getFormControl('countIndex').enable(); + this.onSubmit(); + } else { + this.checkUpdateType(); + } } /** Ns Update on submit */ @@ -222,7 +279,7 @@ export class NsUpdateComponent implements OnInit { removeVnfInstanceId: this.instanceId }; this.nsUpdateInitialization(nsUpdateTerminatePayload); - } else { + } else if (this.terminateVnf === 'CHANGE_VNFPKG') { const nsUpdatePayload: NSUPDATE = { lcmOperationType: 'update', updateType: this.nsUpdateForm.value.updateType, @@ -233,6 +290,19 @@ export class NsUpdateComponent implements OnInit { } }; this.nsUpdateInitialization(nsUpdatePayload); + } else if (this.terminateVnf === 'VERTICAL_SCALE') { + const nsUpdatePayload: NSUPDATE = { + lcmOperationType: 'update', + updateType: this.nsUpdateForm.value.updateType, + nsInstanceId: this.params.id, + verticalScaleVnf: { + vnfInstanceId: this.instanceId, + vnfdId: this.nsUpdateForm.value.vnfdId, + countIndex: 0, + vduId: this.nsUpdateForm.value.vduId + } + }; + this.nsUpdateInitialization(nsUpdatePayload); } } @@ -243,7 +313,7 @@ export class NsUpdateComponent implements OnInit { this.isLoadingResults = true; if (this.nsUpdateForm.value.updateType === 'CHANGE_VNFPKG') { this.checkVersion(); - } else { + } else if (this.nsUpdateForm.value.updateType === 'REMOVE_VNF') { // eslint-disable-next-line security/detect-non-literal-fs-filename const modalRef: NgbModalRef = this.modalService.open(WarningComponent, { backdrop: 'static' }); modalRef.componentInstance.heading = this.translateService.instant('TERMINATEVNF'); @@ -297,7 +367,7 @@ export class NsUpdateComponent implements OnInit { this.onSubmit(); } }).catch((): void => { //empty - } + } ); } else { // eslint-disable-next-line security/detect-non-literal-fs-filename @@ -310,7 +380,7 @@ export class NsUpdateComponent implements OnInit { this.onSubmit(); } }).catch((): void => { //empty - }); + }); } }, (error: ERRORDATA): void => { this.restService.handleError(error, 'get'); @@ -349,13 +419,30 @@ export class NsUpdateComponent implements OnInit { this.terminateVnf = value; if (this.terminateVnf === 'REMOVE_VNF') { this.vnfdIdShow = true; + this.vduIdShow = false; this.getFormControl('vnfdId').disable(); - } else { + this.getFormControl('vduId').disable(); + this.getFormControl('countIndex').disable(); + } else if (this.terminateVnf === 'CHANGE_VNFPKG') { this.vnfdIdShow = false; + this.vduIdShow = false; this.getFormControl('vnfdId').enable(); + this.getFormControl('vduId').disable(); + this.getFormControl('countIndex').disable(); + } else if (this.terminateVnf === 'VERTICAL_SCALE') { + this.vnfdIdShow = false; + this.vduIdShow = true; + this.getFormControl('vnfdId').enable(); + this.getFormControl('vduId').enable(); + this.getFormControl('countIndex').disable(); } } + /** Getting count-index by filtering id */ + public getCountIndex(): void { + this.getFormControl('countIndex').patchValue('0'); + } + /** Used to get the AbstractControl of controlName passed @private */ private getFormControl(controlName: string): AbstractControl { // eslint-disable-next-line security/detect-object-injection