Skip to content

Commit

Permalink
feat: support JSON output from bundle gui-submit (#380)
Browse files Browse the repository at this point in the history
Signed-off-by: Joel Wong <127782171+joel-wong-aws@users.noreply.github.com>
  • Loading branch information
joel-wong-aws authored Jul 2, 2024
1 parent 26ee376 commit eb9acb0
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 13 deletions.
49 changes: 46 additions & 3 deletions src/deadline/client/cli/_groups/bundle_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
"""
from __future__ import annotations

import json
import logging
import re
from typing import Any, Optional

import click
from contextlib import ExitStack
Expand Down Expand Up @@ -249,8 +251,20 @@ def _decide_cancel_submission(upload_group: AssetUploadGroup) -> bool:
is_flag=True,
help="Allows user to choose Bundle and adds a 'Load a different job bundle' option to the Job-Specific Settings UI",
)
@click.option(
"--output",
type=click.Choice(
["verbose", "json"],
case_sensitive=False,
),
default="verbose",
help="Specifies the output format of the messages printed to stdout.\n"
"VERBOSE: Displays messages in a human-readable text format.\n"
"JSON: Displays messages in JSON line format, so that the info can be easily "
"parsed/consumed by custom scripts.",
)
@_handle_error
def bundle_gui_submit(job_bundle_dir, browse, **args):
def bundle_gui_submit(job_bundle_dir, browse, output, **args):
"""
Opens GUI to submit an Open Job Description job bundle to AWS Deadline Cloud.
"""
Expand All @@ -263,6 +277,7 @@ def bundle_gui_submit(job_bundle_dir, browse, **args):
raise DeadlineOperationError(
"Specify a job bundle directory or run the bundle command with the --browse flag"
)
output = output.lower()

submitter = show_job_bundle_submitter(input_job_bundle_dir=job_bundle_dir, browse=browse)

Expand All @@ -276,10 +291,38 @@ def bundle_gui_submit(job_bundle_dir, browse, **args):
response = None
if submitter:
response = submitter.create_job_response
if response:

_print_response(
output=output,
submitted=True if response else False,
job_bundle_dir=job_bundle_dir,
job_history_bundle_dir=submitter.job_history_bundle_dir,
job_id=response["jobId"] if response else None,
)


def _print_response(
output: str,
submitted: bool,
job_bundle_dir: str,
job_history_bundle_dir: Optional[str],
job_id: Optional[str],
):
if output == "json":
if submitted:
response: dict[str, Any] = {
"status": "SUBMITTED",
"jobId": job_id,
"jobHistoryBundleDirectory": job_history_bundle_dir,
}
click.echo(json.dumps(response))
else:
click.echo(json.dumps({"status": "CANCELED"}))
else:
if submitted:
click.echo("Submitted job bundle:")
click.echo(f" {job_bundle_dir}")
click.echo(f"Job ID: {response['jobId']}")
click.echo(f"Job ID: {job_id}")
else:
click.echo("Job submission canceled.")

Expand Down
21 changes: 11 additions & 10 deletions src/deadline/client/ui/dialogs/submit_job_to_deadline_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def __init__(
self.job_settings_type = type(initial_job_settings)
self.on_create_job_bundle_callback = on_create_job_bundle_callback
self.create_job_response: Optional[Dict[str, Any]] = None
self.job_history_bundle_dir: Optional[str] = None
self.deadline_authentication_status = DeadlineAuthenticationStatus.getInstance()
self.show_host_requirements_tab = show_host_requirements_tab

Expand Down Expand Up @@ -339,15 +340,15 @@ def on_export_bundle(self):

# Save the bundle
try:
job_history_bundle_dir = create_job_history_bundle_dir(
self.job_history_bundle_dir = create_job_history_bundle_dir(
settings.submitter_name, settings.name
)

if self.show_host_requirements_tab:
requirements = self.host_requirements.get_requirements()
self.on_create_job_bundle_callback(
self,
job_history_bundle_dir,
self.job_history_bundle_dir,
settings,
queue_parameters,
asset_references,
Expand All @@ -358,21 +359,21 @@ def on_export_bundle(self):
# Maintaining backward compatibility for submitters that do not support host_requirements yet
self.on_create_job_bundle_callback(
self,
job_history_bundle_dir,
self.job_history_bundle_dir,
settings,
queue_parameters,
asset_references,
purpose=JobBundlePurpose.EXPORT,
)

logger.info(f"Saved the submission as a job bundle: {job_history_bundle_dir}")
logger.info(f"Saved the submission as a job bundle: {self.job_history_bundle_dir}")
if sys.platform == "win32":
# Open the directory in the OS's file explorer
os.startfile(job_history_bundle_dir)
os.startfile(self.job_history_bundle_dir)
QMessageBox.information(
self,
f"{settings.submitter_name} job submission",
f"Saved the submission as a job bundle:\n{job_history_bundle_dir}",
f"Saved the submission as a job bundle:\n{self.job_history_bundle_dir}",
)
# Close the submitter window to signal the submission is done
self.close()
Expand Down Expand Up @@ -405,15 +406,15 @@ def on_submit(self):
try:
deadline = api.get_boto3_client("deadline")

job_history_bundle_dir = create_job_history_bundle_dir(
self.job_history_bundle_dir = create_job_history_bundle_dir(
settings.submitter_name, settings.name
)

if self.show_host_requirements_tab:
requirements = self.host_requirements.get_requirements()
self.on_create_job_bundle_callback(
self,
job_history_bundle_dir,
self.job_history_bundle_dir,
settings,
queue_parameters,
asset_references,
Expand All @@ -424,7 +425,7 @@ def on_submit(self):
# Maintaining backward compatibility for submitters that do not support host_requirements yet
self.on_create_job_bundle_callback(
self,
job_history_bundle_dir,
self.job_history_bundle_dir,
settings,
queue_parameters,
asset_references,
Expand Down Expand Up @@ -473,7 +474,7 @@ def on_submit(self):
farm_id,
queue_id,
storage_profile,
job_history_bundle_dir,
self.job_history_bundle_dir,
queue_parameters,
asset_manager,
deadline,
Expand Down

0 comments on commit eb9acb0

Please sign in to comment.