This repository has been archived by the owner on Nov 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes #386 JRA-313 #closes JRA-314 #closes
- Loading branch information
Showing
26 changed files
with
1,559 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package control | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/intelsdi-x/pulse/control/plugin" | ||
"github.com/intelsdi-x/pulse/core/cdata" | ||
"github.com/intelsdi-x/pulse/core/ctypes" | ||
) | ||
|
||
// type configData map[string]*cdata.ConfigDataNode | ||
|
||
type pluginConfig struct { | ||
all *cdata.ConfigDataNode | ||
collector map[string]*pluginConfigItem | ||
publisher map[string]*pluginConfigItem | ||
processor map[string]*pluginConfigItem | ||
pluginCache map[string]*cdata.ConfigDataNode | ||
} | ||
|
||
type pluginConfigItem struct { | ||
*cdata.ConfigDataNode | ||
versions map[int]*cdata.ConfigDataNode | ||
} | ||
|
||
type config struct { | ||
control *cdata.ConfigDataNode | ||
scheduler *cdata.ConfigDataNode | ||
plugins *pluginConfig | ||
} | ||
|
||
func newConfig() *config { | ||
return &config{ | ||
control: cdata.NewNode(), | ||
scheduler: cdata.NewNode(), | ||
plugins: newPluginConfig(), | ||
} | ||
} | ||
|
||
func newPluginConfig() *pluginConfig { | ||
return &pluginConfig{ | ||
all: cdata.NewNode(), | ||
collector: make(map[string]*pluginConfigItem), | ||
processor: make(map[string]*pluginConfigItem), | ||
publisher: make(map[string]*pluginConfigItem), | ||
pluginCache: make(map[string]*cdata.ConfigDataNode), | ||
} | ||
} | ||
|
||
func newPluginConfigItem(opts ...pluginConfigOpt) *pluginConfigItem { | ||
p := &pluginConfigItem{ | ||
ConfigDataNode: cdata.NewNode(), | ||
versions: make(map[int]*cdata.ConfigDataNode), | ||
} | ||
|
||
for _, opt := range opts { | ||
opt(p) | ||
} | ||
|
||
return p | ||
} | ||
|
||
type pluginConfigOpt func(*pluginConfigItem) | ||
|
||
func optAddPluginConfigItem(key string, value ctypes.ConfigValue) pluginConfigOpt { | ||
return func(p *pluginConfigItem) { | ||
p.AddItem(key, value) | ||
} | ||
} | ||
|
||
func (p *pluginConfig) get(pluginType plugin.PluginType, name string, ver int) *cdata.ConfigDataNode { | ||
// check cache | ||
key := fmt.Sprintf("%d:%s:%d", pluginType, name, ver) | ||
if res, ok := p.pluginCache[key]; ok { | ||
return res | ||
} | ||
|
||
//todo process/interpolate values | ||
|
||
p.pluginCache[key] = cdata.NewNode() | ||
p.pluginCache[key].Merge(p.all) | ||
|
||
// check for plugin config | ||
switch pluginType { | ||
case plugin.CollectorPluginType: | ||
if res, ok := p.collector[name]; ok { | ||
p.pluginCache[key].Merge(res.ConfigDataNode) | ||
if res2, ok2 := res.versions[ver]; ok2 { | ||
p.pluginCache[key].Merge(res2) | ||
} | ||
} | ||
case plugin.ProcessorPluginType: | ||
if res, ok := p.processor[name]; ok { | ||
p.pluginCache[key].Merge(res.ConfigDataNode) | ||
if res2, ok2 := res.versions[ver]; ok2 { | ||
p.pluginCache[key].Merge(res2) | ||
} | ||
} | ||
case plugin.PublisherPluginType: | ||
if res, ok := p.publisher[name]; ok { | ||
p.pluginCache[key].Merge(res.ConfigDataNode) | ||
if res2, ok2 := res.versions[ver]; ok2 { | ||
p.pluginCache[key].Merge(res2) | ||
} | ||
} | ||
} | ||
|
||
return p.pluginCache[key] | ||
} |
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,35 @@ | ||
package control | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/intelsdi-x/pulse/control/plugin" | ||
"github.com/intelsdi-x/pulse/core/cdata" | ||
"github.com/intelsdi-x/pulse/core/ctypes" | ||
. "github.com/smartystreets/goconvey/convey" | ||
) | ||
|
||
func TestPluginConfig(t *testing.T) { | ||
Convey("Given a plugin config", t, func() { | ||
cfg := newConfig() | ||
So(cfg, ShouldNotBeNil) | ||
Convey("with an entry for ALL plugins", func() { | ||
cfg.plugins.all.AddItem("gvar", ctypes.ConfigValueBool{Value: true}) | ||
So(len(cfg.plugins.all.Table()), ShouldEqual, 1) | ||
Convey("an entry for a specific plugin of any version", func() { | ||
cfg.plugins.collector["test"] = newPluginConfigItem(optAddPluginConfigItem("pvar", ctypes.ConfigValueBool{Value: true})) | ||
So(len(cfg.plugins.collector["test"].Table()), ShouldEqual, 1) | ||
Convey("and an entry for a specific plugin of a specific version", func() { | ||
cfg.plugins.collector["test"].versions[1] = cdata.NewNode() | ||
cfg.plugins.collector["test"].versions[1].AddItem("vvar", ctypes.ConfigValueBool{Value: true}) | ||
So(len(cfg.plugins.collector["test"].versions[1].Table()), ShouldEqual, 1) | ||
Convey("we can get the merged conf for the given plugin", func() { | ||
cd := cfg.plugins.get(plugin.CollectorPluginType, "test", 1) | ||
So(len(cd.Table()), ShouldEqual, 3) | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
}) | ||
} |
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
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
Oops, something went wrong.
Should
So(len(mts), ShouldBeGreaterThan, 0)
happen first?