当前位置: 首页>>代码示例>>Golang>>正文


Golang config.Store类代码示例

本文整理汇总了Golang中github.com/litl/galaxy/config.Store的典型用法代码示例。如果您正苦于以下问题:Golang Store类的具体用法?Golang Store怎么用?Golang Store使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Store类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: AppRestart

func AppRestart(Store *config.Store, app, env string) error {
	err := Store.NotifyRestart(app, env)
	if err != nil {
		return fmt.Errorf("could not restart %s: %s", app, err)
	}
	return nil
}
开发者ID:carriercomm,项目名称:galaxy,代码行数:7,代码来源:app.go

示例2: AppAssign

func AppAssign(configStore *config.Store, app, env, pool string) error {
	// Don't allow deleting runtime hosts entries
	if app == "hosts" || app == "pools" {
		return fmt.Errorf("invalid app name: %s", app)
	}

	exists, err := configStore.PoolExists(env, pool)
	if err != nil {
		return err
	}

	if !exists {
		log.Warnf("WARN: Pool %s does not exist.", pool)
	}

	created, err := configStore.AssignApp(app, env, pool)

	if err != nil {
		return err
	}

	if created {
		log.Printf("Assigned %s in env %s to pool %s.\n", app, env, pool)
	} else {
		log.Printf("%s already assigned to pool %s in env %s.\n", app, pool, env)
	}
	return nil
}
开发者ID:carriercomm,项目名称:galaxy,代码行数:28,代码来源:app.go

示例3: ConfigList

func ConfigList(configStore *config.Store, app, env string) error {

	cfg, err := configStore.GetApp(app, env)
	if err != nil {
		return err
	}

	if cfg == nil {
		return fmt.Errorf("unable to list config for %s.", app)
	}

	keys := sort.StringSlice{"ENV"}
	for k, _ := range cfg.Env() {
		keys = append(keys, k)
	}

	keys.Sort()

	for _, k := range keys {
		if k == "ENV" {
			log.Printf("%s=%s\n", k, env)
			continue
		}
		fmt.Printf("%s=%s\n", k, cfg.Env()[k])
	}

	return nil
}
开发者ID:sguzwf,项目名称:galaxy,代码行数:28,代码来源:config.go

示例4: RuntimeUnset

func RuntimeUnset(configStore *config.Store, app, env, pool string, options RuntimeOptions) (bool, error) {

	cfg, err := configStore.GetApp(app, env)
	if err != nil {
		return false, err
	}

	if options.Ps != 0 {
		cfg.SetProcesses(pool, -1)
	}

	if options.Memory != "" {
		cfg.SetMemory(pool, "")
	}

	vhosts := strings.Split(cfg.Env()["VIRTUAL_HOST"], ",")
	if options.VirtualHost != "" && utils.StringInSlice(options.VirtualHost, vhosts) {
		vhosts = utils.RemoveStringInSlice(options.VirtualHost, vhosts)
		cfg.EnvSet("VIRTUAL_HOST", strings.Join(vhosts, ","))
	}

	if options.Port != "" {
		cfg.EnvSet("GALAXY_PORT", "")
	}

	return configStore.UpdateApp(cfg, env)
}
开发者ID:zombor,项目名称:galaxy,代码行数:27,代码来源:runtime.go

示例5: RuntimeSet

func RuntimeSet(configStore *config.Store, app, env, pool string, options RuntimeOptions) (bool, error) {

	cfg, err := configStore.GetApp(app, env)
	if err != nil {
		return false, err
	}

	if options.Ps != 0 && options.Ps != cfg.GetProcesses(pool) {
		cfg.SetProcesses(pool, options.Ps)
	}

	if options.Memory != "" && options.Memory != cfg.GetMemory(pool) {
		cfg.SetMemory(pool, options.Memory)
	}

	vhosts := []string{}
	vhostsFromEnv := cfg.Env()["VIRTUAL_HOST"]
	if vhostsFromEnv != "" {
		vhosts = strings.Split(cfg.Env()["VIRTUAL_HOST"], ",")
	}

	if options.VirtualHost != "" && !utils.StringInSlice(options.VirtualHost, vhosts) {
		vhosts = append(vhosts, options.VirtualHost)
		cfg.EnvSet("VIRTUAL_HOST", strings.Join(vhosts, ","))
	}

	if options.Port != "" {
		cfg.EnvSet("GALAXY_PORT", options.Port)
	}

	return configStore.UpdateApp(cfg, env)
}
开发者ID:zombor,项目名称:galaxy,代码行数:32,代码来源:runtime.go

