Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sync/__init__.py
Original file line number Diff line number Diff line change
@@ -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"
18 changes: 18 additions & 0 deletions sync/api/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
28 changes: 27 additions & 1 deletion sync/cli/_databricks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions sync/cli/awsdatabricks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
create_submission,
get_cluster_report,
get_recommendation,
get_submission,
monitor_cluster,
run_job,
run_prediction,
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions sync/cli/azuredatabricks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
create_submission,
get_cluster_report,
get_recommendation,
get_submission,
monitor_cluster,
run_job,
run_prediction,
Expand All @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions sync/clients/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

**params might make for a friendlier interface so long as we don't want to call any params out.

return self._send(
self._client.build_request(
"GET", f"/v1/projects/{project_id}/submissions", params=params
)
)
Comment on lines +147 to +152
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one doesn't get used (yet), but I included for parity with the get_project_recommendations method elsewhere in this file.


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(
Expand Down