Esempio n. 1
0
def test_get_job_categories():
    session_name = generate_random_string()
    js = JobSession(session_name)
    job_categories = js.get_job_categories()
    assert (type(job_categories) == type([]))
    print('\nThere are %s job categories: %s' %
          (len(job_categories), job_categories))
def test_run_job():
    session_name = generate_random_string()
    js = JobSession(session_name)
    j = js.run_job({'remote_command': '/bin/sleep', 'args': ['5']})
    j_id = j.id
    assert (len(j_id) > 0)
    print('\nSubmitted job id: %s' % j_id)
def test_get_job_array():
    session_name = generate_random_string()
    js = JobSession(session_name)
    ja = js.run_bulk_jobs({'remote_command': '/bin/sleep', 'args': ['5']}, 1, 10, 5, 2)
    ja2 = js.get_job_array(ja.id)
    assert (ja.id == ja2.id)
    print('\nRetrieved job array: %s' % ja2)
Esempio n. 4
0
def test_new_session():
    session_name = generate_random_string()
    existing_session_names = JobSession.list_session_names()
    js = JobSession(session_name)
    session_names = JobSession.list_session_names()
    assert (len(session_names) == len(existing_session_names) + 1)
    print('\nCreated new session: %s' % (session_name))
def test_run_bulk_jobs():
    session_name = generate_random_string()
    js = JobSession(session_name)
    ja = js.run_bulk_jobs({'remote_command': '/bin/sleep', 'args': ['5']}, 1, 10, 5, 2)
    jl = ja.job_list
    ja_id = ja.id
    assert (len(ja_id) > 0)
    assert (len(jl) == 2)
    print('\nSubmitted job array id: %s' % ja_id)
Esempio n. 6
0
def test_job_info_from_job():
    session_name = generate_random_string()
    js = JobSession(session_name)
    job_name = 'drmaa2python-%s' % generate_random_string()
    d = {'remote_command': '/bin/sleep', 'args': ['10'], 'job_name': job_name}
    j = js.run_job(d)
    ji = j.get_info()
    assert (ji.job_name == job_name)
    print('\nJob info from job: %s' % (ji))
Esempio n. 7
0
def test_destroy_session():
    session_names = JobSession.list_session_names()
    print('\nExisting session names: %s' % session_names)
    for name in session_names:
        print('Destroying session: %s' % name)
        JobSession.destroy_by_name(name)
    session_names = JobSession.list_session_names()
    print('Remaining session names: %s' % session_names)
    assert (len(session_names) == 0)
Esempio n. 8
0
def test_get_info():
    session_name = 'drmaa2python-%s' % generate_random_string()
    js = JobSession(session_name)
    jn = 'drmaa2python-%s' % generate_random_string()
    d = {'remote_command': '/bin/sleep', 'args': ['10'], 'job_name': jn, 'output_path': '/dev/null', 'join_files': True}
    j = js.run_job(d)
    ji = j.get_info()
    assert (ji.job_name == jn)
    print('\nGet info: %s' % (ji))
Esempio n. 9
0
def test_get_template():
    session_name = generate_random_string()
    js = JobSession(session_name)
    job_name = 'drmaa2python-%s' % generate_random_string()
    d = {'remote_command': '/bin/sleep', 'args': ['5'], 'job_name': job_name, 'output_path': '/dev/null', 'join_files': True}
    ja = js.run_bulk_jobs(d, 1, 10, 3, 2)
    jt = ja.get_template()
    assert (jt.job_name == job_name)
    print('\nGet template: %s' % (jt))
Esempio n. 10
0
def test_wait_any_started():
    session_name = generate_random_string()
    js = JobSession(session_name)
    ja = js.run_bulk_jobs({'remote_command': '/bin/sleep', 'args': ['5']}, 1, 10, 5, 2)
    jl = ja.job_list
    jl_ids = list(map(lambda j: j.id, jl))
    print('\nWaiting on start of any job with id from %s' % jl_ids)
    j = js.wait_any_started(jl)
    assert (j.id in jl_ids)
    print('Job %s started' % j)
Esempio n. 11
0
def test_get_jobs():
    js = JobSession('js-01')
    j_name = 'drmaa2python-%s' % int(random.uniform(0, 1000))
    j = js.run_job({'remote_command': '/bin/sleep', 'args': ['10'], 'job_name': j_name})
    print('\nSubmitted job: %s' % j)
    ji = j.get_info()
    print('Retrieving jobs matching job info %s' % ji)
    j_list = js.get_jobs(ji)
    print('Got jobs: %s' % j_list)
    assert (len(j_list) >= 1)
