Skip to content

Commit

Permalink
Merge branch 'develop' into enhancement/implement_callbacks_for_houdi…
Browse files Browse the repository at this point in the history
…ni_plugins
  • Loading branch information
MustafaJafar authored Nov 15, 2024
2 parents e09b62f + b4f6362 commit 1351e83
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
# -*- coding: utf-8 -*-
"""Collect Deadline servers from instance.
This is resolving index of server lists stored in `deadlineServers` instance
attribute or using default server if that attribute doesn't exists.
"""
import os

import pyblish.api
Expand Down Expand Up @@ -44,6 +37,7 @@ class CollectDeadlineJobEnvVars(pyblish.api.ContextPlugin):
]

def process(self, context):

env = {}
for key in self.ENV_KEYS:
value = os.getenv(key)
Expand All @@ -53,3 +47,15 @@ def process(self, context):

# Transfer some environment variables from current context
context.data.setdefault(JOB_ENV_DATA_KEY, {}).update(env)


class CollectAYONServerToFarmJob(CollectDeadlineJobEnvVars):
label = "Add AYON Server URL to farm job"
settings_category = "deadline"

# Defined via settings
enabled = False

ENV_KEYS = [
"AYON_SERVER_URL"
]
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class ProcessSubmittedJobOnFarm(pyblish.api.InstancePlugin,
}

# list of family names to transfer to new family if present
families_transfer = ["render3d", "render2d", "ftrack", "slate"]
families_transfer = ["render3d", "render2d", "slate"]
plugin_pype_version = "3.0"

# poor man exclusion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,12 @@ CategoryOrder=2
Index=0
Default=
Description=API key for service account on Ayon Server

