示例#1
0
func DeletePool(name string) error {
	if name == "" {
		return errors.New("Please specify a name")
	}

	return routerzk.DelPool(zkConn.Conn, name)
}
示例#2
0
func DeleteFromPool(containers []string) error {
	pools := map[bool]map[string]*poolDefinition{}
	pools[true] = map[string]*poolDefinition{}
	pools[false] = map[string]*poolDefinition{}
	for _, cont := range containers {
		inst, err := GetInstance(cont)
		if err != nil {
			// instance doesn't exist
			continue
		}
		name := helper.CreatePoolName(inst.App, inst.Sha, inst.Env)
		zkApp, err := GetApp(inst.App)
		if err != nil {
			return err
		}
		poolDef := pools[zkApp.Internal][name]
		if poolDef == nil {
			poolDef = &poolDefinition{
				app:   inst.App,
				sha:   inst.Sha,
				env:   inst.Env,
				insts: []*ZkInstance{},
			}
			pools[zkApp.Internal][name] = poolDef
		}
		pools[zkApp.Internal][name].insts = append(poolDef.insts, inst)
	}
	for internal, allPools := range pools {
		helper.SetRouterRoot(internal)
		for name, poolDef := range allPools {
			// remove hosts
			hosts := []string{}
			for _, inst := range poolDef.insts {
				hosts = append(hosts, fmt.Sprintf("%s:%d", inst.Host, inst.Port))
			}
			routerzk.DelHosts(Zk.Conn, name, hosts)
			// delete pool if no hosts exist
			getHosts, err := routerzk.GetHosts(Zk.Conn, name)
			if err != nil || len(getHosts) == 0 {
				err = routerzk.DelPool(Zk.Conn, name)
				if err != nil {
					log.Println("Error trying to clean up pool:", err)
				}
				err = CleanupCreatedPoolRefs(internal, poolDef.app, poolDef.sha, poolDef.env)
				if err != nil {
					log.Println("Error trying to clean up pool:", err)
				}
			}
		}
	}
	return nil
}
示例#3
0
func (e *DeletePoolExecutor) Execute(t *Task) (err error) {
	if e.arg.Name == "" {
		return errors.New("Please specify a name")
	}
	helper.SetRouterRoot(e.arg.Internal)
	err = routerzk.DelPool(datamodel.Zk.Conn, e.arg.Name)
	if err != nil {
		e.reply.Status = StatusError
	} else {
		e.reply.Status = StatusOk
	}
	return err
}