Ejemplo n.º 1
0
func (c *Controller) InitEtcdLayout() error {
	// Initilize the job epoch to 0
	etcdutil.MustCreate(c.etcdclient, c.logger, etcdutil.EpochPath(c.name), "0", 0)
	c.setupWatchOnJobStatus()
	// initiate etcd data layout for tasks
	// currently it creates as many unassigned tasks as task masters.
	for i := uint64(0); i < c.numOfTasks; i++ {
		key := etcdutil.FreeTaskPath(c.name, strconv.FormatUint(i, 10))
		etcdutil.MustCreate(c.etcdclient, c.logger, key, "", 0)
		key = etcdutil.MetaPath(c.name, i)
		etcdutil.MustCreate(c.etcdclient, c.logger, key, "", 0)
	}
	return nil
}
Ejemplo n.º 2
0
func (c *Controller) setupWatchOnJobStatus() {
	c.jobStatusChan = make(chan string, 1)
	key := etcdutil.JobStatusPath(c.name)
	resp := etcdutil.MustCreate(c.etcdclient, c.logger, key, "", 0)
	go func() {
		resp, err := c.etcdclient.Watch(key, resp.EtcdIndex+1, false, nil, nil)
		if err != nil {
			c.logger.Panicf("Watch on job status (%v) failed: %v", key, err)
		}
		c.jobStatusChan <- resp.Node.Value
	}()
}