Feature 11038: Enhancement of Vertical Scale Feature and merge in update API
[osm/NG-UI.git] / src / app / utilities / ns-update / NsUpdateComponent.ts
index 724bba3..d5eb443 100644 (file)
@@ -28,9 +28,10 @@ import { APIURLHEADER, CONFIGCONSTANT, ERRORDATA, MODALCLOSERESPONSEDATA, URLPAR
 import { environment } from 'environment';
 import { NSUPDATE, TERMINATEVNF } from 'NSInstanceModel';
 import { RestService } from 'RestService';
-import { SharedService, isNullOrUndefined } from 'SharedService';
+import { isNullOrUndefined } from 'SharedService';
+import { SharedService } from 'SharedService';
 import { VNFD } from 'VNFDModel';
-import { InstanceData, VNFInstanceDetails } from 'VNFInstanceModel';
+import { InstanceData, VDUDETAIL, VDUR, VNFInstanceDetails } from 'VNFInstanceModel';
 import { WarningComponent } from 'WarningComponent';
 
 /**
@@ -65,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 */
@@ -83,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 */
@@ -116,6 +123,10 @@ export class NsUpdateComponent implements OnInit {
             {
                 title: this.translateService.instant('REMOVEVNF'),
                 value: 'REMOVE_VNF'
+            },
+            {
+                title: this.translateService.instant('VERTICALSCALE'),
+                value: 'VERTICAL_SCALE'
             }
         ];
     }
@@ -139,7 +150,9 @@ 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]]
         });
     }
 
@@ -191,6 +204,7 @@ 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 =>
@@ -207,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 */
@@ -226,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,
@@ -237,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);
         }
     }
 
@@ -247,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');
@@ -353,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