func NewAppConfig(app, version string) App { svcCfg := &AppConfig{ name: app, versionVMap: utils.NewVersionedMap(), environmentVMap: utils.NewVersionedMap(), portsVMap: utils.NewVersionedMap(), runtimeVMap: utils.NewVersionedMap(), } svcCfg.SetVersion(version) return svcCfg }
func (r *RedisBackend) UpdateHost(env, pool string, host HostInfo) error { key := path.Join(env, pool, "hosts", host.HostIP, "info") existing := utils.NewVersionedMap() err := r.LoadVMap(key, existing) if err != nil { return err } save := false if existing.Get("HostIP") != host.HostIP { existing.Set("HostIP", host.HostIP) save = true } if save { err = r.SaveVMap(key, existing) if err != nil { return err } } _, err = r.Expire(key, DefaultTTL) return err }
// FIXME: We still have a function that returns just an *AppConfig for the // RedisBackend. Unify these somehow, and preferebly decouple this from // config.Store. func (s *Store) NewAppConfig(app, version string) App { var appCfg App switch s.Backend.(type) { case *RedisBackend: appCfg = &AppConfig{ name: app, versionVMap: utils.NewVersionedMap(), environmentVMap: utils.NewVersionedMap(), portsVMap: utils.NewVersionedMap(), runtimeVMap: utils.NewVersionedMap(), } case *ConsulBackend: appCfg = &AppDefinition{ AppName: app, Environment: make(map[string]string), } default: panic("unknown backend") } appCfg.SetVersion(version) return appCfg }
func (r *RedisBackend) ListHosts(env, pool string) ([]HostInfo, error) { key := path.Join(env, pool, "hosts", "*", "info") keys, err := r.Keys(key) if err != nil { return nil, err } hosts := []HostInfo{} for _, k := range keys { existing := utils.NewVersionedMap() err := r.LoadVMap(k, existing) if err != nil { return nil, err } hosts = append(hosts, HostInfo{ HostIP: existing.Get("HostIP"), }) } return hosts, nil }