コード例 #1
0
ファイル: job.go プロジェクト: funkygao/gafka
func (this *Job) connectMysqlCluster(appid string) int {
	b, err := this.zkzone.KatewayJobClusterConfig()
	if err != nil {
		panic(err)
	}
	var mcc = &config.ConfigMysql{}
	if err = mcc.From(b); err != nil {
		panic(err)
	}

	this.mc = mysql.New(mcc)
	return jm.App_id(appid)
}
コード例 #2
0
ファイル: controller.go プロジェクト: funkygao/gafka
func New(zkzone *zk.ZkZone, listenAddr string, managerType string) Controller {
	// mysql cluster config
	b, err := zkzone.KatewayJobClusterConfig()
	if err != nil {
		panic(err)
	}
	var mcc = &config.ConfigMysql{}
	if err = mcc.From(b); err != nil {
		panic(err)
	}

	this := &controller{
		quiting:      make(chan struct{}),
		orchestrator: zkzone.NewOrchestrator(),
		mc:           mysql.New(mcc),
		ListenAddr:   listenAddr,
		Version:      gafka.BuildId,
	}
	this.ident, err = this.generateIdent()
	if err != nil {
		panic(err)
	}

	// hostname:95f333fb-731c-9c95-c598-8d6b99a9ec7d
	p := strings.SplitN(this.ident, ":", 2)
	this.shortId = fmt.Sprintf("%s:%s", p[0], this.ident[strings.LastIndexByte(this.ident, '-')+1:])
	this.setupAuditor()

	switch managerType {
	case "mysql":
		cf := mmysql.DefaultConfig(zkzone.Name())
		cf.Refresh = time.Minute * 5
		manager.Default = mmysql.New(cf)

	case "dummy":
		manager.Default = mdummy.New("")

	default:
		panic("unknown manager: " + managerType)
	}

	return this
}
コード例 #3
0
ファイル: actord.go プロジェクト: funkygao/gafka
func (this *WatchActord) Init(ctx monitor.Context) {
	this.Zkzone = ctx.ZkZone()
	this.Stop = ctx.StopChan()
	this.Wg = ctx.Inflight()

	b, err := this.Zkzone.KatewayJobClusterConfig()
	if err != nil {
		log.Error(err)
		return
	}
	var mcc = &config.ConfigMysql{}
	if err = mcc.From(b); err != nil {
		log.Error(err)
		return
	}

	this.mc = mysql.New(mcc)
	manager.Default = dummy.New("")
}
コード例 #4
0
ファイル: mysql.go プロジェクト: funkygao/gafka
func New(id string, cf *config.ConfigMysql) (job.JobStore, error) {
	if cf == nil {
		return nil, fmt.Errorf("job store: empty mysql config")
	}

	wid, err := strconv.Atoi(id)
	if err != nil {
		return nil, err
	}

	ig, err := idgen.NewIdGenerator(wid)
	if err != nil {
		return nil, err
	}

	cf.DefaultLookupTable = appLookupTable
	return &mysqlStore{
		idgen: ig,
		mc:    mysql.New(cf),
	}, nil
}
コード例 #5
0
ファイル: servant.go プロジェクト: lucmichalski/fae
// TODO kill some servant if new conf turns it off
func (this *FunServantImpl) recreateServants(cf *config.ConfigServant) {
	log.Info("recreating servants...")

	if this.conf.IdgenWorkerId != cf.IdgenWorkerId {
		log.Debug("recreating servant: idgen")
		var err error
		this.idgen, err = idgen.NewIdGenerator(cf.IdgenWorkerId)
		if err != nil {
			panic(err)
		}
	}

	if cf.Lcache.Enabled() &&
		this.conf.Lcache.MaxItems != cf.Lcache.MaxItems {
		log.Debug("recreating servant: lcache")
		this.lc = cache.NewLruCache(cf.Lcache.MaxItems)
		this.lc.OnEvicted = this.onLcLruEvicted
	}

	if cf.Memcache.Enabled() &&
		!reflect.DeepEqual(*this.conf.Memcache, *cf.Memcache) {
		log.Debug("recreating servant: memcache")
		this.mc = memcache.New(cf.Memcache)
	}

	if cf.Redis.Enabled() &&
		!reflect.DeepEqual(*this.conf.Redis, *cf.Redis) {
		log.Debug("recreating servant: redis")
		this.rd = redis.New(cf.Redis)
	}

	if cf.Mysql.Enabled() &&
		!reflect.DeepEqual(*this.conf.Mysql, *cf.Mysql) {
		log.Debug("recreating servant: mysql")
		this.my = mysql.New(cf.Mysql)

		switch cf.Mysql.CacheStore {
		case "mem":
			this.dbCacheStore = store.NewMemStore(cf.Mysql.CacheStoreMemMaxItems)

		case "redis":
			this.dbCacheStore = store.NewRedisStore(cf.Mysql.CacheStoreRedisPool,
				cf.Redis)

		default:
			panic("unknown cache store")
		}
	}

	if cf.Mongodb.Enabled() &&
		!reflect.DeepEqual(*this.conf.Mongodb, *cf.Mongodb) {
		log.Debug("recreating servant: mongodb")
		this.mg = mongo.New(cf.Mongodb)
	}

	if cf.Couchbase.Enabled() &&
		!reflect.DeepEqual(*this.conf.Couchbase, *cf.Couchbase) {
		log.Debug("recreating servant: couchbase")

		var err error
		// pool is always 'default'
		this.cb, err = couch.New(cf.Couchbase.Servers, "default")
		if err != nil {
			log.Error("couchbase: %s", err)
		}
	}

	this.conf = cf

	log.Info("servants recreated")
}
コード例 #6
0
ファイル: servant.go プロジェクト: lucmichalski/fae
func (this *FunServantImpl) createServants() {
	log.Info("creating servants...")

	// proxy can dynamically auto discover peers
	if this.conf.Proxy.Enabled() {
		log.Debug("creating servant: proxy")
		this.proxy = proxy.New(this.conf.Proxy)
	} else {
		panic("peers proxy required")
	}

	log.Debug("creating servant: idgen")
	var err error
	this.idgen, err = idgen.NewIdGenerator(this.conf.IdgenWorkerId)
	if err != nil {
		panic(err)
	}

	if this.conf.Lcache.Enabled() {
		log.Debug("creating servant: lcache")
		this.lc = cache.NewLruCache(this.conf.Lcache.MaxItems)
		this.lc.OnEvicted = this.onLcLruEvicted
	}

	if this.conf.Memcache.Enabled() {
		log.Debug("creating servant: memcache")
		this.mc = memcache.New(this.conf.Memcache)
	}

	if this.conf.Redis.Enabled() {
		log.Debug("creating servant: redis")
		this.rd = redis.New(this.conf.Redis)
	}

	if this.conf.Lock.Enabled() {
		log.Debug("creating servant: lock")
		this.lk = lock.New(this.conf.Lock)
	}

	if this.conf.Mysql.Enabled() {
		log.Debug("creating servant: mysql")
		this.my = mysql.New(this.conf.Mysql)

		switch this.conf.Mysql.CacheStore {
		case "mem":
			this.dbCacheStore = store.NewMemStore(this.conf.Mysql.CacheStoreMemMaxItems)

		case "redis":
			this.dbCacheStore = store.NewRedisStore(this.conf.Mysql.CacheStoreRedisPool,
				this.conf.Redis)

		default:
			panic("unknown mysql cache store")
		}
	}

	if this.conf.Mongodb.Enabled() {
		log.Debug("creating servant: mongodb")
		this.mg = mongo.New(this.conf.Mongodb)
		if this.conf.Mongodb.DebugProtocol ||
			this.conf.Mongodb.DebugHeartbeat {
			mgo.SetLogger(&mongoProtocolLogger{})
			mgo.SetDebug(this.conf.Mongodb.DebugProtocol)
		}
	}

	if this.conf.Couchbase.Enabled() {
		log.Debug("creating servant: couchbase")

		var err error
		// pool is always 'default'
		this.cb, err = couch.New(this.conf.Couchbase.Servers, "default")
		if err != nil {
			log.Error("couchbase: %s", err)
		}
	}

	log.Info("servants created")
}