Пример #1
0
func apiSlotRangeSet(task RangeSetTask) (int, string) {
	conn := CreateCoordConn()
	defer conn.Close()

	lock := utils.GetCoordLock(conn, globalEnv.ProductName())
	lock.Lock(fmt.Sprintf("set slot range, %+v", task))
	defer func() {
		err := lock.Unlock()
		if err != nil {
			log.Warning(err)
		}
	}()

	// default set online
	if len(task.Status) == 0 {
		task.Status = string(models.SLOT_STATUS_ONLINE)
	}

	err := models.SetSlotRange(conn, globalEnv.ProductName(), task.FromSlot, task.ToSlot, task.NewGroupId, models.SlotStatus(task.Status))
	if err != nil {
		log.Warning(err)
		return 500, err.Error()
	}

	return jsonRetSucc()
}
Пример #2
0
func (s *testProxyRouterSuite) initEnv(c *C) {
	go once.Do(func() {
		conn = zkhelper.NewConn()
		conf = &Conf{
			ProductName:     "test",
			CoordinatorAddr: "localhost:2181",
			NetTimeout:      5,
			f:               func(string) (zkhelper.Conn, error) { return conn, nil },
			Proto:           "tcp4",
			ProxyID:         "proxy_test",
			Addr:            ":19000",
			HTTPAddr:        ":11000",
			ProxyAuth:       proxyAuth,
			StoreAuth:       storeAuth,
		}

		// init action path
		prefix := models.GetWatchActionPath(conf.ProductName)
		err := models.CreateActionRootPath(conn, prefix)
		c.Assert(err, IsNil)

		// init slot
		err = models.InitSlotSet(conn, conf.ProductName, 1024)
		c.Assert(err, IsNil)

		// init  server group
		g1 := models.NewServerGroup(conf.ProductName, 1)
		g1.Create(conn)
		g2 := models.NewServerGroup(conf.ProductName, 2)
		g2.Create(conn)

		s1 := models.NewServer(models.SERVER_TYPE_MASTER, s.s1.addr)
		s2 := models.NewServer(models.SERVER_TYPE_MASTER, s.s2.addr)

		g1.AddServer(conn, s1, storeAuth)
		g2.AddServer(conn, s2, storeAuth)

		// set slot range
		err = models.SetSlotRange(conn, conf.ProductName, 0, 511, 1, models.SLOT_STATUS_ONLINE)
		c.Assert(err, IsNil)

		err = models.SetSlotRange(conn, conf.ProductName, 512, 1023, 2, models.SLOT_STATUS_ONLINE)
		c.Assert(err, IsNil)

		go func() { //set proxy online
			time.Sleep(3 * time.Second)
			err := models.SetProxyStatus(conn, conf.ProductName, conf.ProxyID, models.PROXY_STATE_ONLINE)
			c.Assert(err, IsNil)

			time.Sleep(2 * time.Second)
			proxyMutex.Lock()
			defer proxyMutex.Unlock()

			pi := ss.getProxyInfo()
			c.Assert(pi.State, Equals, models.PROXY_STATE_ONLINE)
		}()

		proxyMutex.Lock()
		ss = NewServer(conf)
		proxyMutex.Unlock()
		ss.Run()
	})

	waitonce.Do(func() {
		time.Sleep(10 * time.Second)
	})
}