Advanced Cluster Management - NGUI
- Added new OKA packages module under packages
- Added Profiless, KSU under k8s section
- Feature 11020. 11022, 11023, 11024, 11025, 11026
Change-Id: Ibddeb4d5693ce24d80e378277693405c810f6e04
Signed-off-by: SANDHYA.JS <sandhya.j@tataelxsi.co.in>
diff --git a/src/app/utilities/compose-packages/ComposePackages.ts b/src/app/utilities/compose-packages/ComposePackages.ts
index 0dff17a..17adaa0 100644
--- a/src/app/utilities/compose-packages/ComposePackages.ts
+++ b/src/app/utilities/compose-packages/ComposePackages.ts
@@ -34,6 +34,7 @@
import * as pako from 'pako';
import { RestService } from 'RestService';
import { SharedService, isNullOrUndefined } from 'SharedService';
+import { VNFD } from 'VNFDModel';
/** This is added globally by the tar.js library */
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -77,6 +78,9 @@
/** contains NSD name @public */
public nsName: {}[] = [];
+ /** set the ns archieve file @public */
+ public okafile: File;
+
/** contains NSD details @public */
public nsdDetails: {}[];
@@ -92,12 +96,30 @@
/** Check if template or not @public */
public template = false;
+ /** Check if template or not @public */
+ public oka = false;
+
+ /** Check if template or not @public */
+ public package_name: string;
+
+ /** Element ref for fileInputConfigLabel @public */
+ @ViewChild('fileInput') fileInput: ElementRef<HTMLInputElement>;
+
+ /** Element ref for fileInputConfigLabel @public */
+ @ViewChild('fileInputLabel') fileInputLabel: ElementRef<HTMLLabelElement>;
+
/** Data of NS config @public */
public details: NSConfigData;
+ /** Data of OKA packages @public */
+ public packageData: VNFD;
+
/** Data of NF packages @public */
public nsConfigData: NSConfigData[] = [];
+ /** Contains selected file name @public */
+ public selectedFileName: string = 'Choose file...';
+
/** Element ref for fileInputConfig @public */
@ViewChild('fileInputConfig') fileInputConfig: ElementRef<HTMLInputElement>;
@@ -156,14 +178,34 @@
this.initializeForm();
if (this.params.page === 'ns-config-template') {
this.template = true;
+ this.oka = false;
this.getNsdPackageDetails();
+ this.getFormControl('description').disable();
} else if (this.params.page === 'ns-config-template-edit') {
this.template = true;
+ this.oka = false;
this.getNsdPackageDetails();
this.getFormControl('nsdId').disable();
- } else {
+ this.getFormControl('description').disable();
+ } else if (this.params.page === 'oka-packages') {
+ this.oka = true;
+ this.template = false;
this.getFormControl('nsdId').disable();
this.getFormControl('config').disable();
+ } else if (this.params.page === 'oka-packages-edit') {
+ this.oka = true;
+ this.template = false;
+ this.addNullValueForInvalidFiles();
+ this.packagesForm.value.package = '';
+ this.getOkaDetails();
+ this.getFormControl('nsdId').disable();
+ this.getFormControl('config').disable();
+ } else {
+ this.oka = false;
+ this.template = false;
+ this.getFormControl('nsdId').disable();
+ this.getFormControl('config').disable();
+ this.getFormControl('description').disable();
}
}
@@ -172,15 +214,17 @@
this.packagesForm = this.formBuilder.group({
name: ['', [Validators.required]],
nsdId: [null, [Validators.required]],
- config: [null]
+ config: [null],
+ description: ['', [Validators.required]],
+ package: ['']
});
}
/** Get NSD Package details @public */
public getNsdPackageDetails(): void {
- this.restService.getResource(environment.NSDESCRIPTORSCONTENT_URL)
- .subscribe((nsdPackageData: NSDDetails[]): void => {
- nsdPackageData.forEach((nsData: NSDDetails): void => {
+ this.restService.getResource(environment.OKAPACKAGES_URL)
+ .subscribe((nsdPackageData: []): void => {
+ nsdPackageData.forEach((nsData: VNFD): void => {
const names: {} = {
nsName: nsData.name,
nsId: nsData._id
@@ -196,6 +240,23 @@
});
}
+ /** Get NSD Package details @public */
+ public getOkaDetails(): void {
+ this.addNullValueForInvalidFiles();
+ this.restService.getResource(environment.OKAPACKAGES_URL + '/' + this.params.id)
+ .subscribe((nsdPackageData: VNFD): void => {
+ this.packageData = nsdPackageData;
+ this.packagesForm.value.package = '';
+ this.package_name = nsdPackageData.name;
+ const package_file = nsdPackageData._admin.storage.zipfile;
+ this.selectedFileName = package_file;
+ this.packagesForm.patchValue({ name: this.package_name, description: nsdPackageData.description });
+ this.fileInput.nativeElement.value = null;
+ }, (error: ERRORDATA): void => {
+ this.restService.handleError(error, 'get');
+ });
+ }
+
/** Get the NSD Content List & patch value in edit form @public */
public getNSConfigDetails(URL: string, name: {}[]): void {
this.restService.getResource(URL).subscribe((content: NSConfigData): void => {
@@ -226,6 +287,7 @@
this.modalData = {
message: 'Done'
};
+ this.addNullValueForInvalidFiles();
this.sharedService.cleanForm(this.packagesForm);
if (!this.packagesForm.invalid) {
this.isLoadingResults = true;
@@ -247,6 +309,29 @@
this.isLoadingResults = false;
this.notifierService.notify('error', this.translateService.instant('ERROR'));
}
+ } else if (this.oka) {
+ try {
+ this.headers = new HttpHeaders({
+ Accept: 'application/json',
+ 'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0'
+ });
+ if (this.params.page === 'oka-packages') {
+ const apiURLHeader: APIURLHEADER = {
+ url: environment.OKAPACKAGES_URL,
+ httpOptions: { headers: this.headers }
+ };
+ this.saveFileData(apiURLHeader);
+ } else {
+ const apiURLHeader: APIURLHEADER = {
+ url: environment.OKAPACKAGES_URL + '/' + this.params.id,
+ httpOptions: { headers: this.headers }
+ };
+ this.editFileData(apiURLHeader);
+ }
+ } catch (e) {
+ this.isLoadingResults = false;
+ this.notifierService.notify('error', this.translateService.instant('ERROR'));
+ }
} else {
try {
this.headers = new HttpHeaders({
@@ -351,6 +436,68 @@
this.restService.handleError(error, 'post');
});
}
+
+ /** Drag and drop feature and fetchind the details of files @public */
+ public onFileDropped(files: FileList): void {
+ if (files && files.length === 1) {
+ const file: File = files[0];
+ if (this.sharedService.vaildataFileInfo(file, 'gz')) {
+ this.removeValidationDragDropFiles();
+ this.okafile = file;
+ this.selectedFileName = '';
+ if (this.params.page === 'oka-packages-edit') {
+ this.selectedFileName = files[0].name;
+ } else {
+ this.fileInputLabel.nativeElement.innerText = files[0].name;
+ this.fileInput.nativeElement.value = null;
+ }
+ } else {
+ this.notifierService.notify('error', this.translateService.instant('GZFILETYPEERRROR'));
+ this.addNullValueForInvalidFiles();
+ }
+ } else if (files && files.length > 1) {
+ this.notifierService.notify('error', this.translateService.instant('DROPFILESVALIDATION'));
+ }
+ }
+
+ /** Add Null value for invalid Files @public */
+ public addNullValueForInvalidFiles(): void {
+ this.getFormControl('package').setValue('');
+ }
+
+ /** Remove validation after drag drop Files @public */
+ public removeValidationDragDropFiles(): void {
+ this.getFormControl('package').setValidators([]);
+ this.getFormControl('package').updateValueAndValidity();
+ }
+
+
+ /** Post the droped files and reload the page @public */
+ public saveFileData(urlHeader: APIURLHEADER): void {
+ this.isLoadingResults = true;
+ this.packagesForm.value.package = this.okafile;
+ this.restService.postResource(urlHeader, this.toFormData(this.packagesForm.value)).subscribe((result: {}): void => {
+ this.activeModal.close(this.modalData);
+ this.isLoadingResults = false;
+ this.notifierService.notify('success', this.translateService.instant('OKA Package Created Successfully'));
+ }, (error: ERRORDATA): void => {
+ this.restService.handleError(error, 'post');
+ this.isLoadingResults = false;
+ });
+ }
+
+ /** Post the droped files and reload the page @public */
+ public editFileData(urlHeader: APIURLHEADER): void {
+ this.isLoadingResults = true;
+ this.restService.patchResource(urlHeader, this.toFormData(this.packagesForm.value)).subscribe((result: {}): void => {
+ this.activeModal.close(this.modalData);
+ this.isLoadingResults = false;
+ this.notifierService.notify('success', this.translateService.instant('OKA Package Edited Successfully'));
+ }, (error: ERRORDATA): void => {
+ this.restService.handleError(error, 'post');
+ this.isLoadingResults = false;
+ });
+ }
/** Config file process @private */
public configFile(files: FileList): void {
if (files && files.length === 1) {
@@ -453,6 +600,55 @@
return jsyaml.dump(packageYaml, { sortKeys: true });
}
+ /** Form data @private */
+ private toFormData<T>(formValue: T): FormData {
+ const formData: FormData = new FormData();
+ for (const key of Object.keys(formValue)) {
+ // eslint-disable-next-line security/detect-object-injection
+ const value: string = formValue[key];
+ if (key === 'name') {
+ if (this.params.page === 'oka-packages') {
+ if (!isNullOrUndefined(this.packagesForm.value.name)) {
+ formData.append(key, this.packagesForm.value.name);
+ }
+ } else if (this.params.page === 'oka-packages-edit') {
+ if (this.package_name.localeCompare(this.packagesForm.value.name) === 0) {
+ delete this.packagesForm.value.name;
+ } else {
+ formData.append(key, this.packagesForm.value.name);
+ }
+ }
+ else {
+ formData.append(key, '');
+ }
+ } else if (key === 'description') {
+ if (this.params.page === 'oka-packages') {
+ if (!isNullOrUndefined(this.packagesForm.value.description)) {
+ formData.append(key, this.packagesForm.value.description);
+ }
+ } else if (this.params.page === 'oka-packages-edit') {
+ if (this.packageData.description.localeCompare(this.packagesForm.value.description) === 0) {
+ delete this.packagesForm.value.description;
+ } else {
+ formData.append(key, this.packagesForm.value.description);
+ }
+ }
+ else {
+ formData.append(key, '');
+ }
+ } else if (key === 'package') {
+ if (!isNullOrUndefined(this.okafile)) {
+ formData.append(key, this.okafile);
+ } else {
+ delete this.packagesForm.value.package;
+ }
+ } else {
+ formData.append(key, value);
+ }
+ }
+ return formData;
+ }
+
/** Used to get the AbstractControl of controlName passed @private */
private getFormControl(controlName: string): AbstractControl {
// eslint-disable-next-line security/detect-object-injection