Class: Rbcli::State::DynamoDBStorage

Inherits:
StateStorage show all
Defined in:
lib/rbcli/stateful_systems/storagetypes/remotestate_dynamodb.rb

Defined Under Namespace

Classes: RemoteStateError

Instance Method Summary collapse

Methods inherited from StateStorage

#[], #[]=, #clear, #commit, #delete, #disconnect, #each, #initialize, #key?, #rbclidata, #refresh, #set_rbclidata, #to_h, #to_s

Constructor Details

This class inherits a constructor from Rbcli::State::StateStorage

Instance Method Details

#create_state ⇒ Object



77
78
79
80
81
# File 'lib/rbcli/stateful_systems/storagetypes/remotestate_dynamodb.rb', line 77

def create_state
	make_dynamo_call do
		@dynamodb.create_table
	end
end

#error(text) ⇒ Object



103
104
105
# File 'lib/rbcli/stateful_systems/storagetypes/remotestate_dynamodb.rb', line 103

def error text
	raise RemoteStateError.new "Error accessing remote state: #{text}"
end

#load_state ⇒ Object



83
84
85
86
87
# File 'lib/rbcli/stateful_systems/storagetypes/remotestate_dynamodb.rb', line 83

def load_state
	make_dynamo_call do
		@data = @dynamodb.get_object.deep_symbolize!
	end
end

#lock ⇒ Object



95
96
97
# File 'lib/rbcli/stateful_systems/storagetypes/remotestate_dynamodb.rb', line 95

def lock
	@dynamodb.lock_or_wait if @locking
end

#save_state ⇒ Object



89
90
91
92
93
# File 'lib/rbcli/stateful_systems/storagetypes/remotestate_dynamodb.rb', line 89

def save_state
	make_dynamo_call do
		@dynamodb.save_object @data
	end
end

#state_exists? ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
75
# File 'lib/rbcli/stateful_systems/storagetypes/remotestate_dynamodb.rb', line 72

def state_exists?
	return false unless make_dynamo_call { @dynamodb.table_exists? }
	make_dynamo_call { @dynamodb.object_exists? }
end

#state_subsystem_init ⇒ Object

def initialize dynamodb_table, region, force_creation: false, halt_on_error: true

# Set defaults in Rbcli's config
Rbcli::State::RemoteStorage::Connectors::DynamoDB.save_defaults

# Create DynamoDB Connector
@dynamodb = Rbcli::State::RemoteStorage::Connectors::DynamoDB.new dynamodb_table, region, Rbcli::config[:aws_access_key_id], Rbcli::config[:aws_secret_access_key]

super dynamodb_table, force_creation: force_creation, halt_on_error: halt_on_error

end



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/rbcli/stateful_systems/storagetypes/remotestate_dynamodb.rb', line 60

def state_subsystem_init
	@locking = Rbcli::ConfigurateStorage::data[:remotestate_init_params][:locking]
	dynamodb_table = Rbcli::ConfigurateStorage::data[:remotestate_init_params][:dynamodb_table]
	region = Rbcli::ConfigurateStorage::data[:remotestate_init_params][:region]

	# Set defaults in Rbcli's config
	Rbcli::State::RemoteConnectors::DynamoDB.save_defaults

	# Create DynamoDB Connector
	@dynamodb = Rbcli::State::RemoteConnectors::DynamoDB.new dynamodb_table, region, Rbcli::config[:aws_access_key_id], Rbcli::config[:aws_secret_access_key], locking: Rbcli::ConfigurateStorage::data[:remotestate_init_params][:locking]
end

#unlock ⇒ Object



99
100
101
# File 'lib/rbcli/stateful_systems/storagetypes/remotestate_dynamodb.rb', line 99

def unlock
	@dynamodb.unlock if @locking
end