Skip to content

Commit

Permalink
refactor: rebase upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
chuntaojun committed Sep 4, 2022
1 parent cdcfcc3 commit 94c79a9
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 59 deletions.
9 changes: 1 addition & 8 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 @@ -85,13 +84,7 @@ func Run(bootstrapConfigPath string, importPath string) {
}

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 := discovery.GetConfigCenter().ImportConfiguration(c); err != nil {
log.Fatal("failed to import configuration from %s: %v", importPath, err)
if !boot.RunImport(bootstrapConfigPath, importPath) {
return
}
}
Expand Down
50 changes: 2 additions & 48 deletions cmd/tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package tools

import (
"context"
"github.com/arana-db/arana/pkg/boot"
"os"
)

Expand All @@ -28,10 +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 Down Expand Up @@ -63,48 +60,5 @@ func run(_ *cobra.Command, _ []string) {
}

func Run(importConfPath, configPath string) {
bootCfg, err := boot.LoadBootOptions(importConfPath)
if err != nil {
log.Fatalf("load bootstrap config failed: %+v", err)
}

if err := config.Init(*bootCfg.Config, bootCfg.APIVersion); err != nil {
log.Fatal()
}

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

tenantOp, err := config.NewTenantOperator(config.GetStoreOperate())
if err != nil {
log.Fatal("build tenant operator failed: %+v", configPath, err)
return
}

for i := range cfg.Data.Tenants {
if err := tenantOp.CreateTenant(cfg.Data.Tenants[i].Name); err != nil {
log.Fatal("create tenant failed: %+v", configPath, err)
return
}
}

for i := range cfg.Data.Tenants {

tenant := cfg.Data.Tenants[i]

tenant.APIVersion = cfg.APIVersion
tenant.Metadata = cfg.Metadata

op := config.NewCenter(tenant.Name, config.GetStoreOperate())

if err := op.Import(context.Background(), tenant); err != nil {
log.Fatalf("persist config to config.store failed: %+v", err)
return
}
}

log.Infof("finish import config into config_center")
boot.RunImport(importConfPath, configPath)
}
84 changes: 84 additions & 0 deletions pkg/boot/discovery_import.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* 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"
"github.com/arana-db/arana/pkg/config"
"github.com/arana-db/arana/pkg/util/log"
)

func RunImport(importConfPath, configPath string) bool {
bootCfg, err := LoadBootOptions(importConfPath)
if err != nil {
log.Fatalf("load bootstrap config failed: %+v", err)
}

if err := config.Init(*bootCfg.Config, bootCfg.APIVersion); err != nil {
log.Fatal()
}

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

tenantOp, err := config.NewTenantOperator(config.GetStoreOperate())
if err != nil {
log.Fatal("build tenant operator failed: %+v", configPath, err)
return false
}

defer tenantOp.Close()

for i := range cfg.Data.Tenants {
if err := tenantOp.CreateTenant(cfg.Data.Tenants[i].Name); err != nil {
log.Fatal("create tenant failed: %+v", configPath, err)
return false
}
}

for i := range cfg.Data.Tenants {

tenant := cfg.Data.Tenants[i]

tenant.APIVersion = cfg.APIVersion
tenant.Metadata = cfg.Metadata

ok := func() bool {
op := config.NewCenter(tenant.Name, config.GetStoreOperate())
defer op.Close()

if err := op.Import(context.Background(), tenant); err != nil {
log.Fatalf("persist config to config.store failed: %+v", err)
return false
}

return true
}()

if !ok {
return false
}
}

log.Infof("finish import config into config_center")
return true
}
3 changes: 0 additions & 3 deletions pkg/boot/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,6 @@ type Discovery interface {
// ListListeners lists the listener names
ListListeners(ctx context.Context) []*config.Listener

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

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

0 comments on commit 94c79a9

Please sign in to comment.