Version Differences for Miscellaneous Scripts

(Added AHPSCRIPTS-1 (yay!))
(AHPSCRIPTS-2 Added)
Line 29:
  user1.addRole(buildRole);    user1.addRole(buildRole); 
  user1.store();</pre>    user1.store();</pre> 
       
    + = Properties Contained Within Variables =  
       
    + '''AHPSCRIPTS-2'''  
       
    + Script Notes:  
    + * ''The idea here is that the user has identified a couple agent items (a Track and technology type) that span environments. This scirpt filters agents so that the technology type must always match the technology type specified on the workflow property. The tracks are similar but some agents may participate in mulitple tracks (prod is that same for all) so prod would have a track value of something like 1|2|3 to indicate that it supports tracks 1, 2 and 3. So we need to inspect it to see if any match.''  
    + * ''I changed the Track one to just see if the agent value contains the requested value. It should work fine until you get up to track 10, then you have to do 01, 02, etc.''  
       
    + <pre>import com.urbancode.anthill3.domain.agent.Agent;  
    + import com.urbancode.anthill3.runtime.scripting.helpers.* ;  
    + import com.urbancode.anthill3.services.agent.AgentRemoteControl;  
    + import com.urbancode.devilfish.services.var.VarServiceClient;  
    + import java.util.*;  
       
    + public class PropertyBasedAgentVarEqualsCriteria extends VariableEqualsCriteria {  
       
    + String propertyname;  
       
    + public PropertyBasedAgentVarEqualsCriteria(String propertyname, String varName) {  
    + super(varName);  
    + this.propertyname = propertyname;  
    + }  
       
    + public Agent[] filter(Agent[] agents) {  
    + String value = PropertyLookup.get(propertyname);  
    + if (value == null || value.length() == 0 || "null".equals(value)) {  
    + value = BuildLifeLookup.getCurrent().getOriginatingWorkflow().getRequest().getProperty(propertyname);  
    + }  
    + this.setValue(value);  
    + return super.filter(agents);  
    + }  
    + }  
       
    + public class PropertyBasedAgentVarContainsCriteria extends Criteria {  
       
    + String propertyname;  
    + String varName;  
       
    + public PropertyBasedAgentVarContainsCriteria(String propertyname, String varName) {  
    + this.propertyname = propertyname;  
    + this.varName = varName;  
    + }  
       
    + public Agent[] filter(Agent[] agents) {  
    + ArrayList resultList = new ArrayList();  
    +  
    + String value = PropertyLookup.get(propertyname);  
    + if (value == null || value.length() == 0 || "null".equals(value)) {  
    + value = BuildLifeLookup.getCurrent().getOriginatingWorkflow().getRequest().getProperty(propertyname);  
    + }  
    +  
    + for (int i = 0; i < agents.length; i++) {  
    + Agent agent = agents[i];  
    +  
    + AgentRemoteControl remote = new AgentRemoteControl(agent);  
    + VarServiceClient client;  
    + try {  
    + client = remote.getVarServiceClient();  
       
    + String varValue = client.getVarValue(varName);  
    + if (varValue != null && varValue.contains(value)) {  
    + resultList.add(agent);  
    + }  
    + }  
    + catch (Exception e) {  
    + throw new RuntimeException(e);  
    + }  
    + }  
    +  
    + Agent[] result = new Agent[resultList.size()];  
    + resultList.toArray(result);  
    + return result;  
    + }  
    + }  
       
       
    + /**** Start Script *****/  
    + return Where.all(  
    + new PropertyBasedAgentVarContainsCriteria("Track", "Track"),  
    + new PropertyBasedAgentVarEqualsCriteria("TechType", "TechType")  
    + );</pre>