Skip to content

Commit

Permalink
Feat/admin api (#401)
Browse files Browse the repository at this point in the history
* feat: add admin api server skeleton (#330)

* feat(config): add config updater api (#336)

* add http server api for cluster. (#352)

* add http server api for tenant (#366)

* add http server api for tenant

* fix import format

* fix go format

Co-authored-by: Zhang Aphelios <aphelios.zhang@shopee.com>

* add  http api for nodes#344 (#371)

* add  http api for nodes

* fix:bug

* fix:bug

* fix:bug

* fix:bug

* feat: add arana-admin into docker compose file

* fix 🐛  HTTP API For UI (#399)

* change

* change

* feat(config): support new config & Feat config listener (#374)

* feat: add group api for UI module #344 (#373)

* add: missing interfaces in proto files and discovery files

* feat: group api in file db_groups.go (#344)

* style: add license header and add tool: imports-formatter

* style: fix import

* feat: support notify event

* refactor:config center

* none

* feat: none

* refactor:split config and add change watch

* style: fix code style

* fix: fix func call error

* fix: ci error

* style:fix code style

* fix: fix code style

* refactor: rebase upstream

* fix:add cluster info to list groups

Co-authored-by: chovychan <51713304+chovychan@users.noreply.github.com>
Co-authored-by: Jeffsky <jjeffcaii@outlook.com>

* fix: compile failure

* fix:unit test (#403)

* Feat/admin api (#404)

* Feat/admin api (#406)

* fix:unit test

* fix:unit test

* fix:file unit test

Co-authored-by: Zonglei Dong <dongzonglei@apache.org>
Co-authored-by: Aphelios <996933971@qq.com>
Co-authored-by: Zhang Aphelios <aphelios.zhang@shopee.com>
Co-authored-by: 龚娜 <2036479155@qq.com>
Co-authored-by: liaochuntao <liaochuntao@live.com>
Co-authored-by: chovychan <51713304+chovychan@users.noreply.github.com>
  • Loading branch information
7 people authored Sep 10, 2022
1 parent 4052423 commit 3dcd8ab
Show file tree
Hide file tree
Showing 49 changed files with 4,448 additions and 1,380 deletions.
91 changes: 91 additions & 0 deletions cmd/admin/admin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* 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 admin

import (
"context"
"fmt"
"os"
"path/filepath"
)

import (
"github.com/spf13/cobra"
)

import (
"github.com/arana-db/arana/cmd/cmds"
"github.com/arana-db/arana/pkg/admin"
_ "github.com/arana-db/arana/pkg/admin/router"
"github.com/arana-db/arana/pkg/boot"
"github.com/arana-db/arana/pkg/constants"
"github.com/arana-db/arana/pkg/util/log"
)

const (
_keyPort = "port"
_defaultPort = 8080
)

func init() {
cmd := &cobra.Command{
Use: "admin",
Short: "admin",
Example: "arana admin -c bootstrap.yaml -p 8080",
RunE: run,
}
cmd.PersistentFlags().
StringP(constants.ConfigPathKey, "c", os.Getenv(constants.EnvBootstrapPath), "bootstrap configuration file path")
cmd.PersistentFlags().
Uint16P(_keyPort, "p", _defaultPort, "listen port")

cmds.Handle(func(root *cobra.Command) {
root.AddCommand(cmd)
})
}

func Run(bootstrapPath string, addr string) error {
discovery := boot.NewDiscovery(bootstrapPath)
if err := discovery.Init(context.Background()); err != nil {
log.Fatal("start admin api server failed: %v", err)
return err
}
adminServer := admin.New(discovery)
return adminServer.Listen(addr)
}

func run(cmd *cobra.Command, args []string) error {
_ = args
btPath, _ := cmd.PersistentFlags().GetString(constants.ConfigPathKey)
port, _ := cmd.PersistentFlags().GetUint16("port")
if len(btPath) < 1 {
// search bootstrap yaml
for _, path := range constants.GetConfigSearchPathList() {
btPath = filepath.Join(path, "bootstrap.yaml")
if _, err := os.Stat(btPath); err == nil {
break
}
btPath = filepath.Join(path, "bootstrap.yml")
if _, err := os.Stat(btPath); err == nil {
break
}
}
}

return Run(btPath, fmt.Sprintf(":%d", port))
}
1 change: 1 addition & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
)

import (
_ "github.com/arana-db/arana/cmd/admin"
"github.com/arana-db/arana/cmd/cmds"
_ "github.com/arana-db/arana/cmd/start"
_ "github.com/arana-db/arana/cmd/tools"
Expand Down
22 changes: 5 additions & 17 deletions cmd/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
import (
"github.com/arana-db/arana/cmd/cmds"
"github.com/arana-db/arana/pkg/boot"
"github.com/arana-db/arana/pkg/config"
"github.com/arana-db/arana/pkg/constants"
"github.com/arana-db/arana/pkg/executor"
"github.com/arana-db/arana/pkg/mysql"
Expand Down Expand Up @@ -78,37 +77,26 @@ func Run(bootstrapConfigPath string, importPath string) {
// print slogan
fmt.Printf("\033[92m%s\033[0m\n", slogan) // 92m: light green

provider := boot.NewProvider(bootstrapConfigPath)
if err := provider.Init(context.Background()); err != nil {
discovery := boot.NewDiscovery(bootstrapConfigPath)
if err := discovery.Init(context.Background()); err != nil {
log.Fatal("start failed: %v", err)
return
}

if len(importPath) > 0 {
c, err := config.Load(importPath)
if err != nil {
log.Fatal("failed to import configuration from %s: %v", importPath, err)
return
}
if err := provider.GetConfigCenter().ImportConfiguration(c); err != nil {
log.Fatal("failed to import configuration from %s: %v", importPath, err)
if !boot.RunImport(bootstrapConfigPath, importPath) {
return
}
}

if err := boot.Boot(context.Background(), provider); err != nil {
if err := boot.Boot(context.Background(), discovery); err != nil {
log.Fatal("start failed: %v", err)
return
}

propeller := server.NewServer()

listenersConf, err := provider.ListListeners(context.Background())
if err != nil {
log.Fatal("start failed: %v", err)
return
}

listenersConf := discovery.ListListeners(context.Background())
for _, listenerConf := range listenersConf {
listener, err := mysql.NewListener(listenerConf)
if err != nil {
Expand Down
30 changes: 6 additions & 24 deletions cmd/tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package tools

import (
"context"
"os"
)

Expand All @@ -29,9 +28,7 @@ import (
import (
"github.com/arana-db/arana/cmd/cmds"
"github.com/arana-db/arana/pkg/boot"
"github.com/arana-db/arana/pkg/config"
"github.com/arana-db/arana/pkg/constants"
"github.com/arana-db/arana/pkg/util/log"
)

var (
Expand All @@ -45,7 +42,7 @@ func init() {
Use: "import",
Short: "import arana config",
Example: "./arana import -c ../docker/conf/bootstrap.yaml -s ../docker/conf/config.yaml",
Run: Run,
Run: run,
}

cmd.PersistentFlags().
Expand All @@ -58,25 +55,10 @@ func init() {
})
}

func Run(cmd *cobra.Command, args []string) {
_, _ = cmd, args

provider := boot.NewProvider(importBootConfPath)
if err := provider.Init(context.Background()); err != nil {
log.Fatal("init failed: %+v", err)
return
}

cfg, err := config.Load(sourceConfigPath)
if err != nil {
log.Fatal("load config from %s failed: %+v", sourceConfigPath, err)
return
}

c := provider.GetConfigCenter()
func run(_ *cobra.Command, _ []string) {
Run(importBootConfPath, sourceConfigPath)
}

if err := c.ImportConfiguration(cfg); err != nil {
log.Fatal("persist config to config.store failed: %+v", err)
return
}
func Run(importConfPath, configPath string) {
boot.RunImport(importConfPath, configPath)
}
21 changes: 21 additions & 0 deletions conf/bootstrap.local-etcd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# 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.
#

config:
name: etcd
options:
endpoints: "http://127.0.0.1:2379"
34 changes: 22 additions & 12 deletions conf/bootstrap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,29 @@
# limitations under the License.
#

kind: ConfigMap
apiVersion: "1.0"
listeners:
- protocol_type: mysql
server_version: 5.7.0
socket_address:
address: 0.0.0.0
port: 13306
config:
name: file
options:

# name: etcd
# options:
# endpoints: "http://localhost:2379"
# name: nacos
# options:
# endpoints: "localhost:8080"
# namespace: arana
# group: arana
# contextPath: /nacos
# scheme: http
# username: nacos
# password: nacos
# name: etcd
# root_path: arana
# options:
# endpoints: "http://127.0.0.1:2379"

# name: nacos
# options:
# endpoints: "127.0.0.1:8848"
# namespace: arana
# group: arana
# contextPath: /nacos
# scheme: http
# username: nacos
# password: nacos
Loading

0 comments on commit 3dcd8ab

Please sign in to comment.