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

Golang gomit.Event类代码示例

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

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



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

示例1: HandleGomitEvent

// Central handling for all async events in scheduler
func (s *scheduler) HandleGomitEvent(e gomit.Event) {

	switch v := e.Body.(type) {
	case *scheduler_event.MetricCollectedEvent:
		log.WithFields(log.Fields{
			"_module":         "scheduler-events",
			"_block":          "handle-events",
			"event-namespace": e.Namespace(),
			"task-id":         v.TaskID,
			"metric-count":    len(v.Metrics),
		}).Debug("event received")
		s.taskWatcherColl.handleMetricCollected(v.TaskID, v.Metrics)
	case *scheduler_event.MetricCollectionFailedEvent:
		log.WithFields(log.Fields{
			"_module":         "scheduler-events",
			"_block":          "handle-events",
			"event-namespace": e.Namespace(),
			"task-id":         v.TaskID,
			"errors-count":    v.Errors,
		}).Debug("event received")
	case *scheduler_event.TaskStartedEvent:
		log.WithFields(log.Fields{
			"_module":         "scheduler-events",
			"_block":          "handle-events",
			"event-namespace": e.Namespace(),
			"task-id":         v.TaskID,
		}).Debug("event received")
		s.taskWatcherColl.handleTaskStarted(v.TaskID)
	case *scheduler_event.TaskStoppedEvent:
		log.WithFields(log.Fields{
			"_module":         "scheduler-events",
			"_block":          "handle-events",
			"event-namespace": e.Namespace(),
			"task-id":         v.TaskID,
		}).Debug("event received")
		s.taskWatcherColl.handleTaskStopped(v.TaskID)
	case *scheduler_event.TaskDisabledEvent:
		log.WithFields(log.Fields{
			"_module":         "scheduler-events",
			"_block":          "handle-events",
			"event-namespace": e.Namespace(),
			"task-id":         v.TaskID,
			"disabled-reason": v.Why,
		}).Debug("event received")
		// We need to unsubscribe from deps when a task goes disabled
		task, _ := s.getTask(v.TaskID)
		depGroups := getWorkflowPlugins(task.workflow.processNodes, task.workflow.publishNodes, task.workflow.metrics)
		for k := range depGroups {
			mgr, err := task.RemoteManagers.Get(k)
			if err == nil {
				mgr.UnsubscribeDeps(task.ID())
			}
		}
		s.taskWatcherColl.handleTaskDisabled(v.TaskID, v.Why)
	default:
		log.WithFields(log.Fields{
			"_module":         "scheduler-events",
			"_block":          "handle-events",
			"event-namespace": e.Namespace(),
		}).Debug("event received")
	}
}
开发者ID:katarzyna-z,项目名称:snap,代码行数:63,代码来源:scheduler.go


示例2: HandleGomitEvent

