Skip to content

Commit f870b3e

Browse files
committed
feat(obcluster): added handler for listing obcluster parameters
1 parent 68c5162 commit f870b3e

File tree

4 files changed

+85
-0
lines changed

4 files changed

+85
-0
lines changed

internal/dashboard/business/oceanbase/obcluster.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020

2121
"github.com/google/uuid"
2222
"github.com/pkg/errors"
23+
"github.com/sirupsen/logrus"
2324
logger "github.com/sirupsen/logrus"
2425
corev1 "k8s.io/api/core/v1"
2526
apiresource "k8s.io/apimachinery/pkg/api/resource"
@@ -34,8 +35,10 @@ import (
3435
"github.com/oceanbase/ob-operator/internal/dashboard/business/common"
3536
"github.com/oceanbase/ob-operator/internal/dashboard/business/constant"
3637
modelcommon "github.com/oceanbase/ob-operator/internal/dashboard/model/common"
38+
clustermodel "github.com/oceanbase/ob-operator/internal/dashboard/model/obcluster"
3739
"github.com/oceanbase/ob-operator/internal/dashboard/model/param"
3840
"github.com/oceanbase/ob-operator/internal/dashboard/model/response"
41+
"github.com/oceanbase/ob-operator/internal/dashboard/utils"
3942
oberr "github.com/oceanbase/ob-operator/pkg/errors"
4043
)
4144

@@ -877,3 +880,30 @@ func DeleteOBServers(ctx context.Context, nn *param.K8sObjectIdentity, param *pa
877880

878881
return buildOBClusterResponse(ctx, obcluster)
879882
}
883+
884+
func ListOBClusterParameters(ctx context.Context, nn *param.K8sObjectIdentity) ([]clustermodel.ParameterItem, error) {
885+
obcluster, err := clients.GetOBCluster(ctx, nn.Namespace, nn.Name)
886+
if err != nil {
887+
return nil, errors.Wrapf(err, "Get obcluster %s %s", nn.Namespace, nn.Name)
888+
}
889+
observerList := v1alpha1.OBServerList{}
890+
err = clients.ServerClient.List(ctx, nn.Namespace, &observerList, metav1.ListOptions{
891+
LabelSelector: fmt.Sprintf("%s=%s", oceanbaseconst.LabelRefOBCluster, nn.Name),
892+
})
893+
if err != nil {
894+
logrus.WithError(err).Error("Failed to list observers")
895+
return nil, errors.Wrap(err, "List observers")
896+
}
897+
conn, err := utils.GetOBConnection(ctx, obcluster, "root", "sys", obcluster.Spec.UserSecrets.Root)
898+
if err != nil {
899+
logrus.Info("Failed to get OceanBase database connection")
900+
return nil, errors.Wrap(err, "Get OceanBase database connection")
901+
}
902+
parameterItems := make([]clustermodel.ParameterItem, 0)
903+
err = conn.QueryList(ctx, &parameterItems, "SHOW PARAMETERS")
904+
if err != nil {
905+
logrus.WithError(err).Error("Failed to query parameters")
906+
return nil, errors.Wrap(err, "Query parameters")
907+
}
908+
return parameterItems, nil
909+
}

internal/dashboard/handler/obcluster_handler.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/oceanbase/ob-operator/internal/clients"
2525
oceanbaseconst "github.com/oceanbase/ob-operator/internal/const/oceanbase"
2626
"github.com/oceanbase/ob-operator/internal/dashboard/business/oceanbase"
27+
"github.com/oceanbase/ob-operator/internal/dashboard/model/obcluster"
2728
"github.com/oceanbase/ob-operator/internal/dashboard/model/param"
2829
"github.com/oceanbase/ob-operator/internal/dashboard/model/response"
2930
crypto "github.com/oceanbase/ob-operator/pkg/crypto"
@@ -473,3 +474,25 @@ func DeleteOBServers(c *gin.Context) (*response.OBCluster, error) {
473474
logger.Infof("Delete observers with param: %+v", deleteParam)
474475
return oceanbase.DeleteOBServers(c, obclusterIdentity, deleteParam)
475476
}
477+
478+
// @ID ListOBClusterParameters
479+
// @Summary List OBCluster Parameters
480+
// @Description List OBCluster Parameters by namespace and name
481+
// @Tags OBCluster
482+
// @Accept application/json
483+
// @Produce application/json
484+
// @Param namespace path string true "namespace of obcluster resource"
485+
// @Param name path string true "name of obcluster resource"
486+
// @Success 200 object response.APIResponse{data=[]obcluster.ParameterItem}
487+
// @Failure 400 object response.APIResponse
488+
// @Failure 401 object response.APIResponse
489+
// @Failure 500 object response.APIResponse
490+
// @Router /api/v1/obclusters/namespace/{namespace}/name/{name}/parameters [GET]
491+
func ListOBClusterParameters(c *gin.Context) ([]obcluster.ParameterItem, error) {
492+
nn := &param.K8sObjectIdentity{}
493+
err := c.BindUri(nn)
494+
if err != nil {
495+
return nil, httpErr.NewBadRequest(err.Error())
496+
}
497+
return oceanbase.ListOBClusterParameters(c, nn)
498+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Copyright (c) 2024 OceanBase
3+
ob-operator is licensed under Mulan PSL v2.
4+
You can use this software according to the terms and conditions of the Mulan PSL v2.
5+
You may obtain a copy of Mulan PSL v2 at:
6+
http://license.coscl.org.cn/MulanPSL2
7+
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
8+
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
9+
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
10+
See the Mulan PSL v2 for more details.
11+
*/
12+
13+
package obcluster
14+
15+
// ParameterItem defines the parameter item returned by 'show parameters' command
16+
type ParameterItem struct {
17+
Zone string `json:"zone"`
18+
SvrType string `json:"svrType" db:"svr_type"`
19+
SvrIP string `json:"svrIP" db:"svr_ip"`
20+
SvrPort string `json:"svrPort" db:"svr_port"`
21+
Name string `json:"name"`
22+
DataType string `json:"dataType" db:"data_type"`
23+
Value string `json:"value"`
24+
Info string `json:"info"`
25+
Section string `json:"section"`
26+
Scope string `json:"scope"`
27+
Source string `json:"source"`
28+
EditLevel string `json:"editLevel" db:"edit_level"`
29+
DefaultValue string `json:"defaultValue" db:"default_value"`
30+
IsDefault bool `json:"isDefault" db:"isdefault"`
31+
}

internal/dashboard/router/v1/obcluster_router.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ func InitOBClusterRoutes(g *gin.RouterGroup) {
3535
g.PATCH("/obclusters/namespace/:namespace/name/:name", h.Wrap(h.PatchOBCluster, acbiz.PathGuard("obcluster", ":namespace+:name", "write")))
3636
g.POST("/obclusters/namespace/:namespace/name/:name/restart", h.Wrap(h.RestartOBServers, acbiz.PathGuard("obcluster", ":namespace+:name", "write")))
3737
g.DELETE("/obclusters/namespace/:namespace/name/:name/observers", h.Wrap(h.DeleteOBServers, acbiz.PathGuard("obcluster", ":namespace+:name", "write")))
38+
g.GET("/obclusters/namespace/:namespace/name/:name/parameters", h.Wrap(h.ListOBClusterParameters, acbiz.PathGuard("obcluster", ":namespace+:name", "read")))
3839
}

0 commit comments

Comments
 (0)