class Dopv::StateStore

Public Class Methods

new(plan_name, plan_store) click to toggle source
# File lib/dopv/state_store.rb, line 7
def initialize(plan_name, plan_store)
  @plan_store  = plan_store
  @plan_name   = plan_name
  @state_store = @plan_store.state_store(plan_name, 'dopv')
end

Public Instance Methods

export() click to toggle source
# File lib/dopv/state_store.rb, line 30
def export
  @state_store.transaction(true) do
    @state_store[:data_volumes] || {}
  end
end
import(data_volumes) click to toggle source
# File lib/dopv/state_store.rb, line 36
def import(data_volumes)
  @state_store.transaction do
    @state_store[:data_volumes] = data_volumes
  end
end
method_missing(m, *args, &block) click to toggle source
# File lib/dopv/state_store.rb, line 42
def method_missing(m, *args, &block)
  @state_store.send(m, *args, &block)
end
update(options = {}) click to toggle source
# File lib/dopv/state_store.rb, line 13
def update(options = {})
  if options[:clear]
    clear(options)
  elsif options[:ignore]
    ignore(options)
  else
    update_state(options)
  end
rescue DopCommon::UnknownVersionError => e
  Dopv.log.warn("The state had an unknown plan version #{e.message}")
  Dopv.log.warn("Bumping state to most recent version")
  ignore(options)
rescue => e
  Dopv.log.error("An error occured during update: #{e.message}")
  Dopv.log.error("Please update with the 'clear' or 'ignore' option")
end

Private Instance Methods

clear(options) click to toggle source
# File lib/dopv/state_store.rb, line 48
def clear(options)
  @state_store.transaction do
    Dopv.log.debug("Clearing the disk state for plan #{@plan_name}")
    ver = @plan_store.show_versions(@plan_name).last
    @state_store[:data_volumes] = {}
    @state_store[:version] = ver
  end
end
ignore(options) click to toggle source
# File lib/dopv/state_store.rb, line 57
def ignore(options)
  @state_store.transaction do
    ver = @plan_store.show_versions(@plan_name).last
    Dopv.log.debug("Ignoring update and setting disk state version of plan #{@plan_name} to #{ver}")
    @state_store[:version] = ver
  end
end
update_state(options) click to toggle source
# File lib/dopv/state_store.rb, line 65
def update_state(options)
  @state_store.update do |plan_diff|
    Dopv.log.debug("Updating disk state for plan #{@plan_name}. This is the diff:")
    Dopv.log.debug(plan_diff.to_s)
    #TODO: Add update logic for plan updates here
  end
end