AppController/djinn.rb
# Writes new nginx and haproxy configuration files for the App Engine
# applications hosted in this deployment. Callers should invoke this
# method whenever there is a change in the number of machines hosting
# App Engine apps.
Writes new nginx and haproxy configuration files for the App Engine
applications hosted in this deployment. Callers should invoke this
method whenever there is a change in the number of machines hosting
App Engine apps.
Writes new nginx and haproxy configuration files for the App Engine applications hosted in this deployment . Callers should invoke this method whenever there is a change in the number of machines hosting App Engine apps .
def regenerate_routing_config()
    Djinn.log_debug("Regenerating nginx and haproxy config files for apps.")
    my_public = my_node.public_ip
    my_private = my_node.private_ip
    login_ip = get_login.private_ip
    apps_to_check = @apps_loaded
    apps_to_check.each { |app|
      next if app == "none"
      running = false
      unless (@app_info_map[app].nil? or @app_info_map[app]['nginx'].nil? or
              @app_info_map[app]['nginx_https'].nil? or
              @app_info_map[app]['haproxy'].nil? or
              @app_info_map[app]['appengine'].nil? or
              @app_info_map[app]['language'].nil?)
        http_port = @app_info_map[app]['nginx']
        https_port = @app_info_map[app]['nginx_https']
        proxy_port = @app_info_map[app]['haproxy']
        app_language = @app_info_map[app]['language']
        Djinn.log_debug("Regenerating nginx config for app #{app}, on http " +
          "port #{http_port}, https port #{https_port}, and haproxy port " +
          "#{proxy_port}.")
        @app_info_map[app]['appengine'].each { |location|
          host, port = location.split(":")
          next if Integer(port) < 0
          running = true
          break
        }
      end
      unless running
        Djinn.log_debug("Removing routing for #{app} since no appserver is running.")
        Nginx.remove_app(app)
        HAProxy.remove_app(app)
        next
      end
      begin
        static_handlers = HelperFunctions.parse_static_data(app)
      rescue => except
        error_msg = "ERROR: Unable to parse app.yaml file for #{app}. "\
          "Exception of #{except.class} with message #{except.message}"
        place_error_app(app, error_msg, app_language)
        static_handlers = []
      end
      HAProxy.update_app_config(my_private, app, @app_info_map[app])
      if Nginx.write_fullproxy_app_config(app, http_port, https_port,
          my_public, my_private, proxy_port, static_handlers, login_ip,
          app_language)
        uac = UserAppClient.new(my_node.private_ip, @@secret)
        begin
          if uac.add_instance(app, my_public, http_port, https_port)
            Djinn.log_info("Committed application info for #{app} " +
              "to user_app_server")
          end
        rescue FailedNodeException
          Djinn.log_warn("Failed to talk to UAServer to add_instance for #{app}.")
        end
      end
    }
    Djinn.log_debug("Done updating nginx and haproxy config files.")
  end
def regenerate_routing_config ( ) Djinn . log_debug ( "Regenerating nginx and haproxy config files for apps." ) my_public = my_node . public_ip my_private = my_node . private_ip login_ip = get_login . private_ip apps_to_check = @apps_loaded apps_to_check . each { | app | next if app == "none" running = false unless ( @app_info_map [ app ] . nil? or @app_info_map [ app ] [ 'nginx' ] . nil? or @app_info_map [ app ] [ 'nginx_https' ] . nil? or @app_info_map [ app ] [ 'haproxy' ] . nil? or @app_info_map [ app ] [ 'appengine' ] . nil? or @app_info_map [ app ] [ 'language' ] . nil? ) http_port = @app_info_map [ app ] [ 'nginx' ] https_port = @app_info_map [ app ] [ 'nginx_https' ] proxy_port = @app_info_map [ app ] [ 'haproxy' ] app_language = @app_info_map [ app ] [ 'language' ] Djinn . log_debug ( "Regenerating nginx config for app #{app}, on http " + "port #{http_port}, https port #{https_port}, and haproxy port " + "#{proxy_port}." ) @app_info_map [ app ] [ 'appengine' ] . each { | location | host , port = location . split ( ":" ) next if Integer ( port ) < 0 running = true break } end unless running Djinn . log_debug ( "Removing routing for #{app} since no appserver is running." ) Nginx . remove_app ( app ) HAProxy . remove_app ( app ) next end begin static_handlers = HelperFunctions . parse_static_data ( app ) rescue => except error_msg = "ERROR: Unable to parse app.yaml file for #{app}. " "Exception of #{except.class} with message #{except.message}" place_error_app ( app , error_msg , app_language ) static_handlers = [ ] end HAProxy . update_app_config ( my_private , app , @app_info_map [ app ] ) if Nginx . write_fullproxy_app_config ( app , http_port , https_port , my_public , my_private , proxy_port , static_handlers , login_ip , app_language ) uac = UserAppClient . new ( my_node . private_ip , @@secret ) begin if uac . add_instance ( app , my_public , http_port , https_port ) Djinn . log_info ( "Committed application info for #{app} " + "to user_app_server" ) end rescue FailedNodeException Djinn . log_warn ( "Failed to talk to UAServer to add_instance for #{app}." ) end end } Djinn . log_debug ( "Done updating nginx and haproxy config files." ) end
Writes new nginx and haproxy configuration files for the App Engine
applications hosted in this deployment.
Writes new nginx and haproxy configuration files for the App Engine applications hosted in this deployment .
# Check that we have the application information needed to # regenerate the routing configuration. # Let's see if we already have any AppServers running for this # application. # This specific exception may be a JSON parse error. # If nginx config files have been updated, we communicate the app's # ports to the UserAppServer to make sure we have the latest info.