Beispiel #1
0
     def validJob( self, num_nodes=None, kernel=None, **kwargs ):
          """
          This is a bounds-check:  Will the job EVER work.
          
          validates a current job against Heckle to see if it is
               ever possible with *current* node setup.
          Gameplan:
               Return list of all nodes from heckle which match HW and Image
               (doesn't matter, allocated or unallocated)
          """
          self.name="valid Job"
          logger.debug("HICCUP: Debug: validJob: vals are %s" % self.__dict__ )
          #Check for required fields in options:
          logger.debug("HICCUP: Debug: valid Job: Options are: %s" % kwargs )
          opts, hw_criteria = self.validhw( function=findNodes, **kwargs )
          image_name = self.get_image( ret_type=ListType, kernel=kernel )
          valid_job_criteria={}
          valid_job_criteria['session'] = self.session
          valid_job_criteria['hardware_criteria'] = hw_criteria
          valid_job_criteria.update(opts)
          logger.debug("HICCUP: Debug: valid Job: Criteria is: %s" % valid_job_criteria)

          nodelist = heckle_findNodes(**valid_job_criteria )
          
          try:
               if len(nodelist) >= int(kwargs["nodect"]):
                    nodelist = []
          except:
               pass
          
          return nodelist
Beispiel #2
0
    def find_job_location( self, attrs, nodes, walltime, start=None, \
                               forbidden=None, **kwargs ):
        """
        This function returns a list of nodes which match the attributes

        attrs is a dictionary of string pairs, key:value, for hardware requirements
        nodes is an integer, the count of number of nodes desired
        walltime is an integer, representing the timetime, in seconds, for reservation
        forbidden is a list of strings, node names not to use.  (currently not used.)
        
        There may be many other arguments passed in by other functions, unused by this
        function, which have to be accepted and disregarded; this is accomplished by
        the **kwargs.
        """
        if not start:
            start = datetime.now()
        node_criteria = {}
        node_criteria['session'] = self.session
        node_criteria['start'] = start
        node_criteria['end'] = datetime.now() + timedelta(int(walltime))
        node_criteria['node_num'] = int(nodes)
        node_criteria['hardware_criteria'] = self.get_hw_criteria( attrs )
        LOGGER.debug(
        "HICCUP:find_job_location: Find_Node_Criteria is %s" % node_criteria)
        if nodes > 0:
            found = heckle_findNodes( **node_criteria )
            if forbidden:
                found_len = len( found )
                bad_len = len( list( set( found ).intersection( set( forbidden ) ) ) )
                node_criteria['node_num'] = node_criteria['node_num'] + bad_len
                while found_len < ( bad_len + int(nodes) ):
                    found = heckle_findNodes( **node_criteria )
                    found_len = len( found )
                    bad_len = len( list( set( found ).intersection( set( forbidden ) ) ) )
                    node_criteria['node_num'] = int(nodes) + bad_len
                found = list( set( found ).difference( set( forbidden ) ) )
            found.sort
            LOGGER.debug( 
                "HICCUP:find_job_location: appropriate nodes are %s" %
                found )
            return found
        else:
            return []
Beispiel #3
0
 def list_available_nodes( self, start=None, end=None, kernel='default', \
     attrs=None ):
     """
     Returns a list of available nodes which match HW and Time criteria
     """
     #print "HICCUP:list_available_nodes: vals are ", self.__dict__
     opts = {}
     opts['session'] = self.session
     opts['start'] = start
     opts['end'] = end
     opts['hardware_criteria'] = self.get_hw_criteria( attrs=attrs )
     if kernel and not attrs:
         opts['image_criteria'] = kernel
     print "List Options are: ", opts
     nodes = heckle_findNodes(**opts )
     nodes.sort()
     return nodes
