Skip to content

Commit

Permalink
Merge pull request #49 from ynput/feature/AY-6789_Render-instance-sup…
Browse files Browse the repository at this point in the history
…port-of-Frame-List

Refactor Deadline Submission JobInfo
  • Loading branch information
kalisp authored Nov 22, 2024
2 parents 1c4dbf6 + 0defb2f commit 59b8fa3
Show file tree
Hide file tree
Showing 23 changed files with 1,765 additions and 2,502 deletions.
472 changes: 98 additions & 374 deletions client/ayon_deadline/abstract_submit_deadline.py

Large diffs are not rendered by default.

151 changes: 107 additions & 44 deletions client/ayon_deadline/addon.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
import os
import sys

import requests
import six
from typing import Optional, List

from ayon_core.lib import Logger
from ayon_core.addon import AYONAddon, IPluginPaths

from .lib import (
get_deadline_workers,
get_deadline_groups,
get_deadline_limit_groups,
get_deadline_pools
)
from .version import __version__


DEADLINE_ADDON_ROOT = os.path.dirname(os.path.abspath(__file__))


class DeadlineWebserviceError(Exception):
"""
Exception to throw when connection to Deadline server fails.
"""


class DeadlineAddon(AYONAddon, IPluginPaths):
name = "deadline"
version = __version__
Expand All @@ -38,6 +35,11 @@ def initialize(self, studio_settings):

self.deadline_servers_info = deadline_servers_info

self._pools_by_server_name = {}
self._limit_groups_by_server_name = {}
self._groups_by_server_name = {}
self._machines_by_server_name = {}

def get_plugin_paths(self):
"""Deadline plugin paths."""
# Note: We are not returning `publish` key because we have overridden
Expand All @@ -46,47 +48,108 @@ def get_plugin_paths(self):
# abstract on the parent class
return {}

def get_publish_plugin_paths(self, host_name=None):
def get_publish_plugin_paths(
self,
host_name: Optional[str] = None
) -> List[str]:
publish_dir = os.path.join(DEADLINE_ADDON_ROOT, "plugins", "publish")
paths = [os.path.join(publish_dir, "global")]
if host_name:
paths.append(os.path.join(publish_dir, host_name))
return paths

@staticmethod
def get_deadline_pools(webservice, auth=None, log=None):
"""Get pools from Deadline.
def get_pools_by_server_name(self, server_name: str) -> List[str]:
"""Returns dictionary of pools per DL server
Args:
server_name (str): Deadline Server name from Project Settings.
Returns:
Dict[str, List[str]]: {"default": ["pool1", "pool2"]}
"""
pools = self._pools_by_server_name.get(server_name)
if pools is None:
dl_server_info = self.deadline_servers_info[server_name]

auth = (dl_server_info["default_username"],
dl_server_info["default_password"])
pools = get_deadline_pools(
dl_server_info["value"],
auth
)
self._pools_by_server_name[server_name] = pools

return pools

def get_groups_by_server_name(self, server_name: str) -> List[str]:
"""Returns dictionary of groups per DL server
Args:
server_name (str): Deadline Server name from Project Settings.
Returns:
Dict[str, List[str]]: {"default": ["group1", "group2"]}
"""
groups = self._groups_by_server_name.get(server_name)
if groups is None:
dl_server_info = self.deadline_servers_info[server_name]

auth = (dl_server_info["default_username"],
dl_server_info["default_password"])
groups = get_deadline_groups(
dl_server_info["value"],
auth
)
self._groups_by_server_name[server_name] = groups

return groups

def get_limit_groups_by_server_name(self, server_name: str) -> List[str]:
"""Returns dictionary of limit groups per DL server
Args:
server_name (str): Deadline Server name from Project Settings.
Returns:
Dict[str, List[str]]: {"default": ["limit1", "limit2"]}
"""
limit_groups = self._limit_groups_by_server_name.get(server_name)
if limit_groups is None:
dl_server_info = self.deadline_servers_info[server_name]

auth = (dl_server_info["default_username"],
dl_server_info["default_password"])
limit_groups = get_deadline_limit_groups(
dl_server_info["value"],
auth
)
self._limit_groups_by_server_name[server_name] = limit_groups

return limit_groups

def get_machines_by_server_name(self, server_name: str) -> List[str]:
"""Returns dictionary of machines/workers per DL server
Args:
webservice (str): Server url.
auth (Optional[Tuple[str, str]]): Tuple containing username,
password
log (Optional[Logger]): Logger to log errors to, if provided.
server_name (str): Deadline Server name from Project Settings.
Returns:
List[str]: Pools.
Throws:
RuntimeError: If deadline webservice is unreachable.
Dict[str, List[str]]: {"default": ["renderNode1", "PC1"]}
"""
from .abstract_submit_deadline import requests_get

if not log:
log = Logger.get_logger(__name__)

argument = "{}/api/pools?NamesOnly=true".format(webservice)
try:
kwargs = {}
if auth:
kwargs["auth"] = auth
response = requests_get(argument, **kwargs)
except requests.exceptions.ConnectionError as exc:
msg = 'Cannot connect to DL web service {}'.format(webservice)
log.error(msg)
six.reraise(
DeadlineWebserviceError,
DeadlineWebserviceError('{} - {}'.format(msg, exc)),
sys.exc_info()[2])
if not response.ok:
log.warning("No pools retrieved")
return []

return response.json()
machines = self._machines_by_server_name.get(server_name)
if machines is None:
dl_server_info = self.deadline_servers_info[server_name]

auth = (dl_server_info["default_username"],
dl_server_info["default_password"])
machines = get_deadline_workers(
dl_server_info["value"],
auth
)
self._machines_by_server_name[server_name] = machines

return machines
Loading

0 comments on commit 59b8fa3

Please sign in to comment.