示例6: AppDeploy

func AppDeploy(configStore *config.Store, serviceRuntime *runtime.ServiceRuntime, app, env, version string) error {
	log.Printf("Pulling image %s...", version)

	image, err := serviceRuntime.PullImage(version, "")
	if image == nil || err != nil {
		return fmt.Errorf("unable to pull %s. Has it been released yet?", version)
	}

	svcCfg, err := configStore.GetApp(app, env)
	if err != nil {
		return fmt.Errorf("unable to deploy app: %s.", err)
	}

	if svcCfg == nil {
		return fmt.Errorf("app %s does not exist. Create it first.", app)
	}

	svcCfg.SetVersion(version)
	svcCfg.SetVersionID(utils.StripSHA(image.ID))

	updated, err := configStore.UpdateApp(svcCfg, env)
	if err != nil {
		return fmt.Errorf("could not store version: %s", err)
	}
	if !updated {
		return fmt.Errorf("%s NOT deployed.", version)
	}
	log.Printf("Deployed %s.\n", version)
	return nil
}
开发者ID:carriercomm,项目名称:galaxy,代码行数:30,代码来源:app.go

示例7: RuntimeList

func RuntimeList(configStore *config.Store, app, env, pool string) error {

	envs := []string{env}

	if env == "" {
		var err error
		envs, err = configStore.ListEnvs()
		if err != nil {
			return err
		}
	}

	columns := []string{"ENV | NAME | POOL | PS | MEM | VHOSTS | PORT | MAINT"}

	for _, env := range envs {

		appList, err := configStore.ListApps(env)
		if err != nil {
			return err
		}

		for _, appCfg := range appList {

			if app != "" && appCfg.Name() != app {
				continue
			}

			for _, p := range appCfg.RuntimePools() {

				if pool != "" && p != pool {
					continue
				}

				name := appCfg.Name()
				ps := appCfg.GetProcesses(p)
				mem := appCfg.GetMemory(p)

				columns = append(columns, strings.Join([]string{
					env,
					name,
					p,
					strconv.FormatInt(int64(ps), 10),
					mem,
					appCfg.Env()["VIRTUAL_HOST"],
					appCfg.Env()["GALAXY_PORT"],
					fmt.Sprint(appCfg.GetMaintenanceMode(p)),
				}, " | "))
			}
		}
	}
	output := columnize.SimpleFormat(columns)
	fmt.Println(output)
	return nil

}
开发者ID:sguzwf,项目名称:galaxy,代码行数:55,代码来源:runtime.go

示例8: ConfigGet

func ConfigGet(configStore *config.Store, app, env string, envVars []string) error {

	cfg, err := configStore.GetApp(app, env)
	if err != nil {
		return err
	}

	for _, arg := range envVars {
		fmt.Printf("%s=%s\n", strings.ToUpper(arg), cfg.Env()[strings.ToUpper(arg)])
	}
	return nil
}
开发者ID:sguzwf,项目名称:galaxy,代码行数:12,代码来源:config.go

示例9: unregisterShuttle

