(→Agent Filter Script to Choose the Agent of the First Job of the Originating Workflow)
|
(→AHPSCRIPTS-43)
|
Line 123: | |||
} | } | ||
};</pre> | };</pre> | ||
+ | = Least Used Agent for Each Criteria = | ||
+ | ==== AHPSCRIPTS-79 ==== | ||
+ | <pre>import com.urbancode.anthill3.domain.agent.Agent; | ||
+ | import com.urbancode.anthill3.runtime.scripting.helpers.*; | ||
+ | import java.util.*; | ||
+ | public class LeastUsedForEach extends Where{ | ||
+ | Criteria[] criteria; | ||
+ | |||
+ | //-------------------------------------------------- | ||
+ | public LeastUsedForEach(Criteria[] criteriaArray) { | ||
+ | criteria = criteriaArray; | ||
+ | } | ||
+ | //-------------------------------------------------- | ||
+ | public Agent[] filter(Agent[] agents){ | ||
+ | ArrayList agentList = new ArrayList(); | ||
+ | |||
+ | for (int i = 0; i < criteria.length; i++) { | ||
+ | Agent[] agentsMatchingCriteria = criteria[i].filter(agents); | ||
+ | |||
+ | // Agents are sorted by most available before filtering | ||
+ | if (agentsMatchingCriteria.length > 0) { | ||
+ | agentList.add(agentsMatchingCriteria[0]); | ||
+ | } | ||
+ | } | ||
+ | Agent[] result = new Agent[agentList.size()]; | ||
+ | agentList.toArray(result); | ||
+ | return result; | ||
+ | } | ||
+ | } | ||
+ | return new LeastUsedForEach( new Criteria[] | ||
+ | { Variable.equals("sys/os.name", "Windows XP"), | ||
+ | Variable.equals("sys/os.name", "Linux") }); | ||
+ | });</pre> |