Inspired by Mark's ideas, I wrote a pre-process include which runs through the appropriate agent group and assigns the Nth active host in the group to the job ("N" being declared as a variable on the job object or task properties). If there are fewer than N hosts in the group, the assignment will roll over to an active host, essentially using the "next" model.
Because I want to track which agent groups are used for which jobs (with simple "search for use" and without using SQL), I want the agent group specified on the job objects (as their assigned agent) rather than in variables. Unfortunately, I don't think there's any way to know the relevant agent group using only scripting -- because once the job gets to pre-process, the individual agent is already selected, and you can't determine the original agent group.
So I made a SQL variable to get the original agent group name from the job's definition, then used PREP_PROCESS_AGENTGROUP to loop through it, assigning host #N as requested, or another host if there aren't enough hosts. As a bonus, when there aren't as many hosts as expected, I can toss out a notification that more hosts should be added.
This is a rather tight use case that might not work for other shops, but I think it will work for our environment: we tend to have jobs so large that they are split up to run the same job across multiple hosts, the only difference being the data segment. And we have pools of VMs which are dedicated to each job, but the VMs are rather unstable, and come and go frequently. So we have JOB_1 through JOB_10, and a pool with ~about~ 10 hosts.
I have a strong feeling this might be overkill and a simpler way will appear. :blush: But just in case anyone else has the same challenge, here's what I've got so far...
&HOST_GROUP_LNR# is assigned on the job object, as the requested host number
=====PRE-PROCESS INCLUDE=====
!Identify the original host group assigned to the job
:SET &MY_HOST_GROUP# = GET_VAR(VARA.SQL.MY_HOST_GROUP)
!Loop through the host group to find out how many active hosts it has
:SET &hnd1# = PREP_PROCESS_AGENTGROUP(&MY_HOST_GROUP#,,"ALL")
:SET &ct#=0
:PROCESS &hnd1#
: SET &IS_ACTIVE# = GET_PROCESS_LINE(&hnd1#,2)
: IF &IS_ACTIVE# = "Y"
: SET &ct#=&ct#+1
: ENDIF
:ENDPROCESS
:SET &ct#=FORMAT(&ct#,"9")
!Now check if we have enough hosts to assign the host number we want
:PRINT "Requested line number &HOST_GROUP_LNR# in &MY_HOST_GROUP#"
:IF &HOST_GROUP_LNR# > &ct#
! If not, assign a mod of the host number and send a notification that we're short of hosts
: SET &MOD_LNR# = MOD(&HOST_GROUP_LNR#,&ct#)
: IF &MOD_LNR# = 0
: SET &SELECTED_LNR# = &ct#
: ELSE
: SET &SELECTED_LNR# = &MOD_LNR#
: ENDIF
: SET &SELECTED_LNR# = FORMAT(&SELECTED_LNR#,"9")
: PRINT "Host group &MY_HOST_GROUP# has &ct# active members"
: PRINT "Not enough hosts to assign line number &HOST_GROUP_LNR#"
: PRINT "Selected new line number &SELECTED_LNR#"
! Some variables for the notification
: PUT_READ_BUFFER MY_HOST_GROUP# = &MY_HOST_GROUP#
: PUT_READ_BUFFER CT# = &ct#
! Send the notification
: SET &ACT# = ACTIVATE_UC_OBJECT(INSUFFICIENT_HOSTS_NOTIFICATION,,,,,PASS_VALUES)
:ELSE
: SET &SELECTED_LNR# = &HOST_GROUP_LNR#
:ENDIF
!Go through the host group and find the Nth active host, and assign the job to it
:SET &hnd2# = PREP_PROCESS_AGENTGROUP(&MY_HOST_GROUP#,,"ALL")
:SET &ct#=0
:PROCESS &hnd2#
: SET &IS_ACTIVE# = GET_PROCESS_LINE(&hnd2#,2)
: IF &IS_ACTIVE# = "Y"
: SET &ct#=&ct#+1
: IF &SELECTED_LNR# = &ct#
: SET &AGENT_NAME#=GET_PROCESS_LINE(&hnd2#,1)
: PRINT "&AGENT_NAME# is active host number &SELECTED_LNR# in host group &MY_HOST_GROUP#"
: PRINT "Assigning this job to &AGENT_NAME#"
: PUT_ATT HOST = &AGENT_NAME#
: ENDIF
: ENDIF
:ENDPROCESS
=====VARA.SQL.MY_HOST_GROUP====
SELECT hgoh.oh_name
FROM oh joh inner join jba on jba_oh_idnr = joh.oh_idnr
INNER JOIN oh hgoh ON jba_hostdst = hgoh.oh_name AND hgoh.oh_client = &$CLIENT#
WHERE joh.oh_name = '&$NAME#'
AND joh.oh_deleteflag = 0
AND joh.oh_client = &$CLIENT#