Skip to content

Commit

Permalink
etcdctl/ctlv3: replace "dbStatus" with "snapshot.Status"
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 22, 2018
1 parent 6d0c300 commit b89d990
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 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,9 +20,10 @@ import (
"strings"

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

pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
"github.com/coreos/etcd/snapshot"

"github.com/dustin/go-humanize"
)

type printer interface {
Expand All @@ -48,7 +49,7 @@ type printer interface {
MoveLeader(leader, target uint64, r v3.MoveLeaderResponse)

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

RoleAdd(role string, r v3.AuthRoleAddResponse)
RoleGet(role string, r v3.AuthRoleGetResponse)
Expand Down Expand Up @@ -150,7 +151,7 @@ func newPrinterUnsupported(n string) printer {

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) DBStatus(snapshot.Status) { p.p(nil) }

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

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

func makeDBStatusTable(ds dbstatus) (hdr []string, rows [][]string) {
func makeDBStatusTable(ds snapshot.Status) (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 @@ -172,7 +173,7 @@ func (p *fieldsPrinter) Alarm(r v3.AlarmResponse) {
}
}

func (p *fieldsPrinter) DBStatus(r dbstatus) {
func (p *fieldsPrinter) DBStatus(r snapshot.Status) {
fmt.Println(`"Hash" :`, r.Hash)
fmt.Println(`"Revision" :`, r.Revision)
fmt.Println(`"Keys" :`, r.TotalKey)
Expand Down
4 changes: 3 additions & 1 deletion 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 @@ -30,7 +32,7 @@ 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) DBStatus(r snapshot.Status) { 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.Status) {
_, rows := makeDBStatusTable(ds)
for _, row := range rows {
fmt.Println(strings.Join(row, ", "))
Expand Down
7 changes: 4 additions & 3 deletions etcdctl/ctlv3/command/printer_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ package command
import (
"os"

"github.com/olekukonko/tablewriter"

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

"github.com/olekukonko/tablewriter"
)

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.Status) {
hdr, rows := makeDBStatusTable(r)
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader(hdr)
Expand Down
12 changes: 3 additions & 9 deletions etcdctl/ctlv3/command/snapshot_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"github.com/coreos/etcd/raft"
"github.com/coreos/etcd/raft/raftpb"
"github.com/coreos/etcd/snap"
"github.com/coreos/etcd/snapshot"
"github.com/coreos/etcd/store"
"github.com/coreos/etcd/wal"
"github.com/coreos/etcd/wal/walpb"
Expand Down Expand Up @@ -400,19 +401,12 @@ func makeDB(snapdir, dbfile string, commit int) {
be.Close()
}

type dbstatus struct {
Hash uint32 `json:"hash"`
Revision int64 `json:"revision"`
TotalKey int `json:"totalKey"`
TotalSize int64 `json:"totalSize"`
}

func dbStatus(p string) dbstatus {
func dbStatus(p string) snapshot.Status {
if _, err := os.Stat(p); err != nil {
ExitWithError(ExitError, err)
}

ds := dbstatus{}
ds := snapshot.Status{}

db, err := bolt.Open(p, 0400, &bolt.Options{ReadOnly: true})
if err != nil {
Expand Down

0 comments on commit b89d990

Please sign in to comment.