Esempio n. 12
0
def test_wait_terminated():
    session_name = 'drmaa2python-%s' % generate_random_string()
    js = JobSession(session_name)
    job_name = 'drmaa2python-%s' % generate_random_string()
    d = {'remote_command': '/bin/sleep', 'args': ['10'], 'job_name': job_name}
    j = js.run_job(d)
    j.wait_terminated()
    s, ss = j.get_state()
    assert (s == JobState.DONE)
    print('\nWait terminated for job: %s' % (j))
    ji = j.get_info()
    print('\nGet info: %s' % (ji))
Esempio n. 13
0
def test_wait_all_terminated():
    session_name = generate_random_string()
    js = JobSession(session_name)
    ja = js.run_bulk_jobs({'remote_command': '/bin/sleep', 'args': ['5']}, 1, 10, 5, 2)
    jl = ja.job_list
    jl_ids = list(map(lambda j: j.id, jl))
    jl_ids.sort()
    print('\nWaiting on termination of all jobs: %s' % jl_ids)
    jl2 = js.wait_all_terminated(jl)
    jl2_ids = list(map(lambda j: j.id, jl2))
    jl2_ids.sort()
    assert (jl_ids == jl2_ids)
    print('Jobs terminated: ' % jl2_ids)
Esempio n. 14
0
def test_get_job_array():
    session_name = generate_random_string()
    js = JobSession(session_name)
    d = {
        'remote_command': '/bin/sleep',
        'args': ['5'],
        'output_path': '/dev/null',
        'join_files': True
    }
    ja = js.run_bulk_jobs(d, 1, 10, 5, 2)
    ja2 = js.get_job_array(ja.id)
    assert (ja.id == ja2.id)
    print('\nRetrieved job array: %s' % ja2)
Esempio n. 15
0
def test_get_template():
    session_name = generate_random_string()
    js = JobSession(session_name)
    job_name = 'drmaa2python-%s' % generate_random_string()
    ja = js.run_bulk_jobs(
        {
            'remote_command': '/bin/sleep',
            'args': ['5'],
            'job_name': job_name
        }, 1, 10, 3, 2)
    jt = ja.get_template()
    assert (jt.job_name == job_name)
    print('\nGet template: %s' % (jt))
Esempio n. 16
0
def test_run_job():
    session_name = generate_random_string()
    js = JobSession(session_name)
    d = {
        'remote_command': '/bin/sleep',
        'args': ['5'],
        'output_path': '/dev/null',
        'join_files': True
    }
    j = js.run_job(d)
    j_id = j.id
    assert (len(j_id) > 0)
    print('\nSubmitted job id: %s' % j_id)
Esempio n. 17
0
def test_terminate():
    session_name = generate_random_string()
    js = JobSession(session_name)
    d = {'remote_command': '/bin/sleep', 'args': ['10'], 'output_path': '/dev/null', 'join_files': True}
    ja = js.run_bulk_jobs(d, 1, 10, 3, 2)
    ja.terminate()
    j_list = ja.job_list
    failed_jobs = []
    for j in j_list:
        s, ss = j.get_state()
        if s == JobState.FAILED:
            failed_jobs.append(j)
    assert (len(failed_jobs) > 0)
    print('\nTerminate job array: %s' % (ja))
Esempio n. 18
0
def test_run_bulk_jobs():
    session_name = generate_random_string()
    js = JobSession(session_name)
    d = {
        'remote_command': '/bin/sleep',
        'args': ['5'],
        'output_path': '/dev/null',
        'join_files': True
    }
    ja = js.run_bulk_jobs(d, 1, 10, 5, 2)
    jl = ja.job_list
    ja_id = ja.id
    assert (len(ja_id) > 0)
    assert (len(jl) == 2)
    print('\nSubmitted job array id: %s' % ja_id)
Esempio n. 19
0
def test_get_state():
    session_name = 'drmaa2python-%s' % generate_random_string()
    js = JobSession(session_name)
    job_name = 'drmaa2python-%s' % generate_random_string()
    d = {
        'remote_command': '/bin/sleep',
        'args': ['10'],
        'job_name': job_name,
        'output_path': '/dev/null',
        'join_files': True
    }
    j = js.run_job(d)
    (j_state, j_sub_state) = j.get_state()
    assert (isinstance(j_state, JobState))
    print('\nGet state %s for job %s' % (j_state, j))
