class Elastomer::CLI::Snapshot

Public Instance Methods

create(repository, name) click to toggle source
# File lib/elastomer/cli/snapshot.rb, line 13
def create(repository, name)
  wait = !!options.delete(:wait_for_completion)
  puts "Waiting for snapshot completion..." if wait
  response = client.snapshot(repository, name).create(options, :wait_for_completion => wait, :pretty => true)
  puts response
end
delete(repository, name) click to toggle source
# File lib/elastomer/cli/snapshot.rb, line 80
def delete(repository, name)
  response = client.snapshot(repository, name).delete
  puts "Successfully deleted #{name} in #{repository}"
end
get(repository, name=nil) click to toggle source
# File lib/elastomer/cli/snapshot.rb, line 21
def get(repository, name=nil)
  response = client.snapshot(repository, name).get(:pretty => true)
  puts response
end
list(repository) click to toggle source
# File lib/elastomer/cli/snapshot.rb, line 27
def list(repository)
  response = client.snapshot(repository).get(:pretty => true)
  puts Terminal::Table.new(
    :headings => ['NAME', 'STATE', 'DURATION', 'START TIME', 'INDICES'],
    :rows => response["snapshots"].collect do |snapshot|
      [
        snapshot["snapshot"],
        snapshot["state"],
        "%2.3fs" % (snapshot["duration_in_millis"] / 1000.0),
        snapshot["start_time"],
        snapshot["indices"].count,
      ]
    end
  )
end
restore(repository, name) click to toggle source
# File lib/elastomer/cli/snapshot.rb, line 73
def restore(repository, name)
  wait = options.delete(:wait_for_completion)
  response = client.snapshot(repository, name).restore(options, :wait_for_completion => wait, :pretty => true)
  puts response
end
status(repository=nil, name=nil) click to toggle source
# File lib/elastomer/cli/snapshot.rb, line 44
def status(repository=nil, name=nil)
  response = client.snapshot(repository, name).status(:pretty => true)
  response["snapshots"].each do |snapshot|
    puts Terminal::Table.new(
      :headings => ["SNAPSHOT STATUS", snapshot["snapshot"]],
      :rows => [
        ["Repository", snapshot["repository"]],
        ["State", snapshot["state"]],
        ["Start Time", Time.at(snapshot["stats"]["start_time_in_millis"].to_i / 1000)],
        ["Duration", "%2.3fs" % (snapshot["stats"]["time_in_millis"] / 1000.0)],
        ["Processed Files", processed_files(snapshot)],
        ["Processed Bytes", processed_bytes(snapshot)],
        ["Shard Status", shard_status(snapshot)],
        ["Shards Failed", snapshot["shards_stats"]["failed"]],
        ["Total Shards", snapshot["shards_stats"]["total"]],
        ["Total Indices", snapshot["indices"].size],
      ]
    )
  end
end

Private Instance Methods

processed_bytes(snapshot) click to toggle source
# File lib/elastomer/cli/snapshot.rb, line 93
def processed_bytes(snapshot)
  total = snapshot["stats"]["total_size_in_bytes"]
  processed = snapshot["stats"]["processed_size_in_bytes"]

  "%.1f%% (%d / %d)" % [processed / total.to_f * 100, processed, total]
end
processed_files(snapshot) click to toggle source
# File lib/elastomer/cli/snapshot.rb, line 86
def processed_files(snapshot)
  total = snapshot["stats"]["number_of_files"]
  processed = snapshot["stats"]["processed_files"]

  "%.1f%% (%d / %d)" % [processed / total.to_f * 100, processed, total]
end
shard_status(snapshot) click to toggle source
# File lib/elastomer/cli/snapshot.rb, line 100
def shard_status(snapshot)
  status = []
  %w(initializing started finalizing done).each do |state|
    count = snapshot["shards_stats"][state]
    if count > 0
      status << "#{count} #{state}"
    end
  end
  status.join(", ")
end