mirror of https://github.com/ceph/go-ceph
internal commands: swap over to common subpkg for interface types
Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
parent
bbd88f0b85
commit
274fc16d95
|
@ -3,28 +3,10 @@ package commands
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
|
ccom "github.com/ceph/go-ceph/common/commands"
|
||||||
"github.com/ceph/go-ceph/rados"
|
"github.com/ceph/go-ceph/rados"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MgrCommander in an interface for the API needed to execute JSON formatted
|
|
||||||
// commands on the ceph mgr.
|
|
||||||
type MgrCommander interface {
|
|
||||||
MgrCommand(buf [][]byte) ([]byte, string, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MonCommander is an interface for the API needed to execute JSON formatted
|
|
||||||
// commands on the ceph mon(s).
|
|
||||||
type MonCommander interface {
|
|
||||||
MonCommand(buf []byte) ([]byte, string, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
// RadosCommander provides an interface for APIs needed to execute JSON
|
|
||||||
// formatted commands on the Ceph cluster.
|
|
||||||
type RadosCommander interface {
|
|
||||||
MgrCommander
|
|
||||||
MonCommander
|
|
||||||
}
|
|
||||||
|
|
||||||
func validate(m interface{}) error {
|
func validate(m interface{}) error {
|
||||||
if m == nil {
|
if m == nil {
|
||||||
return rados.ErrNotConnected
|
return rados.ErrNotConnected
|
||||||
|
@ -34,7 +16,7 @@ func validate(m interface{}) error {
|
||||||
|
|
||||||
// RawMgrCommand takes a byte buffer and sends it to the MGR as a command.
|
// RawMgrCommand takes a byte buffer and sends it to the MGR as a command.
|
||||||
// The buffer is expected to contain preformatted JSON.
|
// The buffer is expected to contain preformatted JSON.
|
||||||
func RawMgrCommand(m MgrCommander, buf []byte) Response {
|
func RawMgrCommand(m ccom.MgrCommander, buf []byte) Response {
|
||||||
if err := validate(m); err != nil {
|
if err := validate(m); err != nil {
|
||||||
return Response{err: err}
|
return Response{err: err}
|
||||||
}
|
}
|
||||||
|
@ -43,7 +25,7 @@ func RawMgrCommand(m MgrCommander, buf []byte) Response {
|
||||||
|
|
||||||
// MarshalMgrCommand takes an generic interface{} value, converts it to JSON
|
// MarshalMgrCommand takes an generic interface{} value, converts it to JSON
|
||||||
// and sends the json to the MGR as a command.
|
// and sends the json to the MGR as a command.
|
||||||
func MarshalMgrCommand(m MgrCommander, v interface{}) Response {
|
func MarshalMgrCommand(m ccom.MgrCommander, v interface{}) Response {
|
||||||
b, err := json.Marshal(v)
|
b, err := json.Marshal(v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Response{err: err}
|
return Response{err: err}
|
||||||
|
@ -53,7 +35,7 @@ func MarshalMgrCommand(m MgrCommander, v interface{}) Response {
|
||||||
|
|
||||||
// RawMonCommand takes a byte buffer and sends it to the MON as a command.
|
// RawMonCommand takes a byte buffer and sends it to the MON as a command.
|
||||||
// The buffer is expected to contain preformatted JSON.
|
// The buffer is expected to contain preformatted JSON.
|
||||||
func RawMonCommand(m MonCommander, buf []byte) Response {
|
func RawMonCommand(m ccom.MonCommander, buf []byte) Response {
|
||||||
if err := validate(m); err != nil {
|
if err := validate(m); err != nil {
|
||||||
return Response{err: err}
|
return Response{err: err}
|
||||||
}
|
}
|
||||||
|
@ -62,7 +44,7 @@ func RawMonCommand(m MonCommander, buf []byte) Response {
|
||||||
|
|
||||||
// MarshalMonCommand takes an generic interface{} value, converts it to JSON
|
// MarshalMonCommand takes an generic interface{} value, converts it to JSON
|
||||||
// and sends the json to the MGR as a command.
|
// and sends the json to the MGR as a command.
|
||||||
func MarshalMonCommand(m MonCommander, v interface{}) Response {
|
func MarshalMonCommand(m ccom.MonCommander, v interface{}) Response {
|
||||||
b, err := json.Marshal(v)
|
b, err := json.Marshal(v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Response{err: err}
|
return Response{err: err}
|
||||||
|
|
|
@ -2,12 +2,14 @@ package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
ccom "github.com/ceph/go-ceph/common/commands"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewTraceCommander is a RadosCommander that wraps a given RadosCommander
|
// NewTraceCommander is a RadosCommander that wraps a given RadosCommander
|
||||||
// and when commands are executes prints debug level "traces" to the
|
// and when commands are executes prints debug level "traces" to the
|
||||||
// standard output.
|
// standard output.
|
||||||
func NewTraceCommander(c RadosCommander) RadosCommander {
|
func NewTraceCommander(c ccom.RadosCommander) ccom.RadosCommander {
|
||||||
return &tracingCommander{c}
|
return &tracingCommander{c}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +19,7 @@ func NewTraceCommander(c RadosCommander) RadosCommander {
|
||||||
// interface in FSAdmin. You can layer any sort of debugging, error injection,
|
// interface in FSAdmin. You can layer any sort of debugging, error injection,
|
||||||
// or whatnot between the FSAdmin layer and the RADOS layer.
|
// or whatnot between the FSAdmin layer and the RADOS layer.
|
||||||
type tracingCommander struct {
|
type tracingCommander struct {
|
||||||
conn RadosCommander
|
conn ccom.RadosCommander
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *tracingCommander) MgrCommand(buf [][]byte) ([]byte, string, error) {
|
func (t *tracingCommander) MgrCommand(buf [][]byte) ([]byte, string, error) {
|
||||||
|
|
Loading…
Reference in New Issue