示例#1
0
 def testMD5(self):
     adm_md5 = "adm_dummy"
     ## Default
     os.unlink(Admin.FILENAME)
     Admin.create(self.cfg.test_dir, None, None, None)
     adm = Admin(Admin.FILENAME)
     self.assertEqual(adm.getMd5(), None)
     ## Set value
     adm.setMd5(adm_md5)
     self.assertEqual(adm.getMd5(), adm_md5)
     ## Missing key
     adm.me.clear()
     self.assertEqual(adm.getMd5(), None)
示例#2
0
def over_limit(job):
    """
    check if the user (same email) has a similar job (same command line or same workflow name) running
    @param job: the job to check before to submit it to Execution
    @type job: L{Job} instance
    @raise UserValueError: if the number of similar jobs exceed the Config.SIMULTANEOUS_JOBS
    """
    from hashlib import md5
    import glob
    from Mobyle.Admin import Admin
    from Mobyle.MobyleError import UserValueError, MobyleError

    max_same_jobs = job.cfg.max_similar_job_per_user()
    max_user_jobs = job.cfg.max_job_per_user()

    user_email = str(job.getEmail())
    newMd5 = md5()
    newMd5.update(job.getCommandLine())
    newDigest = newMd5.hexdigest()

    work_dir = job.getDir()
    thisJobAdm = Admin(work_dir)
    thisJobAdm.setMd5(newDigest)
    thisJobAdm.commit()

    if thisJobAdm.getWorkflowID():
        # this job is a subtask of a workflow
        # we allow a workflow to run several identical job in parallel
        return True
    mask = os.path.normpath("%s/*.*" % (job.cfg.admindir()))
    jobs = glob.glob(mask)

    same_jobs_nb = 0
    jobs_nb = 0
    msg = None
    for one_job in jobs:
        try:
            oldAdm = Admin(one_job)
        except MobyleError, err:
            if os.path.lexists(one_job):
                p_log.critical("%s/%s: invalid job in ADMINDIR : %s" % (job.getServiceName(), job.getKey(), err))
            continue
        if (oldAdm.getWorkflowID()):
            # this job is NOT a workflow but
            # this job is the "same" than a workflow subtasks
            # we allow a workflow to run several identical job in parallel
            continue
        old_email = oldAdm.getEmail()
        oldDigest = oldAdm.getMd5()
        if user_email == old_email:
            oldStatus = job.getStatus()
            if oldStatus.isEnded():
                p_log.debug("oldStatus.isEnded() = True")
                continue
            jobs_nb += 1
            if max_user_jobs and jobs_nb >= max_user_jobs:
                msg = "%d jobs (%s) have been already submitted (md5 = %s)" % (jobs_nb,
                                                                               os.path.basename(one_job),
                                                                               newDigest
                                                                               )
                userMsg = " %d job(s) have been already submitted, and are(is) not finished yet. Please wait for the end of these jobs before you resubmit." % (
                jobs_nb)
                p_log.warning(msg + " : run aborted ")
                raise UserValueError(parameter=None, msg=userMsg)
            if newDigest == oldDigest:
                same_jobs_nb += 1
                if max_same_jobs and same_jobs_nb >= max_same_jobs:
                    msg = "%d similar jobs (%s) have been already submitted (md5 = %s)" % (
                        same_jobs_nb,
                        os.path.basename(one_job),
                        newDigest
                    )
                    userMsg = " %d similar job(s) have been already submitted, and are(is) not finished yet. Please wait for the end of these jobs before you resubmit." % (
                    same_jobs_nb)
                    p_log.warning(msg + " : run aborted ")
                    raise UserValueError(parameter=None, msg=userMsg)