consulutil

package
Version: v4.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2021 License: Apache-2.0 Imports: 13 Imported by: 4

Documentation

Index

Constants

View Source
const CommonsTypesKVPrefix string = yorcPrefix + "/commons_types"

CommonsTypesKVPrefix is the prefix in Consul KV store for commons types

View Source
const ConsulGenericErrMsg = "Consul communication error"

ConsulGenericErrMsg is a generic error message used when wrapping Consul errors

View Source
const (
	// ConsulStoreTxnTimeoutEnvName is the name of the environment variable that allows
	// to activate the feature that packs ConsulStore operations into transactions.
	// If the variable is empty or not set then the process is the same as usual
	// and operations are sent individually to Consul.
	// Otherwise if set to a valid Go duration then operations are packed into transactions
	// up to 64 ops and this timeout represent the time to wait for new operations before
	// sending an incomplete (less than 64 ops) transaction to Consul.
	ConsulStoreTxnTimeoutEnvName = "YORC_CONSUL_STORE_TXN_TIMEOUT"
)
View Source
const DeploymentKVPrefix string = yorcPrefix + "/deployments"

DeploymentKVPrefix is the prefix in Consul KV store for deployments

View Source
const EventsPrefix = yorcPrefix + "/events"

EventsPrefix is the prefix in Consul KV store for events concerning all the deployments

View Source
const ExecutionsTaskPrefix = yorcPrefix + "/executions"

ExecutionsTaskPrefix is the prefix in Consul KV store for execution task

View Source
const HostsPoolPrefix = yorcPrefix + "/hosts_pool"

HostsPoolPrefix is the prefix on KV store for the hosts pool service

View Source
const LocationsPrefix = yorcPrefix + "/locations"

LocationsPrefix is the prefix on KV store for deployment locations

View Source
const LogsPrefix = yorcPrefix + "/logs"

LogsPrefix is the prefix on KV store for logs concerning all the deployments

View Source
const MonitoringKVPrefix string = yorcPrefix + "/monitoring"

MonitoringKVPrefix is the prefix in Consul KV store for monitoring

View Source
const PurgedDeploymentKVPrefix string = yorcPrefix + "/purged"

PurgedDeploymentKVPrefix is the prefix in Consul KV store for deployments

View Source
const SchedulingKVPrefix string = yorcPrefix + "/scheduling"

SchedulingKVPrefix is the prefix in Consul KV store for scheduling

View Source
const StoresPrefix string = yorcPrefix + "/stores"

StoresPrefix is the prefix in Consul KV store for stores

View Source
const TasksPrefix = yorcPrefix + "/tasks"

TasksPrefix is the prefix in Consul KV store for tasks

View Source
const WorkflowsPrefix = yorcPrefix + "/workflows"

WorkflowsPrefix is the prefix in Consul KV store for workflows runtime data

View Source
const YorcManagementPrefix = yorcPrefix + "/.yorc_management"

YorcManagementPrefix is the prefix on KV store for the orchestrator own management

View Source
const YorcSchemaVersion = "1.3.1"

YorcSchemaVersion is the version of the data schema in Consul understood by this version of Yorc

View Source
const YorcSchemaVersionPath = yorcPrefix + "/database_schema_version"

YorcSchemaVersionPath is the path where the data schema version is stored in Consul

View Source
const YorcService = "yorc"

YorcService is the service name for yorc as a Consul service

View Source
const YorcServicePrefix = yorcPrefix + "/service"

YorcServicePrefix is the prefix used for storing services keys

Variables

This section is empty.

Functions

func Delete

func Delete(key string, recursive bool) error

Delete delete the key-value from the store If recurse is true, it delete all sub keys too.

func ExecuteSplittableTransaction

func ExecuteSplittableTransaction(ops api.KVTxnOps, preOpSplit, postOpSplit *api.KVTxnOp) error

ExecuteSplittableTransaction executes a transaction taking care to split the transaction if ever the number of operations in the transaction exceeds the maximum number of operations in a transaction supported by Consul. In the case where the transaction has to be split, and a pre-operation and post-operation are provided, this function will add the pre and post operations to the operations, else if will execute the operations within a single transaction.

func GetAgentName

func GetAgentName(cc *api.Client) (string, error)

GetAgentName allows to return the local consul agent name

func GetKV

func GetKV() *api.KV

GetKV returns the KV associated to the consul publisher

func GetKeys

func GetKeys(key string) ([]string, error)

GetKeys returns the sub-keys list from a specified key

func GetSession

func GetSession(cc *api.Client, serviceKey, agentName string) (string, error)

GetSession allows to return the session ID for a defined service leader key

