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

Commit

Permalink
Merges global plugin config when validating a task
Browse files Browse the repository at this point in the history
  • Loading branch information
jcooklin committed Oct 17, 2015
1 parent 6d82687 commit cdac3ca
Show file tree
Hide file tree
Showing 33 changed files with 123 additions and 50 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#http://www.apache.org/licenses/LICENSE-2.0.txt
#
#
#Copyright 2015 Intel Coporation
#Copyright 2015 Intel Corporation
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
http://www.apache.org/licenses/LICENSE-2.0.txt
Copyright 2015 Intel Coporation
Copyright 2015 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion cmd/pulsectl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
http://www.apache.org/licenses/LICENSE-2.0.txt
Copyright 2015 Intel Coporation
Copyright 2015 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
19 changes: 19 additions & 0 deletions control/config.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*
http://www.apache.org/licenses/LICENSE-2.0.txt
Copyright 2015 Intel Corporation
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 control

import (
Expand Down
19 changes: 19 additions & 0 deletions control/config_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*
http://www.apache.org/licenses/LICENSE-2.0.txt
Copyright 2015 Intel Corporation
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 control

import (
Expand Down
13 changes: 13 additions & 0 deletions control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,11 @@ func (p *pluginControl) ValidateDeps(mts []core.Metric, plugins []core.Subscribe

//validate plugins
for _, plg := range plugins {
typ, err := core.ToPluginType(plg.TypeName())
if err != nil {
return []perror.PulseError{perror.New(err)}
}
plg.Config().Merge(p.Config.Plugins.getPluginConfigDataNode(typ, plg.Name(), plg.Version()))
errs := p.validatePluginSubscription(plg)
if len(errs) > 0 {
perrs = append(perrs, errs...)
Expand Down Expand Up @@ -408,8 +413,16 @@ func (p *pluginControl) validateMetricTypeSubscription(mt core.RequestedMetric,
perrs = append(perrs, perror.New(errors.New(fmt.Sprintf("no metric found cannot subscribe: (%s) version(%d)", mt.Namespace(), mt.Version()))))
return nil, perrs
}

m.config = cd

// merge global plugin config
typ, perr := core.ToPluginType(m.Plugin.TypeName())
if perr != nil {
return nil, []perror.PulseError{perror.New(err)}
}
m.config.Merge(p.Config.Plugins.getPluginConfigDataNode(typ, m.Plugin.Name(), m.Plugin.Version()))

// When a metric is added to the MetricCatalog, the policy of rules defined by the plugin is added to the metric's policy.
// If no rules are defined for a metric, we set the metric's policy to an empty ConfigPolicyNode.
// Checking m.policy for nil will not work, we need to check if rules are nil.
Expand Down
64 changes: 43 additions & 21 deletions control/control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,26 +658,47 @@ func (m MockMetricType) Data() interface{} {
}

func TestMetricConfig(t *testing.T) {
c := New()
c.Start()
lpe := newListenToPluginEvent()
c.eventManager.RegisterHandler("Control.PluginLoaded", lpe)
c.Load(JSONRPC_PluginPath)
<-lpe.done
cd := cdata.NewNode()
m1 := MockMetricType{
namespace: []string{"intel", "dummy", "foo"},
}
metric, errs := c.validateMetricTypeSubscription(m1, cd)
Convey("So metric should not be valid without config", t, func() {
So(metric, ShouldBeNil)
So(errs, ShouldNotBeNil)
Convey("required config provided by task", t, func() {
c := New()
c.Start()
lpe := newListenToPluginEvent()
c.eventManager.RegisterHandler("Control.PluginLoaded", lpe)
c.Load(JSONRPC_PluginPath)
<-lpe.done
cd := cdata.NewNode()
m1 := MockMetricType{
namespace: []string{"intel", "dummy", "foo"},
}
metric, errs := c.validateMetricTypeSubscription(m1, cd)
Convey("So metric should not be valid without config", func() {
So(metric, ShouldBeNil)
So(errs, ShouldNotBeNil)
})
cd.AddItem("password", ctypes.ConfigValueStr{Value: "testval"})
metric, errs = c.validateMetricTypeSubscription(m1, cd)
Convey("So metric should be valid with config", func() {
So(errs, ShouldBeNil)
So(metric, ShouldNotBeNil)
})
})
cd.AddItem("password", ctypes.ConfigValueStr{Value: "testval"})
metric, errs = c.validateMetricTypeSubscription(m1, cd)
Convey("So metric should be valid with config", t, func() {
So(errs, ShouldBeNil)
So(metric, ShouldNotBeNil)
Convey("required config provided by global plugin config", t, func() {
config := NewConfig()
c := New(OptSetConfig(config))
c.Start()
lpe := newListenToPluginEvent()
c.eventManager.RegisterHandler("Control.PluginLoaded", lpe)
c.Load(JSONRPC_PluginPath)
<-lpe.done
cd := cdata.NewNode()
m1 := MockMetricType{
namespace: []string{"intel", "dummy", "foo"},
}
config.Plugins.All.AddItem("password", ctypes.ConfigValueStr{Value: "testval"})
metric, errs := c.validateMetricTypeSubscription(m1, cd)
Convey("So metric should be valid with config", func() {
So(errs, ShouldBeNil)
So(metric, ShouldNotBeNil)
})
})
}

Expand Down Expand Up @@ -793,7 +814,8 @@ func TestPublishMetrics(t *testing.T) {
plugin.PingTimeoutDurationDefault = time.Second * 1

// Create controller
c := New()
config := NewConfig()
c := New(OptSetConfig(config))
lpe := newListenToPluginEvent()
c.eventManager.RegisterHandler("TestPublishMetrics", lpe)
c.pluginRunner.(*runner).monitor.duration = time.Millisecond * 100
Expand All @@ -812,7 +834,7 @@ func TestPublishMetrics(t *testing.T) {

Convey("Subscribe to file publisher with good config", func() {
n := cdata.NewNode()
n.AddItem("file", ctypes.ConfigValueStr{Value: "/tmp/pulse-TestPublishMetrics.out"})
config.Plugins.Publisher.Plugins[lp.Name()] = newPluginConfigItem(optAddPluginConfigItem("file", ctypes.ConfigValueStr{Value: "/tmp/pulse-TestPublishMetrics.out"}))
p := mockPlugin{
name: "file",
pluginType: core.PublisherPluginType,
Expand Down
2 changes: 1 addition & 1 deletion control/plugin_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func TestLoadPlugin(t *testing.T) {
Convey("loads plugin with cache TTL set", func() {
p := newPluginManager()
p.SetMetricCatalog(newMetricCatalog())
lp, err := p.LoadPlugin(PluginPath, nil)
lp, err := p.LoadPlugin(JSONRPC_PluginPath, nil)

So(err, ShouldBeNil)
So(lp.Meta.CacheTTL, ShouldNotBeNil)
Expand Down
2 changes: 1 addition & 1 deletion docs/PULSED.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
http://www.apache.org/licenses/LICENSE-2.0.txt
Copyright 2015 Intel Coporation
Copyright 2015 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
http://www.apache.org/licenses/LICENSE-2.0.txt
Copyright 2015 Intel Coporation
Copyright 2015 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion examples/influxdb-grafana/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
http://www.apache.org/licenses/LICENSE-2.0.txt
Copyright 2015 Intel Coporation
Copyright 2015 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion examples/influxdb-grafana/influxdb/0.9/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#http://www.apache.org/licenses/LICENSE-2.0.txt
#
#
#Copyright 2015 Intel Coporation
#Copyright 2015 Intel Corporation
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion examples/influxdb-grafana/run-pcm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#http://www.apache.org/licenses/LICENSE-2.0.txt
#
#
#Copyright 2015 Intel Coporation
#Copyright 2015 Intel Corporation
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion examples/influxdb-grafana/run-psutil.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#http://www.apache.org/licenses/LICENSE-2.0.txt
#
#
#Copyright 2015 Intel Coporation
#Copyright 2015 Intel Corporation
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion examples/influxdb-grafana/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#http://www.apache.org/licenses/LICENSE-2.0.txt
#
#
#Copyright 2015 Intel Coporation
#Copyright 2015 Intel Corporation
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion examples/linux_prep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#http://www.apache.org/licenses/LICENSE-2.0.txt
#
#
#Copyright 2015 Intel Coporation
#Copyright 2015 Intel Corporation
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion examples/riemann/Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#http://www.apache.org/licenses/LICENSE-2.0.txt
#
#
#Copyright 2015 Intel Coporation
#Copyright 2015 Intel Corporation
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion examples/riemann/script/init.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#http://www.apache.org/licenses/LICENSE-2.0.txt
#
#
#Copyright 2015 Intel Coporation
#Copyright 2015 Intel Corporation
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion examples/tasks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
http://www.apache.org/licenses/LICENSE-2.0.txt
Copyright 2015 Intel Coporation
Copyright 2015 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion examples/videos.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#http://www.apache.org/licenses/LICENSE-2.0.txt
#
#
#Copyright 2015 Intel Coporation
#Copyright 2015 Intel Corporation
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion mgmt/rest/client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
http://www.apache.org/licenses/LICENSE-2.0.txt
Copyright 2015 Intel Coporation
Copyright 2015 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion mgmt/rest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
http://www.apache.org/licenses/LICENSE-2.0.txt
Copyright 2015 Intel Coporation
Copyright 2015 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion mgmt/rest/rbody/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
http://www.apache.org/licenses/LICENSE-2.0.txt
Copyright 2015 Intel Coporation
Copyright 2015 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion mgmt/rest/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
http://www.apache.org/licenses/LICENSE-2.0.txt
Copyright 2015 Intel Coporation
Copyright 2015 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion plugin/collector/pulse-collector-dummy1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
http://www.apache.org/licenses/LICENSE-2.0.txt
Copyright 2015 Intel Coporation
Copyright 2015 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion plugin/collector/pulse-collector-dummy2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
http://www.apache.org/licenses/LICENSE-2.0.txt
Copyright 2015 Intel Coporation
Copyright 2015 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion plugin/publisher/pulse-publisher-file/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
http://www.apache.org/licenses/LICENSE-2.0.txt
Copyright 2015 Intel Coporation
Copyright 2015 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion scripts/build-plugin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#http://www.apache.org/licenses/LICENSE-2.0.txt
#
#
#Copyright 2015 Intel Coporation
#Copyright 2015 Intel Corporation
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#http://www.apache.org/licenses/LICENSE-2.0.txt
#
#
#Copyright 2015 Intel Coporation
#Copyright 2015 Intel Corporation
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion scripts/deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#http://www.apache.org/licenses/LICENSE-2.0.txt
#
#
#Copyright 2015 Intel Coporation
#Copyright 2015 Intel Corporation
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
Expand Down
Loading

0 comments on commit cdac3ca

Please sign in to comment.