Ejemplo n.º 1
0
def cancel_cli(api_client, run_id, version):
    """
    Cancels the run specified.
    """
    check_version(api_client, version)
    click.echo(pretty_format(
        RunsApi(api_client).cancel_run(run_id, version=version)))
Ejemplo n.º 2
0
def get_output_cli(api_client, run_id, version):
    """
    Gets the output of a run

    The output schema is documented https://docs.databricks.com/api/latest/jobs.html#runs-get-output
    """
    check_version(api_client, version)
    click.echo(pretty_format(
        RunsApi(api_client).get_run_output(run_id, version=version)))
Ejemplo n.º 3
0
def get_cli(api_client, run_id, version):
    """
    Gets the metadata about a run in json form.

    The output schema is documented https://docs.databricks.com/api/latest/jobs.html#runs-get.
    """
    check_version(api_client, version)
    click.echo(pretty_format(
        RunsApi(api_client).get_run(run_id, version=version)))
Ejemplo n.º 4
0
def submit_cli(api_client, json_file, json, version):
    """
    Submits a one-time run.

    The specification for the request json can be found
    https://docs.databricks.com/api/latest/jobs.html#runs-submit
    """
    check_version(api_client, version)
    json_cli_base(json_file, json, lambda json: RunsApi(
        api_client).submit_run(json, version=version))
Ejemplo n.º 5
0
def list_cli(api_client, job_id, active_only, completed_only, offset, limit, output, version):  # noqa
    """
    Lists job runs.

    The limit and offset determine which runs will be listed. Runs are always listed
    by descending order of run start time and run ID.

    In the TABLE output mode, the columns are as follows.

      - Run ID

      - Run name

      - Life cycle state

      - Result state (can be n/a)
    """
    check_version(api_client, version)
    runs_json = RunsApi(api_client).list_runs(
        job_id, active_only, completed_only, offset, limit, version=version)
    if OutputClickType.is_json(output):
        click.echo(pretty_format(runs_json))
    else:
        click.echo(tabulate(_runs_to_table(runs_json), tablefmt='plain'))
Ejemplo n.º 6
0
def test_check_version():
    # Without calling `databricks jobs configure --version=2.1`
    api_client = ApiClient(user='******',
                           password='******',
                           host='https://databricks.com',
                           jobs_api_version=None)

    # databricks jobs list
    with mock.patch('databricks_cli.jobs.cli.click.echo') as echo_mock:
        cli.check_version(api_client, None)
        assert echo_mock.called
        assert 'Your CLI is configured to use Jobs API 2.0' in echo_mock.call_args[
            0][0]
        assert echo_mock.call_args_list[0][1]['err'] is True
    # databricks jobs list --version=2.0
    with mock.patch('databricks_cli.jobs.cli.click.echo') as echo_mock:
        cli.check_version(api_client, "2.0")
        assert not echo_mock.called
    # databricks jobs list --version=2.1
    with mock.patch('databricks_cli.jobs.cli.click.echo') as echo_mock:
        cli.check_version(api_client, "2.1")
        assert not echo_mock.called

    # After calling `databricks jobs configure --version=2.1`
    api_client = ApiClient(user='******',
                           password='******',
                           host='https://databricks.com',
                           jobs_api_version="2.1")
    # databricks jobs list
    with mock.patch('databricks_cli.jobs.cli.click.echo') as echo_mock:
        cli.check_version(api_client, None)
        assert not echo_mock.called
    # databricks jobs list --version=2.0
    with mock.patch('databricks_cli.jobs.cli.click.echo') as echo_mock:
        cli.check_version(api_client, "2.0")
        assert not echo_mock.called
    # databricks jobs list --version=2.1
    with mock.patch('databricks_cli.jobs.cli.click.echo') as echo_mock:
        cli.check_version(api_client, "2.1")
        assert not echo_mock.called

    # After calling `databricks jobs configure --version=2.0`
    api_client = ApiClient(user='******',
                           password='******',
                           host='https://databricks.com',
                           jobs_api_version="2.0")
    # databricks jobs list
    with mock.patch('databricks_cli.jobs.cli.click.echo') as echo_mock:
        cli.check_version(api_client, None)
        assert echo_mock.called
        assert 'Your CLI is configured to use Jobs API 2.0' in echo_mock.call_args[
            0][0]
    # databricks jobs list --version=2.0
    with mock.patch('databricks_cli.jobs.cli.click.echo') as echo_mock:
        cli.check_version(api_client, "2.0")
        assert not echo_mock.called
    # databricks jobs list --version=2.1
    with mock.patch('databricks_cli.jobs.cli.click.echo') as echo_mock:
        cli.check_version(api_client, "2.1")
        assert not echo_mock.called