Exemple #1
0
def test_short_job_management():
    adapter = K8SAdapter()
    adapter.set_command(["/bin/sh", "-c", "env; sleep 1"])
    print("Submitting short jobs")
    jobs_num = 1
    job_ids = adapter.submit_jobs(100, jobs_num, {'URB_FRAMEWORK_ID': 'framework-1', 'URB_FRAMEWORK_NAME':'short-test'})
    print("Got job ids: %s" % job_ids)
    assert job_ids != None
    gevent.sleep(3)
    for jid in job_ids:
        try:
            adapter.get_job_status(jid[0])
        except CompletedJob as e:
            print("Job status: completed")
        gevent.spawn(adapter.delete_job, jid[0])
    gevent.sleep(2)
    for jid in job_ids:
        try:
            print("Get status of the finished job: %s" % jid[0])
            adapter.get_job_status(jid[0])
            assert False
        except ApiException as e:
            if e.reason == "Not Found":
                pass
            else:
                assert False
        except CompletedJob as e:
            pass
Exemple #2
0
def test_register_framework():
    print("Registering framework")
    cm = ConfigManager.get_instance()
    cf = ChannelFactory.get_instance()
    framework_env = {
        'URB_CONFIG_FILE' : cm.get_config_file(),
        'URB_FRAMEWORK_ID' : '1',
        'URB_FRAMEWORK_NAME':'test',
        'URB_MASTER' : cf.get_message_broker_connection_url(),
    }
    adapter = K8SAdapter()
    adapter.set_command(["/bin/sh", "-c", "env; sleep 100"])
    max_tasks = 5
    concurrent_tasks = 1
    # specify unused parameters
    kwargs = {'class': 'class',
              'submit_options': 'submit_options'};
    job_ids = adapter.register_framework(max_tasks, concurrent_tasks, framework_env, **kwargs)
    print 'JOB IDs: ', job_ids
    framework = {
        'job_ids' : job_ids,
        'name' : 'framework_name',
        'id' : {'value' : 1},
        'config' : {'mem' : 1024, 'disk' : 16384, 'cpus' : 1, 
                    'ports' : '[(30000,31000)]',
                    'max_rejected_offers' : 1,
                    'max_tasks' : 5
        }
    }
    FrameworkTracker.get_instance().add(1, framework)
    assert job_ids != None
Exemple #3
0
def test_unregister_framework():
    framework = FrameworkTracker.get_instance().get(1)
    print("Unregistering framework: %s" % framework)
    framework_name = framework.get('name')
    job_ids = framework.get('job_ids')
    assert job_ids != None
    j_list = list(job_ids)
    adapter = K8SAdapter()
    adapter.unregister_framework(framework)
    gevent.sleep(3)
    for i in range(0,12):
        j_del = []
        print("Job list: %s" % j_list)
        for job_id in j_list:
            try:
                jid = job_id[0]
                print("Get job status for: %s" % jid)
                resp = adapter.get_job_status(jid)
                print("Status: %s" % resp.status)
            except ApiException as e:
                if e.reason == "Not Found":
                    print("Was deleted")
                    j_del.append(job_id)
                    pass
        j_list = [x for x in j_list if x not in j_del]
        if len(j_list) == 0:
            break
        gevent.sleep(1)
    else:
        raise URBException("Jobs %s were not deleted" % j_list)
    print("Jobs %s were deleted" % job_ids)