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 job_start(secret)
    return BAD_SECRET_MSG unless valid_secret?(secret)
    Djinn.log_info("==== Starting AppController (pid: #{Process.pid}) ====")
    HelperFunctions.write_file(PID_FILE, "#{Process.pid}")
    if File.exists?(ZK_LOCATIONS_FILE)
      begin
        my_ip = HelperFunctions.read_file("#{APPSCALE_CONFIG_DIR}/my_private_ip")
      rescue Errno::ENOENT
        @state = "Cannot find my old private IP address."
        HelperFunctions.log_and_crash(@state, WAIT_TO_CRASH)
      end
      zookeeper_data = HelperFunctions.read_json_file(ZK_LOCATIONS_FILE)
      @zookeeper_data = zookeeper_data['locations']
      if @zookeeper_data.include?(my_ip) and !is_zookeeper_running?
        begin
          start_zookeeper(false)
        rescue FailedZooKeeperOperationException
          @state = "Couldn't start Zookeeper."
          HelperFunctions.log_and_crash(@state, WAIT_TO_CRASH)
        end
      end
      pick_zookeeper(@zookeeper_data)
    end
    start_infrastructure_manager()
    unless restore_appcontroller_state()
      RESERVED_APPS.each { |reserved_app|
        app_dir = "#{HelperFunctions.get_app_path(reserved_app)}/app"
        app_path = "#{PERSISTENT_MOUNT_POINT}/apps/#{reserved_app}.tar.gz"
        FileUtils.rm_rf([app_dir, app_path])
      }
      erase_old_data()
      wait_for_data()
    end
    parse_options()
    @kill_sig_received = false
    mount_persistent_storage
    if my_node.is_shadow?
      Djinn.log_info("Spawning/setting up other nodes.")
      spawn_and_setup_appengine
    end
    initialize_server
    start_api_services
    set_appcontroller_monit()
    @done_loading = true
    write_zookeeper_locations()
    pick_zookeeper(@zookeeper_data)
    write_our_node_info()
    wait_for_nodes_to_finish_loading(@nodes)
    last_print = Time.now.to_i
    check_health = nil
    until @kill_sig_received do
      write_database_info()
      update_firewall()
      write_memcache_locations()
      write_zookeeper_locations()
      pick_zookeeper(@zookeeper_data)
      @state = "Done starting up AppScale, now in heartbeat mode"
      if my_node.is_shadow?
        flush_log_buffer()
        send_instance_info_to_dashboard()
        update_node_info_cache()
        backup_appcontroller_state()
        if check_health.nil?
          check_health = Thread.new {
            check_nodes_health()
          }
        elsif !check_health.alive?
          check_health.join()
          check_health = nil
        end
        APPS_LOCK.synchronize {
          starts_new_apps_or_appservers()
          scale_appservers_within_nodes()
        }
        scale_appservers_across_nodes()
      elsif !restore_appcontroller_state()
        Djinn.log_warn("Cannot talk to zookeeper: in isolated mode.")
        next
      end
      check_running_apps()
      check_stopped_apps()
      if my_node.is_load_balancer?
        APPS_LOCK.synchronize {
          regenerate_routing_config()
        }
      end
      if last_print < (Time.now.to_i - 60 * PRINT_STATS_MINUTES)
        stats = JSON.parse(get_all_stats(secret))
        Djinn.log_info("--- Node at #{stats['public_ip']} has " +
          "#{stats['memory']['available']/(1024*1024)}MB memory available " +
          "and knows about these apps #{stats['apps']}.")
        last_print = Time.now.to_i
      end
      Kernel.sleep(DUTY_CYCLE)
    end
  end
