From 017df364be742ba4d89013ae32572c2b300e2a29 Mon Sep 17 00:00:00 2001 From: "SANDHYA.JS" Date: Mon, 2 May 2022 06:57:11 +0530 Subject: [PATCH] Feature 10911-Vertical scaling of VM instances from OSM *Added NG-UI support for Vertical scaling *In NS Instances page. Click "Vertical Scaling" in the VIM action menu. *Then a new pop-up page will be opened. *In the popup there will be fields containing membervnfIndex, vduid, count index mandatory fields with Virtual Memory, size of storage and vcpu count field to vertically scale *When the fields are selected then Click Apply button. *The pop-up window is closed and the page is directed to "History of operations" page Change-Id: I6d898c8637b361af69dc7e516e46834a346cda82 Signed-off-by: SANDHYA.JS --- src/app/AppModule.ts | 7 +- .../NSInstancesActionComponent.html | 4 + .../NSInstancesActionComponent.ts | 14 ++ .../VerticalScalingComponent.html | 101 ++++++++ .../VerticalScalingComponent.scss | 17 ++ .../VerticalScalingComponent.ts | 233 ++++++++++++++++++ src/assets/i18n/de.json | 4 + src/assets/i18n/en.json | 4 + src/assets/i18n/es.json | 4 + src/assets/i18n/pt.json | 4 + src/models/NSInstanceModel.ts | 25 ++ tsconfig.json | 3 +- 12 files changed, 417 insertions(+), 3 deletions(-) create mode 100644 src/app/utilities/vertical-scaling/VerticalScalingComponent.html create mode 100644 src/app/utilities/vertical-scaling/VerticalScalingComponent.scss create mode 100644 src/app/utilities/vertical-scaling/VerticalScalingComponent.ts diff --git a/src/app/AppModule.ts b/src/app/AppModule.ts index 30c6842..5244bb2 100644 --- a/src/app/AppModule.ts +++ b/src/app/AppModule.ts @@ -78,6 +78,7 @@ import { StartStopRebuildComponent } from 'StartStopRebuildComponent'; import { SwitchProjectComponent } from 'SwitchProjectComponent'; import { UsersActionComponent } from 'UsersActionComponent'; import { UserSettingsComponent } from 'UserSettingsComponent'; +import { VerticalScalingComponent } from 'VerticalScalingComponent'; import { VimAccountsActionComponent } from 'VimAccountsAction'; import { VmMigrationComponent } from 'VmMigrationComponent'; import { VNFInstancesActionComponent } from 'VNFInstancesActionComponent'; @@ -135,7 +136,8 @@ const customNotifierOptions: NotifierOptions = { VmMigrationComponent, NsUpdateComponent, WarningComponent, - StartStopRebuildComponent + StartStopRebuildComponent, + VerticalScalingComponent ], imports: [ NotifierModule.withConfig(customNotifierOptions), @@ -213,7 +215,8 @@ const customNotifierOptions: NotifierOptions = { VmMigrationComponent, NsUpdateComponent, WarningComponent, - StartStopRebuildComponent + StartStopRebuildComponent, + VerticalScalingComponent ] }) diff --git a/src/app/utilities/ns-instances-action/NSInstancesActionComponent.html b/src/app/utilities/ns-instances-action/NSInstancesActionComponent.html index db3311a..f84fcff 100644 --- a/src/app/utilities/ns-instances-action/NSInstancesActionComponent.html +++ b/src/app/utilities/ns-instances-action/NSInstancesActionComponent.html @@ -45,6 +45,10 @@ Author: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.i data-container="body" ngbTooltip="{{'REBUILD' | translate}}"> {{'REBUILD' | translate}} +
diff --git a/src/app/utilities/ns-instances-action/NSInstancesActionComponent.ts b/src/app/utilities/ns-instances-action/NSInstancesActionComponent.ts index 1c3f1f2..751389b 100644 --- a/src/app/utilities/ns-instances-action/NSInstancesActionComponent.ts +++ b/src/app/utilities/ns-instances-action/NSInstancesActionComponent.ts @@ -37,6 +37,7 @@ import { SharedService } from 'SharedService'; import { ShowInfoComponent } from 'ShowInfoComponent'; import { StartStopRebuildComponent } from 'StartStopRebuildComponent'; import { isNullOrUndefined } from 'util'; +import { VerticalScalingComponent } from 'VerticalScalingComponent'; import { VmMigrationComponent } from 'VmMigrationComponent'; import { DF, VDU, VNFD } from 'VNFDModel'; /** @@ -306,6 +307,19 @@ export class NSInstancesActionComponent { }).catch(); } + /** To open the vertical Scaling pop-up */ + public openVerticalScaling(): void { + const modalRef: NgbModalRef = this.modalService.open(VerticalScalingComponent, { backdrop: 'static' }); + modalRef.componentInstance.params = { + id: this.instanceID + }; + modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => { + if (result) { + this.sharedService.callData(); + } + }).catch(); + } + /** * Check any changes in the child component @public */ diff --git a/src/app/utilities/vertical-scaling/VerticalScalingComponent.html b/src/app/utilities/vertical-scaling/VerticalScalingComponent.html new file mode 100644 index 0000000..cef0ff2 --- /dev/null +++ b/src/app/utilities/vertical-scaling/VerticalScalingComponent.html @@ -0,0 +1,101 @@ + + +
+ + +
+ \ No newline at end of file diff --git a/src/app/utilities/vertical-scaling/VerticalScalingComponent.scss b/src/app/utilities/vertical-scaling/VerticalScalingComponent.scss new file mode 100644 index 0000000..c55461a --- /dev/null +++ b/src/app/utilities/vertical-scaling/VerticalScalingComponent.scss @@ -0,0 +1,17 @@ +/* + Copyright 2020 TATA ELXSI + + Licensed under the Apache License, Version 2.0 (the 'License'); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + Author: SANDHYA JS (sandhya.j@tataelxsi.co.in) +*/ \ No newline at end of file diff --git a/src/app/utilities/vertical-scaling/VerticalScalingComponent.ts b/src/app/utilities/vertical-scaling/VerticalScalingComponent.ts new file mode 100644 index 0000000..69eb9eb --- /dev/null +++ b/src/app/utilities/vertical-scaling/VerticalScalingComponent.ts @@ -0,0 +1,233 @@ +/* + Copyright 2020 TATA ELXSI + + Licensed under the Apache License, Version 2.0 (the 'License'); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + Author: SANDHYA JS (sandhya.j@tataelxsi.co.in) +*/ +/** + * @file VerticalScaling Component + */ +import { HttpHeaders } from '@angular/common/http'; +import { Component, Injector, Input, OnInit } from '@angular/core'; +import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms'; +import { Router } from '@angular/router'; +import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; +import { TranslateService } from '@ngx-translate/core'; +import { NotifierService } from 'angular-notifier'; +import { APIURLHEADER, ERRORDATA, MODALCLOSERESPONSEDATA, URLPARAMS } from 'CommonModel'; +import { environment } from 'environment'; +import { VerticalScaling } from 'NSInstanceModel'; +import { RestService } from 'RestService'; +import { SharedService } from 'SharedService'; +import { isNullOrUndefined } from 'util'; +import { VDUR, VNFInstanceDetails } from 'VNFInstanceModel'; + +/** + * Creating component + * @Component takes VerticalScalingComponent.html as template url + */ +@Component({ + selector: 'app-vertical-scaling', + templateUrl: './VerticalScalingComponent.html', + styleUrls: ['./VerticalScalingComponent.scss'] +}) +export class VerticalScalingComponent implements OnInit { + /** To inject services @public */ + public injector: Injector; + /** Instance for active modal service @public */ + public activeModal: NgbActiveModal; + /** Check the loading results @public */ + public isLoadingResults: Boolean = false; + /** Give the message for the loading @public */ + public message: string = 'PLEASEWAIT'; + /** FormGroup instance added to the form @ html @public */ + public scalingForm: FormGroup; + /** Items for the memberVNFIndex @public */ + public memberTypes: {}[]; + /** Contains MemberVNFIndex values @public */ + public memberVnfIndex: {}[] = []; + /** Contains vnfInstanceId of the selected MemberVnfIndex @public */ + public instanceId: string; + /** Items for vduId & countIndex @public */ + public vdu: {}[]; + /** Selected VNFInstanceId @public */ + public selectedvnfId: string = ''; + /** Array holds VNFR Data filtered with nsr ID @public */ + public nsIdFilteredData: {}[] = []; + /** Form valid on submit trigger @public */ + public submitted: boolean = false; + /** Input contains component objects @private */ + @Input() private params: URLPARAMS; + /** FormBuilder instance added to the formBuilder @private */ + private formBuilder: FormBuilder; + /** Instance of the rest service @private */ + private restService: RestService; + /** Controls the header form @private */ + private headers: HttpHeaders; + /** Contains all methods related to shared @private */ + private sharedService: SharedService; + /** Notifier service to popup notification @private */ + private notifierService: NotifierService; + /** Contains tranlsate instance @private */ + private translateService: TranslateService; + /** Holds the instance of AuthService class of type AuthService @private */ + private router: Router; + constructor(injector: Injector) { + this.injector = injector; + this.restService = this.injector.get(RestService); + this.activeModal = this.injector.get(NgbActiveModal); + this.formBuilder = this.injector.get(FormBuilder); + this.sharedService = this.injector.get(SharedService); + this.notifierService = this.injector.get(NotifierService); + this.translateService = this.injector.get(TranslateService); + this.router = this.injector.get(Router); + } + /** convenience getter for easy access to form fields */ + get f(): FormGroup['controls'] { return this.scalingForm.controls; } + /** + * Lifecyle Hooks the trigger before component is instantiate + */ + public ngOnInit(): void { + this.initializeForm(); + this.getMemberVnfIndex(); + this.headers = new HttpHeaders({ + 'Content-Type': 'application/json', + Accept: 'application/json', + 'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0' + }); + } + /** Initialize Scaling Forms @public */ + public initializeForm(): void { + this.scalingForm = this.formBuilder.group({ + memberVnfIndex: [null, [Validators.required]], + vduId: [null, [Validators.required]], + countIndex: [null, [Validators.required]], + virtualMemory: [null, [Validators.required]], + sizeOfStorage: [null, [Validators.required]], + numVirtualCpu: [null, [Validators.required]] + }); + } + + /** Getting MemberVnfIndex using VNFInstances API @public */ + public getMemberVnfIndex(): void { + const vnfInstanceData: {}[] = []; + this.restService.getResource(environment.VNFINSTANCES_URL).subscribe((vnfInstancesData: VNFInstanceDetails[]): void => { + vnfInstancesData.forEach((vnfData: VNFInstanceDetails): void => { + const vnfDataObj: {} = + { + VNFD: vnfData['vnfd-ref'], + VNFInstanceId: vnfData._id, + MemberIndex: vnfData['member-vnf-index-ref'], + NS: vnfData['nsr-id-ref'], + VNFID: vnfData['vnfd-id'] + }; + vnfInstanceData.push(vnfDataObj); + }); + const nsId: string = 'NS'; + this.nsIdFilteredData = vnfInstanceData.filter((vnfdData: {}[]): boolean => vnfdData[nsId] === this.params.id); + this.nsIdFilteredData.forEach((resVNF: {}[]): void => { + const memberIndex: string = 'MemberIndex'; + const vnfinstanceID: string = 'VNFInstanceId'; + const assignMemberIndex: {} = { + id: resVNF[memberIndex], + vnfinstanceId: resVNF[vnfinstanceID] + }; + this.memberVnfIndex.push(assignMemberIndex); + }); + this.memberTypes = this.memberVnfIndex; + this.isLoadingResults = false; + }, (error: ERRORDATA): void => { + this.restService.handleError(error, 'get'); + this.isLoadingResults = false; + }); + } + + /** 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']; + const VDU: string = 'vdur'; + if (vnfInstanceDetail[VDU] !== undefined) { + vnfInstanceDetail[VDU].forEach((vdu: VDUR): void => { + const vnfInstanceDataObj: {} = + { + 'count-index': vdu['count-index'], + VDU: vdu['vdu-id-ref'] + + }; + vnfInstanceData.push(vnfInstanceDataObj); + }); + this.vdu = vnfInstanceData; + } + }, (error: ERRORDATA): void => { + this.restService.handleError(error, 'get'); + this.isLoadingResults = false; + }); + } + } + + /** Vertical Scaling on submit */ + public triggerVerticalScaling(): void { + this.submitted = true; + this.sharedService.cleanForm(this.scalingForm); + if (!this.scalingForm.invalid) { + const scalingPayload: VerticalScaling = { + lcmOperationType: 'verticalscale', + verticalScale: 'CHANGE_VNFFLAVOR', + nsInstanceId: this.params.id, + changeVnfFlavorData: { + vnfInstanceId: this.instanceId, + additionalParams: { + vduid: this.scalingForm.value.vduId, + vduCountIndex: this.scalingForm.value.countIndex, + virtualMemory: Number(this.scalingForm.value.virtualMemory), + sizeOfStorage: Number(this.scalingForm.value.sizeOfStorage), + numVirtualCpu: Number(this.scalingForm.value.numVirtualCpu) + } + } + }; + this.verticalscaleInitialization(scalingPayload); + } + } + + /** Initialize the vertical scaling operation @public */ + public verticalscaleInitialization(scalingPayload: object): void { + this.isLoadingResults = true; + const apiURLHeader: APIURLHEADER = { + url: environment.NSDINSTANCES_URL + '/' + this.params.id + '/verticalscale', + httpOptions: { headers: this.headers } + }; + const modalData: MODALCLOSERESPONSEDATA = { + message: 'Done' + }; + this.restService.postResource(apiURLHeader, scalingPayload).subscribe((result: {}): void => { + this.activeModal.close(modalData); + this.router.navigate(['/instances/ns/history-operations/' + this.params.id]).catch(); + }, (error: ERRORDATA): void => { + this.restService.handleError(error, 'post'); + this.isLoadingResults = false; + }); + } + + /** Used to get the AbstractControl of controlName passed @private */ + private getFormControl(controlName: string): AbstractControl { + return this.scalingForm.controls[controlName]; + } +} diff --git a/src/assets/i18n/de.json b/src/assets/i18n/de.json index 3da4bea..d65ddcd 100644 --- a/src/assets/i18n/de.json +++ b/src/assets/i18n/de.json @@ -187,6 +187,10 @@ "START": "Start", "STOP": "Halt", "VIMACTION": "VIM-Aktion", + "VERTICALSCALING": "Vertikale Skalierung", + "MEMORYMB": "Arbeitsspeicher MB", + "STORAGEGB": "Speicher GB", + "VCPUCOUNT": "VCPU-Anzahl", "PAGE": { "DASHBOARD": { "DASHBOARD": "Instrumententafel", diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index 8825b38..2dfbd94 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -187,6 +187,10 @@ "START": "Start", "STOP": "Stop", "VIMACTION": "VIM Action", + "VERTICALSCALING": "Vertical Scaling", + "MEMORYMB": "Memory MB", + "STORAGEGB": "Storage GB", + "VCPUCOUNT": "VCPU Count", "PAGE": { "DASHBOARD": { "DASHBOARD": "Dashboard", diff --git a/src/assets/i18n/es.json b/src/assets/i18n/es.json index c45ef4d..5658926 100644 --- a/src/assets/i18n/es.json +++ b/src/assets/i18n/es.json @@ -187,6 +187,10 @@ "START": "Comienzo", "STOP": "Parada", "VIMACTION": "Acción VIM", + "VERTICALSCALING": "Escala vertical", + "MEMORYMB": "MB de memoria", + "STORAGEGB": "GB de almacenamiento", + "VCPUCOUNT": "Recuento de VCPU", "PAGE": { "DASHBOARD": { "DASHBOARD": "Tablero", diff --git a/src/assets/i18n/pt.json b/src/assets/i18n/pt.json index 7e936ce..266e93a 100644 --- a/src/assets/i18n/pt.json +++ b/src/assets/i18n/pt.json @@ -187,6 +187,10 @@ "START": "Começar", "STOP": "Pare", "VIMACTION": "Ação VIM", + "VERTICALSCALING": "Escala vertical", + "MEMORYMB": "MB de memória", + "STORAGEGB": "GB de armazenamento", + "VCPUCOUNT": "Contagem de VCPU", "PAGE": { "DASHBOARD": { "DASHBOARD": "painel de controle", diff --git a/src/models/NSInstanceModel.ts b/src/models/NSInstanceModel.ts index 99af8d7..c10c5ce 100644 --- a/src/models/NSInstanceModel.ts +++ b/src/models/NSInstanceModel.ts @@ -205,6 +205,31 @@ export interface ADDITIONALPARAMS { 'count-index': string; } +/** Interface for VerticalScaling */ +export interface VerticalScaling { + lcmOperationType: string; + verticalScale: string; + nsInstanceId: string; + changeVnfFlavorData: CHANGEVNFFLAVORDATAPARAM; +} + +/** Interface for changeVnfFlavorData in Vertical Scaling */ +export interface CHANGEVNFFLAVORDATAPARAM { + vnfInstanceId: string; + additionalParams: ADDITIONALPARAM; + +} + +/** Interface for additionalParam in Vertical Scaling */ +export interface ADDITIONALPARAM { + vduid: string; + vduCountIndex: string; + virtualMemory: number; + sizeOfStorage: number; + numVirtualCpu: number; + +} + /** Interface for InstantiateParam */ interface InstantiateParam { nsdId: string; diff --git a/tsconfig.json b/tsconfig.json index cce28e0..0965b55 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -155,7 +155,8 @@ "VmMigrationComponent": ["src/app/utilities/vm-migration/VmMigrationComponent"], "NsUpdateComponent": ["src/app/utilities/ns-update/NsUpdateComponent"], "WarningComponent": ["src/app/utilities/warning/WarningComponent"], - "StartStopRebuildComponent": ["src/app/utilities/start-stop-rebuild/StartStopRebuildComponent"] + "StartStopRebuildComponent": ["src/app/utilities/start-stop-rebuild/StartStopRebuildComponent"], + "VerticalScalingComponent": ["src/app/utilities/vertical-scaling/VerticalScalingComponent"] } } } \ No newline at end of file -- 2.17.1