예제 #1
0
파일: node.go 프로젝트: guanqun/cockroach
func runStatusNode(cmd *cobra.Command, args []string) error {
	var nodeStatuses []status.NodeStatus

	switch len(args) {
	case 0:
		// Show status for all nodes.
		jsonResponse := map[string][]status.NodeStatus{}
		if err := getJSON(cliContext.Addr, server.PathForNodeStatus(""), &jsonResponse); err != nil {
			return err
		}
		nodeStatuses = jsonResponse["d"]

	case 1:
		nodeStatus := status.NodeStatus{}
		nodeID := args[0]
		if err := getJSON(cliContext.Addr, server.PathForNodeStatus(nodeID), &nodeStatus); err != nil {
			return err
		}
		if nodeStatus.Desc.NodeID == 0 {
			// I'm not sure why the status call doesn't return an error when the given NodeID doesn't
			// exist. This should be revisited.
			//
			// TODO(cdo): Look into why status call returns erroneous data when given node ID of 0.
			return fmt.Errorf("Error: node %s doesn't exist", nodeID)
		}
		nodeStatuses = []status.NodeStatus{nodeStatus}

	default:
		mustUsage(cmd)
		return util.Errorf("expected no arguments or a single node ID")
	}

	printQueryOutput(os.Stdout, nodesColumnHeaders, nodeStatusesToRows(nodeStatuses))
	return nil
}
예제 #2
0
파일: node.go 프로젝트: guanqun/cockroach
func runLsNodes(cmd *cobra.Command, args []string) error {
	if len(args) != 0 {
		mustUsage(cmd)
	}

	// Extract Node IDs from NodeStatuses.
	nodeStatuses := map[string][]status.NodeStatus{}
	if err := getJSON(cliContext.Addr, server.PathForNodeStatus(""), &nodeStatuses); err != nil {
		return err
	}

	var rows [][]string
	for _, nodeStatus := range nodeStatuses["d"] {
		rows = append(rows, []string{
			strconv.FormatInt(int64(nodeStatus.Desc.NodeID), 10),
		})
	}

	printQueryOutput(os.Stdout, lsNodesColumnHeaders, rows)
	return nil
}