当前位置: 首页>>代码示例>>Golang>>正文


Golang cdata.NewNode函数代码示例

本文整理汇总了Golang中github.com/intelsdi-x/snap/core/cdata.NewNode函数的典型用法代码示例。如果您正苦于以下问题:Golang NewNode函数的具体用法?Golang NewNode怎么用?Golang NewNode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewNode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: UnmarshalBody

func UnmarshalBody(t string, b []byte) (Body, error) {
	switch t {
	case PluginListType:
		return unmarshalAndHandleError(b, &PluginList{})
	case PluginsLoadedType:
		return unmarshalAndHandleError(b, &PluginsLoaded{})
	case PluginUnloadedType:
		return unmarshalAndHandleError(b, &PluginUnloaded{})
	case PluginReturnedType:
		return unmarshalAndHandleError(b, &PluginReturned{})
	case ScheduledTaskListReturnedType:
		return unmarshalAndHandleError(b, &ScheduledTaskListReturned{})
	case ScheduledTaskReturnedType:
		return unmarshalAndHandleError(b, &ScheduledTaskReturned{})
	case ScheduledTaskType:
		return unmarshalAndHandleError(b, &ScheduledTask{})
	case AddScheduledTaskType:
		return unmarshalAndHandleError(b, &AddScheduledTask{})
	case ScheduledTaskStartedType:
		return unmarshalAndHandleError(b, &ScheduledTaskStarted{})
	case ScheduledTaskStoppedType:
		return unmarshalAndHandleError(b, &ScheduledTaskStopped{})
	case ScheduledTaskRemovedType:
		return unmarshalAndHandleError(b, &ScheduledTaskRemoved{})
	case ScheduledTaskEnabledType:
		return unmarshalAndHandleError(b, &ScheduledTaskEnabled{})
	case MetricReturnedType:
		return unmarshalAndHandleError(b, &MetricReturned{})
	case MetricsReturnedType:
		return unmarshalAndHandleError(b, &MetricsReturned{})
	case ScheduledTaskWatchingEndedType:
		return unmarshalAndHandleError(b, &ScheduledTaskWatchingEnded{})
	case TribeMemberListType:
		return unmarshalAndHandleError(b, &TribeMemberList{})
	case TribeListAgreementType:
		return unmarshalAndHandleError(b, &TribeListAgreement{})
	case TribeAddAgreementType:
		return unmarshalAndHandleError(b, &TribeAddAgreement{})
	case TribeDeleteAgreementType:
		return unmarshalAndHandleError(b, &TribeDeleteAgreement{})
	case TribeMemberShowType:
		return unmarshalAndHandleError(b, &TribeMemberShow{})
	case TribeJoinAgreementType:
		return unmarshalAndHandleError(b, &TribeJoinAgreement{})
	case TribeLeaveAgreementType:
		return unmarshalAndHandleError(b, &TribeLeaveAgreement{})
	case TribeGetAgreementType:
		return unmarshalAndHandleError(b, &TribeGetAgreement{})
	case PluginConfigItemType:
		return unmarshalAndHandleError(b, &PluginConfigItem{*cdata.NewNode()})
	case SetPluginConfigItemType:
		return unmarshalAndHandleError(b, &SetPluginConfigItem{*cdata.NewNode()})
	case DeletePluginConfigItemType:
		return unmarshalAndHandleError(b, &DeletePluginConfigItem{*cdata.NewNode()})
	case ErrorType:
		return unmarshalAndHandleError(b, &Error{})
	default:
		return nil, ErrCannotUnmarshalBody
	}
}
开发者ID:IRCody,项目名称:snap,代码行数:60,代码来源:body.go

示例2: TestGetMetricConfigItem

