def get_jobs_by_label(self, label, name, job_states): """ :param label: the label value of the job :param name: the name of the job :param job_states: the job status :type label: str :type name: str :type job_states: dict :rtype: Response """ request = job.QueryRequest( respoolID=peloton.ResourcePoolID(value=self.respool_id), spec=job.QuerySpec( pagination=query.PaginationSpec(offset=0, limit=100), labels=[ peloton.Label(key="cluster_name", value=label), peloton.Label(key="module_name", value=name), ], jobStates=job_states, ), ) try: records = self.client.job_svc.Query( request, metadata=self.client.jobmgr_metadata, timeout=default_timeout, ).records ids = [record.id.value for record in records] return ids except Exception as e: print_fail("Exception calling Get job :%s" % str(e)) raise
def test__query_active_jobs(create_jobs): salt = create_jobs[0] respoolID = create_jobs[1] running_jobs = create_jobs[2]['RUNNING'] spec_active_jobs = job_pb2.QuerySpec( keywords=[salt], jobStates=[ job_pb2.JobState.Value('RUNNING'), job_pb2.JobState.Value('PENDING'), job_pb2.JobState.Value('INITIALIZED'), ], pagination=query.PaginationSpec( offset=0, limit=500, maxLimit=1000, orderBy=[query.OrderBy( order=query.OrderBy.Order.Value('DESC'), property=query.PropertyPath(value='creation_time'), )], ), ) resp = query_by_spec(respoolID, spec=spec_active_jobs) assert len(resp.results) == NUM_JOBS_PER_STATE # test descending order, the last created active job should show up first assert resp.results[0].name == running_jobs[NUM_JOBS_PER_STATE - 1].get_info().config.name
def test__query_completed_jobs(create_jobs): salt = create_jobs[0] respoolID = create_jobs[1] failed_jobs = create_jobs[2]['FAILED'] # name is structured as "TestJob-<6 letter salt>-<count>" # we will use <salt> to restrict the query scope. spec_completed_jobs = job_pb2.QuerySpec( keywords=[salt], jobStates=[ job_pb2.JobState.Value('SUCCEEDED'), job_pb2.JobState.Value('KILLED'), job_pb2.JobState.Value('FAILED'), ], pagination=query.PaginationSpec( offset=0, limit=500, maxLimit=1000, orderBy=[query.OrderBy( order=query.OrderBy.Order.Value('DESC'), property=query.PropertyPath(value='completion_time'), )], ), ) resp = query_by_spec(respoolID, spec=spec_completed_jobs) # We should see NUM_JOBS_PER_STATE SUCCEEDED # and NUM_JOBS_PER_STATE FAILED jobs assert len(resp.results) == 2 * NUM_JOBS_PER_STATE # test descending order, the job that completed last should show up first # in this case it should be the last job in the failed jobs list assert resp.results[0].name == failed_jobs[NUM_JOBS_PER_STATE - 1].get_info().config.name
def test__query_pagination(create_jobs): salt = create_jobs[0] respoolID = create_jobs[1] pagination = query.PaginationSpec( offset=0, limit=2, maxLimit=5, ) spec_pagination = job_pb2.QuerySpec( keywords=[salt], pagination=pagination, ) resp = query_by_spec(respoolID, spec=spec_pagination) assert len(resp.results) == 2 pagination.maxLimit = 2 spec_pagination = job_pb2.QuerySpec( keywords=[salt], pagination=pagination, ) resp = query_by_spec(respoolID, spec=spec_pagination) assert len(resp.results) == 2 pagination.offset = 1 spec_pagination = job_pb2.QuerySpec( keywords=[salt], pagination=pagination, ) resp = query_by_spec(respoolID, spec=spec_pagination) assert len(resp.results) == 1
] log = logging.getLogger(__name__) ################################### # Common setup and helper functions ################################### SORT_BY_FILEDS = ["state", "creation_time"] ORDER = ["DESC", "ASC"] default_pagination = query.PaginationSpec( offset=0, limit=500, maxLimit=1000, orderBy=[ query.OrderBy( order=query.OrderBy.Order.Value("DESC"), property=query.PropertyPath(value="creation_time"), ) ], ) def to_spec(task_state): """ Creates a task.TaskState message. """ assert task_state in TASK_STATES spec = task.TaskState.Value(task_state) return spec def query_request(job_id,