func unregisterShuttle(configStore *config.Store, env, hostIP, shuttleAddr string) {

	if client == nil {
		return
	}

	registrations, err := configStore.ListRegistrations(env)
	if err != nil {
		log.Errorf("ERROR: Unable to list registrations: %s", err)
		return
	}

	backends := make(map[string]*shuttle.ServiceConfig)

	for _, r := range registrations {

		// Registration for a container on a different host? Skip it.
		if r.ExternalIP != hostIP {
			continue
		}

		// No service ports exposed on the host, skip it.
		if r.ExternalAddr() == "" || r.Port == "" {
			continue
		}

		service := backends[r.Name]
		if service == nil {
			service = &shuttle.ServiceConfig{
				Name:         r.Name,
				VirtualHosts: r.VirtualHosts,
			}
			if r.Port != "" {
				service.Addr = "0.0.0.0:" + r.Port
			}
			backends[r.Name] = service
		}
		b := shuttle.BackendConfig{
			Name: r.ContainerID[0:12],
			Addr: r.ExternalAddr(),
		}
		service.Backends = append(service.Backends, b)
	}

	for _, service := range backends {

		err := client.RemoveService(service.Name)
		if err != nil {
			log.Errorf("ERROR: Unable to remove shuttle service: %s", err)
		}
	}

}
开发者ID:zombor,项目名称:galaxy,代码行数:53,代码来源:shuttle.go

示例10: AppShell

func AppShell(configStore *config.Store, serviceRuntime *runtime.ServiceRuntime, app, env, pool string) error {
	appCfg, err := configStore.GetApp(app, env)
	if err != nil {
		return fmt.Errorf("unable to run command: %s.", err)
	}

	err = serviceRuntime.StartInteractive(env, pool, appCfg)
	if err != nil {
		return fmt.Errorf("could not start container: %s", err)
	}
	return nil
}
开发者ID:carriercomm,项目名称:galaxy,代码行数:12,代码来源:app.go

示例11: Status

func Status(serviceRuntime *runtime.ServiceRuntime, configStore *config.Store, env, pool, hostIP string) error {

	containers, err := serviceRuntime.ManagedContainers()
	if err != nil {
		panic(err)
	}

	//FIXME: addresses, port, and expires missing in output
	columns := []string{
		"APP | CONTAINER ID | IMAGE | EXTERNAL | INTERNAL | PORT | CREATED | EXPIRES"}

	for _, container := range containers {
		name := serviceRuntime.EnvFor(container)["GALAXY_APP"]
		registered, err := configStore.GetServiceRegistration(
			env, pool, hostIP, container)
		if err != nil {
			return err
		}

		if registered != nil {
			columns = append(columns,
				strings.Join([]string{
					registered.Name,
					registered.ContainerID[0:12],
					registered.Image,
					registered.ExternalAddr(),
					registered.InternalAddr(),
					registered.Port,
					utils.HumanDuration(time.Now().UTC().Sub(registered.StartedAt)) + " ago",
					"In " + utils.HumanDuration(registered.Expires.Sub(time.Now().UTC())),
				}, " | "))

		} else {
			columns = append(columns,
				strings.Join([]string{
					name,
					container.ID[0:12],
					container.Image,
					"",
					"",
					"",
					utils.HumanDuration(time.Now().Sub(container.Created)) + " ago",
					"",
				}, " | "))
		}

	}

	result, _ := columnize.SimpleFormat(columns)
	log.Println(result)
	return nil
}
开发者ID:zombor,项目名称:galaxy,代码行数:52,代码来源:discovery.go

示例12: AppRun

func AppRun(configStore *config.Store, serviceRuntime *runtime.ServiceRuntime, app, env string, args []string) error {
	appCfg, err := configStore.GetApp(app, env)
	if err != nil {
		return fmt.Errorf("unable to run command: %s.", err)

	}

	_, err = serviceRuntime.RunCommand(env, appCfg, args)
	if err != nil {
		return fmt.Errorf("could not start container: %s", err)
	}
	return nil
}
开发者ID:carriercomm,项目名称:galaxy,代码行数:13,代码来源:app.go

示例13: AppList