func GetStringValue

func GetStringValue(key string) (bool, string, error)

GetStringValue retrieves the value for the specified key in string type If the key doesn't exist, it returns false

func GetValue

func GetValue(key string) (bool, []byte, error)

GetValue retrieves the value for the specified key in bytes array If the key doesn't exist, it returns false

func InitConsulPublisher

func InitConsulPublisher(maxItems int, kv *api.KV)

InitConsulPublisher starts a Consul Publisher and limit the number of parallel call to the Consul API to store keys with the given maxItems.

It is safe but discouraged to call several times this function. Only the last call will be taken into account. The only valid reason to do so is for reconfiguration and changing the limit.

func IsAnyLeader

func IsAnyLeader(cc *api.Client, serviceKey string, waitIndex uint64) (bool, string, uint64, error)

IsAnyLeader allows to return true if any leader exists for a defined service key

func List

func List(key string) (map[string][]byte, error)

List returns the key-value map of all sub-keys from a specified key

func RegisterServerAsConsulService

func RegisterServerAsConsulService(cfg config.Configuration, cc *api.Client, chShutdown chan struct{}) error

RegisterServerAsConsulService allows to register the Yorc server as a Consul service

func StoreConsulKey

func StoreConsulKey(key string, value []byte) error

StoreConsulKey is equivalent to StoreConsulKeyWithFlags(key, []byte(value),0)

func StoreConsulKeyAsString

func StoreConsulKeyAsString(key, value string) error

StoreConsulKeyAsString is equivalent to StoreConsulKeyWithFlags(key, []byte(value),0)

func StoreConsulKeyAsStringWithFlags

func StoreConsulKeyAsStringWithFlags(key, value string, flags uint64) error

StoreConsulKeyAsStringWithFlags is equivalent to StoreConsulKeyWithFlags(key, []byte(value),flags)

func StoreConsulKeyWithFlags

func StoreConsulKeyWithFlags(key string, value []byte, flags uint64) error

StoreConsulKeyWithFlags stores a Consul key without the use of a ConsulStore you should avoid to use it when storing several keys that could be stored concurrently as this function has an important overhead of creating an execution context using the WithContext function and waiting for the key to be store in Consul using errGroup.Wait() The given flags mask is associated to the K/V (See Flags in api.KVPair).

func StoreConsulKeyWithJSONValue

func StoreConsulKeyWithJSONValue(key string, value interface{}) error

StoreConsulKeyWithJSONValue marshals a value into JSON before storing it

func UnregisterServerAsConsulService

func UnregisterServerAsConsulService(cfg config.Configuration, cc *api.Client)

UnregisterServerAsConsulService allows to unregister the Yorc server as a Consul service

func WatchLeaderElection

func WatchLeaderElection(cc *api.Client, serviceKey string, chStop chan struct{}, leaderServiceStart func(), leaderServiceStop func())

WatchLeaderElection allows to watch for leader election for defined service. It elects leader if needed and can start the related service or stop it if node is no longer leader

Types

type AutoDeleteLock

type AutoDeleteLock struct {
	*api.Lock
}

AutoDeleteLock is a composition of an consul Lock but its Unlock function also call the Destroy function

func AcquireLock

func AcquireLock(cc *api.Client, key string, timeout time.Duration) (*AutoDeleteLock, error)

AcquireLock returns an AutoDeleteLock on a specified key it skips "Missing check 'serfHealth' registration" error With specified timeout or default 10s

func (*AutoDeleteLock) Unlock

func (adl *AutoDeleteLock) Unlock() error

Unlock calls in sequence Unlock from the original lock then destroy

type ConsulStore

type ConsulStore interface {
	StoreConsulKey(key string, value []byte)
	StoreConsulKeyWithFlags(key string, value []byte, flags uint64)
	StoreConsulKeyAsString(key, value string)
	StoreConsulKeyAsStringWithFlags(key, value string, flags uint64)
}

ConsulStore allows to store keys in Consul

func WithContext

func WithContext(ctx context.Context) (context.Context, *errgroup.Group, ConsulStore)

WithContext uses a given context to create an errgroup.Group that will be use to store keys in Consul in parallel.

If the given context is cancelled then keys storing are not executed. If an error occurs when storing a key then the context is cancelled and others keys are not stored. The error could be retrieved with the Wait() function of the errgroup.Group.

Here is a typical use case for this function:

errCtx, errGroup, consulStore := consulutil.WithContext(ctx)
consulStore.StoreConsulKey(key1, val1)
// several concurrent keys storing
consulStore.StoreConsulKey(keyN, valN)
err := errGroup.Wait()

Jump to

Keyboard shortcuts

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