Browse Source

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

Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
Gyuho Lee 8 years ago
parent
commit
c3ba417737

+ 6 - 5
etcdctl/ctlv3/command/printer.go

@@ -20,9 +20,10 @@ import (
 	"strings"
 	"strings"
 
 
 	v3 "github.com/coreos/etcd/clientv3"
 	v3 "github.com/coreos/etcd/clientv3"
-	"github.com/dustin/go-humanize"
-
 	pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
 	pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
+	"github.com/coreos/etcd/snapshot"
+
+	"github.com/dustin/go-humanize"
 )
 )
 
 
 type printer interface {
 type printer interface {
@@ -48,7 +49,7 @@ type printer interface {
 	MoveLeader(leader, target uint64, r v3.MoveLeaderResponse)
 	MoveLeader(leader, target uint64, r v3.MoveLeaderResponse)
 
 
 	Alarm(v3.AlarmResponse)
 	Alarm(v3.AlarmResponse)
-	DBStatus(dbstatus)
+	DBStatus(snapshot.Status)
 
 
 	RoleAdd(role string, r v3.AuthRoleAddResponse)
 	RoleAdd(role string, r v3.AuthRoleAddResponse)
 	RoleGet(role string, r v3.AuthRoleGetResponse)
 	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) EndpointStatus([]epStatus) { p.p(nil) }
 func (p *printerUnsupported) EndpointHashKV([]epHashKV) { 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) }
 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
 	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"}
 	hdr = []string{"hash", "revision", "total keys", "total size"}
 	rows = append(rows, []string{
 	rows = append(rows, []string{
 		fmt.Sprintf("%x", ds.Hash),
 		fmt.Sprintf("%x", ds.Hash),

+ 2 - 1
etcdctl/ctlv3/command/printer_fields.go

@@ -20,6 +20,7 @@ import (
 	v3 "github.com/coreos/etcd/clientv3"
 	v3 "github.com/coreos/etcd/clientv3"
 	pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
 	pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
 	spb "github.com/coreos/etcd/mvcc/mvccpb"
 	spb "github.com/coreos/etcd/mvcc/mvccpb"
+	"github.com/coreos/etcd/snapshot"
 )
 )
 
 
 type fieldsPrinter struct{ printer }
 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(`"Hash" :`, r.Hash)
 	fmt.Println(`"Revision" :`, r.Revision)
 	fmt.Println(`"Revision" :`, r.Revision)
 	fmt.Println(`"Keys" :`, r.TotalKey)
 	fmt.Println(`"Keys" :`, r.TotalKey)

+ 3 - 1
etcdctl/ctlv3/command/printer_json.go

@@ -18,6 +18,8 @@ import (
 	"encoding/json"
 	"encoding/json"
 	"fmt"
 	"fmt"
 	"os"
 	"os"
+
+	"github.com/coreos/etcd/snapshot"
 )
 )
 
 
 type jsonPrinter struct{ printer }
 type jsonPrinter struct{ printer }
@@ -30,7 +32,7 @@ func newJSONPrinter() printer {
 
 
 func (p *jsonPrinter) EndpointStatus(r []epStatus) { printJSON(r) }
 func (p *jsonPrinter) EndpointStatus(r []epStatus) { printJSON(r) }
 func (p *jsonPrinter) EndpointHashKV(r []epHashKV) { 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{}) {
 func printJSON(v interface{}) {
 	b, err := json.Marshal(v)
 	b, err := json.Marshal(v)

+ 2 - 1
etcdctl/ctlv3/command/printer_simple.go

@@ -21,6 +21,7 @@ import (
 	v3 "github.com/coreos/etcd/clientv3"
 	v3 "github.com/coreos/etcd/clientv3"
 	pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
 	pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
 	"github.com/coreos/etcd/pkg/types"
 	"github.com/coreos/etcd/pkg/types"
+	"github.com/coreos/etcd/snapshot"
 )
 )
 
 
 type simplePrinter struct {
 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)
 	_, rows := makeDBStatusTable(ds)
 	for _, row := range rows {
 	for _, row := range rows {
 		fmt.Println(strings.Join(row, ", "))
 		fmt.Println(strings.Join(row, ", "))

+ 4 - 3
etcdctl/ctlv3/command/printer_table.go

@@ -17,9 +17,10 @@ package command
 import (
 import (
 	"os"
 	"os"
 
 
-	"github.com/olekukonko/tablewriter"
-
 	v3 "github.com/coreos/etcd/clientv3"
 	v3 "github.com/coreos/etcd/clientv3"
+	"github.com/coreos/etcd/snapshot"
+
+	"github.com/olekukonko/tablewriter"
 )
 )
 
 
 type tablePrinter struct{ printer }
 type tablePrinter struct{ printer }
@@ -54,7 +55,7 @@ func (tp *tablePrinter) EndpointHashKV(r []epHashKV) {
 	table.SetAlignment(tablewriter.ALIGN_RIGHT)
 	table.SetAlignment(tablewriter.ALIGN_RIGHT)
 	table.Render()
 	table.Render()
 }
 }
-func (tp *tablePrinter) DBStatus(r dbstatus) {
+func (tp *tablePrinter) DBStatus(r snapshot.Status) {
 	hdr, rows := makeDBStatusTable(r)
 	hdr, rows := makeDBStatusTable(r)
 	table := tablewriter.NewWriter(os.Stdout)
 	table := tablewriter.NewWriter(os.Stdout)
 	table.SetHeader(hdr)
 	table.SetHeader(hdr)

+ 3 - 9
etcdctl/ctlv3/command/snapshot_command.go

@@ -39,6 +39,7 @@ import (
 	"github.com/coreos/etcd/raft"
 	"github.com/coreos/etcd/raft"
 	"github.com/coreos/etcd/raft/raftpb"
 	"github.com/coreos/etcd/raft/raftpb"
 	"github.com/coreos/etcd/snap"
 	"github.com/coreos/etcd/snap"
+	"github.com/coreos/etcd/snapshot"
 	"github.com/coreos/etcd/store"
 	"github.com/coreos/etcd/store"
 	"github.com/coreos/etcd/wal"
 	"github.com/coreos/etcd/wal"
 	"github.com/coreos/etcd/wal/walpb"
 	"github.com/coreos/etcd/wal/walpb"
@@ -400,19 +401,12 @@ func makeDB(snapdir, dbfile string, commit int) {
 	be.Close()
 	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 {
 	if _, err := os.Stat(p); err != nil {
 		ExitWithError(ExitError, err)
 		ExitWithError(ExitError, err)
 	}
 	}
 
 
-	ds := dbstatus{}
+	ds := snapshot.Status{}
 
 
 	db, err := bolt.Open(p, 0400, &bolt.Options{ReadOnly: true})
 	db, err := bolt.Open(p, 0400, &bolt.Options{ReadOnly: true})
 	if err != nil {
 	if err != nil {