AppController/djinn.rb
# Restores the state of each of the instance variables that the AppController
# holds by pulling it from ZooKeeper (previously populated by the Shadow
# node, who always has the most up-to-date version of this data).
#
# Returns:
#   A boolean to indicate if we were able to restore the state.
Restores the state of each of the instance variables that the AppController
holds by pulling it from ZooKeeper (previously populated by the Shadow
node, who always has the most up-to-date version of this data).

A boolean to indicate if we were able to restore the state.
Restores the state of each of the instance variables that the AppController holds by pulling it from ZooKeeper ( previously populated by the Shadow node who always has the most up - to - date version of this data ) . A boolean to indicate if we were able to restore the state .
def restore_appcontroller_state()
    Djinn.log_debug("Reloading deployment state.")
    json_state=""
    unless File.exists?(ZK_LOCATIONS_FILE)
      Djinn.log_info("#{ZK_LOCATIONS_FILE} doesn't exist: not restoring data.")
      return false
    end
    loop {
      begin
        json_state = ZKInterface.get_appcontroller_state()
      rescue => e
        Djinn.log_debug("Saw exception #{e.message} reading appcontroller state.")
        json_state = ""
        Kernel.sleep(SMALL_WAIT)
      end
      break unless json_state.empty?
      Djinn.log_warn("Unable to get state from zookeeper: trying again.")
      pick_zookeeper(@zookeeper_data)
    }
    Djinn.log_debug("Reload State : #{json_state}.")
    APPS_LOCK.synchronize {
      @@secret = json_state['@@secret']
      keyname = json_state['@options']['keyname']
      json_state.each { |k, v|
        next if k == "@@secret"
        if k == "@nodes"
          v = Djinn.convert_location_array_to_class(JSON.load(v), keyname)
        end
        if k == "@my_private_ip"
          @my_private_ip = HelperFunctions.read_file("#{APPSCALE_CONFIG_DIR}/my_private_ip").chomp
        elsif k == "@my_public_ip"
          @my_public_ip = HelperFunctions.read_file("#{APPSCALE_CONFIG_DIR}/my_public_ip").chomp
        elsif DEPLOYMENT_STATE.include?(k)
          instance_variable_set(k, v)
        end
      }
      unless HelperFunctions.get_all_local_ips().include?(@my_private_ip)
        Djinn.log_info("IP changed old private:#{@my_private_ip} public:#{@my_public_ip}.")
        update_state_with_new_local_ip()
        Djinn.log_info("IP changed new private:#{@my_private_ip} public:#{@my_public_ip}.")
      end
      Djinn.log_debug("app_info_map after restore is #{@app_info_map}.")
    }
    find_me_in_locations()
    return true
  end
def restore_appcontroller_state ( ) Djinn . log_debug ( "Reloading deployment state." ) json_state = "" unless File . exists? ( ZK_LOCATIONS_FILE ) Djinn . log_info ( "#{ZK_LOCATIONS_FILE} doesn't exist: not restoring data." ) return false end loop { begin json_state = ZKInterface . get_appcontroller_state ( ) rescue => e Djinn . log_debug ( "Saw exception #{e.message} reading appcontroller state." ) json_state = "" Kernel . sleep ( SMALL_WAIT ) end break unless json_state . empty? Djinn . log_warn ( "Unable to get state from zookeeper: trying again." ) pick_zookeeper ( @zookeeper_data ) } Djinn . log_debug ( "Reload State : #{json_state}." ) APPS_LOCK . synchronize { @@secret = json_state [ '@@secret' ] keyname = json_state [ '@options' ] [ 'keyname' ] json_state . each { | k , v | next if k == "@@secret" if k == "@nodes" v = Djinn . convert_location_array_to_class ( JSON . load ( v ) , keyname ) end if k == "@my_private_ip" @my_private_ip = HelperFunctions . read_file ( "#{APPSCALE_CONFIG_DIR}/my_private_ip" ) . chomp elsif k == "@my_public_ip" @my_public_ip = HelperFunctions . read_file ( "#{APPSCALE_CONFIG_DIR}/my_public_ip" ) . chomp elsif DEPLOYMENT_STATE . include? ( k ) instance_variable_set ( k , v ) end } unless HelperFunctions . get_all_local_ips ( ) . include? ( @my_private_ip ) Djinn . log_info ( "IP changed old private:#{@my_private_ip} public:#{@my_public_ip}." ) update_state_with_new_local_ip ( ) Djinn . log_info ( "IP changed new private:#{@my_private_ip} public:#{@my_public_ip}." ) end Djinn . log_debug ( "app_info_map after restore is #{@app_info_map}." ) } find_me_in_locations ( ) return true end
Restores the state of each of the instance variables that the AppController
holds by pulling it from ZooKeeper (previously populated by the Shadow
node, who always has the most up-to-date version of this data).
Restores the state of each of the instance variables that the AppController holds by pulling it from ZooKeeper ( previously populated by the Shadow node who always has the most up - to - date version of this data ) .
# Puts json_state. # my_private_ip and my_public_ip instance variables are from the head # node. This node may or may not be the head node, so set those # from local files. state_change_lock is a Monitor: no need to # restore it. # Check to see if our IP address has changed. If so, we need to update all # of our internal state to use the new public and private IP anywhere the # old ones were present. # Now that we've restored our state, update the pointer that indicates # which node in @nodes is ours