AppController/djinn.rb
# Starts the given roles by using open nodes, spawning new nodes, or some
# combination of the two. 'nodes_needed' should be an Array, where each
# item is an Array of the roles to start on each node.
Starts the given roles by using open nodes, spawning new nodes, or some
combination of the two. 'nodes_needed' should be an Array, where each
item is an Array of the roles to start on each node.
Starts the given roles by using open nodes spawning new nodes or some combination of the two . ' nodes_needed ' should be an Array where each item is an Array of the roles to start on each node .
def start_new_roles_on_nodes(nodes_needed, instance_type, secret)
    return BAD_SECRET_MSG unless valid_secret?(secret)
    if nodes_needed.class != Array
      Djinn.log_error("Was expecting nodes_needed to be an Array, not " +
        "a #{nodes_needed.class}")
      return BAD_INPUT_MSG
    end
    Djinn.log_info("Received a request to acquire nodes with roles " +
      "#{nodes_needed.join(', ')}, with instance type #{instance_type} for " +
      "new nodes")
    vms_to_use = []
    ZKInterface.lock_and_run {
      @nodes.each { |node|
        if node.is_open?
          Djinn.log_info("Will use node #{node} to run new roles")
          node.jobs = nodes_needed[vms_to_use.length]
          vms_to_use << node
          if vms_to_use.length == nodes_needed.length
            Djinn.log_info("Only using open nodes to run new roles")
            break
          end
        end
      }
      vms_to_spawn = nodes_needed.length - vms_to_use.length
      if vms_to_spawn > 0 and !is_cloud?
        Djinn.log_error("Still need #{vms_to_spawn} more nodes, but we " +
        "aren't in a cloud environment, so we can't acquire more nodes - " +
        "failing the caller's request.")
        return NOT_ENOUGH_OPEN_NODES
      end
      if vms_to_spawn > 0
        Djinn.log_info("Need to spawn up #{vms_to_spawn} VMs")
        allowed_vms = Integer(@options['max_images']) - @nodes.length
        if allowed_vms < vms_to_spawn
          Djinn.log_info("Can't spawn up #{vms_to_spawn} VMs, because that " +
            "would put us over the user-specified limit of #{@options['max_images']} " +
            "VMs. Instead, spawning up #{allowed_vms}.")
          vms_to_spawn = allowed_vms
          if vms_to_spawn <= 0
            Djinn.log_error("Reached the maximum number of VMs that we " +
              "can use in this cloud deployment, so not spawning more nodes.")
            return "Reached maximum number of VMs we can use."
          end
        end
        disks = Array.new(vms_to_spawn, nil)  
        imc = InfrastructureManagerClient.new(@@secret)
        begin
          new_nodes_info = imc.spawn_vms(vms_to_spawn, @options, "open", disks)
        rescue FailedNodeException, AppScaleException => exception
          Djinn.log_error("Couldn't spawn #{vms_to_spawn} VMs with roles " +
            "open because: #{exception.message}")
          return exception.message
        end
        Djinn.log_debug("info about new nodes is " +
          "[#{new_nodes_info.join(', ')}]")
        add_nodes(new_nodes_info)
        new_nodes = Djinn.convert_location_array_to_class(new_nodes_info,
          @options['keyname'])
        vms_to_use << convert_fqdns_to_ips(new_nodes)
        vms_to_use.flatten!
      end
    }
    wait_for_nodes_to_finish_loading(vms_to_use)
    nodes_needed.each_index { |i|
      begin
        ZKInterface.add_roles_to_node(nodes_needed[i], vms_to_use[i],
          @options['keyname'])
        Djinn.log_info("Added roles #{nodes_needed[i].join(', ')} " +
          "to virtual machine #{vms_to_use[i]}")
      rescue FailedZooKeeperOperationException => e
        Djinn.log_warn("(start_new_roles_on_nodes) couldn't talk to " +
          "zookeeper while adding roles with #{e.message}.")
      end
    }
    wait_for_nodes_to_finish_loading(vms_to_use)
    return "OK"
  end
