Documentation ¶
Index ¶
- Constants
- func Delete(key string, recursive bool) error
- func ExecuteSplittableTransaction(ops api.KVTxnOps, preOpSplit, postOpSplit *api.KVTxnOp) error
- func GetAgentName(cc *api.Client) (string, error)
- func GetKV() *api.KV
- func GetKeys(key string) ([]string, error)
- func GetSession(cc *api.Client, serviceKey, agentName string) (string, error)
- func GetStringValue(key string) (bool, string, error)
- func GetValue(key string) (bool, []byte, error)
- func InitConsulPublisher(maxItems int, kv *api.KV)
- func IsAnyLeader(cc *api.Client, serviceKey string, waitIndex uint64) (bool, string, uint64, error)
- func List(key string) (map[string][]byte, error)
- func RegisterServerAsConsulService(cfg config.Configuration, cc *api.Client, chShutdown chan struct{}) error
- func StoreConsulKey(key string, value []byte) error
- func StoreConsulKeyAsString(key, value string) error
- func StoreConsulKeyAsStringWithFlags(key, value string, flags uint64) error
- func StoreConsulKeyWithFlags(key string, value []byte, flags uint64) error
- func StoreConsulKeyWithJSONValue(key string, value interface{}) error
- func UnregisterServerAsConsulService(cfg config.Configuration, cc *api.Client)
- func WatchLeaderElection(cc *api.Client, serviceKey string, chStop chan struct{}, ...)
- type AutoDeleteLock
- type ConsulStore
Constants ¶
const CommonsTypesKVPrefix string = yorcPrefix + "/commons_types"
CommonsTypesKVPrefix is the prefix in Consul KV store for commons types
const ConsulGenericErrMsg = "Consul communication error"
ConsulGenericErrMsg is a generic error message used when wrapping Consul errors
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" )
const DeploymentKVPrefix string = yorcPrefix + "/deployments"
DeploymentKVPrefix is the prefix in Consul KV store for deployments
const EventsPrefix = yorcPrefix + "/events"
EventsPrefix is the prefix in Consul KV store for events concerning all the deployments
const ExecutionsTaskPrefix = yorcPrefix + "/executions"
ExecutionsTaskPrefix is the prefix in Consul KV store for execution task
const HostsPoolPrefix = yorcPrefix + "/hosts_pool"
HostsPoolPrefix is the prefix on KV store for the hosts pool service
const LocationsPrefix = yorcPrefix + "/locations"
LocationsPrefix is the prefix on KV store for deployment locations
const LogsPrefix = yorcPrefix + "/logs"
LogsPrefix is the prefix on KV store for logs concerning all the deployments
const MonitoringKVPrefix string = yorcPrefix + "/monitoring"
MonitoringKVPrefix is the prefix in Consul KV store for monitoring
const PurgedDeploymentKVPrefix string = yorcPrefix + "/purged"
PurgedDeploymentKVPrefix is the prefix in Consul KV store for deployments
const SchedulingKVPrefix string = yorcPrefix + "/scheduling"
SchedulingKVPrefix is the prefix in Consul KV store for scheduling
const StoresPrefix string = yorcPrefix + "/stores"
StoresPrefix is the prefix in Consul KV store for stores
const TasksPrefix = yorcPrefix + "/tasks"
TasksPrefix is the prefix in Consul KV store for tasks
const WorkflowsPrefix = yorcPrefix + "/workflows"
WorkflowsPrefix is the prefix in Consul KV store for workflows runtime data
const YorcManagementPrefix = yorcPrefix + "/.yorc_management"
YorcManagementPrefix is the prefix on KV store for the orchestrator own management
const YorcSchemaVersion = "1.3.1"
YorcSchemaVersion is the version of the data schema in Consul understood by this version of Yorc
const YorcSchemaVersionPath = yorcPrefix + "/database_schema_version"
YorcSchemaVersionPath is the path where the data schema version is stored in Consul
const YorcService = "yorc"
YorcService is the service name for yorc as a Consul service
const YorcServicePrefix = yorcPrefix + "/service"
YorcServicePrefix is the prefix used for storing services keys
Variables ¶
This section is empty.
Functions ¶
func Delete ¶
Delete delete the key-value from the store If recurse is true, it delete all sub keys too.
func ExecuteSplittableTransaction ¶
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 ¶
GetAgentName allows to return the local consul agent name
func GetSession ¶
GetSession allows to return the session ID for a defined service leader key
func GetStringValue ¶
GetStringValue retrieves the value for the specified key in string type If the key doesn't exist, it returns false
func GetValue ¶
GetValue retrieves the value for the specified key in bytes array If the key doesn't exist, it returns false
func InitConsulPublisher ¶
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 ¶
IsAnyLeader allows to return true if any leader exists for a defined service 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 ¶
StoreConsulKey is equivalent to StoreConsulKeyWithFlags(key, []byte(value),0)
func StoreConsulKeyAsString ¶
StoreConsulKeyAsString is equivalent to StoreConsulKeyWithFlags(key, []byte(value),0)
func StoreConsulKeyAsStringWithFlags ¶
StoreConsulKeyAsStringWithFlags is equivalent to StoreConsulKeyWithFlags(key, []byte(value),flags)
func StoreConsulKeyWithFlags ¶
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 ¶
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 ¶
AutoDeleteLock is a composition of an consul Lock but its Unlock function also call the Destroy function
func AcquireLock ¶
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 ¶
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()