forked from arana-db/arana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ISSUE arana-db#125、arana-db#126] support nacos and import config int…
…o nacos、etcd (arana-db#130) * refactor: 配置中心模块重构 * feat: 添加etcd & file的配置存储实现 * feat: feat issue arana-db#62 * feat: feat issue arana-db#62 * fix: fix pr comment * fix: fix test fail * style: fix import style * fix: fix code style * feat: 支持nacos * feat: support use command to persist into config.store * fix: 修复import逻辑问题 * fix: fix watch error * fix: rollback modify docker/conf/bootstrap.yaml * style: fix codestyle error * style: fix liscense header * style: fix style * refactor: 优化bootstrap.yaml文件结构 * refactor: 调整结构 * fix: fix CI error * style: 移除无效的导入 * style: fix License header * style: fix pr issue * refactor: 调整代码结构 Co-authored-by: springliao <[email protected]>
- Loading branch information
1 parent
2a9fe4b
commit d5e6b7f
Showing
24 changed files
with
1,299 additions
and
264 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* 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 main | ||
|
||
func main() { | ||
Execute() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* 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 main | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
) | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
import ( | ||
"github.com/arana-db/arana/pkg/boot" | ||
"github.com/arana-db/arana/pkg/executor" | ||
filter "github.com/arana-db/arana/pkg/filters" | ||
"github.com/arana-db/arana/pkg/mysql" | ||
"github.com/arana-db/arana/pkg/server" | ||
"github.com/arana-db/arana/pkg/util/log" | ||
) | ||
|
||
var ( | ||
startCommand = &cobra.Command{ | ||
Use: "start", | ||
Short: "start arana", | ||
Example: "arana start -c bootstrap.yaml", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
provider := boot.NewProvider(bootstrapConfigPath) | ||
if err := boot.Boot(context.Background(), provider); err != nil { | ||
log.Fatal("start failed: %v", err) | ||
return | ||
} | ||
|
||
filters, err := provider.ListFilters(context.Background()) | ||
if err != nil { | ||
log.Fatal("start failed: %v", err) | ||
return | ||
} | ||
|
||
for _, filterConf := range filters { | ||
factory := filter.GetFilterFactory(filterConf.Name) | ||
if factory == nil { | ||
panic(errors.Errorf("there is no filter factory for filter: %s", filterConf.Name)) | ||
} | ||
f, err := factory.NewFilter(filterConf.Config) | ||
if err != nil { | ||
panic(errors.WithMessagef(err, "failed to create filter: %s", filterConf.Name)) | ||
} | ||
filter.RegisterFilter(f.GetName(), f) | ||
} | ||
|
||
propeller := server.NewServer() | ||
|
||
listenersConf, err := provider.ListListeners(context.Background()) | ||
if err != nil { | ||
log.Fatal("start failed: %v", err) | ||
return | ||
} | ||
|
||
for _, listenerConf := range listenersConf { | ||
listener, err := mysql.NewListener(listenerConf) | ||
if err != nil { | ||
log.Fatalf("create listener failed: %v", err) | ||
return | ||
} | ||
executor := executor.NewRedirectExecutor() | ||
listener.SetExecutor(executor) | ||
propeller.AddListener(listener) | ||
} | ||
propeller.Start() | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
c := make(chan os.Signal, 2) | ||
signal.Notify(c, os.Interrupt, syscall.SIGTERM) | ||
go func() { | ||
<-c | ||
cancel() | ||
<-c | ||
os.Exit(1) // second signal. Exit directly. | ||
}() | ||
select { | ||
case <-ctx.Done(): | ||
return | ||
} | ||
}, | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* 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 main | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
import ( | ||
"github.com/arana-db/arana/pkg/boot" | ||
"github.com/arana-db/arana/pkg/config" | ||
"github.com/arana-db/arana/pkg/util/log" | ||
) | ||
|
||
var ( | ||
sourceConfigPath string | ||
) | ||
|
||
var ( | ||
confImportCommand = &cobra.Command{ | ||
Use: "import", | ||
Short: "import arana config", | ||
Example: "./arana import -c ../docker/conf/bootstrap.yaml -s ../docker/conf/config.yaml", | ||
Run: func(*cobra.Command, []string) { | ||
provider := boot.NewProvider(importBootConfPath) | ||
if err := provider.Init(context.Background()); err != nil { | ||
log.Fatal("init failed: %+v", err) | ||
return | ||
} | ||
|
||
cfg, err := config.LoadV2(sourceConfigPath) | ||
if err != nil { | ||
log.Fatal("load config from %s failed: %+v", sourceConfigPath, err) | ||
return | ||
} | ||
|
||
c := provider.GetConfigCenter() | ||
|
||
if err := c.ImportConfiguration(cfg); err != nil { | ||
log.Fatal("persist config to config.store failed: %+v", err) | ||
return | ||
} | ||
}, | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.