Advanced Cluster Enhancements
- Added edit cluster, profile type in OKA
- State to Git State in all pages
- Changed mandatory fields of edit profile
- Changed api in cluster page
Change-Id: I8a3239f83eb58a3997e4550fc030694c0a2a6c72
Signed-off-by: SANDHYA.JS <sandhya.j@tataelxsi.co.in>
diff --git a/src/app/k8s/k8s-action/K8sActionComponent.html b/src/app/k8s/k8s-action/K8sActionComponent.html
index 5482868..28c3fd8 100644
--- a/src/app/k8s/k8s-action/K8sActionComponent.html
+++ b/src/app/k8s/k8s-action/K8sActionComponent.html
@@ -42,7 +42,7 @@
</button>
<div *ngIf="isCluster || !isCluster && !isKSU && !isProfile && getK8sType !== 'repo' " class="btn-group" placement="bottom-right" ngbDropdown
display="dynamic" container="body">
- <button type="button" class="btn btn-primary" [disabled]="!isCluster" ngbDropdownToggle placement="top"
+ <button type="button" class="btn btn-primary" [disabled]="!isCluster || state != 'CREATED'" ngbDropdownToggle placement="top"
container="body" ngbTooltip="{{'Attach Profile' | translate}}">
<i class="fas fa-link"></i>
</button>
@@ -67,12 +67,16 @@
</div>
</div>
<div *ngIf="((isCluster || !isCluster)&& !isKSU && !isProfile && getK8sType !== 'repo' )" class="btn-group" ngbDropdown display="dynamic" container="body">
- <button type="button" [disabled]="!isCluster" class="btn btn-primary dropdown-toggle action-button"
+ <button type="button" [disabled]="!isCluster || state != 'CREATED'" class="btn btn-primary dropdown-toggle action-button"
ngbDropdownToggle>
{{'ACTION' | translate}}
</button>
<div class="dropdown-menu list-action-dropdown" ngbDropdownMenu>
<button *ngIf="isCluster" type="button" class="btn btn-primary dropdown-item" placement="left"
+ (click)="editCluster('update')" container="body" ngbTooltip="{{'PAGE.K8S.UPDATECLUSTER' | translate}}">
+ <i class="fa fa-edit icons"></i> {{'PAGE.K8S.UPDATECLUSTER' | translate}}
+ </button>
+ <button *ngIf="isCluster" type="button" class="btn btn-primary dropdown-item" placement="left"
(click)="editCluster('upgrade')" container="body" ngbTooltip="{{'PAGE.K8S.UPGRADECLUSTER' | translate}}">
<i class="fa fa-arrow-up"></i> {{'PAGE.K8S.UPGRADECLUSTER' | translate}}
</button>
diff --git a/src/app/k8s/k8s-add-cluster/K8sAddClusterComponent.html b/src/app/k8s/k8s-add-cluster/K8sAddClusterComponent.html
index 3d623ae..e8b57b6 100644
--- a/src/app/k8s/k8s-add-cluster/K8sAddClusterComponent.html
+++ b/src/app/k8s/k8s-add-cluster/K8sAddClusterComponent.html
@@ -26,6 +26,9 @@
<h4 *ngIf="profileType === 'upgrade'" class="modal-title" id="modal-basic-title">{{'PAGE.K8S.UPGRADECLUSTER' |
translate}}
</h4>
+ <h4 *ngIf="profileType === 'update'" class="modal-title" id="modal-basic-title">{{'PAGE.K8S.UPDATECLUSTER' |
+ translate}}
+ </h4>
<h4 *ngIf="profileType === 'vertical'" class="modal-title" id="modal-basic-title">{{'PAGE.K8S.VERTICALSCALING' |
translate}}
</h4>
@@ -59,6 +62,13 @@
formControlName="name" id="name" [ngClass]="{ 'is-invalid': submitted && f.name.errors }" required>
</div>
</div>
+ <div class="form-group row mb-3" *ngIf="profileType === 'update'">
+ <label class="col-sm-4 col-form-label" for="name">{{'PAGE.K8S.NAME' | translate}}</label>
+ <div class="col-sm-8">
+ <input autocomplete="off" class="form-control" placeholder="{{'PAGE.K8S.NAME' | translate}}" type="text"
+ formControlName="update" id="name" [ngClass]="{ 'is-invalid': submitted && f.update.errors }">
+ </div>
+ </div>
<div class="form-group row mb-3" *ngIf="profileType === 'Manage'|| !isChecked">
<label class="col-sm-4 col-form-label" for="k8s_version">{{'PAGE.K8S.K8SVERSION' | translate}}*</label>
<div class="col-sm-8">
@@ -88,7 +98,7 @@
</ng-select>
</div>
</div>
- <div class="form-group row mb-3" *ngIf="profileType === 'Manage' || profileType === 'Register' || !isChecked">
+ <div class="form-group row mb-3" *ngIf="profileType === 'Manage' || profileType === 'Register' || !isChecked || profileType === 'update'">
<label class="col-sm-4 col-form-label" for="description">{{'PAGE.K8S.DESCRIPTION' | translate}}</label>
<div class="col-sm-8">
<textarea class="form-control" placeholder="{{'PAGE.K8S.DESCRIPTION' | translate}}" type="text"
@@ -179,7 +189,7 @@
<button type="button" class="btn btn-danger" (click)="activeModal.close()">{{'CANCEL' | translate}}</button>
<button *ngIf="profileType === 'Manage'" type="submit" class="btn btn-primary">{{'CREATE' | translate}}</button>
<button *ngIf="profileType === 'Register'" type="submit" class="btn btn-primary">{{'REGISTER' | translate}}</button>
- <button *ngIf="profileType === 'upgrade' || profileType === 'vertical' || profileType === 'horizontal'"
+ <button *ngIf="profileType === 'upgrade' || profileType === 'vertical' || profileType === 'horizontal' || profileType === 'update'"
type="submit" class="btn btn-primary">{{'APPLY'
| translate}}</button>
</div>
diff --git a/src/app/k8s/k8s-add-cluster/K8sAddClusterComponent.ts b/src/app/k8s/k8s-add-cluster/K8sAddClusterComponent.ts
index cf03f0f..37ddc13 100644
--- a/src/app/k8s/k8s-add-cluster/K8sAddClusterComponent.ts
+++ b/src/app/k8s/k8s-add-cluster/K8sAddClusterComponent.ts
@@ -27,7 +27,7 @@
import { APIURLHEADER, ERRORDATA, MODALCLOSERESPONSEDATA, TYPESECTION } from 'CommonModel';
import { environment } from 'environment';
import * as jsyaml from 'js-yaml';
-import { K8SPayload } from 'K8sModel';
+import { K8SCLUSTERDATA, K8SPayload } from 'K8sModel';
import { RestService } from 'RestService';
import { isNullOrUndefined, SharedService } from 'SharedService';
import { VimAccountDetails } from 'VimAccountModel';
@@ -66,6 +66,9 @@
/** Contains all deployment methods selected */
public selectedDeploymentMethods: string[] = ['helm-chart-v3', 'juju-bundle'];
+ /** Contains all action types */
+ public actionTypes: string[] = ['update', 'upgrade', 'horizontal', 'vertical'];
+
/** Instance for active modal service @public */
public activeModal: NgbActiveModal;
@@ -149,6 +152,11 @@
'Content-Type': 'application/json',
'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0'
});
+ this.actionTypes.forEach((type: string): void => {
+ if (type === this.profileType) {
+ this.k8sClusterDetail();
+ }
+ });
}
/** On modal initializing forms @public */
@@ -168,7 +176,8 @@
bootstrap: [true],
k8sVersion: ['', [Validators.required]],
nodeCount: ['', [Validators.required]],
- nodeSize: ['', [Validators.required]]
+ nodeSize: ['', [Validators.required]],
+ update: ['']
});
}
@@ -187,6 +196,26 @@
});
}
+ /** patch the form values for edit @public */
+ public k8sClusterDetail(): void {
+ this.isLoadingResults = true;
+ this.restService.getResource(environment.K8SCREATECLUSTER_URL + '/' + this.profileID).subscribe((k8sData: K8SCLUSTERDATA) => {
+ if (this.profileType === 'update') {
+ this.k8sclusterForm.patchValue({ update: k8sData.name, description: !isNullOrUndefined(k8sData.description) ? k8sData.description : '' });
+ } else if (this.profileType === 'upgrade') {
+ this.k8sclusterForm.patchValue({ k8sVersion: !isNullOrUndefined(k8sData.k8s_version) ? k8sData.k8s_version : '' });
+ } else if (this.profileType === 'horizontal') {
+ this.k8sclusterForm.patchValue({ nodeCount: !isNullOrUndefined(k8sData.node_count) ? k8sData.node_count : '' });
+ } else if (this.profileType === 'vertical') {
+ this.k8sclusterForm.patchValue({ nodeSize: !isNullOrUndefined(k8sData.node_size) ? k8sData.node_size : '' });
+ }
+ this.isLoadingResults = false;
+ }, (error: ERRORDATA) => {
+ this.restService.handleError(error, 'get');
+ this.isLoadingResults = false;
+ });
+ }
+
/** Call the event when checkbox is checked @public */
public getValue(event: Event): void {
this.isChecked = (event.target as HTMLInputElement).checked;
@@ -207,6 +236,7 @@
this.getFormControl('k8sVersion').disable();
this.getFormControl('nodeSize').disable();
this.getFormControl('nodeCount').disable();
+ this.getFormControl('update').disable();
this.manageCluster();
} else if (this.profileType === 'Register' && this.isChecked === true) {
this.clusterUrl = environment.K8SCREATECLUSTER_URL + '/register';
@@ -220,6 +250,7 @@
this.getFormControl('k8sVersion').disable();
this.getFormControl('nodeSize').disable();
this.getFormControl('nodeCount').disable();
+ this.getFormControl('update').disable();
this.registerCluster();
} if (this.isChecked === false && this.profileType === 'Register') {
this.clusterUrl = environment.K8SCLUSTER_URL;
@@ -231,6 +262,7 @@
this.getFormControl('k8sVersion').disable();
this.getFormControl('nodeSize').disable();
this.getFormControl('nodeCount').disable();
+ this.getFormControl('update').disable();
this.oldregisterCluster();
} else if (this.profileType === 'upgrade' || this.profileType === 'horizontal' || this.profileType === 'vertical') {
this.clusterUrl = environment.K8SCREATECLUSTER_URL + '/' + this.profileID + '/' + 'update';
@@ -246,6 +278,7 @@
this.getFormControl('node_count').disable();
this.getFormControl('node_size').disable();
this.getFormControl('k8s_version').disable();
+ this.getFormControl('update').disable();
if (this.profileType === 'upgrade') {
this.getFormControl('nodeCount').disable();
this.getFormControl('nodeSize').disable();
@@ -257,6 +290,24 @@
this.getFormControl('k8sVersion').disable();
}
this.updateCluster();
+ } else if (this.profileType === 'update') {
+ this.clusterUrl = environment.K8SCREATECLUSTER_URL + '/' + this.profileID;
+ this.getFormControl('bootstrap').disable();
+ this.getFormControl('region_name').disable();
+ this.getFormControl('resource_group').disable();
+ this.getFormControl('nets').disable();
+ this.getFormControl('credentials').disable();
+ this.getFormControl('deployment_methods').disable();
+ this.getFormControl('vim_account').disable();
+ this.getFormControl('node_count').disable();
+ this.getFormControl('node_size').disable();
+ this.getFormControl('k8s_version').disable();
+ this.getFormControl('nodeCount').disable();
+ this.getFormControl('k8sVersion').disable();
+ this.getFormControl('nodeSize').disable();
+ this.getFormControl('name').disable();
+
+ this.editCluster();
}
}
@@ -456,6 +507,51 @@
});
}
+
+ /** Update cluster @public */
+ public editCluster(): void {
+ this.submitted = true;
+ this.sharedService.cleanForm(this.k8sclusterForm);
+ if (this.k8sclusterForm.invalid) {
+ return;
+ }
+ const modalData: MODALCLOSERESPONSEDATA = {
+ message: 'Done'
+ };
+ const apiURLHeader: APIURLHEADER = {
+ url: this.clusterUrl,
+ httpOptions: { headers: this.headers }
+ };
+ this.isLoadingResults = true;
+ if (this.k8sclusterForm.value.description === '') {
+ delete this.k8sclusterForm.value.description;
+ this.payload = {
+ name: this.k8sclusterForm.value.update
+ };
+ }
+ if (this.k8sclusterForm.value.update === '') {
+ delete this.k8sclusterForm.value.update;
+ this.payload = {
+ description: this.k8sclusterForm.value.description
+ };
+ }
+ if (this.k8sclusterForm.value.update !== '' && this.k8sclusterForm.value.description !== '') {
+ this.payload = {
+ name: this.k8sclusterForm.value.update,
+ description: this.k8sclusterForm.value.description
+ };
+ }
+ this.restService.patchResource(apiURLHeader, this.payload).subscribe((result: {}) => {
+ this.activeModal.close(modalData);
+ this.isLoadingResults = false;
+ this.notifierService.notify('success',
+ this.translateService.instant('PAGE.K8S.UPDATEDSUCCESSFULLY'));
+ }, (error: ERRORDATA) => {
+ this.restService.handleError(error, 'post');
+ this.isLoadingResults = false;
+ });
+ }
+
/** Nets file process @private */
public netsFile(files: FileList): void {
if (files && files.length === 1) {
diff --git a/src/app/k8s/k8s-ksu/ksu-details/KSUComponent.ts b/src/app/k8s/k8s-ksu/ksu-details/KSUComponent.ts
index 2591b4c..85a19d8 100644
--- a/src/app/k8s/k8s-ksu/ksu-details/KSUComponent.ts
+++ b/src/app/k8s/k8s-ksu/ksu-details/KSUComponent.ts
@@ -121,7 +121,7 @@
name: { title: this.translateService.instant('NAME'), width: '20%', sortDirection: 'asc' },
identifier: { title: this.translateService.instant('IDENTIFIER'), width: '15%' },
state: {
- title: this.translateService.instant('STATE'), width: '15%', type: 'html',
+ title: this.translateService.instant('GITSTATE'), width: '15%', type: 'html',
filter: {
type: 'list',
config: {
diff --git a/src/app/k8s/k8s-profile/k8s-app-profile-details/K8sAppProfileComponent.ts b/src/app/k8s/k8s-profile/k8s-app-profile-details/K8sAppProfileComponent.ts
index 4772c4c..06cd6eb 100644
--- a/src/app/k8s/k8s-profile/k8s-app-profile-details/K8sAppProfileComponent.ts
+++ b/src/app/k8s/k8s-profile/k8s-app-profile-details/K8sAppProfileComponent.ts
@@ -121,7 +121,7 @@
name: { title: this.translateService.instant('NAME'), width: '20%', sortDirection: 'asc' },
identifier: { title: this.translateService.instant('IDENTIFIER'), width: '15%' },
state: {
- title: this.translateService.instant('STATE'), width: '15%', type: 'html',
+ title: this.translateService.instant('GITSTATE'), width: '15%', type: 'html',
filter: {
type: 'list',
config: {
diff --git a/src/app/k8s/k8s-profile/k8s-infra-config-add/K8sInfraConfigAddComponent.html b/src/app/k8s/k8s-profile/k8s-infra-config-add/K8sInfraConfigAddComponent.html
index 493cb5b..d43ff63 100644
--- a/src/app/k8s/k8s-profile/k8s-infra-config-add/K8sInfraConfigAddComponent.html
+++ b/src/app/k8s/k8s-profile/k8s-infra-config-add/K8sInfraConfigAddComponent.html
@@ -23,7 +23,7 @@
<i class="fas fa-times-circle text-danger"></i>
</button>
</div>
- <div class="modal-body modal-body-custom-height">
+ <div class="modal-body modal-body-custom-height" *ngIf="isAdd">
<div class="form-group row mb-3">
<label class="col-sm-12 col-form-label mandatory-label"
[ngClass]="{'text-danger': profileForm.invalid === true && submitted === true}">{{'MANDATORYCHECK' |
@@ -43,6 +43,26 @@
</div>
</div>
</div>
+ <div class="modal-body modal-body-custom-height"*ngIf="isEdit">
+ <div class="form-group row mb-3">
+ <label class="col-sm-12 col-form-label mandatory-label"
+ [ngClass]="{'text-danger': profileForm.invalid === true && submitted === true}">{{'MANDATORYCHECK' |
+ translate}}</label>
+ <label class="col-sm-4 col-form-label" for="name">{{'PAGE.K8S.NAME' | translate}}</label>
+ <div class="col-sm-8">
+ <input autocomplete="off" class="form-control" placeholder="{{'PAGE.K8S.NAME' | translate}}" type="text"
+ formControlName="updatename" id="name" [ngClass]="{ 'is-invalid': submitted && f.updatename.errors }">
+ </div>
+ </div>
+ <div class="form-group row mb-3">
+ <label class="col-sm-4 col-form-label" for="description">{{'PAGE.K8S.DESCRIPTION' | translate}}</label>
+ <div class="col-sm-8">
+ <textarea class="form-control" placeholder="{{'PAGE.K8S.DESCRIPTION' | translate}}" type="text"
+ formControlName="updatedescription" id="description"
+ [ngClass]="{ 'is-invalid': submitted && f.updatedescription.errors }"></textarea>
+ </div>
+ </div>
+ </div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" (click)="activeModal.close()">{{'CANCEL' | translate}}</button>
<button *ngIf="isAdd" type="submit" class="btn btn-primary">{{'CREATE' | translate}}</button>
diff --git a/src/app/k8s/k8s-profile/k8s-infra-config-add/K8sInfraConfigAddComponent.ts b/src/app/k8s/k8s-profile/k8s-infra-config-add/K8sInfraConfigAddComponent.ts
index 5299323..5120f37 100644
--- a/src/app/k8s/k8s-profile/k8s-infra-config-add/K8sInfraConfigAddComponent.ts
+++ b/src/app/k8s/k8s-profile/k8s-infra-config-add/K8sInfraConfigAddComponent.ts
@@ -19,14 +19,14 @@
* @file K8sInfraConfigAddComponent.ts.
*/
import { HttpHeaders } from '@angular/common/http';
-import { Component,Injector, Input, OnInit} from '@angular/core';
+import { Component, Injector, Input, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { TranslateService } from '@ngx-translate/core';
import { NotifierService } from 'angular-notifier';
import { APIURLHEADER, ERRORDATA, MODALCLOSERESPONSEDATA, TYPESECTION, URLPARAMS } from 'CommonModel';
import { environment } from 'environment';
-import { INFRACONFIGPAYLOAD} from 'K8sModel';
+import { INFRACONFIGPAYLOAD } from 'K8sModel';
import { RestService } from 'RestService';
import { SharedService, isNullOrUndefined } from 'SharedService';
/**
@@ -73,11 +73,14 @@
/** Input contains Modal dialog component Instance @public */
@Input() public profileDescription: string;
- /** check Add @public */
- public isAdd = false;
+ /** check Add @public */
+ public isAdd = false;
- /** check Edit @public */
- public isEdit = false;
+ /** check Edit @public */
+ public isEdit = false;
+
+ /** Edit Payload @public */
+ public payload: INFRACONFIGPAYLOAD;
/** FormBuilder instance added to the formBuilder @private */
private formBuilder: FormBuilder;
@@ -128,7 +131,9 @@
this.profileForm = this.formBuilder.group({
name: ['', [Validators.required]],
default: [null],
- description: ['', [Validators.required]]
+ description: ['', [Validators.required]],
+ updatename: [''],
+ updatedescription: ['']
});
}
@@ -168,6 +173,8 @@
};
this.isLoadingResults = true;
+ delete this.profileForm.value.updatename;
+ delete this.profileForm.value.updatedescription;
const payload: INFRACONFIGPAYLOAD = {
name: this.profileForm.value.name,
description: this.profileForm.value.description
@@ -202,12 +209,26 @@
url: this.profileUrl,
httpOptions: { headers: this.headers }
};
- const payload: INFRACONFIGPAYLOAD = {
- name: this.profileForm.value.name,
- description: this.profileForm.value.description
- };
+ delete this.profileForm.value.name;
+ delete this.profileForm.value.description;
+ if (this.profileForm.value.updatename === '') {
+ this.payload = {
+ description: this.profileForm.value.updatedescription
+ };
+ delete this.profileForm.value.updatename;
+ } else if (this.profileForm.value.updatedescription === '') {
+ this.payload = {
+ name: this.profileForm.value.updatename
+ };
+ delete this.profileForm.value.updatedescription;
+ } else {
+ this.payload = {
+ name: this.profileForm.value.updatenamename,
+ description: this.profileForm.value.updatedescription
+ };
+ }
- this.restService.patchResource(apiURLHeader, payload).subscribe((result: {}) => {
+ this.restService.patchResource(apiURLHeader, this.payload).subscribe((result: {}) => {
this.activeModal.close(modalData);
this.isLoadingResults = false;
this.notifierService.notify('success',
diff --git a/src/app/k8s/k8s-profile/k8s-infra-config-details/K8sInfraConfigProfileComponent.ts b/src/app/k8s/k8s-profile/k8s-infra-config-details/K8sInfraConfigProfileComponent.ts
index 760124b..2c76dbf 100644
--- a/src/app/k8s/k8s-profile/k8s-infra-config-details/K8sInfraConfigProfileComponent.ts
+++ b/src/app/k8s/k8s-profile/k8s-infra-config-details/K8sInfraConfigProfileComponent.ts
@@ -121,7 +121,7 @@
name: { title: this.translateService.instant('NAME'), width: '20%', sortDirection: 'asc' },
identifier: { title: this.translateService.instant('IDENTIFIER'), width: '15%' },
state: {
- title: this.translateService.instant('STATE'), width: '15%', type: 'html',
+ title: this.translateService.instant('GITSTATE'), width: '15%', type: 'html',
filter: {
type: 'list',
config: {
diff --git a/src/app/k8s/k8s-profile/k8s-infra-controller-details/K8sInfraControllerProfileComponent.ts b/src/app/k8s/k8s-profile/k8s-infra-controller-details/K8sInfraControllerProfileComponent.ts
index 0402acf..f5c93ae 100644
--- a/src/app/k8s/k8s-profile/k8s-infra-controller-details/K8sInfraControllerProfileComponent.ts
+++ b/src/app/k8s/k8s-profile/k8s-infra-controller-details/K8sInfraControllerProfileComponent.ts
@@ -121,7 +121,7 @@
name: { title: this.translateService.instant('NAME'), width: '20%', sortDirection: 'asc' },
identifier: { title: this.translateService.instant('IDENTIFIER'), width: '15%' },
state: {
- title: this.translateService.instant('STATE'), width: '15%', type: 'html',
+ title: this.translateService.instant('GITSTATE'), width: '15%', type: 'html',
filter: {
type: 'list',
config: {
diff --git a/src/app/k8s/k8s-profile/k8s-resource-profile/K8sResourceProfileComponent.ts b/src/app/k8s/k8s-profile/k8s-resource-profile/K8sResourceProfileComponent.ts
index 296b0f6..b1dbf95 100644
--- a/src/app/k8s/k8s-profile/k8s-resource-profile/K8sResourceProfileComponent.ts
+++ b/src/app/k8s/k8s-profile/k8s-resource-profile/K8sResourceProfileComponent.ts
@@ -121,7 +121,7 @@
name: { title: this.translateService.instant('NAME'), width: '20%', sortDirection: 'asc' },
identifier: { title: this.translateService.instant('IDENTIFIER'), width: '15%' },
state: {
- title: this.translateService.instant('STATE'), width: '15%', type: 'html',
+ title: this.translateService.instant('GITSTATE'), width: '15%', type: 'html',
filter: {
type: 'list',
config: {
diff --git a/src/app/k8s/k8scluster/K8sClusterComponent.ts b/src/app/k8s/k8scluster/K8sClusterComponent.ts
index 95c8e88..c79493e 100644
--- a/src/app/k8s/k8scluster/K8sClusterComponent.ts
+++ b/src/app/k8s/k8scluster/K8sClusterComponent.ts
@@ -165,7 +165,7 @@
}
},
state: {
- title: this.translateService.instant('STATE'), width: '15%', type: 'html',
+ title: this.translateService.instant('GITSTATE'), width: '15%', type: 'html',
filter: {
type: 'list',
config: {
@@ -288,66 +288,27 @@
/** Fetching the data from server to Load in the smarttable @protected */
protected generateData(): void {
this.isLoadingResults = true;
- const tempURL: Observable<K8SCLUSTERDATA[]>[] = [];
- const apiUrl1: string = environment.K8SCLUSTER_URL;
- const apiUrl2: string = environment.K8SCREATECLUSTER_URL;
- const response1$: Observable<K8SCLUSTERDATA[]> = this.restService.getResource(apiUrl1).pipe(
- map((data: unknown) =>
- data as K8SCLUSTERDATA[]
- )
- );
- const response2$: Observable<K8SCLUSTERDATA[]> = this.restService.getResource(apiUrl2).pipe(
- map((data: unknown) =>
- data as K8SCLUSTERDATA[]
- )
- );
- tempURL.push(response1$, response2$);
- forkJoin(tempURL).subscribe(
- ([response1, response2]) => {
- if (!isNullOrUndefined(response1) && !isNullOrUndefined(response2)) {
- const combinedResponse: K8SCLUSTERDATA[] = [...response1, ...response2];
- const uniqueResponse = this.removeDuplicates(combinedResponse);
- this.k8sClusterData = [];
- uniqueResponse.forEach((clusterData: K8SCLUSTERDATA) => {
- const k8sClusterDataObj: K8SCLUSTERDATADISPLAY = this.generateK8sclusterData(clusterData);
- this.k8sClusterData.push(k8sClusterDataObj);
- });
- if (this.k8sClusterData.length > 0) {
- this.checkDataClass = 'dataTables_present';
- } else {
- this.checkDataClass = 'dataTables_empty';
- }
- this.dataSource.load(this.k8sClusterData).then((data: boolean) => {
- this.isLoadingResults = false;
- }).catch(() => {
- this.isLoadingResults = false;
- });
+ this.restService.getResource(environment.K8SCREATECLUSTER_URL).subscribe((k8sClusterDatas: K8SCLUSTERDATA[]) => {
+ if (!isNullOrUndefined(k8sClusterDatas)) {
+ this.k8sClusterData = [];
+ k8sClusterDatas.forEach((clusterData: K8SCLUSTERDATA) => {
+ const k8sClusterDataObj: K8SCLUSTERDATADISPLAY = this.generateK8sclusterData(clusterData);
+ this.k8sClusterData.push(k8sClusterDataObj);
+ });
+ if (this.k8sClusterData.length > 0) {
+ this.checkDataClass = 'dataTables_present';
+ } else {
+ this.checkDataClass = 'dataTables_empty';
}
- }, (error: ERRORDATA) => {
- this.restService.handleError(error, 'get');
- this.isLoadingResults = false;
- });
- }
-
- /** Removes duplicates based on 'name' and merges them if necessary */
- private removeDuplicates(response: K8SCLUSTERDATA[]): K8SCLUSTERDATA[] {
- const seenIds = new Set();
- const uniqueResponse: K8SCLUSTERDATA[] = [];
- response.forEach((obj) => {
- if (!seenIds.has(obj.name)) {
- uniqueResponse.push(obj);
- seenIds.add(obj.name);
- } else {
- const existingObj = uniqueResponse.find((o) => o.name === obj.name);
- Object.keys(obj).forEach((key) => {
- // eslint-disable-next-line security/detect-object-injection
- if (existingObj[key] !== obj[key]) {
- // eslint-disable-next-line security/detect-object-injection
- existingObj[key] = obj[key];
- }
+ this.dataSource.load(this.k8sClusterData).then((data: boolean) => {
+ this.isLoadingResults = false;
+ }).catch(() => {
+ this.isLoadingResults = false;
});
}
+ }, (error: ERRORDATA) => {
+ this.restService.handleError(error, 'get');
+ this.isLoadingResults = false;
});
- return uniqueResponse;
}
}