Version Differences for Miscellaneous Scripts

(AHPSCRIPTS-34)
(AHPSCRIPTS-92)
Line 1363:
  e.printStackTrace(commandOutput);     e.printStackTrace(commandOutput);  
  }</pre>    }</pre> 
       
    + = Script to Update Workflow Property with Names of All Agents in Environment =  
       
    + * You can use the script with an Evaluate Script Step. You need to change the projectName, workflowName, envName and propertyName values to match your requirements.  
       
    + ==== AHPSCRIPTS-93 ====  
    + <pre>import com.urbancode.anthill3.domain.agent.Agent;  
    + import com.urbancode.anthill3.domain.agent.AgentFactory;  
    + import com.urbancode.anthill3.domain.project.Project;  
    + import com.urbancode.anthill3.domain.project.ProjectFactory;  
    + import com.urbancode.anthill3.domain.servergroup.ServerGroup;  
    + import com.urbancode.anthill3.domain.servergroup.ServerGroupFactory;  
    + import com.urbancode.anthill3.domain.workflow.Workflow;  
    + import com.urbancode.anthill3.domain.workflow.WorkflowFactory;  
    + import com.urbancode.anthill3.domain.workflow.WorkflowProperty;  
    + import com.urbancode.anthill3.domain.workflow.WorkflowPropertyTypeEnum;  
    + import com.urbancode.devilfish.client.ServiceEndpoint;  
       
    + import java.io.PrintStream;  
    + import java.util.ArrayList;  
    + import java.util.List;  
       
    + try {  
       
    + String projectName = "some project";  
    + String workflowName = "some workflow that has a multi select property defined";  
    + String envName = "some environment";  
    + String propertyName = "the property to update that's defined in the workflow above";  
    + List valueList = new ArrayList();  
       
    + // get all agents that belong to an environment, are configured and not ingnored  
    + ServerGroup envirnoment = ServerGroupFactory.getInstance().restoreForName(envName);  
    + if (envirnoment != null) {  
    + for (ServiceEndpoint endpoint : envirnoment.getServerArray()) {  
    + Agent agent = AgentFactory.getInstance().restoreByEndpoint(endpoint);  
    + if (agent != null && agent.isConfigured() && !agent.isIgnored()) {  
    + valueList.add(agent.getName());  
    + }  
    + }  
    + }  
       
    + // now locate the workflow property that you want to update  
    + Project project = ProjectFactory.getInstance().restoreForName(projectName);  
    + if (project != null) {  
    + Workflow workflow = WorkflowFactory.getInstance().restoreForProjectAndWorkflowName(project, workflowName);  
    + if (workflow != null) {  
    + WorkflowProperty property = workflow.getProperty(propertyName);  
    + // here you can change/remove the check for the property type if you want  
    + if (property != null && property.getType().equals(WorkflowPropertyTypeEnum.MULTI_SELECT)) {  
    + property.setAllowedValues((String[])valueList.toArray(new String[valueList.size()]));  
    + }  
    + }  
    + }  
    + }  
    + catch (Exception e) {  
    + e.printStackTrace(commandOutput);  
    + }</pre>