예제 #1
0
def cl2s_submit(ad, verbose=False):
    """
    Submit the input job ClassAd to CL2S. The important thing to notice is that
    we split job cluster into their N component jobs and submit those as 
    independent jobs to the job queue.
    
    Return the exit code: 0 if success >0 otherwise.
    """
    # Determine the log level.
    if(verbose):
        logutils.logger.setLevel(logging.DEBUG)
    
    # Parse the raw ad. Remember that the parsing code stores the raw ClassAd 
    # attributes both as they are and as lowercase and uppercase.
    classAd = ClassAd.ClassAd(ad)
    logutils.logger.debug('Parsed input ClassAd:\n%s' % (classAd))
    
    # See if we have a Job ad. If not specified, we assume it is a Job ad.
    ad_type = getattr(classAd, 'MyType', 'Job')
    if(ad_type.lower() != 'job'):
        logutils.logger.critical('Expecting a Job ClassAd, got a %s ad.' \
                                 % (ad_type))
        return(1)
    
    # Remember though that Cmd is the parsed value for Executable...
    if(hasattr(classAd, 'Executable'.lower())):
        classAd.Cmd = classAd.executable
    
    # Job ads need a few attributes: Cmd, JobUniverse and Owner.
    required_attrs = ('Cmd', 'JobUniverse', 'Owner')
    for attr in required_attrs:
        if(not hasattr(classAd, attr.lower())):
            logutils.logger.critical('The Job ClassAds needs a %s attribute.' \
                                     % (attr))
            return(2)
    
    # JobUniverse needs to be a valid Condor universe ID but cannot be Standard
    # Universe.
    # UNIVERSE = {"VANILLA": 5, "SCHEDULER": 7, "GRID": 9, "JAVA": 10, 
    #             "PARALLEL": 11, "LOCAL": 12, "VM": 13}
    valid_universe_ids = (5, 7, 9, 10, 11, 12, 13)
    if(classAd.jobuniverse not in valid_universe_ids):
        logutils.logger.critical('The Job ClassAds universe is not valid: %d.' \
                                 % (classAd.jobuniverse))
        return(3)
    
    # See if we need to split a cluster job. In that case, remember to replace 
    # $(Process) with range(classAd.CL2S_INSTANCES)
    num_instances = classAd.CL2S_INSTANCES
    
    # Now set classAd.CL2S_INSTANCES to 1
    print('Submitting job(s).')
    classAd.CL2S_INSTANCES = 1
    new_ad_text = str(classAd)
    for i in range(num_instances):
        # Replace $(Process) with i, create a JOb instance and queue it.
        JobQueue.push(Job.Job(new_ad_text.replace('$(Process)', str(i))))
    print('%d job(s) submitted to cluster -1.' % (num_instances))
    return
예제 #2
0
 def test_push(self):
     n = 0
     for i in range(N):
         j = Job(CLASS_AD.replace('j9am01070', 'j9am0%04d' % (i)))
         JobQueue.push(j)
         n += 1
     self.assertEqual(JobQueue.length(), n)
     return