func TestGetMetricConfigItem(t *testing.T) {

	Convey("Get a value of items from Metrics Config with no error", t, func() {
		// create config
		config := cdata.NewNode()
		config.AddItem("dummy_string", ctypes.ConfigValueStr{Value: dummy_str})
		config.AddItem("dummy_bool", ctypes.ConfigValueBool{Value: dummy_bool})
		config.AddItem("dummy_int", ctypes.ConfigValueInt{Value: dummy_int})
		config.AddItem("dummy_float", ctypes.ConfigValueFloat{Value: dummy_float})

		// create metric and set config
		metric := plugin.MetricType{}
		metric.Config_ = config

		Convey("string type of item", func() {
			result, err := GetMetricConfigItem(metric, "dummy_string")
			So(err, ShouldBeNil)
			So(result, ShouldEqual, dummy_str)
		})

		Convey("bool type of item", func() {
			result, err := GetMetricConfigItem(metric, "dummy_bool")
			So(err, ShouldBeNil)
			So(result, ShouldEqual, dummy_bool)
		})

		Convey("int type of item", func() {
			result, err := GetMetricConfigItem(metric, "dummy_int")
			So(err, ShouldBeNil)
			So(result, ShouldEqual, dummy_int)
		})

		Convey("float type of item", func() {
			result, err := GetMetricConfigItem(metric, "dummy_float")
			So(err, ShouldBeNil)
			So(result, ShouldEqual, dummy_float)
		})
	})

	Convey("Try to get a value of items not defined in Metrics Config", t, func() {
		config := cdata.NewNode()
		config.AddItem("foo", ctypes.ConfigValueStr{Value: "foo_val"})
		metric := plugin.MetricType{}
		metric.Config_ = config

		result, err := GetMetricConfigItem(metric, "foo_not_exist")
		So(err, ShouldNotBeNil)
		So(result, ShouldBeNil)
	})

	Convey("No item defined in Metrics Config", t, func() {
		metric := plugin.MetricType{}
		metric.Config_ = cdata.NewNode()

		result, err := GetMetricConfigItem(metric, "foo")
		So(err, ShouldNotBeNil)
		So(result, ShouldBeNil)
	})
}
开发者ID:intelsdi-x,项目名称:snap-plugin-utilities,代码行数:59,代码来源:config_test.go

示例3: TestMesos_getConfig

func TestMesos_getConfig(t *testing.T) {
	log.SetLevel(log.ErrorLevel) // Suppress warning messages from getConfig

	Convey("Get plugin configuration from snap global config", t, func() {
		Convey("When only a master is provided, getConfig() should return only the master value", func() {
			node := cdata.NewNode()
			node.AddItem("master", ctypes.ConfigValueStr{Value: "mesos-master.example.com:5050"})
			snapCfg := plugin.ConfigType{ConfigDataNode: node}

			parsedCfg, err := getConfig(snapCfg)

			So(parsedCfg["master"], ShouldEqual, "mesos-master.example.com:5050")
			So(parsedCfg["agent"], ShouldEqual, "")
			So(err, ShouldBeNil)
		})

		Convey("When only an agent is provided, getConfig() should return only the agent value", func() {
			node := cdata.NewNode()
			node.AddItem("agent", ctypes.ConfigValueStr{Value: "mesos-agent.example.com:5051"})
			snapCfg := plugin.ConfigType{ConfigDataNode: node}

			parsedCfg, err := getConfig(snapCfg)

			So(parsedCfg["master"], ShouldEqual, "")
			So(parsedCfg["agent"], ShouldEqual, "mesos-agent.example.com:5051")
			So(err, ShouldBeNil)
		})

		Convey("When both a master and an agent are provided, getConfig() should return both values", func() {
			node := cdata.NewNode()
			node.AddItem("master", ctypes.ConfigValueStr{Value: "mesos-master.example.com:5050"})
			node.AddItem("agent", ctypes.ConfigValueStr{Value: "mesos-agent.example.com:5051"})
			snapCfg := plugin.ConfigType{ConfigDataNode: node}

			parsedCfg, err := getConfig(snapCfg)

			So(len(parsedCfg), ShouldEqual, 2)
			So(err, ShouldBeNil)
		})

		Convey("When both master and agent are missing, getConfig() should return an error", func() {
			node := cdata.NewNode()
			node.AddItem("foo", ctypes.ConfigValueStr{Value: "bar"})
			snapCfg := plugin.ConfigType{ConfigDataNode: node}

			parsedCfg, err := getConfig(snapCfg)

			So(len(parsedCfg), ShouldEqual, 0)
			So(err, ShouldNotBeNil)
		})
	})
}
开发者ID:intelsdi-x,项目名称:snap-plugin-collector-mesos,代码行数:52,代码来源:mesos_test.go

