Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
def update_orderby(sort_by, order="DESC"):
    """ Customize query.PaginationSpec object by field to sort on and ordering."""
    assert sort_by in SORT_BY_FILEDS
    assert order in ORDER

    orderby = [
        query.OrderBy(
            order=query.OrderBy.Order.Value(order),
            property=query.PropertyPath(value=sort_by),
        )
    ]
    del default_pagination.orderBy[:]
    default_pagination.orderBy.extend(orderby)
    return default_pagination
Exemplo n.º 4
0
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,
                  task_state=None,
                  pagination=None,
Exemplo n.º 5
0
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,
                  task_state=None,
                  pagination=None,