Skip to content

Commit

Permalink
feat(obcluster): added handler for listing obcluster parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
powerfooI committed Dec 2, 2024
1 parent 68c5162 commit f870b3e
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
30 changes: 30 additions & 0 deletions internal/dashboard/business/oceanbase/obcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/google/uuid"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
logger "github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
apiresource "k8s.io/apimachinery/pkg/api/resource"
Expand All @@ -34,8 +35,10 @@ import (
"github.com/oceanbase/ob-operator/internal/dashboard/business/common"
"github.com/oceanbase/ob-operator/internal/dashboard/business/constant"
modelcommon "github.com/oceanbase/ob-operator/internal/dashboard/model/common"
clustermodel "github.com/oceanbase/ob-operator/internal/dashboard/model/obcluster"
"github.com/oceanbase/ob-operator/internal/dashboard/model/param"
"github.com/oceanbase/ob-operator/internal/dashboard/model/response"
"github.com/oceanbase/ob-operator/internal/dashboard/utils"
oberr "github.com/oceanbase/ob-operator/pkg/errors"
)

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

return buildOBClusterResponse(ctx, obcluster)
}

func ListOBClusterParameters(ctx context.Context, nn *param.K8sObjectIdentity) ([]clustermodel.ParameterItem, error) {
obcluster, err := clients.GetOBCluster(ctx, nn.Namespace, nn.Name)
if err != nil {
return nil, errors.Wrapf(err, "Get obcluster %s %s", nn.Namespace, nn.Name)
}
observerList := v1alpha1.OBServerList{}
err = clients.ServerClient.List(ctx, nn.Namespace, &observerList, metav1.ListOptions{
LabelSelector: fmt.Sprintf("%s=%s", oceanbaseconst.LabelRefOBCluster, nn.Name),
})
if err != nil {
logrus.WithError(err).Error("Failed to list observers")
return nil, errors.Wrap(err, "List observers")
}
conn, err := utils.GetOBConnection(ctx, obcluster, "root", "sys", obcluster.Spec.UserSecrets.Root)
if err != nil {
logrus.Info("Failed to get OceanBase database connection")
return nil, errors.Wrap(err, "Get OceanBase database connection")
}
parameterItems := make([]clustermodel.ParameterItem, 0)
err = conn.QueryList(ctx, &parameterItems, "SHOW PARAMETERS")
if err != nil {
logrus.WithError(err).Error("Failed to query parameters")
return nil, errors.Wrap(err, "Query parameters")
}
return parameterItems, nil
}
23 changes: 23 additions & 0 deletions internal/dashboard/handler/obcluster_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/oceanbase/ob-operator/internal/clients"
oceanbaseconst "github.com/oceanbase/ob-operator/internal/const/oceanbase"
"github.com/oceanbase/ob-operator/internal/dashboard/business/oceanbase"
"github.com/oceanbase/ob-operator/internal/dashboard/model/obcluster"
"github.com/oceanbase/ob-operator/internal/dashboard/model/param"
"github.com/oceanbase/ob-operator/internal/dashboard/model/response"
crypto "github.com/oceanbase/ob-operator/pkg/crypto"
Expand Down Expand Up @@ -473,3 +474,25 @@ func DeleteOBServers(c *gin.Context) (*response.OBCluster, error) {
logger.Infof("Delete observers with param: %+v", deleteParam)
return oceanbase.DeleteOBServers(c, obclusterIdentity, deleteParam)
}

// @ID ListOBClusterParameters
// @Summary List OBCluster Parameters
// @Description List OBCluster Parameters by namespace and name
// @Tags OBCluster
// @Accept application/json
// @Produce application/json
// @Param namespace path string true "namespace of obcluster resource"
// @Param name path string true "name of obcluster resource"
// @Success 200 object response.APIResponse{data=[]obcluster.ParameterItem}
// @Failure 400 object response.APIResponse
// @Failure 401 object response.APIResponse
// @Failure 500 object response.APIResponse
// @Router /api/v1/obclusters/namespace/{namespace}/name/{name}/parameters [GET]
func ListOBClusterParameters(c *gin.Context) ([]obcluster.ParameterItem, error) {
nn := &param.K8sObjectIdentity{}
err := c.BindUri(nn)
if err != nil {
return nil, httpErr.NewBadRequest(err.Error())
}
return oceanbase.ListOBClusterParameters(c, nn)
}
31 changes: 31 additions & 0 deletions internal/dashboard/model/obcluster/params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
Copyright (c) 2024 OceanBase
ob-operator is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/

package obcluster

// ParameterItem defines the parameter item returned by 'show parameters' command
type ParameterItem struct {
Zone string `json:"zone"`
SvrType string `json:"svrType" db:"svr_type"`
SvrIP string `json:"svrIP" db:"svr_ip"`
SvrPort string `json:"svrPort" db:"svr_port"`
Name string `json:"name"`
DataType string `json:"dataType" db:"data_type"`
Value string `json:"value"`
Info string `json:"info"`
Section string `json:"section"`
Scope string `json:"scope"`
Source string `json:"source"`
EditLevel string `json:"editLevel" db:"edit_level"`
DefaultValue string `json:"defaultValue" db:"default_value"`
IsDefault bool `json:"isDefault" db:"isdefault"`
}
1 change: 1 addition & 0 deletions internal/dashboard/router/v1/obcluster_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ func InitOBClusterRoutes(g *gin.RouterGroup) {
g.PATCH("/obclusters/namespace/:namespace/name/:name", h.Wrap(h.PatchOBCluster, acbiz.PathGuard("obcluster", ":namespace+:name", "write")))
g.POST("/obclusters/namespace/:namespace/name/:name/restart", h.Wrap(h.RestartOBServers, acbiz.PathGuard("obcluster", ":namespace+:name", "write")))
g.DELETE("/obclusters/namespace/:namespace/name/:name/observers", h.Wrap(h.DeleteOBServers, acbiz.PathGuard("obcluster", ":namespace+:name", "write")))
g.GET("/obclusters/namespace/:namespace/name/:name/parameters", h.Wrap(h.ListOBClusterParameters, acbiz.PathGuard("obcluster", ":namespace+:name", "read")))
}

0 comments on commit f870b3e

Please sign in to comment.