示例4: testingConfig

func testingConfig() (cfg1 plugin.ConfigType, cfg2 *cdata.ConfigDataNode) {
	cfg1 = plugin.NewPluginConfigType()
	cfg2 = cdata.NewNode()

	cfg1.AddItem("openstack_user", ctypes.ConfigValueStr{Value: "x"})
	cfg1.AddItem("openstack_pass", ctypes.ConfigValueStr{Value: "x"})
	cfg1.AddItem("openstack_tenant", ctypes.ConfigValueStr{Value: "asdf"})
	cfg1.AddItem("openstack_auth_url", ctypes.ConfigValueStr{Value: "x"})

	cfg2.AddItem("openstack_user", ctypes.ConfigValueStr{Value: "x"})
	cfg2.AddItem("openstack_pass", ctypes.ConfigValueStr{Value: "x"})
	cfg2.AddItem("openstack_tenant", ctypes.ConfigValueStr{Value: "asdf"})
	cfg2.AddItem("openstack_auth_url", ctypes.ConfigValueStr{Value: "x"})

	cfg1.AddItem("allocation_ratio_cores", ctypes.ConfigValueFloat{Value: 3})
	cfg1.AddItem("allocation_ratio_ram", ctypes.ConfigValueFloat{Value: 4})
	cfg1.AddItem("reserved_node_cores", ctypes.ConfigValueFloat{Value: 5})
	cfg1.AddItem("reserved_node_ram_mb", ctypes.ConfigValueFloat{Value: 6})

	cfg2.AddItem("allocation_ratio_cores", ctypes.ConfigValueFloat{Value: 3})
	cfg2.AddItem("allocation_ratio_ram", ctypes.ConfigValueFloat{Value: 4})
	cfg2.AddItem("reserved_node_cores", ctypes.ConfigValueFloat{Value: 5})
	cfg2.AddItem("reserved_node_ram_mb", ctypes.ConfigValueFloat{Value: 6})

	return cfg1, cfg2
}
开发者ID:intelsdi-x,项目名称:snap-plugin-collector-nova,代码行数:26,代码来源:plugin_test.go

示例5: configtoConfigDataNode

func configtoConfigDataNode(cmap map[string]interface{}, ns string) (*cdata.ConfigDataNode, error) {
	cdn := cdata.NewNode()
	for ck, cv := range cmap {
		switch v := cv.(type) {
		case string:
			cdn.AddItem(ck, ctypes.ConfigValueStr{Value: v})
		case int:
			cdn.AddItem(ck, ctypes.ConfigValueInt{Value: v})
		case float64:
			//working around the fact that json decodes numbers to floats
			//if we can convert the number to an int without loss it will be an int
			if v == float64(int(v)) {
				cdn.AddItem(ck, ctypes.ConfigValueInt{Value: int(v)})
			} else {
				cdn.AddItem(ck, ctypes.ConfigValueFloat{Value: v})
			}
		case bool:
			cdn.AddItem(ck, ctypes.ConfigValueBool{Value: v})
		default:
			// TODO make sure this is covered in tests!!!
			return nil, errors.New(fmt.Sprintf("Cannot convert config value to config data node: %s=>%+v", ns, v))
		}
	}
	return cdn, nil
}
开发者ID:jcooklin,项目名称:snap,代码行数:25,代码来源:wmap.go

