예제 #1
0
파일: none.go 프로젝트: nanopack/portal
func (n None) SetVips(vips []core.Vip) error {
	err := common.SetVips(vips)
	if err != nil {
		return err
	}
	if database.CentralStore {
		return database.SetVips(vips)
	}
	return nil
}
예제 #2
0
파일: none.go 프로젝트: nanopack/portal
func (n None) Init() error {
	// load services
	services, err := common.GetServices()
	if err != nil {
		return err
	}
	// apply services
	err = common.SetServices(services)
	if err != nil {
		return err
	}

	// load routes
	routes, err := common.GetRoutes()
	if err != nil {
		return err
	}
	// apply routes
	err = common.SetRoutes(routes)
	if err != nil {
		return err
	}

	// load certs
	certs, err := common.GetCerts()
	if err != nil {
		return err
	}
	// apply certs
	err = common.SetCerts(certs)
	if err != nil {
		return err
	}

	// load vips
	vips, err := common.GetVips()
	if err != nil {
		return err
	}
	// apply vips
	err = common.SetVips(vips)
	if err != nil {
		return err
	}
	return nil
}
예제 #3
0
파일: redis.go 프로젝트: nanopack/portal
// todo: clustered
func (r Redis) SetVips(vips []core.Vip) error {
	return common.SetVips(vips)
}
예제 #4
0
파일: redis.go 프로젝트: nanopack/portal
func (r *Redis) Init() error {
	hostname, _ := os.Hostname()
	self = fmt.Sprintf("%v:%v", hostname, config.ApiPort)
	pool = r.newPool(config.ClusterConnection, config.ClusterToken)

	// get services
	services, err := r.GetServices()
	if err != nil {
		return fmt.Errorf("Failed to get services - %v", err)
	}
	// write services
	if services != nil {
		config.Log.Trace("[cluster] - Setting services...")
		err = common.SetServices(services)
		if err != nil {
			return fmt.Errorf("Failed to set services - %v", err)
		}
	}

	// get routes
	routes, err := r.GetRoutes()
	if err != nil {
		return fmt.Errorf("Failed to get routes - %v", err)
	}
	// write routes
	if routes != nil {
		config.Log.Trace("[cluster] - Setting routes...")
		err = common.SetRoutes(routes)
		if err != nil {
			return fmt.Errorf("Failed to set routes - %v", err)
		}
	}

	// get certs
	certs, err := r.GetCerts()
	if err != nil {
		return fmt.Errorf("Failed to get certs - %v", err)
	}
	// write certs
	if certs != nil {
		config.Log.Trace("[cluster] - Setting certs...")
		err = common.SetCerts(certs)
		if err != nil {
			return fmt.Errorf("Failed to set certs - %v", err)
		}
	}

	// get vips
	vips, err := r.GetVips()
	if err != nil {
		return fmt.Errorf("Failed to get vips - %v", err)
	}
	// write vips
	if vips != nil {
		config.Log.Trace("[cluster] - Setting vips...")
		err = common.SetVips(vips)
		if err != nil {
			return fmt.Errorf("Failed to set vips - %v", err)
		}
	}

	// note: keep subconn connection initialization out here or sleep after `go r.subscribe()`
	// don't set read timeout on subscriber - it dies if no 'updates' within that time
	s, err := redis.DialURL(config.ClusterConnection, redis.DialConnectTimeout(30*time.Second), redis.DialPassword(config.ClusterToken))
	if err != nil {
		return fmt.Errorf("Failed to reach redis for subconn - %v", err)
	}

	r.subconn = redis.PubSubConn{s}
	r.subconn.Subscribe("portal")

	p := pool.Get()
	defer p.Close()

	p.Do("SET", self, "alive", "EX", ttl)
	_, err = p.Do("SADD", "members", self)
	if err != nil {
		return fmt.Errorf("Failed to add myself to list of members - %v", err)
	}

	go r.subscribe()
	go r.heartbeat()
	go r.cleanup()

	return nil
}