From 274d2d276aed92e3efbec68c326a52002809a047 Mon Sep 17 00:00:00 2001 From: powerfool Date: Fri, 20 Dec 2024 16:33:45 +0800 Subject: [PATCH] fix(obcluster): list obcluster parameters group by name (#685) --- internal/dashboard/business/oceanbase/obcluster.go | 2 +- internal/dashboard/business/oceanbase/obtenant.go | 1 + internal/dashboard/handler/obtenant_handler.go | 3 --- internal/dashboard/model/response/obtenant.go | 2 ++ pkg/oceanbase-sdk/const/sql/parameter.go | 1 + pkg/oceanbase-sdk/operation/cluster.go | 9 +++++++++ 6 files changed, 14 insertions(+), 4 deletions(-) diff --git a/internal/dashboard/business/oceanbase/obcluster.go b/internal/dashboard/business/oceanbase/obcluster.go index 354fa18b5..8d67678b2 100644 --- a/internal/dashboard/business/oceanbase/obcluster.go +++ b/internal/dashboard/business/oceanbase/obcluster.go @@ -934,7 +934,7 @@ func ListOBClusterParameters(ctx context.Context, nn *param.K8sObjectIdentity) ( logger.Info("Failed to get OceanBase database connection") return nil, errors.Wrap(err, "Get OceanBase database connection") } - parameters, err := conn.ListParametersWithTenantID(ctx, 1) + parameters, err := conn.ListClusterParameters(ctx) if err != nil { logger.WithError(err).Error("Failed to query parameters") return nil, errors.Wrap(err, "Query parameters") diff --git a/internal/dashboard/business/oceanbase/obtenant.go b/internal/dashboard/business/oceanbase/obtenant.go index 4dc6f1ae0..188a8a3e5 100644 --- a/internal/dashboard/business/oceanbase/obtenant.go +++ b/internal/dashboard/business/oceanbase/obtenant.go @@ -211,6 +211,7 @@ func buildOverviewFromApiType(t *v1alpha1.OBTenant) *response.OBTenantOverview { rt.Charset = t.Spec.Charset rt.Locality = t.Status.TenantRecordInfo.Locality rt.PrimaryZone = t.Status.TenantRecordInfo.PrimaryZone + rt.DeletionProtection = t.Annotations[oceanbaseconst.AnnotationsIgnoreDeletion] == "true" for i := range t.Status.Pools { pool := t.Status.Pools[i] diff --git a/internal/dashboard/handler/obtenant_handler.go b/internal/dashboard/handler/obtenant_handler.go index 0cb8ded3a..c97565472 100644 --- a/internal/dashboard/handler/obtenant_handler.go +++ b/internal/dashboard/handler/obtenant_handler.go @@ -243,9 +243,6 @@ func PatchTenant(c *gin.Context) (*response.OBTenantDetail, error) { if err != nil { return nil, httpErr.NewBadRequest(err.Error()) } - if patch.UnitNumber == nil && patch.UnitConfig == nil { - return nil, httpErr.NewBadRequest("unitNumber or unitConfig is required") - } logger.Infof("Patch obtenant with param: %+v", patch) tenant, err := oceanbase.PatchTenant(c, types.NamespacedName{ Namespace: nn.Namespace, diff --git a/internal/dashboard/model/response/obtenant.go b/internal/dashboard/model/response/obtenant.go index 2f8224148..29daf3417 100644 --- a/internal/dashboard/model/response/obtenant.go +++ b/internal/dashboard/model/response/obtenant.go @@ -27,6 +27,8 @@ type OBTenantOverview struct { Locality string `json:"locality" binding:"required"` // Locality of the tenant units Charset string `json:"charset" binding:"required"` // Charset of the tenant PrimaryZone string `json:"primaryZone" binding:"required"` // Primary zone of the tenant + + DeletionProtection bool `json:"deletionProtection" binding:"required"` // Whether the tenant is protected from deletion } type OBTenantDetail struct { diff --git a/pkg/oceanbase-sdk/const/sql/parameter.go b/pkg/oceanbase-sdk/const/sql/parameter.go index 57d783980..9291592b7 100644 --- a/pkg/oceanbase-sdk/const/sql/parameter.go +++ b/pkg/oceanbase-sdk/const/sql/parameter.go @@ -22,4 +22,5 @@ const ( const ( ListParametersWithTenantID = "select name, value, data_type, info, section, default_value, isdefault, edit_level, scope from GV$OB_PARAMETERS where tenant_id = ?" SelectCompatibleOfTenants = "select name, value, tenant_id from GV$OB_PARAMETERS where name = 'compatible'" + ListParametersGroupByName = "select name, value, data_type, info, section, default_value, isdefault, edit_level, scope, svr_ip, zone, svr_port, IFNULL(tenant_id, 0) as tenant_id from GV$OB_PARAMETERS group by name" ) diff --git a/pkg/oceanbase-sdk/operation/cluster.go b/pkg/oceanbase-sdk/operation/cluster.go index e8b8117e6..655ae51da 100644 --- a/pkg/oceanbase-sdk/operation/cluster.go +++ b/pkg/oceanbase-sdk/operation/cluster.go @@ -60,3 +60,12 @@ func (m *OceanbaseOperationManager) GetVersion(ctx context.Context) (*model.OBVe } return version, nil } + +func (m *OceanbaseOperationManager) ListClusterParameters(ctx context.Context) ([]*model.Parameter, error) { + params := make([]*model.Parameter, 0) + err := m.QueryList(ctx, ¶ms, sql.ListParametersGroupByName) + if err != nil { + return nil, errors.Wrap(err, "List cluster parameters") + } + return params, nil +}