Skip to content

Commit

Permalink
Move creation of ProtoBroker to kvdb client (#1561)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrii authored and ondrej-fabry committed Nov 5, 2019
1 parent 6ebd4de commit 2937bdd
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 18 deletions.
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

0 comments on commit 2937bdd

Please sign in to comment.