Exemplo n.º 1
0
 def make_reservation( self, job_dict ):
     """
     Adaptor to make a reservation
     Returns the Heckle Reservation object
     Variables in the job dict:
         location: list of strings,
             containing names of nodes to make reservation
         kernel: string, exact name of kernel image to use
         user: string, user name passed through Cobalt
         fakebuild: boolean, whether to actually build node or fake build it.
         comment: string, any comments to make in the reservation
         kwargs:  Any
     """
     LOGGER.debug("HICCUP:make_reservations: Options are %s"\
         % self.__dict__ )
     reservation_criteria = {} #Build reservation arguments
     reservation_criteria['session'] = self.session
     reservation_criteria['start'] = datetime.now()
     reservation_criteria['end'] = datetime.now() + \
         timedelta( minutes=int( job_dict['walltime'] ) )
     reservation_criteria['node_list'] = job_dict['location']
     reservation_criteria['usernames'] = [job_dict['user'], ]   #Fix this
     try:
         reservation_criteria['comment'] = job_dict['comment']
     except:
         reservation_criteria["comment"] = "Reserved by: %s" % \
             ', '.join( reservation_criteria['usernames'] )
     LOGGER.debug("HICCUP:make_reservation: Reservation Options: %s "\
         % reservation_criteria )
     reservation = heckle_reserve( **reservation_criteria )
     self.session.commit()
     LOGGER.debug("HICCUP:make_reservation: Reservation Made: %s "%\
         reservation )
     #Use Reservation to Allocate
     allocate_criteria = {}   #build allocation arguments
     allocate_criteria['session'] = self.session
     allocate_criteria['res_id'] = reservation.id
     allocate_criteria['nodes'] = job_dict['location']
     allocate_criteria['num_nodes'] = len( job_dict['location'] )
     allocate_criteria["users_and_keys"] = { job_dict['user']:None}
     allocate_criteria["properties"] = None
     allocate_criteria['image_name'] = job_dict['kernel']
     allocate_criteria['fakebuild'] = job_dict['fakebuild']
     LOGGER.debug("HICCUP:make_reservation: Allocate Properties: %s" %\
         allocate_criteria )
     allocated_nodes = heckle_allocate( **allocate_criteria )
     LOGGER.debug("HICCUP:make_reservation: Nodes Allocated: %s" %\
         allocated_nodes )
     self.session.commit()
     return reservation
Exemplo n.º 2
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) )