def test_explicit_group(self): group_spec = self.minimal_group() job_a = util.minimal_job(group=group_spec["uuid"]) job_b = util.minimal_job(group=group_spec["uuid"]) data = {'jobs': [job_a, job_b], 'groups': [group_spec]} resp = util.session.post('%s/rawscheduler' % self.cook_url, json=data) self.assertEqual(resp.status_code, 201) jobs = util.session.get('%s/rawscheduler?job=%s&job=%s' % (self.cook_url, job_a['uuid'], job_b['uuid'])) self.assertEqual(200, jobs.status_code) jobs = jobs.json() self.assertEqual(group_spec['uuid'], jobs[0]['groups'][0]) self.assertEqual(group_spec['uuid'], jobs[1]['groups'][0]) util.wait_for_job(self.cook_url, job_a['uuid'], 'completed') util.wait_for_job(self.cook_url, job_b['uuid'], 'completed')
def test_list_jobs_by_time(self): # schedule two jobs with different submit times job_specs = [util.minimal_job() for _ in range(2)] request_body = {'jobs': [job_specs[0]]} resp = util.session.post('%s/rawscheduler' % self.cook_url, json=request_body) self.assertEqual(resp.status_code, 201) time.sleep(1) request_body = {'jobs': [job_specs[1]]} resp = util.session.post('%s/rawscheduler' % self.cook_url, json=request_body) self.assertEqual(resp.status_code, 201) submit_times = [self.get_job(job_spec['uuid'])['submit_time'] for job_spec in job_specs] user = self.determine_user() # start-ms and end-ms are exclusive # query where start-ms and end-ms are the submit times of jobs 1 & 2 respectively resp = util.session.get('%s/list?user=%s&state=waiting&start-ms=%s&end-ms=%s' % (self.cook_url, user, submit_times[0] - 1, submit_times[1] + 1)) self.assertEqual(200, resp.status_code) jobs = resp.json() self.assertTrue(any(job for job in jobs if job['uuid'] == job_specs[0]['uuid'])) self.assertTrue(any(job for job in jobs if job['uuid'] == job_specs[1]['uuid'])) # query just for job 1 resp = util.session.get('%s/list?user=%s&state=waiting&start-ms=%s&end-ms=%s' % (self.cook_url, user, submit_times[0] - 1, submit_times[1])) self.assertEqual(200, resp.status_code) jobs = resp.json() self.assertTrue(any(job for job in jobs if job['uuid'] == job_specs[0]['uuid'])) self.assertFalse(any(job for job in jobs if job['uuid'] == job_specs[1]['uuid'])) # query just for job 2 resp = util.session.get('%s/list?user=%s&state=waiting&start-ms=%s&end-ms=%s' % (self.cook_url, user, submit_times[0], submit_times[1] + 1)) self.assertEqual(200, resp.status_code) jobs = resp.json() self.assertFalse(any(job for job in jobs if job['uuid'] == job_specs[0]['uuid'])) self.assertTrue(any(job for job in jobs if job['uuid'] == job_specs[1]['uuid'])) # query for neither resp = util.session.get('%s/list?user=%s&state=waiting&start-ms=%s&end-ms=%s' % (self.cook_url, user, submit_times[0], submit_times[1])) self.assertEqual(200, resp.status_code) jobs = resp.json() self.assertFalse(any(job for job in jobs if job['uuid'] == job_specs[0]['uuid'])) self.assertFalse(any(job for job in jobs if job['uuid'] == job_specs[1]['uuid']))
def test_straggler_handling(self): straggler_handling = { 'type': 'quantile-deviation', 'parameters': { 'quantile': 0.5, 'multiplier': 2.0 } } group_spec = self.minimal_group(straggler_handling=straggler_handling) job_fast = util.minimal_job(group=group_spec["uuid"]) job_slow = util.minimal_job(group=group_spec["uuid"], command='sleep 120') data = {'jobs': [job_fast, job_slow], 'groups': [group_spec]} resp = util.session.post('%s/rawscheduler' % self.cook_url, json=data) self.assertEqual(resp.status_code, 201) util.wait_for_job(self.cook_url, job_fast['uuid'], 'completed') util.wait_for_job(self.cook_url, job_slow['uuid'], 'completed') jobs = util.session.get('%s/rawscheduler?job=%s&job=%s' % (self.cook_url, job_fast['uuid'], job_slow['uuid'])) self.assertEqual(200, jobs.status_code) jobs = jobs.json() self.logger.debug('Loaded jobs %s', jobs) self.assertEqual('success', jobs[0]['state']) self.assertEqual('failed', jobs[1]['state']) self.assertEqual(2004, jobs[1]['instances'][0]['reason_code'])
def test_list_jobs_by_state(self): # schedule a bunch of jobs in hopes of getting jobs into different statuses request_body = {'jobs': [util.minimal_job(command="sleep %s" % i) for i in range(1, 20)]} resp = util.session.post('%s/rawscheduler' % self.cook_url, json=request_body) self.assertEqual(resp.status_code, 201) # let some jobs get scheduled time.sleep(10) user = self.determine_user() for state in ['waiting', 'running', 'completed']: resp = util.session.get('%s/list?user=%s&state=%s' % (self.cook_url, user, state)) self.assertEqual(200, resp.status_code) jobs = resp.json() for job in jobs: # print "%s %s" % (job['uuid'], job['status']) self.assertEquals(state, job['status'])
def test_get_job(self): # schedule a job job_spec = util.minimal_job() resp = util.session.post('%s/rawscheduler' % self.cook_url, json={'jobs': [job_spec]}) self.assertEqual(201, resp.status_code) # query for the same job & ensure the response has what it's supposed to have job = util.wait_for_job(self.cook_url, job_spec['uuid'], 'completed') self.assertEquals(job_spec['mem'], job['mem']) self.assertEquals(job_spec['max_retries'], job['max_retries']) self.assertEquals(job_spec['name'], job['name']) self.assertEquals(job_spec['priority'], job['priority']) self.assertEquals(job_spec['uuid'], job['uuid']) self.assertEquals(job_spec['cpus'], job['cpus']) self.assertTrue('labels' in job) self.assertEquals(9223372036854775807, job['max_runtime']) # 9223372036854775807 is MAX_LONG(ish), the default value for max_runtime self.assertEquals('success', job['state']) self.assertTrue('env' in job) self.assertTrue('framework_id' in job) self.assertTrue('ports' in job) self.assertTrue('instances' in job) self.assertEquals('completed', job['status']) self.assertTrue(isinstance(job['submit_time'], int)) self.assertTrue('uris' in job) self.assertTrue('retries_remaining' in job) instance = job['instances'][0] self.assertTrue(isinstance(instance['start_time'], int)) self.assertTrue('executor_id' in instance) self.assertTrue('hostname' in instance) self.assertTrue('slave_id' in instance) self.assertTrue(isinstance(instance['preempted'], bool)) self.assertTrue(isinstance(instance['end_time'], int)) self.assertTrue(isinstance(instance['backfilled'], bool)) self.assertTrue('ports' in instance) self.assertEquals('completed', job['status']) self.assertTrue('task_id' in instance)
def test_error_while_creating_job(self): job1 = util.minimal_job() job2 = util.minimal_job(uuid=job1['uuid']) resp = util.session.post('%s/rawscheduler' % self.cook_url, json={'jobs':[job1, job2]}) self.assertEqual(resp.status_code, 500)
def determine_user(self): job_spec = util.minimal_job() request_body = {'jobs': [job_spec]} resp = util.session.post('%s/rawscheduler' % self.cook_url, json=request_body) self.assertEqual(resp.status_code, 201) return self.get_job(job_spec['uuid'])['user']