client

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 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 (
	ErrZNodeAlreadyExists = zk.ErrNodeExists
	ErrZNodeDoesNotExist  = zk.ErrNoNode
	ErrZNodeHasChildren   = zk.ErrNotEmpty
	ErrConnectionClosed   = zk.ErrConnectionClosed
	ErrInvalidArguments   = zk.ErrBadArguments
)

Re-exporting errors from ZK library for better encapsulation.

View Source
var (
	// ErrUserPassBothOrNone returned when only one of username and password is specified: either both or none is allowed.
	ErrUserPassBothOrNone = errors.New("both username and password must be specified together")
)

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 CannotUpdateDoesNotExistError added in v1.2.1

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

CannotUpdateDoesNotExistError returned when a ZNode cannot be updated because it does not exist.

func NewCannotUpdateDoesNotExistError added in v1.2.1

func NewCannotUpdateDoesNotExistError(path string) *CannotUpdateDoesNotExistError

func (*CannotUpdateDoesNotExistError) Error added in v1.2.1

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 MissingEnvVarError added in v1.2.1

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

MissingEnvVarError returned when a necessary Environment variable is missing.

func NewMissingEnvVarError added in v1.2.1

func NewMissingEnvVarError(varName string) *MissingEnvVarError

func (*MissingEnvVarError) Error added in v1.2.1

func (e *MissingEnvVarError) Error() string

type NonSeqZNodeCannotEndWithPathSeparatorError added in v1.2.1

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

NonSeqZNodeCannotEndWithPathSeparatorError returned when a non sequenzial ZNode ends with a path separator.

func NewNonSeqZNodeCannotEndWithPathSeparatorError added in v1.2.1

func NewNonSeqZNodeCannotEndWithPathSeparatorError(path string) *NonSeqZNodeCannotEndWithPathSeparatorError

func (*NonSeqZNodeCannotEndWithPathSeparatorError) Error added in v1.2.1

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