[Anthill-pro] Select a list of agents from an environment
Peter Steele
psteele at maxiscale.com
Wed Jun 4 15:39:44 CDT 2008
I've tried out this change and it does indeed solve the problem. One
related issue though is the behavior of the filter when no agents match
the input parameters. For example, if a user tells the deploy workflow
to use the environment "Rack 3" but then mistakenly enters a list of
agents that are from environment "Rack 4", my agent filter ends up
returning an empty list of agents. The secondary workflow though still
runs. It doesn't do anything, just sits there with its status showing
"Running", and no agents are assigned to the workflow. It stays like
this forever and has to be explicitly abort. What is the proper way to
code the agent filter in a case like this so that the job will fail
immediately? I've included my filter below. I've tried returning "null"
from the filter method if the agent array's length is zero, but that
doesn't seem to be the right solution (the job fails with a
nullPointerException). Is there a better way?
import com.urbancode.anthill3.domain.agent.Agent;
import com.urbancode.anthill3.runtime.scripting.helpers.*;
Where myWhere = new Where()
{
public Agent[] filter(Agent[] agents)
{
String agentNames =
BuildRequestLookup.getCurrent().getProperty("agentNames");
if (agentNames.equals("all")) return agents;
List agentList = new ArrayList();
StringTokenizer tokens = new StringTokenizer(agentNames);
while (tokens.hasMoreTokens())
{
String agentName = tokens.nextToken();
for (int i = 0; i < agents.length; i++)
{
if (agents[i].name.equals(agentName))
{
agentList.add(agents[i]);
break;
}
}
}
Agent[] selectedAgents = new Agent[agentList.size()];
for (int i = 0; i < selectedAgents.length; i++)
{
selectedAgents[i] = (Agent)agentList.get(i);
}
return selectedAgents;
}
};
return Where.is(myWhere);
-----Original Message-----
From: anthill-pro-bounces at lists.urbancode.com
[mailto:anthill-pro-bounces at lists.urbancode.com] On Behalf Of Varban
Sent: Tuesday, May 27, 2008 11:15 AM
To: AnthillPro user and support list.
Subject: Re: [Anthill-pro] Select a list of agents from an environment
Peter,
we already have a fix for this in place, it will be available in the
next release. Let Steve know if you need a build right away. The only
change as far as you are concerned is that we'll pass all the agents
that are configured (online or otherwise) to the script and after the
script run we'll verify that whatever is returned is online otherwise
fail.
Regards,
Varban
Peter Steele wrote:
> As I have pointed out in my thread "Is this a feature, a bug, or user
> error?", the problem with this approach (as we have recently
discovered)
> is even if one agent is the environment is down, the secondary
workflow
> will not run. It doesn't matter if the user doesn't include this agent
> in his list; if the filter specifies -1 as the agent count for the
> filter, Anthill seems to require all agents to be up in the selected
> environment before the workflow will run. This is a big issue for us;
> not sure what to do for a workaround...
>
>
>
> *From:* anthill-pro-bounces at lists.urbancode.com
> [mailto:anthill-pro-bounces at lists.urbancode.com] *On Behalf Of *Steve
Boone
> *Sent:* Tuesday, May 27, 2008 9:07 AM
> *To:* AnthillPro user and support list.
> *Subject:* Re: [Anthill-pro] Select a list of agents from an
environment
>
>
>
> To make it truly dynamic, the way you have it set up is the best
solution.
>
> It is a bit tedious to have to type the names of the agents in, but
this
> does have some benefits. It will ensure that only those agents are
> used, and that an agent that should not get a job delegated to it,
won't.
>
> On Fri, May 9, 2008 at 7:38 PM, Peter Steele <psteele at maxiscale.com
> <mailto:psteele at maxiscale.com>> wrote:
>
> I am writing a deploy job that will be run as a non-originating
> workflow. We have set of machines that a build can potentially be
> deployed to, and I have these machines grouped in their own
environment.
> On a given run of the deploy workflow I want to be able to filter the
> list of agents that will be selected from this environment, for
example
> as a comma separated list that the user fills in when the secondary
> process is run:
>
>
>
> Workflow: deploy server artifacts
>
> Environment: qa test servers
>
> Servers to Populate: qa-dataserv1,qa-dataserv2,qa-dataserv3
>
> ...
>
>
>
> and so on. The "Servers to Populate" field is a simple text field
which
> the user fills in with the list of servers (agents) that he wants to
> deploy the build to. So, although the "qa test servers" environment
> might have 50 servers in it, on a given run the use can select the
> specific systems he's interested in.
>
>
>
> I created the agent filter below to accomplish this, and it seems to
> work well. My only issue is that requiring the user to enter the agent
> names is a bit tedious, especially if they have to enter more than
three
> or four. Is there a better way I could accomplish what I'm trying to
do
> here? Being able to present the user with a full list of agents that
> they could select multiple entries from would be better for example.
As
> for the script itself, are there any improvements I could make?
>
>
>
> import com.urbancode.anthill3.domain.agent.Agent;
>
> import com.urbancode.anthill3.runtime.scripting.helpers.*;
>
>
>
> Where anyWhere = new Where()
>
> {
>
> public Agent[] filter(Agent[] agents)
>
> {
>
> String agentNames =
BuildRequestLookup.getCurrent().getProperty("agentNames");
>
> List agentList = new ArrayList();
>
>
>
> for (String agentName : (agentNames +",").split(","))
>
> {
>
> for (int i = 0; i < agents.length; i++)
>
> {
>
> if (agents[i].equals(agentName))
>
> {
>
> agentList.add(agents[i]);
>
> break;
>
> }
>
> }
>
> }
>
> Agent[] selectedAgents = new Agent[agentList.size()];
>
> for (int i = 0; i < selectedAgents.length; i++)
>
> {
>
> selectedAgents[i] = (Agent)agentList.get(i);
>
> }
>
>
>
> return selectedAgents;
>
> }
>
> };
>
>
>
> return Where.is(anyWhere);
>
>
> _______________________________________________
> Anthill-pro mailing list
> Anthill-pro at lists.urbancode.com
<mailto:Anthill-pro at lists.urbancode.com>
> http://lists.urbancode.com/mailman/listinfo/anthill-pro
>
>
>
>
>
------------------------------------------------------------------------
>
> _______________________________________________
> Anthill-pro mailing list
> Anthill-pro at lists.urbancode.com
> http://lists.urbancode.com/mailman/listinfo/anthill-pro
_______________________________________________
Anthill-pro mailing list
Anthill-pro at lists.urbancode.com
http://lists.urbancode.com/mailman/listinfo/anthill-pro
More information about the Anthill-pro
mailing list