// Empty handler acting as placeholder until implementation. This helps tests
// pass to ensure registration works.
func (r *runner) HandleGomitEvent(e gomit.Event) {
	switch v := e.Body.(type) {
	case *control_event.DeadAvailablePluginEvent:
		runnerLog.WithFields(log.Fields{
			"_block":  "handle-events",
			"event":   v.Namespace(),
			"aplugin": v.String,
		}).Warning("handling dead available plugin event")

		pool, err := r.availablePlugins.getPool(v.Key)
		if err != nil {
			runnerLog.WithFields(log.Fields{
				"_block":  "handle-events",
				"aplugin": v.String,
			}).Error(err.Error())
			return
		}

		if pool != nil {
			pool.Kill(v.Id, "plugin dead")
		}

		if pool.Eligible() {
			if pool.RestartCount() < MaxPluginRestartCount {
				e := r.restartPlugin(v.Key)
				if e != nil {
					runnerLog.WithFields(log.Fields{
						"_block":  "handle-events",
						"aplugin": v.String,
					}).Error(e.Error())
					return
				}
				pool.IncRestartCount()

				runnerLog.WithFields(log.Fields{
					"_block":        "handle-events",
					"event":         v.Name,
					"aplugin":       v.Version,
					"restart_count": pool.RestartCount(),
				}).Warning("plugin restarted")

				r.emitter.Emit(&control_event.RestartedAvailablePluginEvent{
					Id:      v.Id,
					Name:    v.Name,
					Version: v.Version,
					Key:     v.Key,
					Type:    v.Type,
				})
			} else {
				r.emitter.Emit(&control_event.MaxPluginRestartsExceededEvent{
					Id:      v.Id,
					Name:    v.Name,
					Version: v.Version,
					Key:     v.Key,
					Type:    v.Type,
				})
			}
		}
	case *control_event.PluginUnsubscriptionEvent:
		runnerLog.WithFields(log.Fields{
			"_block":         "subscribe-pool",
			"event":          v.Namespace(),
			"plugin-name":    v.PluginName,
			"plugin-version": v.PluginVersion,
			"plugin-type":    core.PluginType(v.PluginType).String(),
		}).Debug("handling plugin unsubscription event")

		err := r.handleUnsubscription(core.PluginType(v.PluginType).String(), v.PluginName, v.PluginVersion, v.TaskId)
		if err != nil {
			return
		}
	default:
		runnerLog.WithFields(log.Fields{
			"_block": "handle-events",
			"event":  v.Namespace(),
		}).Info("Nothing to do for this event")
	}
}
开发者ID:IRCody,项目名称:snap,代码行数:80,代码来源:runner.go


示例3: HandleGomitEvent

// Central handling for all async events in scheduler
func (s *scheduler) HandleGomitEvent(e gomit.Event) {

	switch v := e.Body.(type) {
	case *scheduler_event.MetricCollectedEvent:
		log.WithFields(log.Fields{
			"_module":         "scheduler-events",
			"_block":          "handle-events",
			"event-namespace": e.Namespace(),
			"task-id":         v.TaskID,
			"metric-count":    len(v.Metrics),
		}).Debug("event received")
		s.taskWatcherColl.handleMetricCollected(v.TaskID, v.Metrics)
	case *scheduler_event.MetricCollectionFailedEvent:
		log.WithFields(log.Fields{
			"_module":         "scheduler-events",
			"_block":          "handle-events",
			"event-namespace": e.Namespace(),
			"task-id":         v.TaskID,
			"errors-count":    v.Errors,
		}).Debug("event received")
	case *scheduler_event.TaskStartedEvent:
		log.WithFields(log.Fields{
			"_module":         "scheduler-events",
			"_block":          "handle-events",
			"event-namespace": e.Namespace(),
			"task-id":         v.TaskID,
		}).Debug("event received")
		s.taskWatcherColl.handleTaskStarted(v.TaskID)
	case *scheduler_event.TaskStoppedEvent:
		log.WithFields(log.Fields{
			"_module":         "scheduler-events",
			"_block":          "handle-events",
			"event-namespace": e.Namespace(),
			"task-id":         v.TaskID,
		}).Debug("event received")
		s.taskWatcherColl.handleTaskStopped(v.TaskID)
	case *scheduler_event.TaskDisabledEvent:
		log.WithFields(log.Fields{
			"_module":         "scheduler-events",
			"_block":          "handle-events",
			"event-namespace": e.Namespace(),
			"task-id":         v.TaskID,
			"disabled-reason": v.Why,
		}).Debug("event received")
		// We need to unsubscribe from deps when a task goes disabled
		task, _ := s.getTask(v.TaskID)
		mts, plugins := s.gatherMetricsAndPlugins(task.workflow)
		cps := returnCorePlugin(plugins)
		s.metricManager.UnsubscribeDeps(task.ID(), mts, cps)
		s.taskWatcherColl.handleTaskDisabled(v.TaskID, v.Why)
	default:
		log.WithFields(log.Fields{
			"_module":         "scheduler-events",
			"_block":          "handle-events",
			"event-namespace": e.Namespace(),
		}).Debug("event received")
	}
}
开发者ID:jcooklin,项目名称:snap,代码行数:59,代码来源:scheduler.go


