diff --git a/bfe_config/bfe_conf/conf_basic.go b/bfe_config/bfe_conf/conf_basic.go index 51a81daa..04bc39bc 100644 --- a/bfe_config/bfe_conf/conf_basic.go +++ b/bfe_config/bfe_conf/conf_basic.go @@ -16,7 +16,6 @@ package bfe_conf import ( "fmt" - "strings" ) import ( @@ -32,11 +31,6 @@ const ( BalancerNone = "NONE" // layer4 balancer not used ) -const ( - // LibrarySuffix defines BFE plugin's file suffix. - LibrarySuffix = ".so" -) - type ConfigBasic struct { HttpPort int // listen port for http HttpsPort int // listen port for https @@ -59,7 +53,6 @@ type ConfigBasic struct { KeepAliveEnabled bool // if false, client connection is shutdown disregard of http headers Modules []string // modules to load - Plugins []string // plugins to load // location of data files for bfe_route HostRuleConf string // path of host_rule.data @@ -217,11 +210,6 @@ func basicConfCheck(cfg *ConfigBasic) error { return fmt.Errorf("MaxHeaderHeaderBytes[%d] should > 0", cfg.MaxHeaderBytes) } - // check Plugins - if err := checkPlugins(cfg); err != nil { - return fmt.Errorf("plugins[%v] check failed. err: %s", cfg.Plugins, err.Error()) - } - return nil } @@ -240,24 +228,6 @@ func checkLayer4LoadBalancer(cfg *ConfigBasic) error { } } -func checkPlugins(cfg *ConfigBasic) error { - plugins := []string{} - for _, pluginPath := range cfg.Plugins { - pluginPath = strings.TrimSpace(pluginPath) - if pluginPath == "" { - continue - } - - if !strings.HasSuffix(pluginPath, LibrarySuffix) { - pluginPath += LibrarySuffix - } - plugins = append(plugins, pluginPath) - } - cfg.Plugins = plugins - - return nil -} - func dataFileConfCheck(cfg *ConfigBasic, confRoot string) error { // check HostRuleConf if cfg.HostRuleConf == "" { diff --git a/bfe_module/bfe_plugin.go b/bfe_module/bfe_plugin.go deleted file mode 100644 index 0f760616..00000000 --- a/bfe_module/bfe_plugin.go +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright (c) 2019 The BFE Authors. -// -// Licensed 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 bfe_module - -import ( - "fmt" - goplugin "plugin" -) - -import ( - "github.com/baidu/go-lib/log" - "github.com/baidu/go-lib/web-monitor/web_monitor" -) - -import ( - "github.com/bfenetworks/bfe/bfe_util/semver" -) - -type BfePlugins struct { - workPlugins map[string]*PluginInfo // work plugins, configure in bfe conf file -} - -// NewBfePlugins create new Plugins -func NewBfePlugins() *BfePlugins { - pl := new(BfePlugins) - pl.workPlugins = make(map[string]*PluginInfo) - - return pl -} - -// RegisterPlugin loads a plugin created with `go build -buildmode=plugin` -func (p *BfePlugins) RegisterPlugin(path string, bfeVersion string) error { - plugin, err := goplugin.Open(path) - if err != nil { - return fmt.Errorf("RegisterPlugin Open plugin path %v err:%v", path, err) - } - - nameSym, err := plugin.Lookup("Name") - if err != nil { - return fmt.Errorf("RegisterPlugin Lookup Name err:%v", err) - } - - versionSym, err := plugin.Lookup("Version") - if err != nil { - return fmt.Errorf("RegisterPlugin Lookup Version err:%v", err) - } - - initSym, err := plugin.Lookup("Init") - if err != nil { - return fmt.Errorf("RegisterPlugin Lookup Init err:%v", err) - } - - version := *versionSym.(*string) - - // Compare versions bfe major version and plugin major version - bfeVer, err := semver.New(bfeVersion) - if err != nil { - return fmt.Errorf("RegisterPlugin bfe version err:%v", err) - } - pluginVer, err := semver.New(version) - if err != nil { - return fmt.Errorf("RegisterPlugin plugin version err:%v", err) - } - if bfeVer.CompareMajor(pluginVer) != 0 { - return fmt.Errorf("RegisterPlugin Major version not match, bfe:%s, plugin:%s", bfeVersion, version) - } - - pluginInfo := &PluginInfo{ - Name: *nameSym.(*string), - Version: version, - Path: path, - Init: initSym.(func(cbs *BfeCallbacks, whs *web_monitor.WebHandlers, cr string) error), - } - p.workPlugins[pluginInfo.Name] = pluginInfo - - return nil -} - -// Init initializes bfe plugins. -// -// Params: -// - cbs: BfeCallbacks -// - whs: WebHandlers -// - cr : root path for config -func (p *BfePlugins) Init(cbs *BfeCallbacks, whs *web_monitor.WebHandlers, cr string) error { - for _, pl := range p.workPlugins { - if err := pl.Init(cbs, whs, cr); err != nil { - log.Logger.Error("Err in plugin.init() for %s [%s]", - pl.Name, err.Error()) - return err - } - - log.Logger.Info("%s:Init() Version:%s OK", pl.Name, pl.Version) - } - - return nil -} diff --git a/bfe_module/bfe_plugin_info.go b/bfe_module/bfe_plugin_info.go deleted file mode 100644 index 23ca4090..00000000 --- a/bfe_module/bfe_plugin_info.go +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) 2019 The BFE Authors. -// -// Licensed 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 bfe_module - -import ( - "github.com/baidu/go-lib/web-monitor/web_monitor" -) - -type PluginInfo struct { - Name string - Version string - Description string - Kind string // TODO plugin kind - Path string - Init func(cbs *BfeCallbacks, whs *web_monitor.WebHandlers, cr string) error -} diff --git a/bfe_server/bfe_server.go b/bfe_server/bfe_server.go index c50fa5f6..cfd5fa3e 100644 --- a/bfe_server/bfe_server.go +++ b/bfe_server/bfe_server.go @@ -76,7 +76,6 @@ type BfeServer struct { // module and callback CallBacks *bfe_module.BfeCallbacks // call back functions Modules *bfe_module.BfeModules // bfe modules - Plugins *bfe_module.BfePlugins // bfe plugins // web server for bfe monitor and reload Monitor *BfeMonitor @@ -121,8 +120,6 @@ func NewBfeServer(cfg bfe_conf.BfeConfig, confRoot string, s.CallBacks = bfe_module.NewBfeCallbacks() // create modules s.Modules = bfe_module.NewBfeModules() - // create plugins - s.Plugins = bfe_module.NewBfePlugins() // initialize balTable s.balTable = bfe_balance.NewBalTable(s.GetCheckConf) @@ -317,26 +314,6 @@ func (srv *BfeServer) InitModules() error { return srv.Modules.Init(srv.CallBacks, srv.Monitor.WebHandlers, srv.ConfRoot) } -func (srv *BfeServer) LoadPlugins(plugins []string) error { - if len(plugins) == 0 { - return nil - } - - for _, pluginPath := range plugins { - if err := srv.Plugins.RegisterPlugin(pluginPath, srv.Version); err != nil { - return err - } - - log.Logger.Info("RegisterPlugin():pluginPath=%s", pluginPath) - } - - return nil -} - -func (srv *BfeServer) InitPlugins() error { - return srv.Plugins.Init(srv.CallBacks, srv.Monitor.WebHandlers, srv.ConfRoot) -} - func (srv *BfeServer) InitSignalTable() { /* create signal table */ srv.SignalTable = signal_table.NewSignalTable() diff --git a/bfe_server/bfe_server_init.go b/bfe_server/bfe_server_init.go index 6124568c..43fa7e85 100644 --- a/bfe_server/bfe_server_init.go +++ b/bfe_server/bfe_server_init.go @@ -79,20 +79,6 @@ func StartUp(cfg bfe_conf.BfeConfig, version string, confRoot string, dryRun boo } log.Logger.Info("StartUp():bfeServer.InitModules() OK") - // load plugins - if err = bfeServer.LoadPlugins(cfg.Server.Plugins); err != nil { - log.Logger.Error("StartUp():bfeServer.LoadPlugins():%s", err.Error()) - return err - } - - // initialize plugins - if err = bfeServer.InitPlugins(); err != nil { - log.Logger.Error("StartUp():bfeServer.InitPlugins():%s", - err.Error()) - return err - } - log.Logger.Info("StartUp():bfeServer.InitPlugins() OK") - if dryRun { return nil }