func ModifyNamespace(namespace *models.Namespace, cfg *models.CCConfig, cluster string) (err error) {
	if err = namespace.Verify(); err != nil {
		return fmt.Errorf("verify namespace error: %v", err)
	}
	if err = namespace.Encrypt(cfg.EncryptKey); err != nil {
		return fmt.Errorf("encrypt namespace error: %v", err)
	}
	client := models.NewClient(models.ConfigEtcd, cfg.CoordinatorAddr, cfg.UserName, cfg.Password, getCoordinatorRoot(cluster))
	storeConn := models.NewStore(client)
	defer storeConn.Close()
	if err := storeConn.UpdateNamespace(namespace); err != nil {
		log.Warn("update namespace failed, %s", string(namespace.Encode()))
		return err
	}
	proxies, err := storeConn.ListProxyMonitorMetrics()
	if err != nil {
		log.Warn("list proxies failed, %v", err)
		return err
	}
	for _, v := range proxies {
		err := proxy.PrepareConfig(v.IP+":"+v.AdminPort, namespace.Name, cfg)
		if err != nil {
			return err
		}
	}
	for _, v := range proxies {
		err := proxy.CommitConfig(v.IP+":"+v.AdminPort, namespace.Name, cfg)
		if err != nil {
			return err
		}
	}
	return nil
}
ModifyNamespace create or modify namespace
package service
import (
	"fmt"
	"sync"
	"github.com/nooncall/shazam/cc/proxy"
	"github.com/nooncall/shazam/log"
	"github.com/nooncall/shazam/models"
)
func getCoordinatorRoot(cluster string) string {
	if cluster != "" {
		return "/" + cluster
	}
	return cluster
}
func ListNamespace(cfg *models.CCConfig, cluster string) ([]string, error) {
	client := models.NewClient(models.ConfigEtcd, cfg.CoordinatorAddr, cfg.UserName, cfg.Password, getCoordinatorRoot(cluster))
	mConn := models.NewStore(client)
	defer mConn.Close()
	return mConn.ListNamespace()
}
func QueryNamespace(names []string, cfg *models.CCConfig, cluster string) (data []*models.Namespace, err error) {
	client := models.NewClient(models.ConfigEtcd, cfg.CoordinatorAddr, cfg.UserName, cfg.Password, getCoordinatorRoot(cluster))
	mConn := models.NewStore(client)
	defer mConn.Close()
	for _, v := range names {
		namespace, err := mConn.LoadNamespace(cfg.EncryptKey, v)
		if err != nil {
			log.Warn("load namespace %s failed, %v", v, err.Error())
			return nil, err
		}
		if namespace == nil {
			log.Warn("namespace %s not found", v)
			return data, nil
		}
		data = append(data, namespace)
	}
	return data, nil
}