zookeeper

package
v1.19.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewStorage

func NewStorage(config *ZkConfig) (storage.Storage, error)

NewStorage create etcd accessor implemented storage interface

Types

type Layer

type Layer struct {
	Index           int              //layer index from path
	IsData          bool             //flag to present this layer store data
	IsWatchChildren bool             //flag for watch children if not
	Name            string           //data type for this layer
	PushEventFunc   PushWatchEventFn //event dispatch function
}

Layer info

type NSClient

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

NSClient implementation storage interface with zookeeper client, all operations are based on namespace-like data types. All data store with namespace feature. so full paths of objects are like /prefix/{dataType}/{namespace}/{name}, all object json contents are hold by name node

func NewNSClient

func NewNSClient(config *ZkConfig) (*NSClient, error)

NewNSClient create new client for namespace-based datas that store in zookeeper. namespace-based datas store in path {namespace}/{name}, namespace nodes store nothing, only name nodes store json data

func (*NSClient) Close

func (s *NSClient) Close()

Close storage conenction, clean resource

func (*NSClient) Create

func (s *NSClient) Create(cxt context.Context, key string, obj meta.Object, ttl int) (out meta.Object, err error)

Create implements storage interface param cxt: context for use decline Creation, not used param key: http full api path param obj: object for creation param ttl: second for time-to-live, not used return out: exist object data

func (*NSClient) Delete

func (s *NSClient) Delete(ctx context.Context, key string) (obj meta.Object, err error)

Delete implements storage interface for http api operation, there are three situations for key * if key likes apis/v1/dns, clean all dns data under version v1 * if key likes apis/v1/dns/namespace/bmsf-system, delete all data under namespace * if key likes apis/v1/dns/namespace/bmsf-system/data, delete detail data in this version, no delete objects reply

func (*NSClient) Get

func (s *NSClient) Get(cxt context.Context, key, version string, ignoreNotFound bool) (meta.Object, error)

Get implements storage interface get exactly data object from http event storage. so key must be resource fullpath param cxt: not used param version: reserved for future

func (*NSClient) List

func (s *NSClient) List(cxt context.Context, key string, selector storage.Selector) ([]meta.Object, error)

List implements storage interface list namespace-based data or all data, detail node should use Get * if key is empty, list all data under prefix, data must be target object * if key is not empty, list all data under prefix/key, data must be target object. if one node errors, we consider all errors. List Function only list leaf data nodes

func (*NSClient) Watch

func (s *NSClient) Watch(cxt context.Context, key, version string, selector storage.Selector) (watch.Interface, error)

Watch implements storage interface * if key empty, watch all data * if key is namespace, watch all data under namespace * if key is namespace/name, watch detail data watch is Stopped when any error occure, close event channel immediatly param cxt: context for background running, not used, only reserved now param version: data version, not used, reserved param selector: labels selector return:

watch: watch implementation for changing event, need to Stop manually

func (*NSClient) WatchList

func (s *NSClient) WatchList(ctx context.Context, key, version string, selector storage.Selector) (watch.Interface, error)

WatchList implements storage interface Watch & WatchList are the same for http api

type Node

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

Node for zookeeper every node

func (*Node) DeleteNextWatch

func (n *Node) DeleteNextWatch(next NodeWatch)

DeleteNextWatch clen next watch when child node deletion

func (*Node) GetSelfPath

func (n *Node) GetSelfPath() string

GetSelfPath get self node path

func (*Node) Run

func (n *Node) Run()

Run start to run all inner event loop

func (*Node) Stop

func (n *Node) Stop()

Stop all events & clean sub node events

type NodeWatch

type NodeWatch interface {
	GetSelfPath() string            //get self node path
	DeleteNextWatch(next NodeWatch) //delete children watch
	Run()                           //ready to start up watch
	Stop()                          //stop watch, only parent watch to stop
}

NodeWatch interface for watch definition

func NewNodeWatch

func NewNodeWatch(index int, selfpath string, parent NodeWatch, c *zkclient.ZkClient, configs map[int]*Layer) (NodeWatch, error)

NewNodeWatch create one nodewatch from configuration

type PodClient

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

PodClient implements storage interface with zookeeper client, all operations are based on one object data types, but data may be stored at different levels of nodes.

func NewPodClient

func NewPodClient(config *ZkConfig) (*PodClient, error)

NewPodClient create pod client for bcs-scheduler in

func (*PodClient) Close

func (s *PodClient) Close()

Close storage conenction, clean resource warnning: if you want to Close client, you have better close Watch first

func (*PodClient) Create

func (s *PodClient) Create(cxt context.Context, key string, obj meta.Object, ttl int) (out meta.Object, err error)

Create implements storage interface

func (*PodClient) Delete

func (s *PodClient) Delete(ctx context.Context, key string) (obj meta.Object, err error)

Delete implements storage interface for http api operation, there are three situations for key * if key likes apis/v1/dns, clean all dns data under version v1 * if key likes apis/v1/dns/namespace/bmsf-system, delete all data under namespace * if key likes apis/v1/dns/namespace/bmsf-system/data, delete detail data in this version, no delete objects reply

func (*PodClient) Get

func (s *PodClient) Get(cxt context.Context, key, version string, ignoreNotFound bool) (meta.Object, error)

Get implements storage interface get exactly data object from http event storage. so key must be resource fullpath param cxt: not used param version: reserved for future

func (*PodClient) List

func (s *PodClient) List(cxt context.Context, key string, selector storage.Selector) ([]meta.Object, error)

List implements storage interface list all data under prefixPath/key, there may be several data type under children nodes of prefixPath, we use selector to filt all types of data. param cxt: context for cancel, not used now param key: key only can be empty, namespace or namespace/{name} param selector: data filter

func (*PodClient) Watch

func (s *PodClient) Watch(cxt context.Context, key, version string, selector storage.Selector) (watch.Interface, error)

Watch implements storage interface * if key empty, watch all data * if key is namespace, watch all data under namespace * if key is namespace/name, watch detail data based-on application watch is Stopped when any error occure, close event channel immediatly param cxt: context for background running, not used, only reserved now param version: data version, not used, reserved param selector: selector for target object data return:

watch: watch implementation for changing event, need to Stop manually

func (*PodClient) WatchList

func (s *PodClient) WatchList(ctx context.Context, key, version string, selector storage.Selector) (watch.Interface, error)

WatchList implements storage interface Watch & WatchList are the same for http api

type PushWatchEventFn

type PushWatchEventFn func(watch.EventType, string, []byte)

PushWatchEventFn function to dispath event param EventType: zk event type param string: event path, especially for delete event param []byte: detail data for object, nil when it's deletion

type ZkConfig

type ZkConfig struct {
	Hosts         []string         //http api host link, ip:host
	PrefixPath    string           //basic path for namespace data
	Name          string           //data type name
	Codec         meta.Codec       //Codec for encoder & decoder
	ObjectNewFunc meta.ObjectNewFn //object pointer for serialization
}

ZkConfig only data type node config

Jump to

Keyboard shortcuts

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