func AppList(configStore *config.Store, env string) error {

	envs := []string{env}

	if env == "" {
		var err error
		envs, err = configStore.ListEnvs()
		if err != nil {
			return err
		}
	}

	columns := []string{"NAME | ENV | VERSION | IMAGE ID | CONFIG | POOLS "}

	for _, env := range envs {

		appList, err := configStore.ListApps(env)
		if err != nil {
			return err
		}

		pools, err := configStore.ListPools(env)
		if err != nil {
			return err
		}

		for _, app := range appList {
			name := app.Name()
			versionDeployed := app.Version()
			versionID := app.VersionID()
			if len(versionID) > 12 {
				versionID = versionID[:12]
			}

			assignments := []string{}
			for _, pool := range pools {
				aa, err := configStore.ListAssignments(env, pool)
				if err != nil {
					return err
				}
				if utils.StringInSlice(app.Name(), aa) {
					assignments = append(assignments, pool)
				}
			}

			columns = append(columns, strings.Join([]string{
				name,
				env,
				versionDeployed,
				versionID,
				strconv.FormatInt(app.ID(), 10),
				strings.Join(assignments, ","),
			}, " | "))
		}
	}
	output := columnize.SimpleFormat(columns)
	fmt.Println(output)
	return nil
}
开发者ID:carriercomm,项目名称:galaxy,代码行数:59,代码来源:app.go

示例14: Register

func Register(serviceRuntime *runtime.ServiceRuntime, configStore *config.Store, env, pool, hostIP, shuttleAddr string) {
	if shuttleAddr != "" {
		client = shuttle.NewClient(shuttleAddr)
	}

	RegisterAll(serviceRuntime, configStore, env, pool, hostIP, shuttleAddr, false)

	containerEvents := make(chan runtime.ContainerEvent)
	err := serviceRuntime.RegisterEvents(env, pool, hostIP, containerEvents)
	if err != nil {
		log.Printf("ERROR: Unable to register docker event listener: %s", err)
	}

	for {

		select {
		case ce := <-containerEvents:
			switch ce.Status {
			case "start":
				reg, err := configStore.RegisterService(env, pool, hostIP, ce.Container)
				if err != nil {
					log.Errorf("ERROR: Unable to register container: %s", err)
					continue
				}

				log.Printf("Registered %s running as %s for %s%s", strings.TrimPrefix(reg.ContainerName, "/"),
					reg.ContainerID[0:12], reg.Name, locationAt(reg))
				registerShuttle(configStore, env, shuttleAddr)
			case "die", "stop":
				reg, err := configStore.UnRegisterService(env, pool, hostIP, ce.Container)
				if err != nil {
					log.Errorf("ERROR: Unable to unregister container: %s", err)
					continue
				}

				if reg != nil {
					log.Printf("Unregistered %s running as %s for %s%s", strings.TrimPrefix(reg.ContainerName, "/"),
						reg.ContainerID[0:12], reg.Name, locationAt(reg))
				}
				RegisterAll(serviceRuntime, configStore, env, pool, hostIP, shuttleAddr, true)
				pruneShuttleBackends(configStore, env, shuttleAddr)
			}

		case <-time.After(10 * time.Second):
			RegisterAll(serviceRuntime, configStore, env, pool, hostIP, shuttleAddr, true)
			pruneShuttleBackends(configStore, env, shuttleAddr)
		}
	}
}
开发者ID:zombor,项目名称:galaxy,代码行数:49,代码来源:discovery.go

示例15: PoolCreate

// Create a pool for an environment
func PoolCreate(configStore *config.Store, env, pool string) error {
	exists, err := configStore.PoolExists(env, pool)
	if err != nil {
		return err
	} else if exists {
		return fmt.Errorf("pool '%s' exists", pool)
	}

	_, err = configStore.CreatePool(pool, env)
	if err != nil {
		return err
	}

	return nil
}
开发者ID:sguzwf,项目名称:galaxy,代码行数:16,代码来源:pool.go


注:本文中的github.com/litl/galaxy/config.Store类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。