AppController/djinn.rb
# Returns true on success, false otherwise
Returns true on success, false otherwise
Returns true on success false otherwise
def copy_app_to_local(appname)
    app_path = "#{PERSISTENT_MOUNT_POINT}/apps/#{appname}.tar.gz"
    if File.exists?(app_path)
      Djinn.log_debug("I already have a copy of app #{appname} - won't grab it remotely")
      return true
    else
      Djinn.log_debug("I don't have a copy of app #{appname} - will grab it remotely")
    end
    nodes_with_app = []
    retries_left = 10
    loop {
      nodes_with_app = ZKInterface.get_app_hosters(appname, @options['keyname'])
      break unless nodes_with_app.empty?
      Djinn.log_info("[#{retries_left} retries left] Waiting for a node to " +
        "have a copy of app #{appname}")
      Kernel.sleep(SMALL_WAIT)
      retries_left -=1
      if retries_left.zero?
        Djinn.log_warn("Nobody appears to be hosting app #{appname}")
        return false
      end
    }
    nodes_with_app.each { |node|
      ssh_key = node.ssh_key
      ip = node.private_ip
      tries = 3
      loop {
        Djinn.log_debug("Trying #{ip}:#{app_path} for the application.")
        Djinn.log_run("scp -o StrictHostkeyChecking=no -i #{ssh_key} #{ip}:#{app_path} #{app_path}")
        if File.exists?(app_path)
          Djinn.log_info("Got a copy of #{appname} from #{ip}.")
          return true
        end
        Djinn.log_warn("Unable to get the application from #{ip}:#{app_path}! scp failed.")
        if tries > 0
          Djinn.log_debug("Trying again in few seconds.")
          tries = tries - 1
          Kernel.sleep(SMALL_WAIT)
        else
          Djinn.log_warn("Giving up on node #{ip} for the application.")
          break
        end
      }
    }
    Djinn.log_error("Unable to get the application from any node.")
    return false
  end
def copy_app_to_local ( appname ) app_path = "#{PERSISTENT_MOUNT_POINT}/apps/#{appname}.tar.gz" if File . exists? ( app_path ) Djinn . log_debug ( "I already have a copy of app #{appname} - won't grab it remotely" ) return true else Djinn . log_debug ( "I don't have a copy of app #{appname} - will grab it remotely" ) end nodes_with_app = [ ] retries_left = 10 loop { nodes_with_app = ZKInterface . get_app_hosters ( appname , @options [ 'keyname' ] ) break unless nodes_with_app . empty? Djinn . log_info ( "[#{retries_left} retries left] Waiting for a node to " + "have a copy of app #{appname}" ) Kernel . sleep ( SMALL_WAIT ) retries_left -= 1 if retries_left . zero? Djinn . log_warn ( "Nobody appears to be hosting app #{appname}" ) return false end } nodes_with_app . each { | node | ssh_key = node . ssh_key ip = node . private_ip tries = 3 loop { Djinn . log_debug ( "Trying #{ip}:#{app_path} for the application." ) Djinn . log_run ( "scp -o StrictHostkeyChecking=no -i #{ssh_key} #{ip}:#{app_path} #{app_path}" ) if File . exists? ( app_path ) Djinn . log_info ( "Got a copy of #{appname} from #{ip}." ) return true end Djinn . log_warn ( "Unable to get the application from #{ip}:#{app_path}! scp failed." ) if tries > 0 Djinn . log_debug ( "Trying again in few seconds." ) tries = tries - 1 Kernel . sleep ( SMALL_WAIT ) else Djinn . log_warn ( "Giving up on node #{ip} for the application." ) break end } } Djinn . log_error ( "Unable to get the application from any node." ) return false end
Returns true on success, false otherwise
Returns true on success false otherwise
# Try 3 times on each node known to have this application. Make sure # we pick a random order to not overload the same host.
appname
<not_specific>