• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang core.ToPluginType函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: handleAddPlugin

func (t *tribe) handleAddPlugin(msg *pluginMsg) bool {
	t.mutex.Lock()
	defer t.mutex.Unlock()

	// update the clock if newer
	t.clock.Update(msg.LTime)

	if t.isDuplicate(msg) {
		return false
	}

	t.msgBuffer[msg.LTime%LTime(len(t.msgBuffer))] = msg

	if _, ok := t.agreements[msg.AgreementName]; ok {
		if t.agreements[msg.AgreementName].PluginAgreement.Add(msg.Plugin) {

			ptype, _ := core.ToPluginType(msg.Plugin.TypeName())
			work := worker.PluginRequest{
				Plugin: agreement.Plugin{
					Name_:    msg.Plugin.Name(),
					Version_: msg.Plugin.Version(),
					Type_:    ptype,
				},
				RequestType: worker.PluginLoadedType,
			}
			t.pluginWorkQueue <- work

			t.processIntents()
			return true
		}
	}

	t.addPluginIntent(msg)
	return true
}
开发者ID:katarzyna-z,项目名称:snap,代码行数:35,代码来源:tribe.go


示例2: ValidateDeps

func (p *pluginControl) ValidateDeps(mts []core.Metric, plugins []core.SubscribedPlugin) []serror.SnapError {
	var serrs []serror.SnapError
	for _, mt := range mts {
		_, errs := p.validateMetricTypeSubscription(mt, mt.Config())
		if len(errs) > 0 {
			serrs = append(serrs, errs...)
		}
	}
	if len(serrs) > 0 {
		return serrs
	}

	//validate plugins
	for _, plg := range plugins {
		typ, err := core.ToPluginType(plg.TypeName())
		if err != nil {
			return []serror.SnapError{serror.New(err)}
		}
		plg.Config().Merge(p.Config.Plugins.getPluginConfigDataNode(typ, plg.Name(), plg.Version()))
		errs := p.validatePluginSubscription(plg)
		if len(errs) > 0 {
			serrs = append(serrs, errs...)
			return serrs
		}
	}

	return serrs
}
开发者ID:gitter-badger,项目名称:snap-1,代码行数:28,代码来源:control.go


示例3: processAddPluginIntents

func (t *tribe) processAddPluginIntents() bool {
	for idx, v := range t.intentBuffer {
		if v.GetType() == addPluginMsgType {
			intent := v.(*pluginMsg)
			if _, ok := t.agreements[intent.AgreementName]; ok {
				if ok, _ := t.agreements[intent.AgreementName].PluginAgreement.Plugins.Contains(intent.Plugin); !ok {
					t.agreements[intent.AgreementName].PluginAgreement.Plugins = append(t.agreements[intent.AgreementName].PluginAgreement.Plugins, intent.Plugin)
					t.intentBuffer = append(t.intentBuffer[:idx], t.intentBuffer[idx+1:]...)

					ptype, _ := core.ToPluginType(intent.Plugin.TypeName())
					work := worker.PluginRequest{
						Plugin: agreement.Plugin{
							Name_:    intent.Plugin.Name(),
							Version_: intent.Plugin.Version(),
							Type_:    ptype,
						},
						RequestType: worker.PluginLoadedType,
					}
					t.pluginWorkQueue <- work

					return false
				}
			}
		}
	}
	return true
}
开发者ID:katarzyna-z,项目名称:snap,代码行数:27,代码来源:tribe.go


示例4: validateMetricTypeSubscription