[AyonAdditionalServerUrls]
Type=multilinestring
Label=Additional AYON Servers
Category=Additional AYON Servers
CategoryOrder=3
Index=0
Default=
Description=An AYON server URL per line suffixed with `@APIKEY` from a service user on that AYON server, e.g. `http://server:5000@veryinsecureapikey`.
79 changes: 70 additions & 9 deletions client/ayon_deadline/repository/custom/plugins/GlobalJobPreLoad.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
FileUtils,
DirectoryUtils,
)
__version__ = "1.1.3"
__version__ = "1.2.0"
VERSION_REGEX = re.compile(
r"(?P<major>0|[1-9]\d*)"
r"\.(?P<minor>0|[1-9]\d*)"
Expand Down Expand Up @@ -410,6 +410,46 @@ def inject_openpype_environment(deadlinePlugin):
raise


def get_ayon_api_key_from_additional_servers(config, server):
"""Get AYON API key from the list of additional servers.
The additional servers are configured on the DeadlineRepository AYON
Plug-in settings using the `AyonAdditionalServerUrls` param. Each line
represents a server URL with an API key, like:
server1:port@APIKEY1
server2:port@APIKEY2
Returns:
Optional[str]: If the server URL is found in the additional servers
then return the API key for that server.
"""
additional_servers: str = config.GetConfigEntryWithDefault(
"AyonAdditionalServerUrls", "").strip()
if not additional_servers:
return

if not isinstance(additional_servers, list):
additional_servers = additional_servers.split(";")

for line in additional_servers:
line = line.strip()
# Ignore empty lines
if not line:
continue

# Log warning if additional server URL is misconfigured
# without an API key
if "@" not in line:
print("Configured additional server URL lacks "
f"`@APIKEY` suffix: {line}")
continue

additional_server, api_key = line.split("@", 1)
if additional_server == server:
return api_key


def inject_ayon_environment(deadlinePlugin):
""" Pull env vars from AYON and push them to rendering process.
Expand Down Expand Up @@ -439,14 +479,35 @@ def inject_ayon_environment(deadlinePlugin):
)

config = RepositoryUtils.GetPluginConfig("Ayon")
ayon_server_url = (
job.GetJobEnvironmentKeyValue("AYON_SERVER_URL") or
config.GetConfigEntryWithDefault("AyonServerUrl", "")
)
ayon_api_key = (
job.GetJobEnvironmentKeyValue("AYON_API_KEY") or
config.GetConfigEntryWithDefault("AyonApiKey", "")
)

ayon_server_url = config.GetConfigEntryWithDefault("AyonServerUrl", "")
ayon_api_key = config.GetConfigEntryWithDefault("AyonApiKey", "")
job_ayon_server_url = job.GetJobEnvironmentKeyValue("AYON_SERVER_URL")
job_ayon_api_key = job.GetJobEnvironmentKeyValue("AYON_API_KEY")

# API key submitted with job environment will always take priority
if job_ayon_api_key:
ayon_api_key = job_ayon_api_key

# Allow custom AYON API key per server URL if server URL is submitted
# along with the job. The custom API keys can be configured on the
# Deadline Repository AYON Plug-in settings, in the format of
# `SERVER:PORT@APIKEY` per line.
elif job_ayon_server_url and job_ayon_server_url != ayon_server_url:
ayon_server_url = job_ayon_server_url
api_key = get_ayon_api_key_from_additional_servers(
config, job_ayon_server_url)
if api_key:
ayon_api_key = api_key
else:
print(
"AYON Server URL submitted with job"
f" '{job_ayon_server_url}' is not the Deadline AYON"
f" Plug-in default server URL '{ayon_server_url}' but"
" has no API key defined in Additional Server URLs."
" Falling back to default API key configured in"
" Deadline repository for the AYON plug-in."
)

if not all([ayon_server_url, ayon_api_key]):
raise RuntimeError((
Expand Down
2 changes: 1 addition & 1 deletion client/ayon_deadline/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-
"""Package declaring AYON addon 'deadline' version."""
__version__ = "0.3.2+dev"
__version__ = "0.4.0+dev"
2 changes: 1 addition & 1 deletion package.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "deadline"
title = "Deadline"
version = "0.3.2+dev"
version = "0.4.0+dev"

client_dir = "ayon_deadline"

Expand Down
18 changes: 17 additions & 1 deletion server/settings/publish_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
)


class CollectAYONServerToFarmJobModel(BaseSettingsModel):
enabled: bool = SettingsField(False, title="Enabled")


class CollectDeadlinePoolsModel(BaseSettingsModel):
"""Settings Deadline default pools."""

Expand Down Expand Up @@ -373,6 +377,15 @@ class PublishPluginsModel(BaseSettingsModel):
CollectDeadlinePools: CollectDeadlinePoolsModel = SettingsField(
default_factory=CollectDeadlinePoolsModel,
title="Default Pools")
CollectAYONServerToFarmJob: CollectAYONServerToFarmJobModel = SettingsField( # noqa
default_factory=CollectAYONServerToFarmJobModel,
title="Add AYON server to farm job",
description=(
"When enabled submit along your `AYON_SERVER_URL` to the farm job."
" On the Deadline AYON Plug-in on the Deadline Repository settings"
" you can specify a custom API key for those server URLs."
)
)
ValidateExpectedFiles: ValidateExpectedFilesModel = SettingsField(
default_factory=ValidateExpectedFilesModel,
title="Validate Expected Files"
Expand Down Expand Up @@ -425,6 +438,9 @@ class PublishPluginsModel(BaseSettingsModel):
"primary_pool": "",
"secondary_pool": ""
},
"CollectAYONServerToFarmJob": {
"enabled": False
},
"ValidateExpectedFiles": {
"enabled": True,
"active": True,
Expand Down Expand Up @@ -570,7 +586,7 @@ class PublishPluginsModel(BaseSettingsModel):
"deadline_group": "",
"deadline_priority": 50,
"skip_integration_repre_list": [],
"families_transfer": ["render3d", "render2d", "ftrack", "slate"],
"families_transfer": ["render3d", "render2d", "slate"],
"aov_filter": [
{
"name": "maya",
Expand Down

0 comments on commit 1351e83

Please sign in to comment.