示例6: setupCfg

func setupCfg(endpoint, user, password, tenant string) plugin.ConfigType {
	node := cdata.NewNode()
	node.AddItem("endpoint", ctypes.ConfigValueStr{Value: endpoint})
	node.AddItem("user", ctypes.ConfigValueStr{Value: user})
	node.AddItem("password", ctypes.ConfigValueStr{Value: password})
	node.AddItem("tenant", ctypes.ConfigValueStr{Value: tenant})
	return plugin.ConfigType{ConfigDataNode: node}
}
开发者ID:intelsdi-x,项目名称:snap-plugin-collector-cinder,代码行数:8,代码来源:collector_test.go

示例7: TestGetMetricConfigItems

func TestGetMetricConfigItems(t *testing.T) {

	Convey("Get values of items from Metrics Config with no error", t, func() {

		// create config
		config := cdata.NewNode()
		config.AddItem("dummy_string", ctypes.ConfigValueStr{Value: dummy_str})
		config.AddItem("dummy_bool", ctypes.ConfigValueBool{Value: dummy_bool})
		config.AddItem("dummy_int", ctypes.ConfigValueInt{Value: dummy_int})
		config.AddItem("dummy_float", ctypes.ConfigValueFloat{Value: dummy_float})

		// create metric and set config
		metric := plugin.MetricType{}
		metric.Config_ = config

		names := []string{"dummy_string", "dummy_bool", "dummy_int", "dummy_float"}

		result, err := GetMetricConfigItems(metric, names)
		So(err, ShouldBeNil)
		for _, name := range names {
			So(result[name], ShouldNotBeEmpty)
		}
	})

	Convey("Try to get values of items not defined in Metrics config", t, func() {
		config := cdata.NewNode()
		config.AddItem("foo", ctypes.ConfigValueStr{Value: "foo_val"})
		metric := plugin.MetricType{}
		metric.Config_ = config

		names := []string{"foo1", "foo2"}
		result, err := GetMetricConfigItems(metric, names)
		So(err, ShouldNotBeNil)
		So(result, ShouldBeNil)
	})

	Convey("No item defined in Metrics Config", t, func() {
		metric := plugin.MetricType{}
		metric.Config_ = cdata.NewNode()
		names := []string{"foo", "bar"}
		result, err := GetMetricConfigItems(metric, names)
		So(err, ShouldNotBeNil)
		So(result, ShouldBeNil)
	})
}
开发者ID:intelsdi-x,项目名称:snap-plugin-utilities,代码行数:45,代码来源:config_test.go

示例8: newPluginConfig

func newPluginConfig() *pluginConfig {
	return &pluginConfig{
		All:         cdata.NewNode(),
		Collector:   newPluginTypeConfigItem(),
		Processor:   newPluginTypeConfigItem(),
		Publisher:   newPluginTypeConfigItem(),
		pluginCache: make(map[string]*cdata.ConfigDataNode),
	}
}
开发者ID:jcooklin,项目名称:snap,代码行数:9,代码来源:config.go

示例9: getMockMetricConfig

func getMockMetricConfig() *cdata.ConfigDataNode {
	// mocking metric config
	cfg := cdata.NewNode()
	cfg.AddItem("host", ctypes.ConfigValueStr{Value: "hostname"})
	cfg.AddItem("port", ctypes.ConfigValueInt{Value: 1234})
	cfg.AddItem("user", ctypes.ConfigValueStr{Value: "test"})
	cfg.AddItem("password", ctypes.ConfigValueStr{Value: "passwd"})

	return cfg
}
开发者ID:intelsdi-x,项目名称:snap-plugin-collector-influxdb,代码行数:10,代码来源:influxdb_small_test.go

示例10: UnmarshalJSON

