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.

groovy script to collect all nodes that can use a a special resource #3885

Henry ·

Hi,

I would like to collect all nodes of my grid that belong to a set of resources.

Example:
Resources: "Windows_NT,Linux_Ubuntu" which have a regex definition in the grid like

Windows_NT
regex
win-[0-9]+

and
Linux_Ubuntu
regex
lin-[0-9]+

Lets say that win-1, win-3, perf-1, lin-1 and lin-5 are authorized.

now I would like to collect all node-hostnames of all nodes that can use the resources of the list above:

like "win-1,win-3,lin-1,lin5"

I tried diverse things but I was not successful. Can you please help me.

Thanx in advance
Henry

  • replies 2
  • views 1199
  • stars 0
robinshen ADMIN ·

The restful API can return list of matched nodes for specific resource:
https://wiki.pmease.com/display/QB70/Interact+with+Resources (check the section: Get total resource count across nodes)

Or if you want to do it within QB via groovy script:

groovy:
import com.pmease.quickbuild.entitymanager.ResourceManager;
def resource = ResourceManager.instance.get("name of your resource");
for (node in grid.getAllNodes()) {
  if (resource.getCount(node)) {
    logger.info(node.address);
  }
}
Henry ·

That works pretty fine.
Thank you very much.

best regards
Henry