Beispiel #4
0
 def list_available_nodes( self, start=None, end=None, kernel=None, **kwargs ):
      """
      Returns a list of available nodes which match HW and Time criteria
      Gameplan:
           get list of all nodes
           Determine allocated nodes
           return list of unallocated nodes
      """
      #print "HICCUP: list_available_nodes: vals are ", self.__dict__
      opts = {}
      opts['session']=self.session
      opts['start']=start
      opts['end']=end
      if kwargs:
           opt, hw_criteria = self.get_hw_criteria( in_kwargs=kwargs, function=findNodes )
           opts['hardware_criteria'] = hw_criteria
      if kernel and not hw_criteria:
           image_name = self.get_image( ret_type=ListType, kernel=kernel )
           opts['image_criteria'] = image_name
      print "List Options are: ", opts
      
      nodes = heckle_findNodes(**opts )
      return nodes
Beispiel #5
0
 def find_job_location( self, attrs, nodes, walltime, start=None, **kwargs ):
      """
      This function returns a list of nodes which match the attributes that are free for the appropriate time
      attrs is a dictionary of string pairs, key:value, for hardware
      nodes is integer count of number of nodes desired
      walltime is time, in seconds, for reservation
      
      To Do:
           Schedule future start times
      """
      find_node_criteria = {}
      find_node_criteria['session']=self.session
      find_node_criteria['start']=datetime.now()
      find_node_criteria['end']=datetime.now() + timedelta(int(walltime))
      find_node_criteria['node_num'] = int(nodes)
      params, hw_criteria = self.get_hw_criteria( in_kwargs=attrs, function=findNodes )
      find_node_criteria['hardware_criteria']=hw_criteria
      logger.debug("HICCUP: find_job_location: Find_Node_Criteria is %s" % find_node_criteria)
      if nodes > 0:
           appropriate_nodes = heckle_findNodes(**find_node_criteria )
           logger.debug( "HICCUP: find_job_location: appropriate nodes are %s" % appropriate_nodes )
           return appropriate_nodes
      else:
           return []
Beispiel #6
0
     def make_reservation( self, uid=None, start=None, end=None, nodecount=None, nodelist=None, location=None, kernel=None, time=None, walltime=None, user=None, attrs=None, fakebuild=False, **kwargs ):
          """
          Adaptor to make a reservation
          Gameplan:
               Make session and user objects
               get list of appropriate nodes from Heckle using options
               get list of chosen nodes from Chooser with list, options
               If chosen nodes list exist
                    Reserve these nodes
                    Allocate those nodes
                    Un-Reserve unneeded nodes
                    Return Reservation ID and Nodes' info
               Else raise error
          """
          #Check for required fields in options:
          #opts = kwargs
          logger.debug("HICCUP: Debug: Make Reservations: Options are %s", self.__dict__ )
          print "uid is %s" % uid
          print "start is %s" % start
          print "end is %s" % end
          print "nodecount is %s" % nodecount
          print "nodelist is %s" % nodelist
          print "location is %s" % location
          print "kernel is %s" % kernel
          print "time is %s" % time
          print "walltime is %s" % walltime
          print "user is %s" % user
          print "attrs is %s" % attrs
          print "fakebuild is %s" % fakebuild
          print "kwargs are %s" % kwargs
          reservation_criteria = {}
          if user:
               usernames = [user]
          elif uid:
               usernames = self.get_usernames(uid)
          else:
               raise Exception("HICCUP: Make Reservations:  Need either User Name or UID.")
          
          #Set up variables
          reservation_criteria['session']=self.session
          if time:
               #print "Time is: ", time
               reservation_criteria['start']=datetime.now()
               reservation_criteria['end']=datetime.now() + timedelta(int(time))
          elif walltime:
               #print "Wall Time is: ", walltime
               reservation_criteria['start']=datetime.now()
               reservation_criteria['end']=datetime.now() + timedelta( minutes=int(walltime) )
          elif start and end:
               reservation_criteria['start']=start
               reservation_criteria['end']=end
          else:
               raise Exception("HICCUP:  Need either a total running time or a start and end time.")
          
          find_node_criteria = {}
          find_node_criteria.update( reservation_criteria )