func (p *ConfigType) UnmarshalJSON(data []byte) error {
	cdn := cdata.NewNode()
	dec := json.NewDecoder(bytes.NewReader(data))
	dec.UseNumber()
	if err := dec.Decode(cdn); err != nil {
		return err
	}
	p.ConfigDataNode = cdn
	return nil
}
开发者ID:IRCody,项目名称:snap,代码行数:10,代码来源:metric.go

示例11: GobDecode

func (p *ConfigType) GobDecode(data []byte) error {
	cdn := cdata.NewNode()
	decoder := gob.NewDecoder(bytes.NewReader(data))
	if err := decoder.Decode(cdn); err != nil {
		return err
	}
	p.ConfigDataNode = cdn

	return nil
}
开发者ID:IRCody,项目名称:snap,代码行数:10,代码来源:metric.go

示例12: TestPublishMetrics

func TestPublishMetrics(t *testing.T) {
	Convey("Given an available file publisher plugin", t, func() {
		// adjust HB timeouts for test
		plugin.PingTimeoutLimit = 1
		plugin.PingTimeoutDurationDefault = time.Second * 1

		// Create controller
		config := NewConfig()
		c := New(OptSetConfig(config))
		lpe := newListenToPluginEvent()
		c.eventManager.RegisterHandler("TestPublishMetrics", lpe)
		c.pluginRunner.(*runner).monitor.duration = time.Millisecond * 100
		c.Start()
		time.Sleep(1 * time.Second)

		// Load plugin
		_, err := load(c, path.Join(SnapPath, "plugin", "snap-publisher-file"))
		<-lpe.done
		So(err, ShouldBeNil)
		So(len(c.pluginManager.all()), ShouldEqual, 1)
		lp, err2 := c.pluginManager.get("publisher:file:3")
		So(err2, ShouldBeNil)
		So(lp.Name(), ShouldResemble, "file")
		So(lp.ConfigPolicy, ShouldNotBeNil)

		Convey("Subscribe to file publisher with good config", func() {
			n := cdata.NewNode()
			config.Plugins.Publisher.Plugins[lp.Name()] = newPluginConfigItem(optAddPluginConfigItem("file", ctypes.ConfigValueStr{Value: "/tmp/snap-TestPublishMetrics.out"}))
			pool, errp := c.pluginRunner.AvailablePlugins().getOrCreatePool("publisher:file:3")
			So(errp, ShouldBeNil)
			pool.subscribe("1", unboundSubscriptionType)
			err := c.pluginRunner.runPlugin(lp.Details)
			So(err, ShouldBeNil)
			time.Sleep(2500 * time.Millisecond)

			Convey("Publish to file", func() {
				metrics := []plugin.PluginMetricType{
					*plugin.NewPluginMetricType([]string{"foo"}, time.Now(), "", nil, nil, 1),
				}
				var buf bytes.Buffer
				enc := gob.NewEncoder(&buf)
				enc.Encode(metrics)
				contentType := plugin.SnapGOBContentType
				errs := c.PublishMetrics(contentType, buf.Bytes(), "file", 3, n.Table())
				So(errs, ShouldBeNil)
				ap := c.AvailablePlugins()
				So(ap, ShouldNotBeEmpty)
			})
		})
		c.Stop()
		time.Sleep(100 * time.Millisecond)

	})
}
开发者ID:andradeandrey,项目名称:snap,代码行数:54,代码来源:control_test.go

示例13: newPluginConfigItem

func newPluginConfigItem(opts ...pluginConfigOpt) *pluginConfigItem {
	p := &pluginConfigItem{
		ConfigDataNode: cdata.NewNode(),
		Versions:       make(map[int]*cdata.ConfigDataNode),
	}

	for _, opt := range opts {
		opt(p)
	}

	return p
}
开发者ID:jcooklin,项目名称:snap,代码行数:12,代码来源:config.go

示例14: TestSubscriptionGroups_GetSpecifiedDynamic

