Esempio n. 1
0
func PostSeeds() {
	if !IsRegionLeader() {
		url := "http://" + RegionLeaderHttpAddress() + api.MergeSeedsPath
		req := api.MergeSeedsParams{
			Region: LocalRegion(),
			Seeds:  meta.seeds,
		}

		glog.Warningf("Post %s seeds %v to be merged", LocalRegion(), meta.seeds)

		utils.HttpPost(url, req, 5*time.Second)
	}
}
Esempio n. 2
0
func fixClusterAction(c *cli.Context) {
	addr := context.GetLeaderAddr()

	url := "http://" + addr + api.FixClusterPath

	resp, err := utils.HttpPost(url, nil, 0)
	if err != nil {
		Put(err)
		return
	}
	if resp != nil {
		ShowResponse(resp)
	} else {
		Put("Nil response")
	}
}
Esempio n. 3
0
func SendRegionTopoSnapshot(nodes []*topo.Node, failureInfo *topo.FailureInfo) error {
	params := &api.RegionSnapshotParams{
		Region:      meta.LocalRegion(),
		PostTime:    time.Now().Unix(),
		Nodes:       nodes,
		FailureInfo: failureInfo,
	}

	resp, err := utils.HttpPost(MkUrl(api.RegionSnapshotPath), params, 30*time.Second)
	if err != nil {
		return err
	}
	if resp.Errno != 0 {
		return fmt.Errorf("%d %s", resp.Errno, resp.Errmsg)
	}
	return nil
}
Esempio n. 4
0
func logAction(c *cli.Context) {
	// tail -n
	if len(c.Args()) == 1 {
		n, err := strconv.Atoi(c.Args()[0])
		if err != nil {
			Put(err)
			return
		}
		addr := context.GetLeaderAddr()
		url := "http://" + addr + api.LogSlicePath
		req := api.LogSliceParams{
			Pos:   0,
			Count: n,
		}
		resp, err := utils.HttpPost(url, req, 5*time.Second)
		if err != nil {
			Put(err)
			return
		}

		var lines []string
		err = utils.InterfaceToStruct(resp.Body, &lines)
		if err != nil {
			Put(err)
			return
		}
		for _, line := range lines {
			Putf(line)
		}
		return
	}

	// blocking tail
	addr := context.GetLeaderWebSocketAddr()
	url := "ws://" + addr + "/log"

	conn, err := websocket.Dial(url, "", url)
	if err != nil {
		Put(err)
		return
	}

	args := c.Args()
	level := "VERBOSE"
	if len(args) > 0 {
		level = args[0]
	}

	var msg streams.LogStreamData
	for {
		err := websocket.JSON.Receive(conn, &msg)
		if err != nil {
			if err == io.EOF {
				break
			}
			Put("Couldn't receive msg " + err.Error())
			break
		}
		if LevelGE(msg.Level, level) {
			Putf("%s %s: [%s] - %s\n", msg.Level, msg.Time.Format("2006/01/02 15:04:05"), msg.Target, msg.Message)
		}
	}
}