Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Move creation of ProtoBroker to kvdb client #1561

Merged
merged 1 commit into from
Nov 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions cmd/agentctl/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@ package cli

import (
"context"
"fmt"
"io"
"runtime"

"github.com/docker/cli/cli/streams"
"github.com/docker/docker/pkg/term"

"github.com/ligato/cn-infra/db/keyval"
"github.com/ligato/cn-infra/db/keyval/kvproto"
"github.com/ligato/cn-infra/logging"

"go.ligato.io/vpp-agent/v2/cmd/agentctl/api"
Expand All @@ -35,7 +32,6 @@ import (
// Cli represents the agent command line client.
type Cli interface {
Client() client.APIClient
KVProtoBroker() (client.KVDBAPIClient, keyval.ProtoBroker, error)

Out() *streams.Out
Err() io.Writer
Expand Down Expand Up @@ -123,18 +119,6 @@ func (cli *AgentCli) DefaultVersion() string {
return cli.clientInfo.DefaultVersion
}

func (cli *AgentCli) KVProtoBroker() (client.KVDBAPIClient, keyval.ProtoBroker, error) {
kvdb, err := cli.Client().KVDBClient()
if err != nil {
return nil, nil, fmt.Errorf("connecting to KVBDB failed: %v", err)
}
return kvdb, jsonProtoBroker(kvdb), nil
}

func jsonProtoBroker(broker keyval.CoreBrokerWatcher) keyval.ProtoBroker {
return kvproto.NewProtoWrapper(broker, &keyval.SerializerJSON{})
}

// ServerInfo stores details about the supported features and platform of the
// server
type ServerInfo struct {
Expand Down
1 change: 1 addition & 0 deletions cmd/agentctl/client/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,6 @@ type MetricsAPIClient interface {

type KVDBAPIClient interface {
keyval.CoreBrokerWatcher
ProtoBroker() keyval.ProtoBroker
CompleteFullKey(key string) (string, error)
}
6 changes: 6 additions & 0 deletions cmd/agentctl/client/kvdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/ligato/cn-infra/datasync"
"github.com/ligato/cn-infra/db/keyval"
"github.com/ligato/cn-infra/db/keyval/kvproto"
"github.com/ligato/cn-infra/logging"
"github.com/ligato/cn-infra/servicelabel"
)
Expand All @@ -24,6 +25,11 @@ func NewKVDBClient(kvdb keyval.CoreBrokerWatcher, serviceLabel string) *KVDBClie
}
}

// ProtoBroker returns ProtoWrapper with JSON serializer for KVDB connection.
func (k *KVDBClient) ProtoBroker() keyval.ProtoBroker {
return kvproto.NewProtoWrapper(k.CoreBrokerWatcher, &keyval.SerializerJSON{})
}

func (k *KVDBClient) Put(key string, data []byte, opts ...datasync.PutOption) (err error) {
key, err = k.CompleteFullKey(key)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions cmd/agentctl/commands/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,11 @@ func RunImport(cli agentcli.Cli, opts ImportOptions) error {
}

} else {
c, db, err := cli.KVProtoBroker()
c, err := cli.Client().KVDBClient()
if err != nil {
return fmt.Errorf("connecting to KVDB failed: %v", err)
return fmt.Errorf("KVDB error: %v", err)
}
db := c.ProtoBroker()

fmt.Printf("importing %d key vals\n", len(keyVals))

Expand Down