def start_new_roles_on_nodes ( nodes_needed , instance_type , secret ) return BAD_SECRET_MSG unless valid_secret? ( secret ) if nodes_needed . class != Array Djinn . log_error ( "Was expecting nodes_needed to be an Array, not " + "a #{nodes_needed.class}" ) return BAD_INPUT_MSG end Djinn . log_info ( "Received a request to acquire nodes with roles " + "#{nodes_needed.join(', ')}, with instance type #{instance_type} for " + "new nodes" ) vms_to_use = [ ] ZKInterface . lock_and_run { @nodes . each { | node | if node . is_open? Djinn . log_info ( "Will use node #{node} to run new roles" ) node . jobs = nodes_needed [ vms_to_use . length ] vms_to_use << node if vms_to_use . length == nodes_needed . length Djinn . log_info ( "Only using open nodes to run new roles" ) break end end } vms_to_spawn = nodes_needed . length - vms_to_use . length if vms_to_spawn > 0 and ! is_cloud? Djinn . log_error ( "Still need #{vms_to_spawn} more nodes, but we " + "aren't in a cloud environment, so we can't acquire more nodes - " + "failing the caller's request." ) return NOT_ENOUGH_OPEN_NODES end if vms_to_spawn > 0 Djinn . log_info ( "Need to spawn up #{vms_to_spawn} VMs" ) allowed_vms = Integer ( @options [ 'max_images' ] ) - @nodes . length if allowed_vms < vms_to_spawn Djinn . log_info ( "Can't spawn up #{vms_to_spawn} VMs, because that " + "would put us over the user-specified limit of #{@options['max_images']} " + "VMs. Instead, spawning up #{allowed_vms}." ) vms_to_spawn = allowed_vms if vms_to_spawn <= 0 Djinn . log_error ( "Reached the maximum number of VMs that we " + "can use in this cloud deployment, so not spawning more nodes." ) return "Reached maximum number of VMs we can use." end end disks = Array . new ( vms_to_spawn , nil ) imc = InfrastructureManagerClient . new ( @@secret ) begin new_nodes_info = imc . spawn_vms ( vms_to_spawn , @options , "open" , disks ) rescue FailedNodeException , AppScaleException => exception Djinn . log_error ( "Couldn't spawn #{vms_to_spawn} VMs with roles " + "open because: #{exception.message}" ) return exception . message end Djinn . log_debug ( "info about new nodes is " + "[#{new_nodes_info.join(', ')}]" ) add_nodes ( new_nodes_info ) new_nodes = Djinn . convert_location_array_to_class ( new_nodes_info , @options [ 'keyname' ] ) vms_to_use << convert_fqdns_to_ips ( new_nodes ) vms_to_use . flatten! end } wait_for_nodes_to_finish_loading ( vms_to_use ) nodes_needed . each_index { | i | begin ZKInterface . add_roles_to_node ( nodes_needed [ i ] , vms_to_use [ i ] , @options [ 'keyname' ] ) Djinn . log_info ( "Added roles #{nodes_needed[i].join(', ')} " + "to virtual machine #{vms_to_use[i]}" ) rescue FailedZooKeeperOperationException => e Djinn . log_warn ( "(start_new_roles_on_nodes) couldn't talk to " + "zookeeper while adding roles with #{e.message}." ) end } wait_for_nodes_to_finish_loading ( vms_to_use ) return "OK" end
Starts the given roles by using open nodes, spawning new nodes, or some
combination of the two.
Starts the given roles by using open nodes spawning new nodes or some combination of the two .
# Make sure the user has said it is ok to add more VMs before doing so. # no persistent disks # start up vms_to_spawn vms as open # initialize them and wait for them to start up # add information about the VMs we spawned to our list, which may # already have info about the open nodes we want to use
nodes_needed
<not_specific>
instance_type
<not_specific>
secret
<not_specific>