client

package
v0.0.0-...-bfb01b6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package client provides a generic access layer for data available in system

Index

Constants

View Source
const (
	Default_REDIS_UNIXSOCKET     string = "/var/run/redis/redis.sock"
	Default_REDIS_LOCAL_TCP_PORT string = "localhost:6379"
)
View Source
const (
	DbIdx    uint = iota // DB name is the first element (no. 0) in path slice.
	TblIdx               // Table name is the second element (no. 1) in path slice.
	KeyIdx               // Key name is the first element (no. 2) in path slice.
	FieldIdx             // Field name is the first element (no. 3) in path slice.
)

For virtual db path

Variables

View Source
var Target2RedisDb = make(map[string]*redis.Client)

redis client connected to each DB

View Source
var UseRedisLocalTcpPort bool = false

Let it be variable visible to other packages for now. May add an interface function for it.

Functions

func GetTableKeySeparator

func GetTableKeySeparator(target string) (string, error)

func ValToResp

func ValToResp(val Value) (*gnmipb.SubscribeResponse, error)

Convert from SONiC Value to its corresponding gNMI proto stream response type.

Types

type Client

type Client interface {
	// StreamRun will start watching service on data source
	// and enqueue data change to the priority queue.
	// It stops all activities upon receiving signal on stop channel
	// It should run as a go routine
	StreamRun(q *queue.PriorityQueue, stop chan struct{}, w *sync.WaitGroup)
	// Poll will  start service to respond poll signal received on poll channel.
	// data read from data source will be enqueued on to the priority queue
	// The service will stop upon detection of poll channel closing.
	// It should run as a go routine
	PollRun(q *queue.PriorityQueue, poll chan struct{}, w *sync.WaitGroup)
	// Get return data from the data source in format of *spb.Value
	Get(w *sync.WaitGroup) ([]*spb.Value, error)
	// Close provides implemenation for explicit cleanup of Client
	Close() error
}

Client defines a set of methods which every client must implement. This package provides one implmentation for now: the DbClient

func NewDbClient

func NewDbClient(paths []*gnmipb.Path, prefix *gnmipb.Path) (Client, error)

func NewNonDbClient

func NewNonDbClient(paths []*gnmipb.Path, prefix *gnmipb.Path) (Client, error)

type DbClient

type DbClient struct {
	// contains filtered or unexported fields
}

func (*DbClient) Close

func (c *DbClient) Close() error

TODO: Log data related to this session

func (*DbClient) Get

func (c *DbClient) Get(w *sync.WaitGroup) ([]*spb.Value, error)

func (*DbClient) PollRun

func (c *DbClient) PollRun(q *queue.PriorityQueue, poll chan struct{}, w *sync.WaitGroup)

func (*DbClient) StreamRun

func (c *DbClient) StreamRun(q *queue.PriorityQueue, stop chan struct{}, w *sync.WaitGroup)

func (*DbClient) String

func (c *DbClient) String() string

String returns the target the client is querying.

type Node

type Node struct {
	// contains filtered or unexported fields
}

Trie implmentation is adpated from https://github.com/derekparker/trie/blob/master/trie.go

func (Node) Children

func (n Node) Children() map[string]*Node

Returns the children of this node.

func (Node) Meta

func (n Node) Meta() interface{}

Returns the meta information of this node.

func (*Node) NewChild

func (n *Node) NewChild(val string, meta interface{}, term bool) *Node

Creates and returns a pointer to a new child for the node.

func (Node) Parent

func (n Node) Parent() *Node

Returns the parent of this node.

func (*Node) RemoveChild

func (n *Node) RemoveChild(r string)

func (Node) Val

func (n Node) Val() string

type NonDbClient

type NonDbClient struct {
	// contains filtered or unexported fields
}

func (*NonDbClient) Close

func (c *NonDbClient) Close() error

TODO: Log data related to this session

func (*NonDbClient) Get

func (c *NonDbClient) Get(w *sync.WaitGroup) ([]*spb.Value, error)

func (*NonDbClient) PollRun

func (c *NonDbClient) PollRun(q *queue.PriorityQueue, poll chan struct{}, w *sync.WaitGroup)

func (*NonDbClient) StreamRun

func (c *NonDbClient) StreamRun(q *queue.PriorityQueue, stop chan struct{}, w *sync.WaitGroup)

To be implemented

func (*NonDbClient) String

func (c *NonDbClient) String() string

String returns the target the client is querying.

type Stream

type Stream interface {
	Send(m *gnmipb.SubscribeResponse) error
}

type Trie

type Trie struct {
	// contains filtered or unexported fields
}

func NewTrie

func NewTrie() *Trie

Creates a new v2r Trie with an initialized root Node.

func (*Trie) Add

func (t *Trie) Add(keys []string, meta interface{}) *Node

Adds the key to the Trie, including meta data. Meta data is stored as `interface{}` and must be type cast by the caller.

func (*Trie) Find

func (t *Trie) Find(keys []string) (*Node, bool)

Finds and returns node associated with `key`.

func (*Trie) Remove

func (t *Trie) Remove(keys []string)

Removes a key from the trie

func (*Trie) Root

func (t *Trie) Root() *Node

Returns the root node for the Trie.

type Value

type Value struct {
	*spb.Value
}

func (Value) Compare

func (val Value) Compare(other queue.Item) int

Implement Compare method for priority queue

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL