etcdctl/ctlv3: replace "dbStatus" with "snapshot.Status"

Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
This commit is contained in:
Gyuho Lee 2018-01-22 15:15:40 -08:00
parent 8b317df97a
commit c3ba417737
6 changed files with 20 additions and 20 deletions

View File

@ -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 {
@ -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)
@ -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) }
@ -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),

View File

@ -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 }
@ -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)

View File

@ -18,6 +18,8 @@ import (
"encoding/json"
"fmt"
"os"
"github.com/coreos/etcd/snapshot"
)
type jsonPrinter struct{ printer }
@ -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)

View File

@ -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 {
@ -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, ", "))

View File

@ -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 }
@ -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)

View File

@ -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"
@ -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 {