Skip to content

Commit

Permalink
etcdctl/ctlv3: use "snapshot" package
Browse files Browse the repository at this point in the history
Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
  • Loading branch information
gyuho committed Jan 8, 2018
1 parent 7ec33ab commit 6e82d57
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 337 deletions.
11 changes: 6 additions & 5 deletions etcdctl/ctlv3/command/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"strings"

v3 "github.com/coreos/etcd/clientv3"
"github.com/coreos/etcd/snapshot"
"github.com/dustin/go-humanize"

pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
Expand Down Expand Up @@ -48,7 +49,7 @@ type printer interface {
MoveLeader(leader, target uint64, r v3.MoveLeaderResponse)

Alarm(v3.AlarmResponse)
DBStatus(dbstatus)
DBStatus(snapshot.DBStatus)

RoleAdd(role string, r v3.AuthRoleAddResponse)
RoleGet(role string, r v3.AuthRoleGetResponse)
Expand Down Expand Up @@ -148,9 +149,9 @@ func newPrinterUnsupported(n string) printer {
return &printerUnsupported{printerRPC{nil, f}}
}

func (p *printerUnsupported) EndpointStatus([]epStatus) { p.p(nil) }
func (p *printerUnsupported) EndpointHashKV([]epHashKV) { p.p(nil) }
func (p *printerUnsupported) DBStatus(dbstatus) { p.p(nil) }
func (p *printerUnsupported) EndpointStatus([]epStatus) { p.p(nil) }
func (p *printerUnsupported) EndpointHashKV([]epHashKV) { p.p(nil) }
func (p *printerUnsupported) DBStatus(snapshot.DBStatus) { p.p(nil) }

func (p *printerUnsupported) MoveLeader(leader, target uint64, r v3.MoveLeaderResponse) { p.p(nil) }

Expand Down Expand Up @@ -199,7 +200,7 @@ func makeEndpointHashKVTable(hashList []epHashKV) (hdr []string, rows [][]string
return hdr, rows
}

func makeDBStatusTable(ds dbstatus) (hdr []string, rows [][]string) {
func makeDBStatusTable(ds snapshot.DBStatus) (hdr []string, rows [][]string) {
hdr = []string{"hash", "revision", "total keys", "total size"}
rows = append(rows, []string{
fmt.Sprintf("%x", ds.Hash),
Expand Down
3 changes: 2 additions & 1 deletion etcdctl/ctlv3/command/printer_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
v3 "github.com/coreos/etcd/clientv3"
pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
spb "github.com/coreos/etcd/mvcc/mvccpb"
"github.com/coreos/etcd/snapshot"
)

type fieldsPrinter struct{ printer }
Expand Down Expand Up @@ -171,7 +172,7 @@ func (p *fieldsPrinter) Alarm(r v3.AlarmResponse) {
}
}

func (p *fieldsPrinter) DBStatus(r dbstatus) {
func (p *fieldsPrinter) DBStatus(r snapshot.DBStatus) {
fmt.Println(`"Hash" :`, r.Hash)
fmt.Println(`"Revision" :`, r.Revision)
fmt.Println(`"Keys" :`, r.TotalKey)
Expand Down
8 changes: 5 additions & 3 deletions etcdctl/ctlv3/command/printer_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"encoding/json"
"fmt"
"os"

"github.com/coreos/etcd/snapshot"
)

type jsonPrinter struct{ printer }
Expand All @@ -28,9 +30,9 @@ func newJSONPrinter() printer {
}
}

func (p *jsonPrinter) EndpointStatus(r []epStatus) { printJSON(r) }
func (p *jsonPrinter) EndpointHashKV(r []epHashKV) { printJSON(r) }
func (p *jsonPrinter) DBStatus(r dbstatus) { printJSON(r) }
func (p *jsonPrinter) EndpointStatus(r []epStatus) { printJSON(r) }
func (p *jsonPrinter) EndpointHashKV(r []epHashKV) { printJSON(r) }
func (p *jsonPrinter) DBStatus(r snapshot.DBStatus) { printJSON(r) }

func printJSON(v interface{}) {
b, err := json.Marshal(v)
Expand Down
3 changes: 2 additions & 1 deletion etcdctl/ctlv3/command/printer_simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
v3 "github.com/coreos/etcd/clientv3"
pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
"github.com/coreos/etcd/pkg/types"
"github.com/coreos/etcd/snapshot"
)

type simplePrinter struct {
Expand Down Expand Up @@ -155,7 +156,7 @@ func (s *simplePrinter) EndpointHashKV(hashList []epHashKV) {
}
}

func (s *simplePrinter) DBStatus(ds dbstatus) {
func (s *simplePrinter) DBStatus(ds snapshot.DBStatus) {
_, rows := makeDBStatusTable(ds)
for _, row := range rows {
fmt.Println(strings.Join(row, ", "))
Expand Down
3 changes: 2 additions & 1 deletion etcdctl/ctlv3/command/printer_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/olekukonko/tablewriter"

v3 "github.com/coreos/etcd/clientv3"
"github.com/coreos/etcd/snapshot"
)

type tablePrinter struct{ printer }
Expand Down Expand Up @@ -54,7 +55,7 @@ func (tp *tablePrinter) EndpointHashKV(r []epHashKV) {
table.SetAlignment(tablewriter.ALIGN_RIGHT)
table.Render()
}
func (tp *tablePrinter) DBStatus(r dbstatus) {
func (tp *tablePrinter) DBStatus(r snapshot.DBStatus) {
hdr, rows := makeDBStatusTable(r)
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader(hdr)
Expand Down
Loading

0 comments on commit 6e82d57

Please sign in to comment.