Esempio n. 20
0
def test_wait_any_terminated():
    session_name = generate_random_string()
    js = JobSession(session_name)
    d = {
        'remote_command': '/bin/sleep',
        'args': ['5'],
        'output_path': '/dev/null',
        'join_files': True
    }
    ja = js.run_bulk_jobs(d, 1, 10, 5, 2)
    jl = ja.job_list
    jl_ids = list(map(lambda j: j.id, jl))
    print('\nWaiting on termination of any job with id from %s' % jl_ids)
    j = js.wait_any_terminated(jl)
    assert (j.id in jl_ids)
    print('Job %s terminated' % j)
Esempio n. 21
0
def test_wait_terminated():
    session_name = 'drmaa2python-%s' % generate_random_string()
    js = JobSession(session_name)
    job_name = 'drmaa2python-%s' % generate_random_string()
    d = {
        'remote_command': '/bin/sleep',
        'args': ['10'],
        'job_name': job_name,
        'output_path': '/dev/null',
        'join_files': True
    }
    j = js.run_job(d)
    j.wait_terminated()
    s, ss = j.get_state()
    assert (s == JobState.DONE)
    print('\nWait terminated for job: %s' % (j))
Esempio n. 22
0
 def run_sagasu_proc(self):
     self.session = JobSession()
     os.chdir(self.path)
     self.job_details = []
     Path(self.projname).mkdir(parents=True, exist_ok=True)
     i = self.highres
     if self.clust == "l":
         tot = (self.lowres - self.highres) * (
             (self.highsites + 1) - self.lowsites)
         pbar = tqdm(desc="SHELXD", total=tot, dynamic_ncols=True)
     else:
         pass
     while not (i >= self.lowres):
         Path(os.path.join(self.projname, str(i))).mkdir(parents=True,
                                                         exist_ok=True)
         i2 = i / 10
         j = self.highsites
         while not (j <= (self.lowsites - 1)):
             os.makedirs(os.path.join(self.projname, str(i), str(j)),
                         exist_ok=True)
             shutil.copy2(self.insin,
                          (os.path.join(self.projname, str(i), str(j))))
             shutil.copy2(self.hklin,
                          (os.path.join(self.projname, str(i), str(j))))
             workpath = os.path.join(self.path, self.projname, str(i),
                                     str(j))
             f = os.path.join(self.path, self.projname, str(i), str(j),
                              self.projname + "_fa.ins")
             self.replace(f, "FIND", "FIND " + str(j) + "\n")
             self.replace(f, "SHEL", "SHEL 999 " + str(i2) + "\n")
             self.replace(f, "NTRY", "NTRY " + str(self.ntry) + "\n")
             if self.clust == "l":
                 os.chdir(workpath)
                 subprocess.run(["shelxd", self.projname + "_fa"],
                                stdout=subprocess.PIPE)
                 pbar.update(1)
                 pbar.refresh()
                 os.chdir(self.path)
             elif self.clust == "c":
                 template = self.drmaa2template(workpath)
                 job = self.session.run_job(template)
                 self.job_details.append([job])
             else:
                 print("error in input...")
             j = j - 1
         i = i + 1
def test_get_all_jobs():
    js = JobSession('js-01')
    j_name = 'drmaa2python-%s' % int(random.uniform(0, 1000))
    j = js.run_job({
        'remote_command': '/bin/sleep',
        'args': ['10'],
        'job_name': j_name
    })
    print('\nSubmitted job: %s' % j)
    ji = j.get_info()
    j.wait_started()
    ms = MonitoringSession('ms-01')
    print('Opened monitoring session: %s' % ms.name)
    ji2 = JobInfo({'job_id': ji.job_id})
    print('Retrieving jobs matching job info %s' % ji2)
    j_list = ms.get_all_jobs(ji2)
    print('Got all jobs: %s' % j_list)
    assert (len(j_list) >= 1)
Esempio n. 24
0
def test_get_jobs():
    js = JobSession('js-01')
    j_name = 'drmaa2python-%s' % int(random.uniform(0, 1000))
    d = {
        'remote_command': '/bin/sleep',
        'args': ['10'],
        'job_name': j_name,
        'output_path': '/dev/null',
        'join_files': True
    }
    j = js.run_job(d)
    print('\nSubmitted job: %s' % j)
    ji = j.get_info()
    print('Retrieving jobs matching job info %s' % ji)
    ji2 = JobInfo({'job_id': ji.job_id})
    j_list = js.get_jobs(ji2)
    print('Got jobs: %s' % j_list)
    assert (len(j_list) >= 1)
