Select Page

Selecting agents using agent filters using roles and hosts with Anthill Pro

Best practice when setting up your deployment workflows with Anthill Pro (or any other tool for that matter) is to classify the hosts in your farm by role and host. This way, you can deploy common artifacts to your roles and specific artifacts to your hosts in an elegant way. As an environment grows and becomes more complex, the need to do this becomes more obvious, however It’s my opinion to set this up from the start. This way, when deploying new hosts to your environments, all that is needed is your system environment as some simple agent properties set. Then, by your hosts simply being members of an environment in Anthill Pro, they automatically receive the proper artifacts that they need. Recommendations on how to separate and organize such artifacts (especially configuration artifacts) is a topic for another post. What I want to discuss is the non-obvious part about setting up anthill to correctly select agents you want for xALL iterations in a given workflow. The additional benefit of this is to ensure your workflows remain autononymous from your environments, so that as you deploy to more non-critical environments (like QA) you have more confidence in the deployment process to more critical environments (like Staging / Production) because you’re using the same workflows.

In a given workflow, it’s common to need to perform similar operations to the same hosts within a given role, for instance. You may want to shut down all “coldfusion” servers, or all “websphere-ejb” servers within those given roles. With anthill pro, you can use a simple agent filter beanshell script to isolate operations to those specific hosts of that role, but it’s not completely straight forward.  Let’s say you have 3 roles in your farm, “coldfusion”, “websphere-ejb” and “apache”. If you wanted to create an agent filter for one of these roles (“apache”) you would use this syntax:

return
 Where.is(
  Variable.equals("role", "apache")
 );
)
Simple enough, but understand that this syntax will only work with 1 criteria, if you wanted to have 2, like “apache” and “coldfusion” you would need to do:
return
 Where.any(
  Variable.equals("role", "apache"),
  Variable.equals("role", "coldfusion"),
 );
)
Notice we’ve changed the “Where.is” to “Where.any”, this is great when you want to have 2 criteria. However, if you want to do 3 or more, “apache”, “coldfusion” and “websphere-ejb” then you have to create an instance of a “Criteria” object like so:
return
 Where.any( new Criteria[] {
  Variable.equals("role", "apache"),
  Variable.equals("role", "coldfusion"),
  Variable.equals("role", "websphere-ejb")
 });
)

Hopefully this post will save you some time when creating custom agent filters based on agent properties in Anthill Pro, if you try to use 3 or more criteria with the Where.any() method, you may be left banging your head against the keyboard trying to understand why you are getting a beanshell error.