Class: MCollective::Util::Playbook::DataStores::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/mcollective/util/playbook/data_stores/base.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, playbook) ⇒ Base

Returns a new instance of Base.



6
7
8
9
10
11
# File 'lib/mcollective/util/playbook/data_stores/base.rb', line 6

def initialize(name, playbook)
  @playbook = playbook
  @name = name

  startup_hook
end

Instance Method Details

#delete(key) ⇒ Object

Note:

deleting non existing data should not raise an error

Deletes a key from a data store

Parameters:

  • key (String)

    the key to delete

Raises:

  • (StandardError)

    when deleting fails



74
75
76
# File 'lib/mcollective/util/playbook/data_stores/base.rb', line 74

def delete(key)
  raise(StandardError, "delete not implemented in %s" % [self.class], caller)
end

#from_hash(properties) ⇒ Base

Parse the data store properties as supplied by the playbook

Parameters:

  • properties (Hash)

    lock properties

Returns:



33
34
35
36
37
38
39
# File 'lib/mcollective/util/playbook/data_stores/base.rb', line 33

def from_hash(properties)
  @properties = properties

  validate_configuration!

  self
end

#lock(key, timeout) ⇒ Object

Note:

when the lock does not exist it should be created

Locks a specific lock in the store

Parameters:

  • key (String)

    the lock name

  • timeout (Integer, Float)

    how long to attempt to get the lock for

Raises:

  • (StandardError)

    when locking fails



56
57
58
# File 'lib/mcollective/util/playbook/data_stores/base.rb', line 56

def lock(key, timeout)
  raise(StandardError, "lock not implemented in %s" % [self.class], caller)
end

#members(key) ⇒ Array<String>

Finds the members in a service

Parameters:

  • key (String)

    the service name

Returns:

Raises:

  • (StandardError)

    when the service is unknown or general error happened



65
66
67
# File 'lib/mcollective/util/playbook/data_stores/base.rb', line 65

def members(key)
  raise(StandardError, "members not implemented in %s" % [self.class], caller)
end

#prepareObject

Prepares the store for use

Here you can do things like connect to data bases, set up pools etc



22
# File 'lib/mcollective/util/playbook/data_stores/base.rb', line 22

def prepare; end

#read(key) ⇒ String

Reads a key from a data store

Parameters:

  • key (String)

    the key to read

Returns:

  • (String)

    string found in the data store

Raises:

  • (StandardError)

    when the key does not exist



92
93
94
# File 'lib/mcollective/util/playbook/data_stores/base.rb', line 92

def read(key)
  raise(StandardError, "read not implemented in %s" % [self.class], caller)
end

#release(key) ⇒ Object

Note:

when the lock does not exist it should not raise an error

Release a lock found in the store

Parameters:

  • key (String)

    the lock name

Raises:

  • (StandardError)

    when releaging fails



46
47
48
# File 'lib/mcollective/util/playbook/data_stores/base.rb', line 46

def release(key)
  raise(StandardError, "release not implemented in %s" % [self.class], caller)
end

#startup_hookObject

Start up processing

Implementations should not create a #initialize instead they should have this hook which will be called once initialization is done



17
# File 'lib/mcollective/util/playbook/data_stores/base.rb', line 17

def startup_hook; end

#validate_configuration!Object

Validate store properties created using from_hash

Raises:

  • (StandardError)

    when configuration is invalid



27
# File 'lib/mcollective/util/playbook/data_stores/base.rb', line 27

def validate_configuration!; end

#write(key, value) ⇒ Object

Writes a value to the key in a data store

Parameters:

  • key (String)

    the key to write

  • value (String)

    the value to write

Raises:

  • (StandardError)

    when writing fails



83
84
85
# File 'lib/mcollective/util/playbook/data_stores/base.rb', line 83

def write(key, value)
  raise(StandardError, "write not implemented in %s" % [self.class], caller)
end