Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

node.getAttribute with regular expresion #2120

nmanos ·
Hi,
Is it possible to use node.getAttribute with regular expression ?

I want to do so in order to find all agents with attribute starting with "COACH_PFB_TA_HP", since I have many Agents that having attributes such as:
"COACH_PFB_TA_HP_XXX"
"COACH_PFB_TA_HP_YYY"
"COACH_PFB_TA_HP_ZZZ"
...


If regexp is not possible in node.getAttribute(), nor String.StartWith("phrase"),
perhaps it is possible to list all Node's attributes, and then search within the list using regular expression ?

Thanks,
Noam.
  • replies 6
  • views 3340
  • stars 0
robinshen ADMIN ·
You may call "node.systemAttributes" (environments and JVM system properties) and "node.userAttributes" to get map of all system and user attributes of a node, and then loop over it via Groovy scripting to find the matching attributes.
nmanos ·
Hi, I added as you suggested this Resource (All nodes with specified script evaluating to true):

groovy:
def usrAtrMap = node.getUserAttributes();
logger.debug("node.userAttributes = " + usrAtrMap );

def foundKey = usrAtrMap.findAll{ key -> key ==~ /COACH_PFB_TA_HP.*/};
logger.debug("Found Key in User Attributes = " + foundKey);
return foundKey.asBoolean();


Now it works without breaking resources, Thanks!
Noam.
nmanos ·
Hi Robin,
The groovy script above is defined in Grid Resources, so I can later iterate over all the nodes in this resource, when running my configuration.
Is it possible that this on-going regexp evaluation on the grid resource on the server side:
usrAtrMap.findAll{ key -> key ==~ /COACH_PFB_TA_HP.*/}

might cause performance issues, especially if I set many resources that uses this kind of regexp search in grid ?
robinshen ADMIN ·
Yes it could be. In your case, this regex will be evaluatded for every attribute of every node of every resource will be evaluated. So to make sure it will not impact the performance, please consider using simple string comparison such as String.beginWith(...) etc.
nmanos ·
And a general question -
Why does a Resource definition being calculated constantly on server side, and not just when it is called by a certain Step that looks for agents of that resource ?
robinshen ADMIN ·
Since QB does not know which resource a certain step requires (as resource declaration might be done in a script), when it is about to evaluate step condition, for every resource, it checks every node to get available count of resource instances on each node, then the step condition evaluation runs by itself to check if certain resource instance is available on certain node. And if the resource is defined to evaluate regex against each user/system attribute, the effect will be that this regex will be evaluated for every attribute on every node. And if all your resources are defined this way, then it multiply with another factor of defined resources.