Skip to content

Commit

Permalink
feat(config): add config updater api
Browse files Browse the repository at this point in the history
  • Loading branch information
jjeffcaii committed Aug 5, 2022
1 parent 265ee7f commit d30318c
Show file tree
Hide file tree
Showing 2 changed files with 231 additions and 41 deletions.
90 changes: 49 additions & 41 deletions pkg/boot/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,62 +69,70 @@ func getRuleExprRegexp() *regexp.Regexp {
return _regexpRuleExpr
}

type Cluster struct {
Tenant string
Type config.DataSourceType
type discovery struct {
path string
options *BootOptions
c *config.Center
}

type ConfigProvider interface {
// ListTenants list tenants name
ListTenants(ctx context.Context) ([]string, error)

// GetTenant returns the tenant info
GetTenant(ctx context.Context, tenant string) (*config.Tenant, error)

// ListClusters lists the cluster names.
ListClusters(ctx context.Context) ([]string, error)

// GetDataSourceCluster returns the dataSourceCluster object
GetDataSourceCluster(ctx context.Context, cluster string) (*config.DataSourceCluster, error)
func (fp *discovery) UpsertTenant(ctx context.Context, tenant string, body *TenantBody) error {
//TODO implement me
panic("implement me")
}

// GetCluster returns the cluster info
GetCluster(ctx context.Context, cluster string) (*Cluster, error)
func (fp *discovery) RemoveTenant(ctx context.Context, tenant string) error {
//TODO implement me
panic("implement me")
}

// ListGroups lists the group names.
ListGroups(ctx context.Context, cluster string) ([]string, error)
func (fp *discovery) UpsertCluster(ctx context.Context, tenant, cluster string, body *ClusterBody) error {
//TODO implement me
panic("implement me")
}

// ListNodes lists the node names.
ListNodes(ctx context.Context, cluster, group string) ([]string, error)
func (fp *discovery) RemoveCluster(ctx context.Context, tenant, cluster string) error {
//TODO implement me
panic("implement me")
}

// GetNode returns the node info.
GetNode(ctx context.Context, cluster, group, node string) (*config.Node, error)
func (fp *discovery) UpsertNode(ctx context.Context, tenant, node string, body *NodeBody) error {
//TODO implement me
panic("implement me")
}

// ListTables lists the table names.
ListTables(ctx context.Context, cluster string) ([]string, error)
func (fp *discovery) RemoveNode(ctx context.Context, tenant, node string) error {
//TODO implement me
panic("implement me")
}

// GetTable returns the table info.
GetTable(ctx context.Context, cluster, table string) (*rule.VTable, error)
func (fp *discovery) UpsertGroup(ctx context.Context, tenant, cluster, group string, body *GroupBody) error {
//TODO implement me
panic("implement me")
}

// GetConfigCenter returns the config center.
GetConfigCenter() *config.Center
func (fp *discovery) RemoveGroup(ctx context.Context, tenant, cluster, group string) error {
//TODO implement me
panic("implement me")
}

type Discovery interface {
ConfigProvider
// ListListeners lists the listener names
ListListeners(ctx context.Context) ([]*config.Listener, error)
func (fp *discovery) BindNode(ctx context.Context, tenant, cluster, group, node string) error {
//TODO implement me
panic("implement me")
}

// ListFilters list the filter names
ListFilters(ctx context.Context) ([]*config.Filter, error)
func (fp *discovery) UnbindNode(ctx context.Context, tenant, cluster, group, node string) error {
//TODO implement me
panic("implement me")
}

// Init initializes discovery with context
Init(ctx context.Context) error
func (fp *discovery) UpsertTable(ctx context.Context, tenant, cluster, table string, body *TableBody) error {
//TODO implement me
panic("implement me")
}

type discovery struct {
path string
options *BootOptions
c *config.Center
func (fp *discovery) RemoveTable(ctx context.Context, tenant, cluster, table string) error {
//TODO implement me
panic("implement me")
}

func (fp *discovery) Init(ctx context.Context) error {
Expand Down
182 changes: 182 additions & 0 deletions pkg/boot/proto.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package boot

import (
"context"
)

import (
"github.com/arana-db/arana/pkg/config"
"github.com/arana-db/arana/pkg/proto/rule"
)

type Cluster struct {
Tenant string `yaml:"tenant" json:"tenant"`
Type config.DataSourceType `yaml:"type" json:"type"`
}

type GroupBody struct {
Nodes []string `yaml:"nodes" json:"nodes"`
}

type ClusterBody struct {
Type config.DataSourceType `yaml:"type" json:"type"`
SqlMaxLimit int `yaml:"sql_max_limit" json:"sql_max_limit,omitempty"`
Parameters config.ParametersMap `yaml:"parameters" json:"parameters,omitempty"`
}

type NodeBody struct {
Host string `yaml:"host" json:"host"`
Port int `yaml:"port" json:"port"`
Username string `yaml:"username" json:"username"`
Password string `yaml:"password" json:"password"`
Database string `yaml:"database" json:"database"`
Weight string `yaml:"weight" json:"weight"`
Parameters config.ParametersMap `yaml:"parameters" json:"parameters,omitempty"`
ConnProps map[string]interface{} `yaml:"conn_props" json:"conn_props,omitempty"`
Labels map[string]string `yaml:"labels" json:"labels,omitempty"`
}

type TenantBody struct {
Users []*config.User `yaml:"users" json:"users"`
}

type TableBody struct {
Sequence *config.Sequence `yaml:"sequence" json:"sequence"`
AllowFullScan bool `yaml:"allow_full_scan" json:"allow_full_scan,omitempty"`
DbRules []*config.Rule `yaml:"db_rules" json:"db_rules"`
TblRules []*config.Rule `yaml:"tbl_rules" json:"tbl_rules"`
Topology *config.Topology `yaml:"topology" json:"topology"`
ShadowTopology *config.Topology `yaml:"shadow_topology" json:"shadow_topology"`
Attributes map[string]string `yaml:"attributes" json:"attributes"`
}

// ConfigProvider provides configurations.
type ConfigProvider interface {
ConfigUpdater

// ListTenants list tenants name
ListTenants(ctx context.Context) ([]string, error)

// GetTenant returns the tenant info
GetTenant(ctx context.Context, tenant string) (*config.Tenant, error)

// ListClusters lists the cluster names.
ListClusters(ctx context.Context) ([]string, error)

// GetDataSourceCluster returns the dataSourceCluster object
GetDataSourceCluster(ctx context.Context, cluster string) (*config.DataSourceCluster, error)

// GetCluster returns the cluster info
GetCluster(ctx context.Context, cluster string) (*Cluster, error)

// ListGroups lists the group names.
ListGroups(ctx context.Context, cluster string) ([]string, error)

// ListNodes lists the node names.
ListNodes(ctx context.Context, cluster, group string) ([]string, error)

// GetNode returns the node info.
GetNode(ctx context.Context, cluster, group, node string) (*config.Node, error)

// ListTables lists the table names.
ListTables(ctx context.Context, cluster string) ([]string, error)

// GetTable returns the table info.
GetTable(ctx context.Context, cluster, table string) (*rule.VTable, error)
}

// ConfigUpdater represents the mutations of configurations.
// The configuration is designed for structure storage, here is a example in tree-view:
// ── tenants
// ├── google
// │ ├── clusters: [mysql-instance-a,...]
// │ │ ├── employees
// │ │ │ ├── groups
// │ │ │ │ ├── employees_0000
// │ │ │ │ ├── ...
// │ │ │ │ └── employees_0007
// │ │ │ └── tables
// │ │ │ ├── employee
// │ │ │ ├── salary
// │ │ │ └── tax
// │ │ └── products
// │ │ └── groups
// │ │ ├── products_0000
// │ │ ├── ...
// │ │ └── products_0007
// │ └── nodes
// │ ├── mysql-instance-a
// │ ├── ...
// │ └── mysql-instance-x
// └── apple
// ├── ...
// └── ...
type ConfigUpdater interface {
// UpsertTenant upserts a tenant.
UpsertTenant(ctx context.Context, tenant string, body *TenantBody) error

// RemoveTenant removes a tenant.
RemoveTenant(ctx context.Context, tenant string) error

// UpsertCluster upserts a cluster into an existing tenant.
UpsertCluster(ctx context.Context, tenant, cluster string, body *ClusterBody) error

// RemoveCluster removes a cluster from an existing tenant.
RemoveCluster(ctx context.Context, tenant, cluster string) error

// UpsertNode upserts a physical node.
UpsertNode(ctx context.Context, tenant, node string, body *NodeBody) error

// RemoveNode removes a physical node.
RemoveNode(ctx context.Context, tenant, node string) error

// UpsertGroup upserts a group into an existing cluster.
UpsertGroup(ctx context.Context, tenant, cluster, group string, body *GroupBody) error

// RemoveGroup removes a group from an existing cluster.
RemoveGroup(ctx context.Context, tenant, cluster, group string) error

// BindNode binds a node into an existing cluster group.
BindNode(ctx context.Context, tenant, cluster, group, node string) error

// UnbindNode unbinds a node from an existing cluster group.
UnbindNode(ctx context.Context, tenant, cluster, group, node string) error

// UpsertTable upserts a new sharding table rule into a cluster.
UpsertTable(ctx context.Context, tenant, cluster, table string, body *TableBody) error

// RemoveTable removes a sharding table config from an existing cluster.
RemoveTable(ctx context.Context, tenant, cluster, table string) error
}

type Discovery interface {
ConfigProvider
// ListListeners lists the listener names
ListListeners(ctx context.Context) ([]*config.Listener, error)

// ListFilters list the filter names
ListFilters(ctx context.Context) ([]*config.Filter, error)

// GetConfigCenter returns the config center.
GetConfigCenter() *config.Center

// Init initializes discovery with context
Init(ctx context.Context) error
}

0 comments on commit d30318c

Please sign in to comment.