func (node *JobNode) initNode() {
	txResponse, err := node.registerJobNode()
	if err != nil {
		log.Fatalf("the job node:%s, fail register to :%s", node.id, node.registerPath)
	}
	if !txResponse.Success {
		log.Fatalf("the job node:%s, fail register to :%s,the job node id exist ", node.id, node.registerPath)
	}
	log.Printf("the job node:%s, success register to :%s", node.id, node.registerPath)
	node.watchRegisterJobNode()
	node.watchElectPath()
	go node.loopStartElect()
}
start register node
package forest
import (
	"fmt"
	_ "github.com/go-sql-driver/mysql"
	"github.com/go-xorm/xorm"
	"github.com/labstack/gommon/log"
	"time"
)
const (
	JobNodePath      = "/forest/server/node/"
	JobNodeElectPath = "/forest/server/elect/leader"
	TTL              = 5
)
type JobNode struct {
	id           string
	registerPath string
	electPath    string
	etcd         *Etcd
	state        int
	apiAddress   string
	api          *JobAPi
	manager      *JobManager
	scheduler    *JobScheduler
	groupManager *JobGroupManager
	exec         *JobExecutor
	engine       *xorm.Engine
	collection   *JobCollection
	failOver     *JobSnapshotFailOver
	listeners    []NodeStateChangeListener
	close        chan bool
}
type NodeStateChangeListener interface {
	notify(int)
}
func NewJobNode(id string, etcd *Etcd, httpAddress, dbUrl string) (node *JobNode, err error) {
	engine, err := xorm.NewEngine("mysql", dbUrl)
	if err != nil {
		return
	}
	node = &JobNode{
		id:           id,
		registerPath: fmt.Sprintf("%s%s", JobNodePath, id),
		electPath:    JobNodeElectPath,
		etcd:         etcd,
		state:        NodeFollowerState,
		apiAddress:   httpAddress,
		close:        make(chan bool),
		engine:       engine,
		listeners:    make([]NodeStateChangeListener, 0),
	}
	node.failOver = NewJobSnapshotFailOver(node)
	node.collection = NewJobCollection(node)
	node.initNode()
	node.exec = NewJobExecutor(node)
	node.groupManager = NewJobGroupManager(node)
	node.scheduler = NewJobScheduler(node)
	node.manager = NewJobManager(node)
	node.api = NewJobAPi(node)
	return
}
func (node *JobNode) addListeners() {
	node.listeners = append(node.listeners, node.scheduler)
}
func (node *JobNode) changeState(state int) {
	node.state = state
	if len(node.listeners) == 0 {
		return
	}
	for _, listener := range node.listeners {
		listener.notify(state)
	}
}