func (p *pluginControl) validateMetricTypeSubscription(mt core.RequestedMetric, cd *cdata.ConfigDataNode) []serror.SnapError {
	var serrs []serror.SnapError
	controlLogger.WithFields(log.Fields{
		"_block":    "validate-metric-subscription",
		"namespace": mt.Namespace(),
		"version":   mt.Version(),
	}).Info("subscription called on metric")

	m, err := p.metricCatalog.Get(mt.Namespace(), mt.Version())

	if err != nil {
		serrs = append(serrs, serror.New(err, map[string]interface{}{
			"name":    mt.Namespace().String(),
			"version": mt.Version(),
		}))
		return serrs
	}

	// No metric found return error.
	if m == nil {
		serrs = append(serrs, serror.New(fmt.Errorf("no metric found cannot subscribe: (%s) version(%d)", mt.Namespace(), mt.Version())))
		return serrs
	}

	m.config = cd

	typ, serr := core.ToPluginType(m.Plugin.TypeName())
	if serr != nil {
		return []serror.SnapError{serror.New(err)}
	}

	// merge global plugin config
	if m.config != nil {
		m.config.ReverseMerge(p.Config.Plugins.getPluginConfigDataNode(typ, m.Plugin.Name(), m.Plugin.Version()))
	} else {
		m.config = 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.
	if m.policy.HasRules() {
		if m.Config() == nil {
			serrs = append(serrs, serror.New(fmt.Errorf("Policy defined for metric, (%s) version (%d), but no config defined in manifest", mt.Namespace(), mt.Version())))
			return serrs
		}
		ncdTable, errs := m.policy.Process(m.Config().Table())
		if errs != nil && errs.HasErrors() {
			for _, e := range errs.Errors() {
				serrs = append(serrs, serror.New(e))
			}
			return serrs
		}
		m.config = cdata.FromTable(*ncdTable)
	}

	return serrs
}
开发者ID:jcooklin,项目名称:snap,代码行数:58,代码来源:control.go


示例5: getPluginType

func getPluginType(t string) (core.PluginType, error) {
	if ityp, err := strconv.Atoi(t); err == nil {
		return core.PluginType(ityp), nil
	}
	ityp, err := core.ToPluginType(t)
	if err != nil {
		return core.PluginType(-1), err
	}
	return ityp, nil
}
开发者ID:IRCody,项目名称:snap,代码行数:10,代码来源:config.go


示例6: joinAgreement

func (t *tribe) joinAgreement(msg *agreementMsg) serror.SnapError {
	if err := t.canJoinAgreement(msg.Agreement(), msg.MemberName); err != nil {
		return err
	}
	// add plugin agreement to the member
	if t.agreements[msg.Agreement()].PluginAgreement != nil {
		t.members[msg.MemberName].PluginAgreement = t.agreements[msg.Agreement()].PluginAgreement
	}
	t.members[msg.MemberName].TaskAgreements[msg.Agreement()] = t.agreements[msg.Agreement()].TaskAgreement

	// update the agreements membership
	t.agreements[msg.Agreement()].Members[msg.MemberName] = t.members[msg.MemberName]

	// get plugins and tasks if this is the node joining
	if msg.MemberName == t.memberlist.LocalNode().Name {
		go func(a *agreement.Agreement) {
			for _, p := range a.PluginAgreement.Plugins {
				ptype, _ := core.ToPluginType(p.TypeName())
				work := worker.PluginRequest{
					Plugin: agreement.Plugin{
						Name_:    p.Name(),
						Version_: p.Version(),
						Type_:    ptype,
					},
					RequestType: worker.PluginLoadedType,
				}
				t.pluginWorkQueue <- work
			}

			for _, tsk := range a.TaskAgreement.Tasks {
				state := t.TaskStateQuery(msg.Agreement(), tsk.ID)
				startOnCreate := false
				if state == core.TaskSpinning || state == core.TaskFiring {
					startOnCreate = true
				}
				work := worker.TaskRequest{
					Task: worker.Task{
						ID:            tsk.ID,
						StartOnCreate: startOnCreate,
					},
					RequestType: worker.TaskCreatedType,
				}
				t.taskWorkQueue <- work
			}
		}(t.agreements[msg.Agreement()])
	}
	return nil
}
开发者ID:katarzyna-z,项目名称:snap,代码行数:48,代码来源:tribe.go


示例7: sendPluginUnsubscriptionEvent

func (p *pluginControl) sendPluginUnsubscriptionEvent(taskId string, pl core.Plugin) serror.SnapError {
	pt, err := core.ToPluginType(pl.TypeName())
	if err != nil {
		return serror.New(err)
	}
	e := &control_event.PluginUnsubscriptionEvent{
		TaskId:        taskId,
		PluginType:    int(pt),
		PluginName:    pl.Name(),
		PluginVersion: pl.Version(),
	}
	if _, err := p.eventManager.Emit(e); err != nil {
		return serror.New(err)
	}
	return nil
}
开发者ID:gitter-badger,项目名称:snap-1,代码行数:16,代码来源:control.go


示例8: sendPluginSubscriptionEvent

func (p *pluginControl) sendPluginSubscriptionEvent(taskID string, pl core.Plugin) serror.SnapError {
	pt, err := core.ToPluginType(pl.TypeName())
	if err != nil {
		return serror.New(err)
	}
	e := &control_event.PluginSubscriptionEvent{
		TaskId:           taskID,
		PluginType:       int(pt),
		PluginName:       pl.Name(),
		PluginVersion:    pl.Version(),
		SubscriptionType: int(strategy.UnboundSubscriptionType),
	}
	if pl.Version() > 0 {
		e.SubscriptionType = int(strategy.BoundSubscriptionType)
	}
	if _, err := p.eventManager.Emit(e); err != nil {
		return serror.New(err)
	}
	return nil
}
开发者ID:jcooklin,项目名称:snap,代码行数:20,代码来源:control.go


示例9: ValidateDeps

func (s *subscriptionGroups) ValidateDeps(requested []core.RequestedMetric,
	plugins []core.SubscribedPlugin,
	configTree *cdata.ConfigDataTree) (serrs []serror.SnapError) {

	// resolve requested metrics and map to collectors
	pluginToMetricMap, collectors, errs := s.getMetricsAndCollectors(requested, configTree)
	if errs != nil {
		serrs = append(serrs, errs...)
	}

	// validateMetricsTypes
	for _, pmt := range pluginToMetricMap {
		for _, mt := range pmt.Metrics() {
			errs := s.validateMetric(mt)
			if len(errs) > 0 {
				serrs = append(serrs, errs...)
			}
		}
	}
	// add collectors to plugins (processors and publishers)
	for _, collector := range collectors {
		plugins = append(plugins, collector)
	}

	// validate plugins
	for _, plg := range plugins {
		typ, err := core.ToPluginType(plg.TypeName())
		if err != nil {
			return []serror.SnapError{serror.New(err)}
		}
		plg.Config().ReverseMerge(
			s.Config.Plugins.getPluginConfigDataNode(
				typ, plg.Name(), plg.Version()))
		errs := s.validatePluginSubscription(plg)
		if len(errs) > 0 {
			serrs = append(serrs, errs...)
			return serrs
		}
	}
	return
}
开发者ID:IRCody,项目名称:snap,代码行数:41,代码来源:subscription_group.go


示例10: validateMetric

func (s *subscriptionGroups) validateMetric(
	metric core.Metric) (serrs []serror.SnapError) {
	m, err := s.metricCatalog.GetMetric(metric.Namespace(), metric.Version())
	if err != nil {
		serrs = append(serrs, serror.New(err, map[string]interface{}{
			"name":    metric.Namespace().String(),
			"version": metric.Version(),
		}))
		return serrs
	}

	// No metric found return error.
	if m == nil {
		serrs = append(
			serrs, serror.New(
				fmt.Errorf("no metric found cannot subscribe: (%s) version(%d)",
					metric.Namespace(), metric.Version())))
		return serrs
	}

	m.config = metric.Config()

	typ, serr := core.ToPluginType(m.Plugin.TypeName())
	if serr != nil {
		return []serror.SnapError{serror.New(err)}
	}

	// merge global plugin config
	if m.config != nil {
		m.config.ReverseMerge(
			s.Config.Plugins.getPluginConfigDataNode(typ,
				m.Plugin.Name(), m.Plugin.Version()))
	} else {
		m.config = s.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.
	if m.policy.HasRules() {
		if m.Config() == nil {
			fields := log.Fields{
				"metric":  m.Namespace(),
				"version": m.Version(),
				"plugin":  m.Plugin.Name(),
			}
			serrs = append(serrs, serror.New(ErrConfigRequiredForMetric, fields))
			return serrs
		}
		ncdTable, errs := m.policy.Process(m.Config().Table())
		if errs != nil && errs.HasErrors() {
			for _, e := range errs.Errors() {
				serrs = append(serrs, serror.New(e))
			}
			return serrs
		}
		m.config = cdata.FromTable(*ncdTable)
	}

	return serrs
}
开发者ID:IRCody,项目名称:snap,代码行数:62,代码来源:subscription_group.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang core.CatalogedPlugin类代码示例发布时间:2022-05-23
下一篇:
Golang core.PluginType函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap