diff --git a/sync/__init__.py b/sync/__init__.py index 8cb805b..fdab5a5 100644 --- a/sync/__init__.py +++ b/sync/__init__.py @@ -1,4 +1,4 @@ """Library for leveraging the power of Sync""" -__version__ = "0.4.11" +__version__ = "0.4.12" TIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ" diff --git a/sync/api/projects.py b/sync/api/projects.py index 97b17ff..1919975 100644 --- a/sync/api/projects.py +++ b/sync/api/projects.py @@ -395,3 +395,21 @@ def get_project_recommendation(project_id: str, recommendation_id: str) -> Respo return Response(**response) return Response(result=response["result"]) + + +def get_project_submission(project_id: str, submission_id: str) -> Response[dict]: + """Get a specific submission for a project id + + :param project_id: project ID + :type project_id: str + :param submission_id: submission ID + :type submission_id: str + :return: submission object + :rtype: Response[dict] + """ + response = get_default_client().get_project_submission(project_id, submission_id) + + if response.get("error"): + return Response(**response) + + return Response(result=response["result"]) diff --git a/sync/cli/_databricks.py b/sync/cli/_databricks.py index 2f92ed3..0a9b2aa 100644 --- a/sync/cli/_databricks.py +++ b/sync/cli/_databricks.py @@ -3,7 +3,11 @@ import click import orjson -from sync.api.projects import create_project_recommendation, get_project_recommendation +from sync.api.projects import ( + create_project_recommendation, + get_project_recommendation, + get_project_submission, +) from sync.cli.util import validate_project from sync.config import CONFIG from sync.models import DatabricksComputeType, DatabricksPlanType, Platform, Preference @@ -190,6 +194,7 @@ def create_recommendation(project: dict): @click.argument("project", callback=validate_project) @click.argument("recommendation-id") def get_recommendation(project: dict, recommendation_id: str): + """Get a project recommendation""" rec_response = get_project_recommendation(project["id"], recommendation_id) recommendation = rec_response.result if recommendation: @@ -206,6 +211,27 @@ def get_recommendation(project: dict, recommendation_id: str): click.echo(f"Failed to get recommendation. {rec_response.error}", err=True) +@click.command +@click.argument("project", callback=validate_project) +@click.argument("submission-id") +def get_submission(project: dict, submission_id: str): + """Get a project submission""" + sub_response = get_project_submission(project["id"], submission_id) + submission = sub_response.result + if submission: + if submission["state"] == "FAILURE": + click.echo("Submission generation failed.", err=True) + else: + click.echo( + orjson.dumps( + submission, + option=orjson.OPT_INDENT_2 | orjson.OPT_NAIVE_UTC | orjson.OPT_UTC_Z, + ) + ) + else: + click.echo(f"Failed to get submission. {sub_response.error}", err=True) + + @click.command @click.argument("run-id") @click.option("--plan", type=click.Choice(DatabricksPlanType), default=DatabricksPlanType.STANDARD) diff --git a/sync/cli/awsdatabricks.py b/sync/cli/awsdatabricks.py index 97fe570..e71ef92 100644 --- a/sync/cli/awsdatabricks.py +++ b/sync/cli/awsdatabricks.py @@ -9,6 +9,7 @@ create_submission, get_cluster_report, get_recommendation, + get_submission, monitor_cluster, run_job, run_prediction, @@ -30,6 +31,7 @@ def aws_databricks(ctx: click.Context): aws_databricks.add_command(create_submission) aws_databricks.add_command(create_recommendation) aws_databricks.add_command(get_recommendation) +aws_databricks.add_command(get_submission) aws_databricks.add_command(apply_recommendation) aws_databricks.add_command(get_cluster_report) aws_databricks.add_command(apply_prediction) diff --git a/sync/cli/azuredatabricks.py b/sync/cli/azuredatabricks.py index a5a494f..f74d9d1 100644 --- a/sync/cli/azuredatabricks.py +++ b/sync/cli/azuredatabricks.py @@ -9,6 +9,7 @@ create_submission, get_cluster_report, get_recommendation, + get_submission, monitor_cluster, run_job, run_prediction, @@ -30,6 +31,7 @@ def azure_databricks(ctx: click.Context): azure_databricks.add_command(create_submission) azure_databricks.add_command(create_recommendation) azure_databricks.add_command(get_recommendation) +azure_databricks.add_command(get_submission) azure_databricks.add_command(apply_recommendation) azure_databricks.add_command(get_cluster_report) azure_databricks.add_command(apply_prediction) diff --git a/sync/clients/sync.py b/sync/clients/sync.py index 46fd75e..54c5d1b 100644 --- a/sync/clients/sync.py +++ b/sync/clients/sync.py @@ -144,6 +144,20 @@ def get_project_recommendation(self, project_id: str, recommendation_id: str) -> ) ) + def get_project_submissions(self, project_id: str, params: dict = None) -> dict: + return self._send( + self._client.build_request( + "GET", f"/v1/projects/{project_id}/submissions", params=params + ) + ) + + def get_project_submission(self, project_id: str, submission_id: str) -> dict: + return self._send( + self._client.build_request( + "GET", f"/v1/projects/{project_id}/submissions/{submission_id}" + ) + ) + def create_workspace_config(self, workspace_id: str, **config) -> dict: headers, content = encode_json(config) return self._send(