Skip to content

Commit

Permalink
support features and bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
chengshiwen committed Sep 19, 2022
1 parent 42e1417 commit da6e69c
Show file tree
Hide file tree
Showing 76 changed files with 7,787 additions and 1,997 deletions.
2 changes: 1 addition & 1 deletion build.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@

supported_builds = {
'darwin': [ "amd64", "arm64" ],
'windows': [ "amd64" ],
'windows': [ "amd64", "static_amd64" ],
'linux': [ "amd64", "i386", "armhf", "arm64", "static_amd64", "static_arm64" ]
}

Expand Down
23 changes: 4 additions & 19 deletions cmd/influxd-ctl/add_data/add_data.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package add_data

import (
"encoding/json"
"errors"
"flag"
"fmt"
"io"
"net/http"
"net/url"
"os"
"strings"

Expand All @@ -34,10 +31,8 @@ func NewCommand(cOpts *common.Options) *Command {
// Run executes the program.
func (cmd *Command) Run(args ...string) error {
args, err := cmd.parseFlags(args)
if err == flag.ErrHelp {
if err != nil {
return nil
} else if err != nil {
return err
}
if len(args) == 0 {
return errors.New("tcpAddr value is empty")
Expand All @@ -48,24 +43,14 @@ func (cmd *Command) Run(args ...string) error {
return common.OperationExitedError(err)
}

// add data addr.
// add data node.
func (cmd *Command) addData(addr string) error {
client := common.NewHTTPClient(cmd.cOpts)
data := url.Values{"addr": {addr}}
resp, err := client.PostForm("/add-data", data)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return meta.DecodeErrorResponse(resp.Body)
}

defer client.Close()
dn := &meta.DataNodeInfo{}
if err = json.NewDecoder(resp.Body).Decode(dn); err != nil {
if err := client.AddData(addr, dn); err != nil {
return err
}

fmt.Fprintf(cmd.Stdout, "Added data node %d at %s\n", dn.ID, dn.TCPAddr)
return nil
}
Expand Down
23 changes: 4 additions & 19 deletions cmd/influxd-ctl/add_meta/add_meta.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package add_meta

import (
"encoding/json"
"errors"
"flag"
"fmt"
"io"
"net/http"
"net/url"
"os"
"strings"

Expand All @@ -34,10 +31,8 @@ func NewCommand(cOpts *common.Options) *Command {
// Run executes the program.
func (cmd *Command) Run(args ...string) error {
args, err := cmd.parseFlags(args)
if err == flag.ErrHelp {
if err != nil {
return nil
} else if err != nil {
return err
}
if len(args) == 0 {
return errors.New("httpAddr value is empty")
Expand All @@ -48,24 +43,14 @@ func (cmd *Command) Run(args ...string) error {
return common.OperationExitedError(err)
}

// add meta addr.
// add meta node.
func (cmd *Command) addMeta(addr string) error {
client := common.NewHTTPClient(cmd.cOpts)
data := url.Values{"addr": {addr}}
resp, err := client.PostForm("/join", data)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return meta.DecodeErrorResponse(resp.Body)
}

defer client.Close()
mn := &meta.MetaNodeInfo{}
if err = json.NewDecoder(resp.Body).Decode(mn); err != nil {
if err := client.Join(addr, mn); err != nil {
return err
}

fmt.Fprintf(cmd.Stdout, "Added meta node %d at %s\n", mn.ID, mn.Addr)
return nil
}
Expand Down
23 changes: 22 additions & 1 deletion cmd/influxd-ctl/common/errors.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
package common

import "fmt"
import (
"encoding/json"
"errors"
"fmt"
"io"
)

var (
ErrPromptNotYes = errors.New("prompt not yes")
)

type Error struct {
Err string `json:"error"`
}

func DecodeError(body io.ReadCloser) error {
e := &Error{}
if err := json.NewDecoder(body).Decode(e); err != nil {
return err
}
return errors.New(e.Err)
}

func OperationExitedError(err error) error {
if err != nil {
Expand Down
Loading

0 comments on commit da6e69c

Please sign in to comment.