Sha256: 49fa8fdc3a247313bfe03e7293cbca1a9258e5a87dd599df1d49bd1a0b5beba1

Contents?: true

Size: 1.99 KB

Versions: 17

Compression:

Stored size: 1.99 KB

Contents

require 'aws'
require 'insxsync'
require 'insxsync/error_handling_iface'

# Represents a single synchronization point
class SyncPoint < ErrorHandlingIface
  attr_reader :epoch_time, :date_time, :id

  # Does this object contain configurations?
  # @return [true, false]
  def configs?
    @configs
  end
  # Does this object contain database dumps?
  # @return [true, false]
  def database?
    @database
  end

  # Creates a SyncPoint object by polling AWS S3 for the contents of sync point with the specified time.
  # @param [String] time The epoch time of the sync point this object represents.
  # @param [Integer] id An optionally specified integer ID for this object
  def initialize(time, id=nil)
    # Ensure time is passed and of the right type
    failValidation if time.nil? or not time.is_a?(String)

    # Ensure the id is of the right type if passed
    failValidation if id.not_nil? and not id.is_a?(Integer)

    # Save object attributes
    @id = id
    @epoch_time = time
    @date_time = Time.at(@epoch_time.to_i).strftime('%Y-%m-%d %H:%M:%S') #converts epoch time to a time and date

    # Retrieve tree representing the folder of the specified sync point
    bucket = AWS::S3.new(:access_key_id => $AWS_ID, :secret_access_key => $AWS_SECRET).buckets[$SYNC_BUCKET]
    tree = bucket.as_tree(:prefix => @epoch_time)

    # Retrieve the subfolders
    components = tree.children.select(&:branch?).collect(&:prefix)
    components = components.map{|x| x.gsub("#{@epoch_time}/", '')}.map(&:chop)

    # set these attributes if the subfolder for a component exists
    @configs = components.include?('configs')
    @database = components.include?('database')
  end

  private

  def parse_time(backup)
    backup.scan(/BACKUP-(\d*)_\d-[0-9a-f]*.tar/).flatten[0]
  end

  def get_usage
    #Usage cases for all the usage in this class
    if @usage.nil?
      init_usage
      @usage['new'] = ['time = Time, dump_id = Integer']
    end

    super
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
insxsync-1.1.0 lib/sync_point.rb
insxsync-1.0.1 lib/sync_point.rb
insxsync-1.0.0 lib/sync_point.rb
insxsync-0.0.14 lib/sync_point.rb
insxsync-0.0.13 lib/sync_point.rb
insxsync-0.0.12 lib/sync_point.rb
insxsync-0.0.11 lib/sync_point.rb
insxsync-0.0.10 lib/sync_point.rb
insxsync-0.0.9 lib/sync_point.rb
insxsync-0.0.8 lib/sync_point.rb
insxsync-0.0.7 lib/sync_point.rb
insxsync-0.0.6 lib/sync_point.rb
insxsync-0.0.5 lib/sync_point.rb
insxsync-0.0.4 lib/sync_point.rb
insxsync-0.0.3 lib/sync_point.rb
insxsync-0.0.2 lib/sync_point.rb
insxsync-0.0.1 lib/sync_point.rb