Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCB-2176 Decompose the plugin and server pkg #937

Merged
merged 1 commit into from
Apr 12, 2021

Conversation

little-cui
Copy link
Member

@little-cui little-cui commented Apr 8, 2021

重构背景

  1. server/plugin/plugin.go本身的设计初衷是作为公共的插件管理器,但由于实现中依赖了server/config包,形成了公共库反向依赖组件server的问题。

  2. 分析了依赖config的原因,在插件实例化过程中,需要提供一个插件实现名字来定义管理器生成的插件实例,当前实现是通过server的配置读取的。

// server/plugin/plugin.go
name := config.GetString(pn.String()+".kind", Buildin, config.WithStandby(pn.String()+"_plugin"))
p, ok = m[ImplName(name)]

解决方案

  1. 依赖反转,plugin提供新的接口,负责插件的业务自定义配置pkg/plugin/types.go 的Configurator,自身也提供默认实现 pkg/plugin/config.go 的DefaultConfigurator
// Configurator provides the interfaces for obtaining configs in
// plugin mgr's operations, user can customize the impl
type Configurator interface {
	GetImplName(kind Kind) string
	GetPluginDir() string
}
  1. server侧实现Configurator接口,server/config/types.go 的 Config。在Init阶段注册到插件管理器
plugin.RegisterConfigurator(Configurations)
  1. 完成1-2后,plugin可以从server中解耦出来。

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a JIRA issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a JIRA issue. Your pull request should address just this issue, without pulling in other changes.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Format the pull request title like [SCB-XXX] Fixes bug in ApproximateQuantiles, where you replace SCB-XXX with the appropriate JIRA issue.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run go build go test go fmt go vet to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.
  • Never comment source code, delete it.
  • UT should has "context, subject, expected result" result as test case name, when you call t.Run().

@tianxiaoliang
Copy link
Contributor

tianxiaoliang commented Apr 12, 2021

please claim your motivation and solution

@tianxiaoliang tianxiaoliang merged commit c8860df into apache:master Apr 12, 2021
@little-cui little-cui deleted the v2.x branch April 12, 2021 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants