Esempio n. 1
0
def deprecated_batch_requests_create(deployment_name, version_name, data, timeout, format_):
    """
    [DEPRECATED] Create a deployment batch request and retrieve request IDs to collect the results later.
    Deployment requests are only stored for deployment versions with `request_retention_mode` 'full' or 'metadata'.

    Use the option `timeout` to specify the timeout of the request. The minimum value is 10 seconds. The maximum value
    is 345600 (96 hours). The default value is 14400 (4 hours).

    Use the version option to make a batch request to a specific deployment version:
    `ubiops deployments batch_requests create <my-deployment> -v <my-version> --data <input>`

    If not specified, a batch request is made to the default version:
    `ubiops deployments batch_requests create <my-deployment> --data <input>`

    Multiple data inputs can be specified at ones by using the '--data' options multiple times:
    `ubiops deployments batch_requests create <my-deployment> --data <input-1> --data <input-2> --data <input-3>`

    For structured input, specify each data input as JSON formatted string. For example:
    `ubiops deployments batch_requests create <my-deployment> --data "{\\"param1\\": 1, \\"param2\\": \\"two\\"}"`
    """

    if format_ != 'json':
        click.secho(
            "Deprecation warning: 'batch_requests create' is deprecated, use 'requests create --batch' instead",
            fg='red'
        )

    data = list(data)

    project_name = get_current_project(error=True)

    client = init_client()
    deployment = client.deployments_get(project_name=project_name, deployment_name=deployment_name)

    if deployment.input_type == STRUCTURED_TYPE:
        input_data = []
        for d in data:
            input_data.append(parse_json(d))
    else:
        input_data = data

    if version_name is not None:
        response = client.batch_deployment_version_requests_create(
            project_name=project_name, deployment_name=deployment_name, version=version_name, data=input_data,
            timeout=timeout
        )
    else:
        response = client.batch_deployment_requests_create(
            project_name=project_name, deployment_name=deployment_name, data=input_data, timeout=timeout
        )
    client.api_client.close()

    if format_ == 'reference':
        click.echo(format_requests_reference(response))
    elif format_ == 'oneline':
        click.echo(format_requests_oneline(response))
    elif format_ == 'json':
        click.echo(format_json(response))
    else:
        click.echo(format_requests_reference(response))
Esempio n. 2
0
def requests_get(deployment_name, version_name, request_id, format_):
    """
    Get one or more stored deployment requests.
    Deployment requests are only stored for deployment versions with `request_retention_mode` 'full' or 'metadata'.

    Use the version option to get a request for a specific deployment version.
    If not specified, the request is retrieved for the default version.

    Multiple request ids can be specified at ones by using the '-id' options multiple times:
    `ubiops deployments requests get <my-deployment> -v <my-version> -id <id-1> -id <id-2> -id <id-3>`
    """

    request_ids = list(request_id)

    project_name = get_current_project(error=True)

    client = init_client()
    if version_name is not None:
        response = client.deployment_version_requests_batch_get(
            project_name=project_name, deployment_name=deployment_name, version=version_name, data=request_ids
        )
    else:
        response = client.deployment_requests_batch_get(
            project_name=project_name, deployment_name=deployment_name, data=request_ids
        )
    client.api_client.close()

    if format_ == 'reference':
        click.echo(format_requests_reference(response))
    elif format_ == 'oneline':
        click.echo(format_requests_oneline(response))
    elif format_ == 'json':
        click.echo(format_json(response))
    else:
        click.echo(format_requests_reference(response))
Esempio n. 3
0
def deprecated_pipelines_request(pipeline_name, version_name, data,
                                 pipeline_timeout, deployment_timeout,
                                 format_):
    """
    [DEPRECATED] Create a pipeline request and retrieve the result.

    Use the version option to make a request to a specific pipeline version:
    `ubiops pipelines request <my-deployment> -v <my-version> --data <input>`

    If not specified, a request is made to the default version:
    `ubiops pipelines request <my-deployment> --data <input>`

    For structured input, specify the data as JSON formatted string. For example:
    `ubiops pipelines request <my-deployment> --data "{\\"param1\\": 1, \\"param2\\": \\"two\\"}"`
    """

    if format_ != 'json':
        click.secho(
            "Deprecation warning: 'request' is deprecated, use 'requests create' instead",
            fg='red')

    project_name = get_current_project(error=True)

    client = init_client()
    pipeline = client.pipelines_get(project_name=project_name,
                                    pipeline_name=pipeline_name)

    if pipeline.input_type == STRUCTURED_TYPE:
        data = parse_json(data)

    if version_name is not None:
        response = client.pipeline_version_requests_create(
            project_name=project_name,
            pipeline_name=pipeline_name,
            version=version_name,
            data=data,
            pipeline_timeout=pipeline_timeout,
            deployment_timeout=deployment_timeout)

    else:
        response = client.pipeline_requests_create(
            project_name=project_name,
            pipeline_name=pipeline_name,
            data=data,
            pipeline_timeout=pipeline_timeout,
            deployment_timeout=deployment_timeout)

    client.api_client.close()
    if format_ == 'reference':
        click.echo(format_pipeline_requests_reference([response]))

    elif format_ == 'oneline':
        click.echo(format_pipeline_requests_oneline([response]))

    elif format_ == 'json':
        click.echo(format_json(response))

    else:
        click.echo(format_pipeline_requests_reference([response]))
Esempio n. 4
0
def deprecated_batch_requests_get(pipeline_name, version_name, request_id,
                                  format_):
    """
    [DEPRECATED] Get the results of one or more pipeline batch requests.
    Pipeline requests are only stored for pipeline versions with `request_retention_mode` 'full' or 'metadata'.

    Use the version option to get a batch request for a specific pipeline version.
    If not specified, the batch request is retrieved for the default version.

    Multiple request ids can be specified at ones by using the '-id' options multiple times:
    `ubiops pipelines batch_requests get <my-pipeline> -v <my-version> -id <id-1> -id <id-2> -id <id-3>`
    """

    if format_ != 'json':
        click.secho(
            "Deprecation warning: 'batch_requests get' is deprecated, use 'requests get' instead",
            fg='red')

    request_ids = list(request_id)

    project_name = get_current_project(error=True)

    client = init_client()
    if version_name is not None:
        response = client.pipeline_version_requests_batch_get(
            project_name=project_name,
            pipeline_name=pipeline_name,
            version=version_name,
            data=request_ids)

    else:
        response = client.pipeline_requests_batch_get(
            project_name=project_name,
            pipeline_name=pipeline_name,
            data=request_ids)

    client.api_client.close()

    if format_ == 'reference':
        click.echo(format_pipeline_requests_reference(response))

    elif format_ == 'oneline':
        click.echo(format_pipeline_requests_oneline(response))

    elif format_ == 'json':
        click.echo(format_json(response))

    else:
        click.echo(format_pipeline_requests_reference(response))
Esempio n. 5
0
def logs_list(deployment_name, deployment_version_name, pipeline_name,
              pipeline_version_name, pipeline_object_name, request_id,
              pipeline_request_id, build_id, system, start_date, start_log,
              date_range, limit, format_):
    """Get the logs of your project.

    Use the command options as filters.
    """

    project_name = get_current_project(error=True)
    client = init_client()

    filters = {}
    if deployment_name:
        filters['deployment_name'] = deployment_name
    if deployment_version_name:
        filters['deployment_version'] = deployment_version_name
    if pipeline_name:
        filters['pipeline_name'] = pipeline_name
    if pipeline_version_name:
        filters['pipeline_version'] = pipeline_version_name
    if pipeline_object_name:
        filters['pipeline_object_name'] = pipeline_object_name
    if build_id:
        filters['build_id'] = build_id
    if request_id:
        filters['deployment_request_id'] = request_id
    if pipeline_request_id:
        filters['pipeline_request_id'] = pipeline_request_id
    if system is not None:
        filters['system'] = system
    if start_date is not None:
        try:
            start_date = format_datetime(parse_datetime(start_date),
                                         fmt='%Y-%m-%dT%H:%M:%SZ')
        except ValueError:
            raise Exception(
                "Failed to parse start_date. Please use iso-format, "
                "for example, '2020-01-01T00:00:00.000000Z'")
    elif start_date is None and start_log is None:
        start_date = str(datetime.now())
    log_filters = api.LogsCreate(filters=filters,
                                 date=start_date,
                                 id=start_log,
                                 date_range=date_range,
                                 limit=limit)
    logs = client.projects_log_list(project_name=project_name,
                                    data=log_filters)
    client.api_client.close()

    if format_ == 'json':
        click.echo(format_json(logs))
        return

    if len(logs) > 0:
        if format_ == 'oneline':
            lines = format_logs_oneline(logs)
        elif format_ == 'reference':
            lines = format_logs_reference(logs)
        elif format_ == 'extended':
            lines = format_logs_reference(
                logs,
                extended=[
                    'deployment_request_id', 'pipeline_request_id',
                    'deployment_name', 'deployment_version', 'pipeline_name',
                    'pipeline_version', 'pipeline_object_name', 'build_id'
                ])
        else:
            lines = format_logs_reference(logs)
        click.echo_via_pager(lines)
    elif start_date:
        starting_point = parse_datetime(start_date).isoformat()
        if date_range > 0:
            end_point = (parse_datetime(start_date) +
                         timedelta(seconds=date_range)).isoformat()
        else:
            end_point = (parse_datetime(start_date) -
                         timedelta(seconds=abs(date_range))).isoformat()
        click.echo("No logs found between <%s> and <%s>" %
                   (starting_point, end_point))
Esempio n. 6
0
def requests_create(deployment_name, version_name, batch, data, json_file, timeout, format_):
    """
    Create a deployment request and retrieve request IDs to collect the results later.
    Use the option `timeout` to specify the timeout of the request. The minimum value is 10 seconds. The maximum value
    is 3600 (1 hour) for express deployments and 345600 (96 hours) for batch deployments. The default value is 300
    (5 minutes) for express deployments and 14400 (4 hours) for batch deployments.

    Use the version option to make a request to a specific deployment version:
    `ubiops deployments requests create <my-deployment> -v <my-version> --data <input>`

    If not specified, a request is made to the default version:
    `ubiops deployments requests create <my-deployment> --data <input>`

    Use `--batch` to make an asynchronous batch request:
    `ubiops deployments requests create <my-deployment> --batch --data <input>`

    Multiple data inputs can be specified at ones and send as batch by using the '--data' options multiple times:
    `ubiops deployments requests create <my-deployment> --batch --data <input-1> --data <input-2> --data <input-3>`

    For structured input, specify data input as JSON formatted string. For example:
    `ubiops deployments requests create <my-deployment> --data "{\\"param1\\": 1, \\"param2\\": \\"two\\"}"`
    """

    data = list(data)

    project_name = get_current_project(error=True)

    client = init_client()
    deployment = client.deployments_get(project_name=project_name, deployment_name=deployment_name)

    if json_file and data:
        raise Exception("Specify data either using the <data> or <json_file> option, not both")

    if json_file:
        input_data = read_json(json_file)
        if not isinstance(input_data, list):
            input_data = [input_data]

    elif data:
        if deployment.input_type == STRUCTURED_TYPE:
            input_data = []
            for d in data:
                input_data.append(parse_json(d))
        else:
            input_data = data

    else:
        raise Exception("Missing option <data> or <json_file>")

    if version_name is not None:
        if batch:
            response = client.batch_deployment_version_requests_create(
                project_name=project_name, deployment_name=deployment_name,
                version=version_name, data=input_data, timeout=timeout
            )
        else:
            response = [client.deployment_version_requests_create(
                project_name=project_name, deployment_name=deployment_name,
                version=version_name, data=input_data, timeout=timeout
            )]
    else:
        if batch:
            response = client.batch_deployment_requests_create(
                project_name=project_name, deployment_name=deployment_name, data=input_data, timeout=timeout
            )
        else:
            response = [client.deployment_requests_create(
                project_name=project_name, deployment_name=deployment_name, data=input_data, timeout=timeout
            )]

    client.api_client.close()

    if format_ == 'reference':
        click.echo(format_requests_reference(response))
    elif format_ == 'oneline':
        click.echo(format_requests_oneline(response))
    elif format_ == 'json':
        click.echo(format_json(response))
    else:
        click.echo(format_requests_reference(response))