Esempio n. 25
0
def test_hold_and_release():
    session_name = generate_random_string()
    js = JobSession(session_name)
    d = {'remote_command': '/bin/sleep', 'args': ['5'], 'output_path': '/dev/null', 'join_files': True}
    ja = js.run_bulk_jobs(d, 1, 10, 3, 2)
    ja.hold()
    held_jobs = []
    j_list = ja.job_list
    for j in j_list:
        s, ss = j.get_state()
        if s.name.endswith('HELD'):
            held_jobs.append(j)
    assert (len(held_jobs) > 0)
    print('\nHold job array: %s' % (ja))
    ja.release()
    for j in held_jobs:
        s, ss = j.get_state()
        assert (not s.name.endswith('HELD'))
    print('Release job array: %s' % (ja))
Esempio n. 26
0
def test_wait_all_started():
    session_name = generate_random_string()
    js = JobSession(session_name)
    d = {
        'remote_command': '/bin/sleep',
        'args': ['5'],
        'output_path': '/dev/null',
        'join_files': True
    }
    ja = js.run_bulk_jobs(d, 1, 10, 5, 2)
    jl = ja.job_list
    jl_ids = list(map(lambda j: j.id, jl))
    jl_ids.sort()
    print('\nWaiting on start of all jobs: %s' % jl_ids)
    jl2 = js.wait_all_started(jl)
    jl2_ids = list(map(lambda j: j.id, jl2))
    jl2_ids.sort()
    assert (jl_ids == jl2_ids)
    print('Jobs started: ' % jl2_ids)
Esempio n. 27
0
def test_terminate():
    session_name = 'drmaa2python-%s' % generate_random_string()
    js = JobSession(session_name)
    job_name = 'drmaa2python-%s' % generate_random_string()
    d = {
        'remote_command': '/bin/sleep',
        'args': ['10'],
        'job_name': job_name,
        'output_path': '/dev/null',
        'join_files': True
    }
    j = js.run_job(d)
    ji = j.get_info()
    assert (ji.terminating_signal is None)
    j.wait_started()
    j.terminate()
    j.wait_terminated()
    ji = j.get_info()
    assert (ji.terminating_signal is not None)
    print('\nTerminate job: %s' % (ji))
Esempio n. 28
0
def test_suspend_and_resume():
    session_name = generate_random_string()
    js = JobSession(session_name)
    d = {'remote_command': '/bin/sleep', 'args': ['5'], 'output_path': '/dev/null', 'join_files': True}
    ja = js.run_bulk_jobs(d, 1, 10, 3, 2)
    j_list = ja.job_list
    js.wait_any_started(j_list)
    ja.suspend()
    suspended_jobs = []
    for j in j_list:
        s, ss = j.get_state()
        if s == JobState.SUSPENDED:
            suspended_jobs.append(j)
    assert (len(suspended_jobs) > 0)
    print('\nSuspend job array: %s' % (ja))
    ja.resume()
    for j in suspended_jobs:
        s, ss = j.get_state()
        assert (s != JobState.SUSPENDED)
    print('Resume job array: %s' % (ja))
Esempio n. 29
0
def test_hold_and_release():
    session_name = 'drmaa2python-%s' % generate_random_string()
    js = JobSession(session_name)
    job_name = 'drmaa2python-%s' % generate_random_string()
    d = {
        'remote_command': '/bin/sleep',
        'args': ['10'],
        'job_name': job_name,
        'output_path': '/dev/null',
        'join_files': True
    }
    j = js.run_job(d)
    ji = j.get_info()
    assert (not ji.job_state.endswith('HELD'))
    j.hold()
    ji = j.get_info()
    assert (ji.job_state.endswith('HELD'))
    print('\nHold job: %s' % (ji))
    j.release()
    ji = j.get_info()
    assert (not ji.job_state.endswith('HELD'))
    print('Release job: %s' % (ji))
Esempio n. 30
0
def test_suspend_and_resume():
    session_name = 'drmaa2python-%s' % generate_random_string()
    js = JobSession(session_name)
    job_name = 'drmaa2python-%s' % generate_random_string()
    d = {
        'remote_command': '/bin/sleep',
        'args': ['10'],
        'job_name': job_name,
        'output_path': '/dev/null',
        'join_files': True
    }
    j = js.run_job(d)
    j.wait_started()
    ji = j.get_info()
    assert (ji.job_state != JobState.SUSPENDED.name)
    j.suspend()
    ji = j.get_info()
    assert (ji.job_state == JobState.SUSPENDED.name)
    print('\nSuspend job: %s' % (ji))
    j.resume()
    ji = j.get_info()
    assert (ji.job_state != JobState.SUSPENDED.name)
    print('Resume job: %s' % (ji))