Skip to content

Commit

Permalink
refactor: rename SpdkJSONRPC to Client
Browse files Browse the repository at this point in the history
Signed-off-by: Boris Glimcher <[email protected]>
  • Loading branch information
glimchb committed Oct 6, 2023
1 parent a088eae commit a66ab69
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func main() {
flag.Parse()

// use like this:
jsonRPC := spdk.NewSpdkJSONRPC(spdkAddress)
jsonRPC := spdk.NewClient(spdkAddress)
version := jsonRPC.GetVersion(ctx)
log.Printf("Received from SPDK: %v", version)

Expand Down
2 changes: 1 addition & 1 deletion spdk/accel.service.impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var _ AccelService = (*AccelServiceImpl)(nil)

// NewAccelService is a constructor for AccelServiceImpl
func NewAccelService() *AccelServiceImpl {
// client := spdk.NewSpdkJSONRPC(spdkAddress)
// client := spdk.NewClient(spdkAddress)
return &AccelServiceImpl{nil}

Check warning on line 25 in spdk/accel.service.impl.go

View check run for this annotation

Codecov / codecov/patch

spdk/accel.service.impl.go#L23-L25

Added lines #L23 - L25 were not covered by tests
}

Expand Down
22 changes: 11 additions & 11 deletions spdk/jsonrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ type JSONRPC interface {
Call(ctx context.Context, method string, args, result interface{}) error
}

// SpdkJSONRPC implements JSONRPC interface
type SpdkJSONRPC struct {
// Client implements JSONRPC interface
type Client struct {
transport string
socket string
id uint64
}

// build time check that struct implements interface
var _ JSONRPC = (*SpdkJSONRPC)(nil)
var _ JSONRPC = (*Client)(nil)

// NewSpdkJSONRPC creates a new instance of JSONRPC which is capable to
// NewClient creates a new instance of JSONRPC which is capable to
// interact with either unix domain socket, e.g.: /var/tmp/spdk.sock
// or with tcp connection ip and port tuple, e.g.: 10.1.1.2:1234
func NewSpdkJSONRPC(socketPath string) JSONRPC {
func NewClient(socketPath string) *Client {
if socketPath == "" {
log.Panic("empty socketPath is not allowed")
}
Expand All @@ -57,20 +57,20 @@ func NewSpdkJSONRPC(socketPath string) JSONRPC {
protocol = "unix"
}
log.Printf("Connection to SPDK will be via: %s detected from %s", protocol, socketPath)
return &SpdkJSONRPC{
return &Client{
transport: protocol,
socket: socketPath,
id: 0,
}
}

// GetID implements low level rpc request/response handling
func (r *SpdkJSONRPC) GetID() uint64 {
func (r *Client) GetID() uint64 {

Check warning on line 68 in spdk/jsonrpc.go

View check run for this annotation

Codecov / codecov/patch

spdk/jsonrpc.go#L68

Added line #L68 was not covered by tests
return r.id
}

// GetVersion implements low level rpc request/response handling
func (r *SpdkJSONRPC) GetVersion(ctx context.Context) string {
func (r *Client) GetVersion(ctx context.Context) string {

Check warning on line 73 in spdk/jsonrpc.go

View check run for this annotation

Codecov / codecov/patch

spdk/jsonrpc.go#L73

Added line #L73 was not covered by tests
var ver GetVersionResult
err := r.Call(ctx, "spdk_get_version", nil, &ver)

Check warning on line 75 in spdk/jsonrpc.go

View check run for this annotation

Codecov / codecov/patch

spdk/jsonrpc.go#L75

Added line #L75 was not covered by tests
if err != nil {
Expand All @@ -83,7 +83,7 @@ func (r *SpdkJSONRPC) GetVersion(ctx context.Context) string {
}

// StartUnixListener is utility function used to create new listener in tests
func (r *SpdkJSONRPC) StartUnixListener() net.Listener {
func (r *Client) StartUnixListener() net.Listener {

Check warning on line 86 in spdk/jsonrpc.go

View check run for this annotation

Codecov / codecov/patch

spdk/jsonrpc.go#L86

Added line #L86 was not covered by tests
if err := os.RemoveAll(r.socket); err != nil {
log.Fatal(err)
}
Expand All @@ -95,7 +95,7 @@ func (r *SpdkJSONRPC) StartUnixListener() net.Listener {
}

// Call implements low level rpc request/response handling
func (r *SpdkJSONRPC) Call(_ context.Context, method string, args, result interface{}) error {
func (r *Client) Call(_ context.Context, method string, args, result interface{}) error {

Check warning on line 98 in spdk/jsonrpc.go

View check run for this annotation

Codecov / codecov/patch

spdk/jsonrpc.go#L98

Added line #L98 was not covered by tests
id := atomic.AddUint64(&r.id, 1)
request := RPCRequest{
RPCVersion: JSONRPCVersion,
Expand Down Expand Up @@ -132,7 +132,7 @@ func (r *SpdkJSONRPC) Call(_ context.Context, method string, args, result interf
return nil
}

func (r *SpdkJSONRPC) communicate(buf []byte) (io.Reader, error) {
func (r *Client) communicate(buf []byte) (io.Reader, error) {

Check warning on line 135 in spdk/jsonrpc.go

View check run for this annotation

Codecov / codecov/patch

spdk/jsonrpc.go#L135

Added line #L135 was not covered by tests
// connect
conn, err := net.Dial(r.transport, r.socket)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions spdk/jsonrpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"testing"
)

func TestSpdk_NewSpdkJSONRPC(t *testing.T) {
func TestSpdk_NewClient(t *testing.T) {
tests := map[string]struct {
address string
transport string
Expand Down Expand Up @@ -43,11 +43,11 @@ func TestSpdk_NewSpdkJSONRPC(t *testing.T) {
defer func() {
r := recover()
if (r != nil) != tt.wantPanic {
t.Errorf("NewSpdkJSONRPC() recover = %v, wantPanic = %v", r, tt.wantPanic)
t.Errorf("NewClient() recover = %v, wantPanic = %v", r, tt.wantPanic)
}
}()
before := NewSpdkJSONRPC(tt.address)
after := &SpdkJSONRPC{
before := NewClient(tt.address)
after := &Client{
transport: tt.transport,
socket: tt.address,
id: 0,
Expand Down
2 changes: 1 addition & 1 deletion spdk/nvmf.service.impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var _ NvmfService = (*NvmfServiceImpl)(nil)

// NewNvmfService is a constructor for NvmfServiceImpl
func NewNvmfService() *NvmfServiceImpl {
// client := spdk.NewSpdkJSONRPC(spdkAddress)
// client := spdk.NewClient(spdkAddress)
return &NvmfServiceImpl{nil}

Check warning on line 24 in spdk/nvmf.service.impl.go

View check run for this annotation

Codecov / codecov/patch

spdk/nvmf.service.impl.go#L22-L24

Added lines #L22 - L24 were not covered by tests
}

Expand Down

0 comments on commit a66ab69

Please sign in to comment.