Ejemplo n.º 1
0
func (c *FakeCluster) addHost(h utils.HostClient) {
	c.hosts[h.ID()] = h

	for ch := range c.hostChannels {
		ch <- createDiscoverdEvent(h.ID(), discoverd.EventKindUp)
	}
}
Ejemplo n.º 2
0
Archivo: host.go Proyecto: rikur/flynn
func NewHost(h utils.HostClient) *Host {
	return &Host{
		ID:      h.ID(),
		client:  h,
		healthy: true,
		stop:    make(chan struct{}),
		done:    make(chan struct{}),
	}
}
Ejemplo n.º 3
0
func NewHost(h utils.HostClient, l log15.Logger) *Host {
	return &Host{
		ID:      h.ID(),
		Tags:    h.Tags(),
		client:  h,
		healthy: true,
		stop:    make(chan struct{}),
		done:    make(chan struct{}),
		logger:  l,
	}
}
Ejemplo n.º 4
0
func (s *Scheduler) followHost(h utils.HostClient) error {
	if _, ok := s.hosts[h.ID()]; ok {
		return nil
	}

	host := NewHost(h)
	jobs, err := host.StreamEventsTo(s.jobEvents)
	if err != nil {
		return err
	}
	s.hosts[host.ID] = host

	for _, job := range jobs {
		s.handleActiveJob(&job)
	}

	s.triggerSyncFormations()

	return nil
}
Ejemplo n.º 5
0
func (s *Scheduler) followHost(h utils.HostClient) {
	if _, ok := s.hostStreams[h.ID()]; ok {
		return
	}

	log := logger.New("fn", "followHost", "host.id", h.ID())
	log.Info("streaming job events")
	events := make(chan *host.Event)
	stream, err := h.StreamEvents("all", events)
	if err != nil {
		log.Error("error streaming job events", "err", err)
		return
	}
	s.hostStreams[h.ID()] = stream

	log.Info("getting active jobs")
	jobs, err := h.ListJobs()
	if err != nil {
		log.Error("error getting active jobs", "err", err)
		return
	}
	log.Info(fmt.Sprintf("got %d active job(s) for host %s", len(jobs), h.ID()))

	for _, job := range jobs {
		s.handleActiveJob(&job)
	}

	s.triggerSyncFormations()

	go func() {
		for e := range events {
			s.jobEvents <- e
		}
		// TODO: reconnect this stream unless unfollowHost was called gh#1921
		log.Error("job event stream closed unexpectedly")
	}()
}