Esempio n. 7
0
def requests_create(pipeline_name, version_name, batch, timeout,
                    deployment_timeout, data, json_file, format_):
    """
    Create a pipeline request. Use `--batch` to create a batch (asynchronous) request.
    It's only possible to create a direct (synchronous) request to pipelines without 'batch' mode deployments. In
    contrast, batch (asynchronous) requests can be made to any pipeline, independent on the deployment modes.

    Pipeline requests are only stored for pipeline versions with `request_retention_mode` 'full' or 'metadata'.

    Use the option `timeout` to specify the timeout of the pipeline request. The minimum value is 10 seconds.
    The maximum value is 7200 (2 hours) for direct requests and 345600 (96 hours) for batch requests. The default value
    is 3600 (1 hour) for direct requests and 14400 (4 hours) for batch requests.

    Use the version option to make a request to a specific pipeline version:
    `ubiops pipelines requests create <my-pipeline> -v <my-version> --data <input>`

    If not specified, a request is made to the default version:
    `ubiops pipelines requests create <my-pipeline> --data <input>`

    Use `--batch` to make an asynchronous batch request:
    `ubiops pipelines requests create <my-pipeline> --batch --data <input>`

    Multiple data inputs can be specified at ones and send as batch by using the '--data' options multiple times:
    `ubiops pipelines requests create <my-pipeline> --batch --data <input-1> --data <input-2> --data <input-3>`

    For structured input, specify each data input as JSON formatted string. For example:
    `ubiops pipelines requests create <my-pipeline> --data "{\\"param1\\": 1, \\"param2\\": \\"two\\"}"`
    """

    data = list(data)

    project_name = get_current_project(error=True)

    client = init_client()
    pipeline = client.pipelines_get(project_name=project_name,
                                    pipeline_name=pipeline_name)

    if batch and deployment_timeout is not None:
        raise Exception(
            "It's not possible to pass a deployment timeout for a batch pipeline request"
        )

    if json_file and data:
        raise Exception(
            "Specify data either using the <data> or <json_file> option, not both"
        )

    if json_file:
        input_data = read_json(json_file)
        if not isinstance(input_data, list):
            input_data = [input_data]

    elif data:
        if pipeline.input_type == STRUCTURED_TYPE:
            input_data = []
            for d in data:
                input_data.append(parse_json(d))
        else:
            input_data = data

    else:
        raise Exception("Missing option <data> or <json_file>")

    if version_name is not None:
        if batch:
            response = client.batch_pipeline_version_requests_create(
                project_name=project_name,
                pipeline_name=pipeline_name,
                version=version_name,
                data=input_data,
                timeout=timeout)
        else:
            response = [
                client.pipeline_version_requests_create(
                    project_name=project_name,
                    pipeline_name=pipeline_name,
                    version=version_name,
                    data=input_data,
                    pipeline_timeout=timeout,
                    deployment_timeout=deployment_timeout)
            ]
    else:
        if batch:
            response = client.batch_pipeline_requests_create(
                project_name=project_name,
                pipeline_name=pipeline_name,
                data=input_data,
                timeout=timeout)
        else:
            response = [
                client.pipeline_requests_create(
                    project_name=project_name,
                    pipeline_name=pipeline_name,
                    data=input_data,
                    pipeline_timeout=timeout,
                    deployment_timeout=deployment_timeout)
            ]

    client.api_client.close()

    if format_ == 'reference':
        click.echo(format_pipeline_requests_reference(response))
    elif format_ == 'oneline':
        click.echo(format_pipeline_requests_oneline(response))
    elif format_ == 'json':
        click.echo(format_json(response))
    else:
        click.echo(format_pipeline_requests_reference(response))