yaotungyu

scheduled_techblast_manager_deadline

Sep 23rd, 2020 (edited)
252
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from System.IO import *
  2. from Deadline.Scripting import *
  3. from DeadlineUI.Controls.Scripting.DeadlineScriptDialog import DeadlineScriptDialog
  4.  
  5. from deadline9.DeadlineConnect import DeadlineCon
  6. from deadline_rest import deadline_tools as dt
  7. from deadline9 import JobReports
  8. from deadline9 import TaskReports
  9. from deadline9 import Slaves
  10. from deadline9 import Jobs
  11. from deadline9 import Limits
  12.  
  13. from deadline_overseer import supplementary_deadline_cmd
  14. reload(supplementary_deadline_cmd)
  15. ddln_conProp = DeadlineCon(**dt.DEADLINE_HOST)
  16. ddln_taskreporter = TaskReports.TaskReports(ddln_conProp.connectionProperties)
  17. ddln_jobreporter = JobReports.JobReports(ddln_conProp.connectionProperties)
  18. ddln_slavereporter = Slaves.Slaves(ddln_conProp.connectionProperties)
  19. ddln_jobs = Jobs.Jobs(ddln_conProp.connectionProperties)
  20. ddln_limits = Limits.LimitGroups(ddln_conProp.connectionProperties)
  21.  
  22. ubl_mcs = ddln_limits.GetLimitGroup('nuke_ubl')['Props']['Slaves']
  23. pub_mcs = ddln_limits.GetLimitGroup('publish')['Props']['Slaves']
  24.  
  25.  
  26.  
  27.  
  28.  
  29. ## loop process starts here:
  30.  
  31.  
  32. #get jobs info first because it takes longer to prevent inaccurate info
  33. active_jobs_get = ddln_jobs.GetJobsInState('1')
  34. queued_tech_blasts = [j for j in active_jobs_get if 'TechBlast' in j['Props']['Name'] if j['DateStart']=='0001-01-01T00:00:00Z']
  35.  
  36. jobs_with_ubl_lim = [j for j in queued_tech_blasts if 'nuke_ubl' in j['Props']['Limits']]
  37. jobs_with_pub_lim = [j for j in queued_tech_blasts if 'publish' in j['Props']['Limits']]
  38. jobs_boostable = [j for j in queued_tech_blasts if 'publish_techblast' in j['Props']['Limits']]
  39.  
  40. #parse slave idleness here
  41. all_slaves_info = ddln_slavereporter.GetSlaveInfos()
  42. idle_pub_machines = [s for s in all_slaves_info if s['_id'] in pub_mcs and s['Stat']==2 and s['Grps']=='sub_servers']
  43. idle_ubl_machines = [s for s in all_slaves_info if s['_id'] in ubl_mcs and s['_id'] not in pub_mcs and s['Stat']==2 and s['Grps']=='sub_servers']
  44. print 'available UBL machines::',len(idle_ubl_machines),'|','available PUB machines::',len(idle_pub_machines)
  45.  
  46.  
  47. ubl_reserve = 2
  48. pub_reserve = 3
  49.  
  50.  
  51. avail_ubl_mc_num = len(idle_ubl_machines)-ubl_reserve-len(jobs_with_ubl_lim)
  52. avail_pub_mc_num = len(idle_pub_machines)-pub_reserve-len(jobs_with_pub_lim)
  53.  
  54. ubl_slaves = [s['_id'] for s in idle_ubl_machines]
  55. pub_slaves = [s['_id'] for s in idle_pub_machines]
  56.  
  57. print 'Transferrable UBL Mcs:',avail_ubl_mc_num,'|','Transferrable PUB Mcs:',avail_pub_mc_num
  58.  
  59.  
  60. job_i = 0
  61. #go through available machines for UBL
  62. for i in range(0,avail_ubl_mc_num):
  63.     print 'Adding UBL Limit on::',jobs_boostable[job_i]['Props']['Name'],'|',jobs_boostable[job_i]['_id']
  64.     jobs_boostable[job_i]['Props']['Limits'].remove('publish_techblast')
  65.     jobs_boostable[job_i]['Props']['Limits'].append('nuke_ubl')
  66.     lim_change_result_ = supplementary_deadline_cmd.update_LimitGroups(jobs_boostable[job_i]['_id'],jobs_boostable[0]['Props']['Limits'])
  67.     for l in lim_change_result_:
  68.         print l
  69.     job_i+=1
  70.  
  71. for i in range(0,avail_pub_mc_num):
  72.     print 'Adding Publish Limit on::',jobs_boostable[job_i]['Props']['Name'],'|',jobs_boostable[job_i]['_id']
  73.     jobs_boostable[job_i]['Props']['Limits'].remove('publish_techblast')
  74.     jobs_boostable[job_i]['Props']['Limits'].append('publish')
  75.     lim_change_result_ = supplementary_deadline_cmd.update_LimitGroups(jobs_boostable[job_i]['_id'],jobs_boostable[0]['Props']['Limits'])
  76.     for l in lim_change_result_:
  77.         print l
  78.     job_i+=1
  79.  
  80.  
  81.  
  82. print len(active_tech_blasts)
  83.  
  84.  
RAW Paste Data