コード例 #1
0
ファイル: jobs.py プロジェクト: hyuni/mycroft
def jobs_filtered(request):
    """
    jobs_filtered handles requests from the jobs endpoint with a log_name and
    optional version.  If there's no version all jobs will be for the given
    log_name will be returned, otherwise all jobs for the log name and version
    combination will be returned.

    **GET /v1/jobs/**\ *{string: log_name}*

    **Query Parameters:**

    * **log_name** - the name of the log for which we want to see jobs

    Example: ``/v1/jobs/ad_click``

    *Example Response* ::

        [
            {'log_name': 'ad_click',
             'log_schema_version': 'initial',
             's3_log_uri': http://ad_click/schema.yaml?Signature=b?Expires=c?AccessKeyId=xxx
             'start_date': '2014-05-01',
             'end_date': '',
             'contact_emails': ['*****@*****.**', '*****@*****.**'],
             'redshift_id': 'abc123',
             'additional_arguments': '{"load_step": ["--force-load"]}'
            },
            {'log_name': 'ad_click',
             'log_schema_version': 'minimal',
             's3_log_uri': http://ad_min/schema.yaml?Signature=b?Expires=b?AccessKeyId=yyy
             'start_date': '2014-05-01',
             'end_date': '2014-05-07',
             'contact_emails': ['*****@*****.**', '*****@*****.**'],
             'redshift_id': 'abc123',
             'additional_arguments': '{"load_step": ["--force-load"]}'
            }
        ]

    ============ ===========
    Status Code  Description
    ============ ===========
    **200**      Success
    **404**      invalid log_name
    **500**      unknown exception
    ============ ===========


    **GET /v1/jobs/**\ *{string: log_name}/{string: log_schema_version}*

    **Query Parameters:**

    * **log_name** - the name of the log for which we want to see jobs
    * **log_schema_version** - the version of the log for which we want to see jobs

    Example: ``/v1/jobs/ad_click/initial``

    *Example Response* ::

        [
            {'log_name': 'ad_click',
             'log_schema_version': 'initial',
             's3_log_uri': http://ad_click/schema.yaml?Signature=b?Expires=c?AccessKeyId=xxx
             'start_date': '2014-05-01',
             'end_date': '',
             'emails': ['*****@*****.**', '*****@*****.**'],
             'redshift_id': 'abc123',
             'additional_arguments': '{"et_step": ["--force-et"]}'
            }
        ]

    ============ ===========
    Status Code  Description
    ============ ===========
    **200**      Success
    **404**      invalid log_name or log_version
    **500**      unknown exception
    ============ ===========

    * **Encoding type:** *application/json*
    """
    log_name = request.matchdict.get("log_name")
    log_version = request.matchdict.get("log_schema_version", None)

    try:
        if log_version is None:
            return 200, list_jobs_by_name(log_name, TableConnection.get_connection("ScheduledJobs"))
        return 200, list_jobs_by_name_version(log_name, log_version, TableConnection.get_connection("ScheduledJobs"))
    except ValueError as e:
        return 404, {"error": repr(e)}
    except Exception as unknown_exception:
        return 500, {"error": repr(unknown_exception)}
コード例 #2
0
ファイル: test_job_actions.py プロジェクト: wlstyy/mycroft
 def test_list_jobs_by_name_bad_input(self, log_name):
     with pytest.raises(ValueError) as e:
         list_jobs_by_name(log_name, None)
     assert e.exconly() == 'ValueError: invalid log_name'
コード例 #3
0
def jobs_filtered(request):
    """
    jobs_filtered handles requests from the jobs endpoint with a log_name and
    optional version.  If there's no version all jobs will be for the given
    log_name will be returned, otherwise all jobs for the log name and version
    combination will be returned.

    **GET /v1/jobs/**\ *{string: log_name}*

    **Query Parameters:**

    * **log_name** - the name of the log for which we want to see jobs

    Example: ``/v1/jobs/ad_click``

    *Example Response* ::

        [
            {'log_name': 'ad_click',
             'log_schema_version': 'initial',
             's3_log_uri': http://ad_click/schema.yaml?Signature=b?Expires=c?AccessKeyId=xxx
             'start_date': '2014-05-01',
             'end_date': '',
             'contact_emails': ['*****@*****.**', '*****@*****.**'],
             'redshift_id': 'abc123',
             'additional_arguments': '{"load_step": ["--force-load"]}'
            },
            {'log_name': 'ad_click',
             'log_schema_version': 'minimal',
             's3_log_uri': http://ad_min/schema.yaml?Signature=b?Expires=b?AccessKeyId=yyy
             'start_date': '2014-05-01',
             'end_date': '2014-05-07',
             'contact_emails': ['*****@*****.**', '*****@*****.**'],
             'redshift_id': 'abc123',
             'additional_arguments': '{"load_step": ["--force-load"]}'
            }
        ]

    ============ ===========
    Status Code  Description
    ============ ===========
    **200**      Success
    **404**      invalid log_name
    **500**      unknown exception
    ============ ===========


    **GET /v1/jobs/**\ *{string: log_name}/{string: log_schema_version}*

    **Query Parameters:**

    * **log_name** - the name of the log for which we want to see jobs
    * **log_schema_version** - the version of the log for which we want to see jobs

    Example: ``/v1/jobs/ad_click/initial``

    *Example Response* ::

        [
            {'log_name': 'ad_click',
             'log_schema_version': 'initial',
             's3_log_uri': http://ad_click/schema.yaml?Signature=b?Expires=c?AccessKeyId=xxx
             'start_date': '2014-05-01',
             'end_date': '',
             'emails': ['*****@*****.**', '*****@*****.**'],
             'redshift_id': 'abc123',
             'additional_arguments': '{"et_step": ["--force-et"]}'
            }
        ]

    ============ ===========
    Status Code  Description
    ============ ===========
    **200**      Success
    **404**      invalid log_name or log_version
    **500**      unknown exception
    ============ ===========

    * **Encoding type:** *application/json*
    """
    log_name = request.matchdict.get('log_name')
    log_version = request.matchdict.get('log_schema_version', None)

    try:
        if log_version is None:
            return 200, list_jobs_by_name(
                log_name, TableConnection.get_connection('ScheduledJobs'))
        return 200, list_jobs_by_name_version(
            log_name, log_version,
            TableConnection.get_connection('ScheduledJobs'))
    except ValueError as e:
        return 404, {'error': repr(e)}
    except Exception as unknown_exception:
        return 500, {'error': repr(unknown_exception)}
コード例 #4
0
ファイル: test_job_actions.py プロジェクト: wlstyy/mycroft
 def test_list_jobs_by_name(self, scheduled_jobs):
     return_value = list_jobs_by_name(SAMPLE_LOG_NAME, scheduled_jobs)
     expected_count = len([job for job in SAMPLE_SCHEDULED_JOBS
                           if job['log_name'] == SAMPLE_LOG_NAME])
     assert len(return_value['jobs']) == expected_count