consulutil

package
v3.2.0-M4 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const ConsulGenericErrMsg = "Consul communication error"

ConsulGenericErrMsg is a generic error message used when wrapping Consul errors

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 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 SchedulingKVPrefix string = yorcPrefix + "/scheduling"

SchedulingKVPrefix is the prefix in Consul KV store for scheduling

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.0.0"

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 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 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 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 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 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 (*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