Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Fixes merging plugin config for specific type, name, version of a plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
jcooklin authored and pittma committed Oct 29, 2015
1 parent 512ba49 commit 816d981
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
36 changes: 36 additions & 0 deletions control/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,18 @@ func (p *pluginConfig) mergePluginConfigDataNode(pluginType core.PluginType, nam
}
res.Merge(cdn)
return
} else {
if name != "" {
cn := cdata.NewNode()
cn.Merge(cdn)
p.Collector.Plugins[name] = newPluginConfigItem()
if ver > 0 {
p.Collector.Plugins[name].Versions = map[int]*cdata.ConfigDataNode{ver: cn}
return
}
p.Collector.Plugins[name].ConfigDataNode = cn
return
}
}
p.Collector.All.Merge(cdn)
case core.ProcessorPluginType:
Expand All @@ -206,6 +218,18 @@ func (p *pluginConfig) mergePluginConfigDataNode(pluginType core.PluginType, nam
}
res.Merge(cdn)
return
} else {
if name != "" {
cn := cdata.NewNode()
cn.Merge(cdn)
p.Processor.Plugins[name] = newPluginConfigItem()
if ver > 0 {
p.Processor.Plugins[name].Versions = map[int]*cdata.ConfigDataNode{ver: cn}
return
}
p.Processor.Plugins[name].ConfigDataNode = cn
return
}
}
p.Processor.All.Merge(cdn)
case core.PublisherPluginType:
Expand All @@ -216,6 +240,18 @@ func (p *pluginConfig) mergePluginConfigDataNode(pluginType core.PluginType, nam
}
res.Merge(cdn)
return
} else {
if name != "" {
cn := cdata.NewNode()
cn.Merge(cdn)
p.Publisher.Plugins[name] = newPluginConfigItem()
if ver > 0 {
p.Publisher.Plugins[name].Versions = map[int]*cdata.ConfigDataNode{ver: cn}
return
}
p.Publisher.Plugins[name].ConfigDataNode = cn
return
}
}
p.Publisher.All.Merge(cdn)
}
Expand Down
13 changes: 12 additions & 1 deletion mgmt/rest/rest_func_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ func TestPluginRestCalls(t *testing.T) {
port := getPort()
startAPI(port)
col := core.CollectorPluginType
pub := core.PublisherPluginType
Convey("A global plugin config is added for all plugins", func() {
cdn := cdata.NewNode()
cdn.AddItem("password", ctypes.ConfigValueStr{Value: "p@ssw0rd"})
Expand Down Expand Up @@ -508,12 +509,22 @@ func TestPluginRestCalls(t *testing.T) {
Convey("A plugin config is added for a specific version of a publisher", func() {
cdn := cdata.NewNode()
cdn.AddItem("rate", ctypes.ConfigValueFloat{Value: .8})
r := setPluginConfigItem(port, core.PublisherPluginType.String(), "influxdb", "", cdn)
r := setPluginConfigItem(port, core.PublisherPluginType.String(), "influxdb", "1", cdn)
So(r.Body, ShouldHaveSameTypeAs, &rbody.SetPluginConfigItem{})
r1 := r.Body.(*rbody.SetPluginConfigItem)
So(r1.Table()["rate"], ShouldResemble, ctypes.ConfigValueFloat{Value: .8})
So(len(r1.Table()), ShouldEqual, 4)

r2 := getPluginConfigItem(port, &pub, "", "")
So(r2.Body, ShouldHaveSameTypeAs, &rbody.PluginConfigItem{})
r3 := r2.Body.(*rbody.PluginConfigItem)
So(len(r3.Table()), ShouldEqual, 2)

r4 := getPluginConfigItem(port, &pub, "influxdb", "1")
So(r4.Body, ShouldHaveSameTypeAs, &rbody.PluginConfigItem{})
r5 := r4.Body.(*rbody.PluginConfigItem)
So(len(r5.Table()), ShouldEqual, 4)

Convey("A global plugin config field is deleted", func() {
r := deletePluginConfigItem(port, "", "", "", []string{"password"})
So(r.Body, ShouldHaveSameTypeAs, &rbody.DeletePluginConfigItem{})
Expand Down

0 comments on commit 816d981

Please sign in to comment.