Example #1
0
// RegisterTaskQ registers the TaskQ application and all its handler in the
// hive.
func RegisterTaskQ(h beehive.Hive, opts ...Option) error {
	if !flag.Parsed() {
		flag.Parse()
	}

	proto, err := NewProtoHandler(addr.Get(opts))
	if err != nil {
		return err
	}

	r := rate.Get(opts)
	taskq := h.NewApp("taskq", beehive.Persistent(repl.Get(opts)),
		beehive.OutRate(bucket.Rate(r), 2*r))
	taskq.Handle(Enque{}, EnQHandler{})
	taskq.Handle(Deque{}, DeQHandler{})
	taskq.Handle(Ack{}, AckHandler{})
	taskq.Handle(Timeout{}, TimeoutHandler{
		ExpDur: 60 * time.Second,
	})

	ah := &AckHTTPHandler{Hive: h}
	taskq.HandleHTTP("/{queue}/tasks/{id:[0-9]+}", ah).Methods("DELETE")
	dh := &DeQHTTPHandler{Hive: h}
	taskq.HandleHTTP("/{queue}/tasks/deque", dh).Methods("POST")
	eh := &EnQHTTPHandler{Hive: h}
	taskq.HandleHTTP("/{queue}/tasks", eh).Methods("POST")

	taskq.Detached(beehive.NewTimer(30*time.Second, func() {
		h.Emit(Timeout(time.Now()))
	}))
	taskq.Detached(proto)

	return nil
}
Example #2
0
// RegisterApps registers Kandoo applications on the hive, with the given
// elephant flow size threshold.
func RegisterApps(hive bh.Hive, threshold uint64) {
	ar := hive.NewApp("Reroute")
	ar.Handle(ElephantDetected{}, Rerouter{})

	ad := hive.NewApp("Detect")
	ad.Handle(nom.FlowStatsQueryResult{}, Detector{})
	ad.Handle(nom.NodeJoined{}, Adder{})

	type poll struct{}
	ad.Handle(poll{}, Poller{})
	ad.Detached(bh.NewTimer(1*time.Second, func() {
		hive.Emit(poll{})
	}))
}
Example #3
0
func RegisterNOMController(h bh.Hive) {
	app := h.NewApp("NOMController", bh.Persistent(3))

	app.Handle(nom.NodeConnected{}, nodeConnectedHandler{})
	app.Handle(nom.NodeDisconnected{}, nodeDisconnectedHandler{})
	app.Handle(nom.PortStatusChanged{}, portStatusHandler{})

	app.Handle(nom.AddFlowEntry{}, addFlowHandler{})
	app.Handle(nom.DelFlowEntry{}, delFlowHandler{})

	app.Handle(nom.FlowStatsQuery{}, queryHandler{})

	app.Handle(nom.PacketOut{}, pktOutHandler{})

	app.Handle(nom.AddTrigger{}, addTriggerHandler{})

	app.Handle(nom.FlowStatsQueryResult{}, Consolidator{})
	app.Handle(nom.Pong{}, HealthChecker{})
	app.Handle(poll{}, Poller{})
	app.Detached(bh.NewTimer(1*time.Second, func() {
		h.Emit(poll{})
	}))
}