Skip to content
Open
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
227 changes: 227 additions & 0 deletions docs/design/in-memory-config.md

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions src/deadline/client/api/_submit_job_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,8 +844,10 @@ def create_job_from_job_bundle(
job_id = create_job_response["jobId"]
print_function_callback("Waiting for Job to be created...")

# If using the default config, set the default job id so it holds the
# most-recently submitted job.
# When no config was provided, the caller is using the public API with
# on-disk defaults — auto-persist the job ID so `deadline job get` works.
# When a config IS provided, the caller (CLI or GUI) owns persistence
# and can resolve the correct hierarchical section via persist_job_id.
if config is None:
set_setting("defaults.job_id", job_id)

Expand Down
19 changes: 10 additions & 9 deletions src/deadline/client/cli/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,21 @@ def wraps(ctx: click.Context, *args, **kwargs):

def _apply_cli_options_to_config(
*, config: Optional[ConfigParser] = None, required_options: Set[str] = set(), **args
) -> Optional[ConfigParser]:
) -> ConfigParser:
"""
Modifies an AWS Deadline Cloud config object to apply standard option names to it, such as
the AWS profile, AWS Deadline Cloud Farm, or AWS Deadline Cloud Queue to use.
Returns an in-memory AWS Deadline Cloud config with standard CLI option overrides applied.
Always returns a fresh copy — never mutates the caller's config or the read_config() cache.

Args:
config (ConfigParser, optional): an AWS Deadline Cloud config, read by config_file.read_config().
If not provided, loads the config from disk.
config (ConfigParser, optional): a base config to copy from. If not provided, loads from disk.
"""
# Only work with a custom config if there are standard options provided
if any(value is not None for value in args.values()):
if config is None:
config = config_file.read_config()
# Always start from a copy so we never mutate the caller's object or the cache
base = config if config is not None else config_file.read_config()
config = ConfigParser()
config.read_dict(base)

# Apply any provided standard options
if any(value is not None for value in args.values()):
aws_profile_name = args.pop("profile", None)
if aws_profile_name:
config_file.set_setting("defaults.aws_profile_name", aws_profile_name, config=config)
Expand Down
29 changes: 18 additions & 11 deletions src/deadline/client/cli/_groups/bundle_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from botocore.exceptions import ClientError

from ... import api
from ...config import config_file
from ...config import config_file, get_setting, persist_job_id
from ...dataclasses import SubmitterInfo
from ....job_attachments.exceptions import (
AssetSyncError,
Expand Down Expand Up @@ -310,17 +310,16 @@ def _check_create_job_wait_canceled() -> bool:
click.echo("Saved job debug snapshot:")
click.echo(f" {save_debug_snapshot}")

# Check Whether the CLI options are modifying any of the default settings that affect
# the job id. If not, we'll save the job id submitted as the default job id.
# Persist the job ID to the on-disk config under the correct
# farm/queue section so `deadline job get` picks it up.
# If a job snapshot directory was provided, the job_id will be None.
if (
args.get("profile") is None
and args.get("farm_id") is None
and args.get("queue_id") is None
and args.get("storage_profile_id") is None
and job_id
):
config_file.set_setting("defaults.job_id", job_id)
if job_id:
persist_job_id(
job_id,
profile=get_setting("defaults.aws_profile_name", config=config),
farm_id=get_setting("defaults.farm_id", config=config),
queue_id=get_setting("defaults.queue_id", config=config),
)

except AssetSyncCancelledError as exc:
if sigint_handler.continue_operation:
Expand Down Expand Up @@ -418,6 +417,10 @@ def _check_create_job_wait_canceled() -> bool:
'OR --submitter-info \'{"submitter_name": "MyApp", "additional_info": {"render_engine": "Cycles"}}\' '
"OR --submitter-info file://path/to/submitter.json",
)
@click.option("--profile", help="The AWS profile to use.")
@click.option("--farm-id", help="The farm to use.")
@click.option("--queue-id", help="The queue to use.")
@click.option("--storage-profile-id", help="The storage profile to use.")
@_handle_error
def bundle_gui_submit(
parameter,
Expand All @@ -439,6 +442,9 @@ def bundle_gui_submit(
Learn more about [job bundles](https://docs.aws.amazon.com/deadline-cloud/latest/developerguide/build-job-bundle.html)
"""

# Apply CLI options (--profile, --farm-id, --queue-id, --storage-profile-id) to an in-memory config.
# _apply_cli_options_to_config always returns a fresh copy, so the on-disk cache is never mutated.
config = _apply_cli_options_to_config(**args)
if submitter_name:
click.echo(
click.style(
Expand Down Expand Up @@ -473,6 +479,7 @@ def bundle_gui_submit(
submitter_info=submitter_info,
known_asset_paths=known_asset_path,
job_parameters=parameter,
session_config=config,
)

if not submitter:
Expand Down
2 changes: 2 additions & 0 deletions src/deadline/client/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"get_setting",
"set_setting",
"clear_setting",
"persist_job_id",
"get_best_profile_for_farm",
"str2bool",
"DEFAULT_DEADLINE_ENDPOINT_URL",
Expand All @@ -27,5 +28,6 @@
get_setting_default,
set_setting,
clear_setting,
persist_job_id,
str2bool,
)
24 changes: 24 additions & 0 deletions src/deadline/client/config/config_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,30 @@ def set_setting(setting_name: str, value: str, config: Optional[ConfigParser] =
write_config(config)


def persist_job_id(job_id: str, profile: str, farm_id: str, queue_id: str) -> None:
"""
Persists a job ID to the on-disk config file under the correct
hierarchical section (profile / farm / queue).

The caller provides the explicit profile, farm, and queue that the job
was submitted to. The job ID is written into the matching section of
the on-disk config without changing the on-disk farm/queue defaults.

Args:
job_id: The job ID to persist.
profile: The AWS profile name used for submission.
farm_id: The farm ID the job was submitted to.
queue_id: The queue ID the job was submitted to.
"""
section = f"profile-{profile} {farm_id} {queue_id} defaults"

disk_config = read_config()
if section not in disk_config:
disk_config[section] = {}
disk_config.set(section, "job_id", job_id)
write_config(disk_config)


def clear_setting(setting_name: str, config: Optional[ConfigParser] = None):
"""
Sets the value of the specified setting back to the default value.
Expand Down
3 changes: 2 additions & 1 deletion src/deadline/client/ui/dialogs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

__all__ = [
"ConfigureSettingsResult",
"DeadlineConfigDialog",
"DeadlineLoginDialog",
"SubmitJobProgressDialog",
Expand All @@ -10,7 +11,7 @@
]

from ._types import JobBundlePurpose
from .deadline_config_dialog import DeadlineConfigDialog
from .deadline_config_dialog import ConfigureSettingsResult, DeadlineConfigDialog
from .deadline_login_dialog import DeadlineLoginDialog
from .submit_job_progress_dialog import SubmitJobProgressDialog
from .submit_job_to_deadline_dialog import SubmitJobToDeadlineDialog
Expand Down
Loading
Loading