AppController/djinn.rb
# An Array of DjinnJobData objects, each of which containing information about
# a node in the currently running AppScale deployment.
An Array of DjinnJobData objects, each of which containing information about
a node in the currently running AppScale deployment.
An Array of DjinnJobData objects each of which containing information about a node in the currently running AppScale deployment .
def update(apps, secret)
    return BAD_SECRET_MSG unless valid_secret?(secret)
    return "apps was not an Array but was a #{apps.class}." if apps.class != Array
    unless my_node.is_shadow?
       Djinn.log_debug("Sending update call for #{apps} to shadow.")
       acc = AppControllerClient.new(get_shadow.private_ip, @@secret)
       begin
         return acc.update(apps)
       rescue FailedNodeException => except
         Djinn.log_warn("Failed to forward update call to shadow (#{get_shadow}).")
         return NOT_READY
       end
    end
    RESERVED_APPS.each { |reserved_app|
      if apps.include?(reserved_app)
        Djinn.log_warn("Cannot update reserved app #{reserved_app}.")
        apps.delete(reserved_app)
      end
    }
    Djinn.log_info("Received request to update these apps: #{apps.join(', ')}.")
    apps_to_restart = []
    failed_apps = []
    APPS_LOCK.synchronize {
      apps_to_restart = @apps_loaded & apps
      Djinn.log_debug("Apps to restart are #{apps_to_restart}.")
      apps.each{ |app|
        if @app_info_map[app] && @app_info_map[app]['language'] &&
          @app_info_map[app]['language'] != get_app_language(app)
          failed_apps << app
        end
      }
    }
    failed_apps.each { |app|
      apps_to_restart.delete(app)
      stop_app(app, @@secret)
      Djinn.log_error("Disabled #{app} since language doesn't match our record.")
    }
    unless apps_to_restart.empty?
      apps_to_restart.each { |appid|
        location = "#{PERSISTENT_MOUNT_POINT}/apps/#{appid}.tar.gz"
        begin
          ZKInterface.clear_app_hosters(appid)
          ZKInterface.add_app_entry(appid, my_node.public_ip, location)
        rescue FailedZooKeeperOperationException => e
          Djinn.log_warn("(update) couldn't talk with zookeeper while " +
            "working on app #{appid} with #{e.message}.")
        end
      }
      @nodes.each_index { |index|
        result = ""
        ip = @nodes[index].private_ip
        if my_node.private_ip == ip
          result = set_apps_to_restart(apps_to_restart, @@secret)
        else
          acc = AppControllerClient.new(ip, @@secret)
          begin
            result = acc.set_apps_to_restart(apps_to_restart)
          rescue FailedNodeException
            Djinn.log_warn("Couldn't tell #{ip} to restart Google App Engine " +
              "apps - skipping for now.")
          end
        end
        Djinn.log_debug("Set apps to restart at #{ip} returned #{result} as class #{result.class}")
      }
    end
    APPS_LOCK.synchronize {
      @app_names |= apps
      @app_names = @app_names - ["none"]
    }
    Djinn.log_debug("Done updating apps!")
    return "OK"
  end
def update ( apps , secret ) return BAD_SECRET_MSG unless valid_secret? ( secret ) return "apps was not an Array but was a #{apps.class}." if apps . class != Array unless my_node . is_shadow? Djinn . log_debug ( "Sending update call for #{apps} to shadow." ) acc = AppControllerClient . new ( get_shadow . private_ip , @@secret ) begin return acc . update ( apps ) rescue FailedNodeException => except Djinn . log_warn ( "Failed to forward update call to shadow (#{get_shadow})." ) return NOT_READY end end RESERVED_APPS . each { | reserved_app | if apps . include? ( reserved_app ) Djinn . log_warn ( "Cannot update reserved app #{reserved_app}." ) apps . delete ( reserved_app ) end } Djinn . log_info ( "Received request to update these apps: #{apps.join(', ')}." ) apps_to_restart = [ ] failed_apps = [ ] APPS_LOCK . synchronize { apps_to_restart = @apps_loaded & apps Djinn . log_debug ( "Apps to restart are #{apps_to_restart}." ) apps . each { | app | if @app_info_map [ app ] && @app_info_map [ app ] [ 'language' ] && @app_info_map [ app ] [ 'language' ] != get_app_language ( app ) failed_apps << app end } } failed_apps . each { | app | apps_to_restart . delete ( app ) stop_app ( app , @@secret ) Djinn . log_error ( "Disabled #{app} since language doesn't match our record." ) } unless apps_to_restart . empty? apps_to_restart . each { | appid | location = "#{PERSISTENT_MOUNT_POINT}/apps/#{appid}.tar.gz" begin ZKInterface . clear_app_hosters ( appid ) ZKInterface . add_app_entry ( appid , my_node . public_ip , location ) rescue FailedZooKeeperOperationException => e Djinn . log_warn ( "(update) couldn't talk with zookeeper while " + "working on app #{appid} with #{e.message}." ) end } @nodes . each_index { | index | result = "" ip = @nodes [ index ] . private_ip if my_node . private_ip == ip result = set_apps_to_restart ( apps_to_restart , @@secret ) else acc = AppControllerClient . new ( ip , @@secret ) begin result = acc . set_apps_to_restart ( apps_to_restart ) rescue FailedNodeException Djinn . log_warn ( "Couldn't tell #{ip} to restart Google App Engine " + "apps - skipping for now." ) end end Djinn . log_debug ( "Set apps to restart at #{ip} returned #{result} as class #{result.class}" ) } end APPS_LOCK . synchronize { @app_names |= apps @app_names = @app_names - [ "none" ] } Djinn . log_debug ( "Done updating apps!" ) return "OK" end
An Array of DjinnJobData objects, each of which containing information about
a node in the currently running AppScale deployment.
An Array of DjinnJobData objects each of which containing information about a node in the currently running AppScale deployment .
# Few sanity checks before acting. # Begin by marking the apps that should be running. # Get a list of the apps we need to restart. # Next, check if the language of the application is correct. # Next, restart any apps that have new code uploaded. # Since we have at least one application running, we don't need to # display anymore 'none' as the list of running applications.
apps
<not_specific>
secret
<not_specific>