示例#1
0
// create new server group
func apiAddServerGroup(newGroup models.ServerGroup) (int, string) {
	lock := utils.GetZkLock(safeZkConn, globalEnv.ProductName())
	if err := lock.LockWithTimeout(0, fmt.Sprintf("add group %+v", newGroup)); err != nil {
		return 500, err.Error()
	}

	defer func() {
		err := lock.Unlock()
		if err != nil && err != zk.ErrNoNode {
			log.ErrorErrorf(err, "unlock node failed")
		}
	}()

	newGroup.ProductName = globalEnv.ProductName()

	exists, err := newGroup.Exists(safeZkConn)
	if err != nil {
		log.ErrorErrorf(err, "check group exits failed")
		return 500, err.Error()
	}
	if exists {
		return 500, "group already exists"
	}
	err = newGroup.Create(safeZkConn)
	if err != nil {
		log.ErrorErrorf(err, "create node for new group failed")
		return 500, err.Error()
	}
	return jsonRetSucc()
}
示例#2
0
// create new server group
func apiAddServerGroup(newGroup models.ServerGroup) (int, string) {
	lock := utils.GetZkLock(safeZkConn, globalEnv.ProductName())
	lock.Lock(fmt.Sprintf("add group %+v", newGroup))

	defer func() {
		err := lock.Unlock()
		if err != nil {
			log.Warning(err)
		}
	}()

	newGroup.ProductName = globalEnv.ProductName()

	exists, err := newGroup.Exists(safeZkConn)
	if err != nil {
		log.Warning(err)
		return 500, err.Error()
	}
	if exists {
		return 500, "group already exists"
	}
	err = newGroup.Create(safeZkConn)
	if err != nil {
		log.Warning(err)
		return 500, err.Error()
	}
	return jsonRetSucc()
}
示例#3
0
// create new server group
func apiAddServerGroup(newGroup models.ServerGroup) (int, string) {
	conn := CreateZkConn()
	defer conn.Close()

	lock := utils.GetZkLock(conn, productName)
	lock.Lock(fmt.Sprintf("add group %+v", newGroup))

	defer func() {
		err := lock.Unlock()
		if err != nil {
			log.Warning(err)
		}
	}()

	newGroup.ProductName = productName

	exists, err := newGroup.Exists(conn)
	if err != nil {
		log.Warning(err)
		return 500, err.Error()
	}
	if exists {
		return jsonRet(map[string]interface{}{
			"ret": 0,
			"msg": "group already exists",
		})
	}
	err = newGroup.Create(conn)
	if err != nil {
		log.Warning(err)
		return 500, err.Error()
	}
	return jsonRetSucc()
}