class Hive::FileSystem

Public Class Methods

new(job_id, home_directory, log) click to toggle source
# File lib/hive/file_system.rb, line 5
def initialize(job_id, home_directory, log)
  @job_id = job_id
  @home_directory = home_directory
  @log = log
  @log.debug "Creating job paths with id=#{@job_id} and home=#{@home_directory}"
  make_directory(home_path)
  make_directory(results_path)
  make_directory(logs_path)
  make_directory(testbed_path)
  FileUtils.touch(script_errors_file)
end

Public Instance Methods

check_build_integrity( destination_path ) click to toggle source
# File lib/hive/file_system.rb, line 62
def check_build_integrity( destination_path )
  output = `file #{destination_path}`
  if output =~ /\s[Zz]ip\s/
    result = `zip -T #{destination_path}`
    @log.info(result)
    $? == 0
  elsif output =~ /\sgzip\s/
    result = `tar -tzf #{destination_path} > /dev/null`
    @log.info(result)
    $? == 0
  else
    true
  end
end
executed_script_path() click to toggle source
# File lib/hive/file_system.rb, line 37
def executed_script_path
  @bash_script_path ||= "#{testbed_path}/executed_script.sh"
end
fetch_build(build_url, destination_path) click to toggle source
# File lib/hive/file_system.rb, line 46
def fetch_build(build_url, destination_path)
  base_url      = Hive.config.network['scheduler']
  apk_url       = base_url + '/' + build_url
  
  job = Hive::Messages::Job.new
  response = job.fetch(apk_url)

  tempfile = Tempfile.new('build.apk')
    File.open(tempfile.path,'w') do |f|
    f.write response.body
  end

  copy_file(tempfile.path, destination_path)
  check_build_integrity( destination_path )
end
finalise_results_directory() click to toggle source

Copy useful stuff into the results directory

# File lib/hive/file_system.rb, line 42
def finalise_results_directory
  copy_file(executed_script_path, "#{results_path}/executed_script.sh")
end
home_path() click to toggle source
# File lib/hive/file_system.rb, line 17
def home_path
  @home_path ||= "#{@home_directory}/#{@job_id.to_s}"
end
logs_path() click to toggle source
# File lib/hive/file_system.rb, line 25
def logs_path
  @logs_path ||= "#{home_path}/logs"
end
results_path() click to toggle source
# File lib/hive/file_system.rb, line 21
def results_path
  @results_path ||= "#{home_path}/results"
end
script_errors_file() click to toggle source
# File lib/hive/file_system.rb, line 29
def script_errors_file
  @script_errors_file ||= File.expand_path('script_errors.txt', logs_path)
end
testbed_path() click to toggle source
# File lib/hive/file_system.rb, line 33
def testbed_path
  @testbed_path ||= "#{home_path}/test_code"
end

Private Instance Methods

copy_file(src, dest) click to toggle source
# File lib/hive/file_system.rb, line 79
def copy_file(src, dest)
  begin
    FileUtils.cp(src, dest)
    @log.debug("Copied file #{src} -> #{dest}")
  rescue => e
    @log.error(e.message)
  end
end
make_directory(directory) click to toggle source
# File lib/hive/file_system.rb, line 88
def make_directory(directory)
  begin
    FileUtils.rm_r(directory) if File.directory?(directory)
    FileUtils.mkdir_p(directory)
    @log.debug("Created directory: #{directory}")
  rescue => e
    @log.fatal(e.message)
  end
end