We have a custom event script setup. It lives in the repository custom events folder with the folowing structure.
$DEADLINE/custom/events/Update
/Update.dlinit
/Update.py
The contents of Update.dlinit are:
Enabled=True
Update.py contents are
from subprocess import (check_output as runcmd, STDOUT, CalledProcessError)
from Deadline.Events import *
## DeadlineAPI is the stand alone python module.
from DeadlineAPI.DeadlineConnect import DeadlineCon as Connect
all_systems = "all"
aws_linux_group = "linux"
aws_windows_group = "windows"
aws_linux_pool = "linux"
aws_windows_pool = "windows"
command = "asgupdate"
######################################################################
## This is the function that Deadline calls to get an instance of the
## main DeadlineEventListener class.
######################################################################
def GetDeadlineEventListener():
return Update()
######################################################################
## This is the function that Deadline calls when the event plugin is
## no longer in use so that it can get cleaned up.
######################################################################
def CleanupDeadlineEventListener(deadlinePlugin):
deadlinePlugin.Cleanup()
######################################################################
## This is the main DeadlineEventListener class for UpdateAWS.
######################################################################
class Update(DeadlineEventListener):
def __init__(self):
# Set up the event callbacks here
self.OnJobSubmittedCallback += self.OnJobSubmittedOrResumed
self.OnJobResumedCallback += self.OnJobSubmittedOrResumed
self.OnSlaveStartedCallback += self.OnSlaveStarted
self.OnSlaveStoppedCallback += self.OnSlaveStopped
self.OnSlaveIdleCallback += self.OnSlaveIdle
self.OnSlaveStalledCallback += self.OnSlaveStalled
self.conn = Connect("localhost", 8080)
def Cleanup(self):
del self.OnJobSubmittedCallback
del self.OnJobResumedCallback
del self.OnSlaveStartedCallback
del self.OnSlaveStoppedCallback
del self.OnSlaveIdleCallback
del self.OnSlaveStalledCallback
del self.conn
self.LogInfo(
"Cleanup called ...<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
def OnJobSubmittedOrResumed(self, job):
# Job is an http://docs.thinkboxsoftware.com/products/deadline/7.1/2_Scripting%20Reference/class_deadline_1_1_jobs_1_1_job.html
self.LogInfo(
"{}.OnJobSubmittedOrResumed fired, attempting to upate desired capacity <<<<<<<<<<<<<<<<<<<<<<<".format(
self.__class__))
try:
runcmd([command, "-op", "job", "-group", job["Plug"]],
stderr=STDOUT)
except CalledProcessError as e:
self.LogInfo("Failed to run deadliner, exit code {}: {}".format(
e.returncod, e.output))
def OnSlaveStarted(self, slave_name):
# Slave name is a string
self.LogInfo(
"{}.OnSlaveStarted fired, attempting to upate desired capacity <<<<<<<<<<<<<<<<<<<<<<<".format(
self.__class__))
slave = self.get_slave_info_settings(slave_name)
os = "windows" if slave.SlaveInfo.MachineOperatingSystem == "Windows" else "linux"
self.LogInfo(self.conn.Slaves.AddPoolToSlave("aws_{}_pool".format(os)))
self.LogInfo(self.conn.Slaves.AddGroupToSlave("aws_{}_group".format(
os)))
def OnSlaveStopped(self, slave_name):
# Slave name is a string
self.LogInfo(
"{}.OnSlaveStopped fired, attempting to upate desired capacity <<<<<<<<<<<<<<<<<<<<<<<".format(
self.__class__))
self.delete_slave(slave_name)
def OnSlaveIdle(self, slave_name):
# Slave name is a string
self.LogInfo(
"{}.OnSlaveIdle fired, attempting to upate desired capacity <<<<<<<<<<<<<<<<<<<<<<<".format(
self.__class__))
self.delete_slave(slave_name)
def OnSlaveStalled(self, slave_name):
# Slave name is a string
self.LogInfo(
"{}.OnSlaveStalled fired, attempting to upate desired capacity <<<<<<<<<<<<<<<<<<<<<<<".format(
self.__class__))
self.delete_slave(slave_name)
def get_slave_info_settings(self, slave_name):
# slave_name is a string
return self.conn.Slaves.GetSlaveInfoSettings(slave_name)
def is_aws_node(self, slave_name):
# slave_name is a string
snig = self.conn.Slaves.GetSlaveNamesInGroup
if slave_name in snig(aws_windows_group) or slave_name in snig(
aws_linux_group):
return True
return False
def delete_slave(self, slave_name):
## We only delete the slave if it is an aws node. See the README.
if self.is_aws_node(slave_name):
res = self.conn.Slaves.DeleteSlave(slave_name)
self.LogInfo("Deleted slave {}: {}".format(slave_name, res))
The plug in seems to get loaded as the cleanup method gets called, but the other callbacks never do. Or they at least don’t make it to the log statement or otherwise log an error.
I am very new to Deadline so I am sure there is a missing incantation or mispelling or something. Does anyone see anything or have any guidance for me?