client

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// EnvZooKeeperServer environment variable containing a comma separated
	// list of 'host:port' pairs, pointing at ZooKeeper Server(s).
	// This is used by NewClientFromEnv.
	EnvZooKeeperServer = "ZOOKEEPER_SERVERS"

	// EnvZooKeeperSessionSec environment variable defining how many seconds
	// a session is considered valid after losing connectivity.
	// This is used by NewClientFromEnv.
	EnvZooKeeperSessionSec = "ZOOKEEPER_SESSION"

	// DefaultZooKeeperSessionSec is the default amount of seconds configured for the
	// Client timeout session, in case EnvZooKeeperSessionSec is not set.
	DefaultZooKeeperSessionSec = 30

	// EnvZooKeeperUsername environment variable providing the username part of a digest auth credentials.
	// This is used by NewClientFromEnv.
	EnvZooKeeperUsername = "ZOOKEEPER_USERNAME"

	// EnvZooKeeperPassword environment variable providing the password part of a digest auth credentials.
	// This is used by NewClientFromEnv.
	EnvZooKeeperPassword = "ZOOKEEPER_PASSWORD"
)

Variables

View Source
var (
	ErrorZNodeAlreadyExists = zk.ErrNodeExists
	ErrorZNodeDoesNotExist  = zk.ErrNoNode
	ErrorZNodeHasChildren   = zk.ErrNotEmpty
	ErrorConnectionClosed   = zk.ErrConnectionClosed
	ErrorInvalidArguments   = zk.ErrBadArguments
)

Re-exporting errors from ZK library for better encapsulation.

Functions

func RemoveSequentialSuffix

func RemoveSequentialSuffix(path string) string

RemoveSequentialSuffix takes the path to a sequential ZNode, maybe created via CreateSequential, and truncates the unique suffix.

See: https://zookeeper.apache.org/doc/r3.6.3/zookeeperProgrammers.html#Sequence+Nodes+--+Unique+Naming

Types

type Client

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

Client wraps a go-zookeeper `zk.Conn` object.

It's designed to offer the functionalities that we will expose via the actual Terraform Provider.

func NewClient

func NewClient(servers string, sessionTimeoutSec int, username string, password string) (*Client, error)

NewClient constructs a new Client instance.

func NewClientFromEnv

func NewClientFromEnv() (*Client, error)

NewClientFromEnv constructs a Client instance from environment variables.

The only mandatory environment variable is EnvZooKeeperServer.

func (*Client) Close added in v1.2.0

func (c *Client) Close()

Close the Client underlying connection.

func (*Client) Create

func (c *Client) Create(path string, data []byte, acl []zk.ACL) (*ZNode, error)

Create a ZNode at the given path.

Note that any necessary ZNode parents will be created if absent.

func (*Client) CreateSequential

func (c *Client) CreateSequential(path string, data []byte, acl []zk.ACL) (*ZNode, error)

CreateSequential will create a ZNode at the given path, using the Sequential Node flag.

See: https://zookeeper.apache.org/doc/r3.6.3/zookeeperProgrammers.html#Sequence+Nodes+--+Unique+Naming

This will ensure unique naming within the same parent ZNode, by appending a monotonically increasing counter in the format `%010d` (that is 10 digits with 0 (zero) padding). Note that if the `path` ends in `/`, the ZNode name will be just the counter described above. For example:

  • input path -> `/this/is/a/path/`
  • created znode path -> `/this/is/a/path/0000000001`

Note also that any necessary ZNode parents will be created if absent.

func (*Client) Delete

func (c *Client) Delete(path string) error

Delete the given ZNode.

Note that will also delete any child ZNode, recursively.

func (*Client) Exists

func (c *Client) Exists(path string) (bool, error)

Exists checks for the existence of the given ZNode.

func (*Client) Read

func (c *Client) Read(path string) (*ZNode, error)

Read the ZNode at the given path.

func (*Client) Update

func (c *Client) Update(path string, data []byte, acl []zk.ACL) (*ZNode, error)

Update the ZNode at the given path, under the assumption that it is there.

Will return an error if it doesn't already exist.

type Pool added in v1.2.0

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

Pool contains a pool of Client. Each client is associated to a unique set of construction parameters.

func NewPool added in v1.2.0

func NewPool() *Pool

func (*Pool) GetOrCreateClient added in v1.2.0

func (p *Pool) GetOrCreateClient(servers string, sessionTimeoutSec int, username string, password string) (*Client, error)

GetOrCreateClient retrieves (or creates) a Client. A new client is created for each unique set of construction parameters.

type ZNode

type ZNode struct {
	Path string
	Stat *zk.Stat
	Data []byte
	ACL  []zk.ACL
}

ZNode represents, obviously, a ZooKeeper Node.

While `Path` and `Data` fields are pretty self-explanatory, the `Stat` contains multiple ZooKeeper related metadata. See `zk.Stat` for details.

Jump to

Keyboard shortcuts

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