func TestSubscriptionGroups_GetSpecifiedDynamic(t *testing.T) {
	log.SetLevel(log.DebugLevel)
	c := New(getTestSGConfig())

	lpe := newLstnToPluginEvents()
	c.eventManager.RegisterHandler("TestSubscriptionGroups_AddRemove", lpe)
	c.Start()

	Convey("Loading a mock collector plugn", t, func() {
		_, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-mock1"))
		So(err, ShouldBeNil)
		<-lpe.load

		Convey("Subscription group created for requested metric with specified instance of dynamic element", func() {
			requested := mockRequestedMetric{namespace: core.NewNamespace("intel", "mock").AddDynamicElement("host", "name of the host").AddStaticElement("baz")}
			// specified dynamic element
			requested.Namespace()[2].Value = "host0"
			subsPlugin := mockSubscribedPlugin{
				typeName: core.CollectorPluginType,
				name:     "mock",
				version:  1,
				config:   cdata.NewNode(),
			}
			subsPluginKey := key(subsPlugin)

			sg := newSubscriptionGroups(c)
			So(sg, ShouldNotBeNil)
			sg.Add("task-id", []core.RequestedMetric{requested}, cdata.NewTree(), []core.SubscribedPlugin{subsPlugin})
			<-lpe.sub
			So(len(sg.subscriptionMap), ShouldEqual, 1)
			val, ok := sg.subscriptionMap["task-id"]
			So(ok, ShouldBeTrue)
			So(val, ShouldNotBeNil)

			pluginToMetricMap, serrs, err := sg.Get("task-id")
			So(len(serrs), ShouldEqual, 0)
			So(err, ShouldBeNil)
			So(len(pluginToMetricMap), ShouldEqual, 1)
			So(pluginToMetricMap, ShouldContainKey, subsPluginKey)
			metrics := pluginToMetricMap[subsPluginKey].Metrics()
			So(len(metrics), ShouldEqual, 1)

			pluginToMetricMap, serrs, err = sg.Get("task-fake-id")
			So(len(serrs), ShouldEqual, 0)
			So(err, ShouldNotBeNil)
			So(err, ShouldResemble, ErrSubscriptionGroupDoesNotExist)
			So(pluginToMetricMap, ShouldBeEmpty)
		})
	})
}
开发者ID:katarzyna-z,项目名称:snap,代码行数:50,代码来源:subscription_group_medium_test.go

示例15: getPluginConfigDataNode

func (p *pluginConfig) getPluginConfigDataNode(pluginType core.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 core.CollectorPluginType:
		p.pluginCache[key].Merge(p.Collector.All)
		if res, ok := p.Collector.Plugins[name]; ok {
			p.pluginCache[key].Merge(res.ConfigDataNode)
			if res2, ok2 := res.Versions[ver]; ok2 {
				p.pluginCache[key].Merge(res2)
			}
		}
	case core.ProcessorPluginType:
		p.pluginCache[key].Merge(p.Processor.All)
		if res, ok := p.Processor.Plugins[name]; ok {
			p.pluginCache[key].Merge(res.ConfigDataNode)
			if res2, ok2 := res.Versions[ver]; ok2 {
				p.pluginCache[key].Merge(res2)
			}
		}
	case core.PublisherPluginType:
		p.pluginCache[key].Merge(p.Publisher.All)
		if res, ok := p.Publisher.Plugins[name]; ok {
			p.pluginCache[key].Merge(res.ConfigDataNode)
			if res2, ok2 := res.Versions[ver]; ok2 {
				p.pluginCache[key].Merge(res2)
			}
		}
	}

	//todo change to debug
	log.WithFields(log.Fields{
		"_block_":            "getPluginConfigDataNode",
		"_module":            "config",
		"config-cache-key":   key,
		"config-cache-value": p.pluginCache[key],
	}).Debug("Getting plugin config")

	return p.pluginCache[key]
}
开发者ID:jcooklin,项目名称:snap,代码行数:50,代码来源:config.go


注:本文中的github.com/intelsdi-x/snap/core/cdata.NewNode函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。