AppController/djinn.rb
# Login nodes will compares the list of applications that should be
# running according to the UserAppServer with the list we have on the
# load balancer, and marks the missing apps for start during the next
# cycle.
Login nodes will compares the list of applications that should be
running according to the UserAppServer with the list we have on the
load balancer, and marks the missing apps for start during the next
cycle.
Login nodes will compares the list of applications that should be running according to the UserAppServer with the list we have on the load balancer and marks the missing apps for start during the next cycle .
def starts_new_apps_or_appservers()
    uac = UserAppClient.new(my_node.private_ip, @@secret)
    Djinn.log_debug("Checking applications that should be running.")
    begin
      app_list = uac.get_all_apps()
    rescue FailedNodeException => except
      Djinn.log_warn("starts_new_apps_or_appservers: failed to get apps (#{except}).")
      app_list = []
    end
    Djinn.log_debug("Apps to check: #{app_list}.") unless app_list.empty?
    app_list.each { |app|
      begin
        next if @app_names.include?(app)
        begin
          next unless uac.is_app_enabled?(app)
        rescue FailedNodeException
          Djinn.log_warn("Failed to talk to the UserAppServer about " +
            "application #{app}.")
          next
        end
        Djinn.log_info("Adding #{app} to running apps.")
        result = uac.get_app_data(app)
        app_data = JSON.load(result)
        Djinn.log_debug("#{app} metadata: #{app_data}")
        app_language = app_data['language']
        Djinn.log_info("Restoring app #{app} (language #{app_language})" +
          " with ports #{app_data['hosts']}.")
        @app_info_map[app] = {} if @app_info_map[app].nil?
        @app_info_map[app]['language'] = app_language if app_language
        if app_data['hosts'].values[0]
          if app_data['hosts'].values[0]['http']
            @app_info_map[app]['nginx'] = app_data['hosts'].values[0]['http']
          end
          if app_data['hosts'].values[0]['https']
            @app_info_map[app]['nginx_https'] = app_data['hosts'].values[0]['https']
          end
        end
        @app_names = @app_names + [app]
      rescue FailedNodeException
        Djinn.log_warn("Couldn't check if app #{app} exists on #{db_private_ip}")
      end
    }
    @app_names.uniq!
    @state = "Preparing to run AppEngine apps if needed."
    apps_to_load = @app_names - @apps_loaded - ["none"]
    apps_to_load.each { |app|
      setup_appengine_application(app)
      maybe_start_taskqueue_worker(app)
    }
  end
def starts_new_apps_or_appservers ( ) uac = UserAppClient . new ( my_node . private_ip , @@secret ) Djinn . log_debug ( "Checking applications that should be running." ) begin app_list = uac . get_all_apps ( ) rescue FailedNodeException => except Djinn . log_warn ( "starts_new_apps_or_appservers: failed to get apps (#{except})." ) app_list = [ ] end Djinn . log_debug ( "Apps to check: #{app_list}." ) unless app_list . empty? app_list . each { | app | begin next if @app_names . include? ( app ) begin next unless uac . is_app_enabled? ( app ) rescue FailedNodeException Djinn . log_warn ( "Failed to talk to the UserAppServer about " + "application #{app}." ) next end Djinn . log_info ( "Adding #{app} to running apps." ) result = uac . get_app_data ( app ) app_data = JSON . load ( result ) Djinn . log_debug ( "#{app} metadata: #{app_data}" ) app_language = app_data [ 'language' ] Djinn . log_info ( "Restoring app #{app} (language #{app_language})" + " with ports #{app_data['hosts']}." ) @app_info_map [ app ] = { } if @app_info_map [ app ] . nil? @app_info_map [ app ] [ 'language' ] = app_language if app_language if app_data [ 'hosts' ] . values [ 0 ] if app_data [ 'hosts' ] . values [ 0 ] [ 'http' ] @app_info_map [ app ] [ 'nginx' ] = app_data [ 'hosts' ] . values [ 0 ] [ 'http' ] end if app_data [ 'hosts' ] . values [ 0 ] [ 'https' ] @app_info_map [ app ] [ 'nginx_https' ] = app_data [ 'hosts' ] . values [ 0 ] [ 'https' ] end end @app_names = @app_names + [ app ] rescue FailedNodeException Djinn . log_warn ( "Couldn't check if app #{app} exists on #{db_private_ip}" ) end } @app_names . uniq! @state = "Preparing to run AppEngine apps if needed." apps_to_load = @app_names - @apps_loaded - [ "none" ] apps_to_load . each { | app | setup_appengine_application ( app ) maybe_start_taskqueue_worker ( app ) } end
Login nodes will compares the list of applications that should be
running according to the UserAppServer with the list we have on the
load balancer, and marks the missing apps for start during the next
cycle.
Login nodes will compares the list of applications that should be running according to the UserAppServer with the list we have on the load balancer and marks the missing apps for start during the next cycle .
# If app is not enabled or if we already know of it, we skip it. # If we don't have a record for this app, we start it. # We query the UserAppServer looking for application data, in # particular ports and language. # And now starts applications.