#Decide Criteria
          if kwargs or attrs:
               if attrs and kwargs:
                    kwargs.update(attrs)
               elif attrs:
                    kwargs=attrs
               params, hw_criteria = self.get_hw_criteria( in_kwargs=kwargs, function=findNodes )
               find_node_criteria['hardware_criteria']=hw_criteria
          else:
               find_node_criteria['image_criteria']=kernel
               params = None
#Use Criteria to choose Nodes
          logger.debug("HICCUP: Debug: Make Reservation: Find_Node_Criteria: %s" % find_node_criteria)
          logger.debug("HICCUP: Debug: Make Reservation: Opts: %s" % reservation_criteria)
          if nodelist or location:
               if location:
                    nodelist = location
               if nodecount and (nodecount > len(nodelist)):
                    logger.debug("HICCUP: Debug: Make Reservation: Finding additional nodes...")
                    node_num = nodecount - len(nodelist)
                    find_node_criteria['node_num'] = int(node_num)
                    appropriate_nodes = heckle_findNodes(**find_node_criteria )
                    logger.debug("HICCUP: Debug: Make Reservation: Appropriate Nodes: %s " % appropriate_nodes )
                    chosen_nodes = choosenodes( appropriate_nodes, node_num )
                    chosen_nodes += nodelist
               else:
                    logger.debug("HICCUP: Debug: Make Reservation: Using existing node list: %s" % nodelist)
                    chosen_nodes = nodelist
          else:
               logger.debug("HICCUP: Debug: Make Reservation: No Nodelist, straight calculation...")
               find_node_criteria['node_num']=nodecount
               logger.debug("HICCUP: Debug: Make Reservation: Find Node Criteria: %s" % find_node_criteria )
               appropriate_nodes = heckle_findNodes(**find_node_criteria )
               logger.debug("HICCUP: Debug: Make Reservation: Appropriate Nodes: %s "% appropriate_nodes )
               chosen_nodes = choosenodes( appropriate_nodes, nodecount )  #stub
          logger.debug("HICCUP: Debug: Make Reservation: Chosen Nodes: %s "% chosen_nodes )
#Use Chosen Nodes to Reserve Nodes
          reservation_criteria['node_list']=chosen_nodes
          reservation_criteria['usernames']=usernames
          try:
               reservation_criteria['comments']=kwargs['comments']
          except:
               reservation_criteria["comment"] = "Reserved by: %s" % ', '.join(usernames)
          logger.debug("HICCUP: Debug: Make Reservation: Reservation Options: %s " % reservation_criteria )
          try:
               reservation =heckle_reserve( **reservation_criteria )
               self.session.commit()
               logger.debug("HICCUP: Debug: Make Reservation: Reservation Made: %s "% reservation )
               #Use Reservation to Allocate
               allocate_criteria = {}
               allocate_criteria['session'] = self.session
               allocate_criteria['res_id'] = reservation.id
               allocate_criteria['nodes'] = chosen_nodes
               allocate_criteria['num_nodes'] = nodecount
               allocate_criteria["users_and_keys"]={usernames[0]:None}
               allocate_criteria["properties"]=self.getBuildProperties( params )
               allocate_criteria['image_name'] = self.get_image(ret_type = StringType, kernel=kernel )
               allocate_criteria['fakebuild'] = fakebuild
               logger.debug("HICCUP: Debug: Make Reservation: Allocate Properties: %s" % allocate_criteria )
               allocated_nodes = heckle_allocate( **allocate_criteria )
               logger.debug("HICCUP: Debug: Make Reservation: Nodes Allocated: %s" % allocated_nodes )
               self.session.commit()
               return reservation
          except Exception as fromHeckle:
               raise Exception("HICCUP: Make Reservation: Per Heckle, Node %s not available.  Exact error is: %s" % (chosen_nodes, fromHeckle) )