state.py 2.32 KB
Newer Older
Michal Simon's avatar
Michal Simon committed
1
#   Copyright notice:
2
#   Copyright CERN, 2014.
3
#
Michal Simon's avatar
Michal Simon committed
4
5
6
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
7
#
Michal Simon's avatar
Michal Simon committed
8
#       http://www.apache.org/licenses/LICENSE-2.0
9
#
Michal Simon's avatar
Michal Simon committed
10
11
12
13
14
15
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

16
17
18
from fts3.rest.client import Inquirer


19
def list_jobs(context, user_dn=None, vo=None, source_se=None, dest_se=None, delegation_id=None, state_in=None):
20
21
22
23
    """
    List active jobs. Can filter by user_dn and vo

    Args:
24
25
26
27
28
        context:       fts3.rest.client.context.Context instance
        user_dn:       Filter by user dn. Can be left empty
        vo:            Filter by vo. Can be left empty
        delegation_id: Filter by delegation ID. Mandatory for state_in
        state_in:      Filter by job state. An iterable is expected (i.e. ['SUBMITTED', 'ACTIVE']
29
30

    Returns:
31
        Decoded JSON message returned by the server (list of jobs)
32
33
    """
    inquirer = Inquirer(context)
34
    return inquirer.get_job_list(user_dn, vo, source_se, dest_se, delegation_id, state_in)
35
36
37
38
39
40
41
42
43
44


def get_job_status(context, job_id, list_files=False):
    """
    Get a job status

    Args:
        context:    fts3.rest.client.context.Context instance
        job_id:     The job ID
        list_files: If True, the status of each individual file will be queried
45
46
47

    Returns:
        Decoded JSON message returned by the server (job status plus, optionally, list of files)
48
49
50
    """
    inquirer = Inquirer(context)
    return inquirer.get_job_status(job_id, list_files)
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

def get_jobs_statuses(context, job_ids, list_files=False):
    """
    Get status for a list of jobs

    Args:
        context:    fts3.rest.client.context.Context instance
        job_ids:    The job list
        list_files: If True, the status of each individual file will be queried

    Returns:
        Decoded JSON message returned by the server (job status plus, optionally, list of files)
    """
    inquirer = Inquirer(context)
    return inquirer.get_jobs_statuses(job_ids, list_files)