示例4: HandleGomitEvent

// HandleGomitEvent handles events emitted from control
func (t *tribe) HandleGomitEvent(e gomit.Event) {
	logger := t.logger.WithFields(log.Fields{
		"_block": "handle-gomit-event",
	})
	switch v := e.Body.(type) {
	case *control_event.LoadPluginEvent:
		logger.WithFields(log.Fields{
			"event":          e.Namespace(),
			"plugin-name":    v.Name,
			"plugin-version": v.Version,
			"plugin-type":    core.PluginType(v.Type).String(),
		}).Debugf("handling load plugin event")
		plugin := agreement.Plugin{
			Name_:    v.Name,
			Version_: v.Version,
			Type_:    core.PluginType(v.Type),
		}
		if m, ok := t.members[t.memberlist.LocalNode().Name]; ok {
			if m.PluginAgreement != nil {
				if ok, _ := m.PluginAgreement.Plugins.Contains(plugin); !ok {
					t.AddPlugin(m.PluginAgreement.Name, plugin)
				}
			}
		}
	case *control_event.UnloadPluginEvent:
		logger.WithFields(log.Fields{
			"event":          e.Namespace(),
			"plugin-name":    v.Name,
			"plugin-version": v.Version,
			"plugin-type":    core.PluginType(v.Type).String(),
		}).Debugf("handling unload plugin event")
		plugin := agreement.Plugin{
			Name_:    v.Name,
			Version_: v.Version,
			Type_:    core.PluginType(v.Type),
		}
		if m, ok := t.members[t.memberlist.LocalNode().Name]; ok {
			if m.PluginAgreement != nil {
				if ok, _ := m.PluginAgreement.Plugins.Contains(plugin); ok {
					t.RemovePlugin(m.PluginAgreement.Name, plugin)
				}
			}
		}
	case *scheduler_event.TaskCreatedEvent:
		if v.Source != "tribe" {
			logger.WithFields(log.Fields{
				"event":                e.Namespace(),
				"task-id":              v.TaskID,
				"task-start-on-create": v.StartOnCreate,
			}).Debugf("handling task create event")
			task := agreement.Task{
				ID:            v.TaskID,
				StartOnCreate: v.StartOnCreate,
			}
			if m, ok := t.members[t.memberlist.LocalNode().Name]; ok {
				if m.TaskAgreements != nil {
					for n, a := range m.TaskAgreements {
						if ok, _ := a.Tasks.Contains(task); !ok {
							t.AddTask(n, task)
						}
					}
				}
			}
		}
	case *scheduler_event.TaskStoppedEvent:
		if v.Source != "tribe" {
			logger.WithFields(log.Fields{
				"event":   e.Namespace(),
				"task-id": v.TaskID,
			}).Debugf("handling task stop event")
			task := agreement.Task{
				ID: v.TaskID,
			}
			if m, ok := t.members[t.memberlist.LocalNode().Name]; ok {
				if m.TaskAgreements != nil {
					for n, a := range m.TaskAgreements {
						if ok, _ := a.Tasks.Contains(task); ok {
							t.StopTask(n, task)
						}
					}
				}
			}
		}
	case *scheduler_event.TaskStartedEvent:
		if v.Source != "tribe" {
			logger.WithFields(log.Fields{
				"event":   e.Namespace(),
				"task-id": v.TaskID,
			}).Debugf("handling task start event")
			task := agreement.Task{
				ID: v.TaskID,
			}
			if m, ok := t.members[t.memberlist.LocalNode().Name]; ok {
				if m.TaskAgreements != nil {
					for n, a := range m.TaskAgreements {
						if ok, _ := a.Tasks.Contains(task); ok {
							t.StartTask(n, task)
						}
					}
//.........这里部分代码省略.........
开发者ID:katarzyna-z,项目名称:snap,代码行数:101,代码来源:tribe.go


示例5: HandleGomitEvent

// Empty handler acting as placeholder until implementation. This helps tests
// pass to ensure registration works.
func (r *runner) HandleGomitEvent(e gomit.Event) {
	switch v := e.Body.(type) {
	case *control_event.DeadAvailablePluginEvent:
		runnerLog.WithFields(log.Fields{
			"_block":  "handle-events",
			"event":   v.Namespace(),
			"aplugin": v.String,
		}).Warning("handling dead available plugin event")

		pool, err := r.availablePlugins.getPool(v.Key)
		if err != nil {
			runnerLog.WithFields(log.Fields{
				"_block":  "handle-events",
				"aplugin": v.String,
			}).Error(err.Error())
			return
		}

		if pool != nil {
			pool.Kill(v.Id, "plugin dead")
		}

		if pool.Eligible() {
			if pool.RestartCount() < MaxPluginRestartCount {
				e := r.restartPlugin(v.Key)
				if e != nil {
					runnerLog.WithFields(log.Fields{
						"_block":  "handle-events",
						"aplugin": v.String,
					}).Error(e.Error())
					return
				}
				pool.IncRestartCount()

				runnerLog.WithFields(log.Fields{
					"_block":        "handle-events",
					"event":         v.Name,
					"aplugin":       v.Version,
					"restart_count": pool.RestartCount(),
				}).Warning("plugin restarted")

				r.emitter.Emit(&control_event.RestartedAvailablePluginEvent{
					Id:      v.Id,
					Name:    v.Name,
					Version: v.Version,
					Key:     v.Key,
					Type:    v.Type,
				})
			} else {
				r.emitter.Emit(&control_event.MaxPluginRestartsExceededEvent{
					Id:      v.Id,
					Name:    v.Name,
					Version: v.Version,
					Key:     v.Key,
					Type:    v.Type,
				})
			}
		}
	case *control_event.PluginUnsubscriptionEvent:
		runnerLog.WithFields(log.Fields{
			"_block":         "subscribe-pool",
			"event":          v.Namespace(),
			"plugin-name":    v.PluginName,
			"plugin-version": v.PluginVersion,
			"plugin-type":    core.PluginType(v.PluginType).String(),
		}).Debug("handling plugin unsubscription event")

		err := r.handleUnsubscription(core.PluginType(v.PluginType).String(), v.PluginName, v.PluginVersion, v.TaskId)
		if err != nil {
			return
		}
	case *control_event.UnloadPluginEvent:
		// On plugin unload,  find the key and pool info for the plugin being unloaded.
		r.availablePlugins.RLock()
		var pool strategy.Pool
		var k string
		for key, p := range r.availablePlugins.table {
			tnv := strings.Split(key, ":")
			if core.PluginType(v.Type).String() == tnv[0] && v.Name == tnv[1] && v.Version == p.Version() {
				pool = p
				k = key
				break
			}
		}

		r.availablePlugins.RUnlock()
		if pool == nil {
			return
		}
		// Check for the highest lower version plugin and move subscriptions that
		// are not bound to a plugin version to this pool.
		plugin, err := r.pluginManager.get(fmt.Sprintf("%s:%s:%d", core.PluginType(v.Type).String(), v.Name, -1))
		if err != nil {
			return
		}
		newPool, err := r.availablePlugins.getOrCreatePool(plugin.Key())
		if err != nil {
			return
//.........这里部分代码省略.........
开发者ID:Collinux,项目名称:snap,代码行数:101,代码来源:runner.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang plugin.Config类代码示例发布时间:2022-05-23
下一篇:
Golang test.NewResponseRecorder函数代码示例发布时间: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