def job_start ( secret ) return BAD_SECRET_MSG unless valid_secret? ( secret ) Djinn . log_info ( "==== Starting AppController (pid: #{Process.pid}) ====" ) HelperFunctions . write_file ( PID_FILE , "#{Process.pid}" ) if File . exists? ( ZK_LOCATIONS_FILE ) begin my_ip = HelperFunctions . read_file ( "#{APPSCALE_CONFIG_DIR}/my_private_ip" ) rescue Errno :: ENOENT @state = "Cannot find my old private IP address." HelperFunctions . log_and_crash ( @state , WAIT_TO_CRASH ) end zookeeper_data = HelperFunctions . read_json_file ( ZK_LOCATIONS_FILE ) @zookeeper_data = zookeeper_data [ 'locations' ] if @zookeeper_data . include? ( my_ip ) and ! is_zookeeper_running? begin start_zookeeper ( false ) rescue FailedZooKeeperOperationException @state = "Couldn't start Zookeeper." HelperFunctions . log_and_crash ( @state , WAIT_TO_CRASH ) end end pick_zookeeper ( @zookeeper_data ) end start_infrastructure_manager ( ) unless restore_appcontroller_state ( ) RESERVED_APPS . each { | reserved_app | app_dir = "#{HelperFunctions.get_app_path(reserved_app)}/app" app_path = "#{PERSISTENT_MOUNT_POINT}/apps/#{reserved_app}.tar.gz" FileUtils . rm_rf ( [ app_dir , app_path ] ) } erase_old_data ( ) wait_for_data ( ) end parse_options ( ) @kill_sig_received = false mount_persistent_storage if my_node . is_shadow? Djinn . log_info ( "Spawning/setting up other nodes." ) spawn_and_setup_appengine end initialize_server start_api_services set_appcontroller_monit ( ) @done_loading = true write_zookeeper_locations ( ) pick_zookeeper ( @zookeeper_data ) write_our_node_info ( ) wait_for_nodes_to_finish_loading ( @nodes ) last_print = Time . now . to_i check_health = nil until @kill_sig_received do write_database_info ( ) update_firewall ( ) write_memcache_locations ( ) write_zookeeper_locations ( ) pick_zookeeper ( @zookeeper_data ) @state = "Done starting up AppScale, now in heartbeat mode" if my_node . is_shadow? flush_log_buffer ( ) send_instance_info_to_dashboard ( ) update_node_info_cache ( ) backup_appcontroller_state ( ) if check_health . nil? check_health = Thread . new { check_nodes_health ( ) } elsif ! check_health . alive? check_health . join ( ) check_health = nil end APPS_LOCK . synchronize { starts_new_apps_or_appservers ( ) scale_appservers_within_nodes ( ) } scale_appservers_across_nodes ( ) elsif ! restore_appcontroller_state ( ) Djinn . log_warn ( "Cannot talk to zookeeper: in isolated mode." ) next end check_running_apps ( ) check_stopped_apps ( ) if my_node . is_load_balancer? APPS_LOCK . synchronize { regenerate_routing_config ( ) } end if last_print < ( Time . now . to_i - 60 * PRINT_STATS_MINUTES ) stats = JSON . parse ( get_all_stats ( secret ) ) Djinn . log_info ( "--- Node at #{stats['public_ip']} has " + "#{stats['memory']['available']/(1024*1024)}MB memory available " + "and knows about these apps #{stats['apps']}." ) last_print = Time . now . to_i end Kernel . sleep ( DUTY_CYCLE ) end 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 .
# This pid is used to control this deployment using the init script. # If we have the ZK_LOCATIONS_FILE, the deployment has already been # configured and started. We need to check if we are a zookeeper host # and start it if needed. # We need to check our saved IPs with the list of zookeeper nodes # (IPs can change in cloud environments). # Restore the initial list of zookeeper nodes. # We are a zookeeper host and we need to start it. # We need to wait for the 'state', that is the deployment layouts and # the options for this deployment. It's either a save state from a # previous start, or it comes from the tools. If the tools communicate # the deployment's data, then we are the headnode. # Remove old copies of the RESERVED apps code. We need a fresh copy # every time we boot. # We reset the kill signal received since we are starting now. # From here on we have the basic local state that allows to operate. # In particular we know our roles, and the deployment layout. Let's # start attaching any permanent disk we may have associated with us. # If we are the headnode, we may need to start/setup all other nodes. # Better do it early on, since it may take some time for the other # nodes to start up. # Initialize the current server and starts all the API and essential # services. The functions are idempotent ie won't restart already # running services and can be ran multiple time with no side effect. # Now that we are done loading, we can set the monit job to check the # AppController. At this point we are resilient to failure (ie the AC # will restart if needed). # This variable is used to keep track of the last time we printed some # statistics to the log. # This call will block if we cannot reach a zookeeper node, but will # be very fast if we have an available connection. The function sets # the state in case we are looking for a zookeeper server. # The following is the core of the duty cycle: start new apps, # restart apps, terminate non-responsive AppServers, and autoscale. # Every other node syncs its state with the login node state. # Login nodes may need to check/update nginx/haproxy. # Print stats in the log recurrently; works as a heartbeat mechanism.
secret
<not_specific>