Class: Braavos::Storage::StorageBase

Inherits:
Object
  • Object
show all
Defined in:
lib/braavos/storage/storage_base.rb

Direct Known Subclasses

File, S3

Instance Method Summary collapse

Instance Method Details

#find_node_id(force_node_id = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/braavos/storage/storage_base.rb', line 20

def find_node_id(force_node_id=nil)
  @node_id = force_node_id if force_node_id
  @node_id ||= -> do
    cluster = get_cluster
    instance_id = Braavos::Service.instance_id
    cluster['nodes'].each do |node_id, node_info|
      if node_info['instance_id'] == instance_id
        return node_id
      end
    end
    raise "Node not found: #{instance_id}"
  end.call
end

#get_clusterObject



4
5
6
# File 'lib/braavos/storage/storage_base.rb', line 4

def get_cluster
  @cluster ||= JSON.parse(load_file(File.join(Braavos.config.backup_path, 'cluster.json')))
end

#list_backups(node_id) ⇒ Object

TODO: option for –completed –pending, maybe return size here



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/braavos/storage/storage_base.rb', line 35

def list_backups(node_id)
  result = {full: [], incr: []}
  listing = list_dir(Braavos.config.backup_path)
  listing.each do |l, z|
    if match = l.match(/\/(full|incr)\/(\w+)\/#{node_id}\/_COMPLETED\Z/)
      path, name = match.captures
      result[path.to_sym] << name
    end
  end
  result
end

#verify_cluster(write_mode) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/braavos/storage/storage_base.rb', line 8

def verify_cluster(write_mode)
  cluster = get_cluster
  if write_mode
    if Braavos.config.name != cluster['name']
      raise "Mismatching name (expecting: #{Braavos.config.name}, found: #{cluster['name']})"
    end
    if Braavos.config.environment != cluster['environment']
      raise "Mismatching environment (expecting: #{Braavos.config.environment}, found: #{cluster['environment']})"
    end
  end
end