Answered by:
Finding number of nodes that are a part of a job template from C# API

Question
-
Hi,I am trying to get the number of nodes that are a part of a particular job template.In the HPC cluster manager, if I go to Configuration-->JobTemplates, I can right click on a job template and set the node group property. I can make several nodes a member of a node group. So when I do the following:ISchedulerJob job = _scheduler.CreateJob();job.SetJobTemplate("job_template_name");The job gets forwarded to one of the nodes on the nodegroups that are specified in the job template named "job_template_name".Before submitting a job to a particular job template, I want to know how many nodes are available in that particular job template. Is there any API to do this?I have tried the following API. There are functions which give me a node list (GetNodeList), a job template list (GetJobTemplateList) and a nodegroup list (GetNodeGroupList).If I get the nodegroups associated with a job template, I can get the nodes using the GetNodesInNodeGroup(nodegroupname) method. But again I could not find any way of getting the nodegroups associated with a "job template".IStringCollection dummy = _scheduler.GetJobTemplateList();IStringCollection dummy1 = _scheduler.GetNodesInNodeGroup(nodegroup);IStringCollection dummy2 = _scheduler.GetNodeGroupList();Another approach might be to use filters with "GetNodeList" method. Following is a simple filter which gives me all the nodes with more than one cores:IFilterCollection filters = null;filters = _scheduler.CreateFilterCollection();filters.Add(FilterOperator.GreaterThanOrEqual, NodePropertyIds.NumCores, 1);ISchedulerCollection nodes = _scheduler.GetNodeList(filters, null);Does anybody have an idea, how to create a filter which says...give me all the nodes for a particular job template?Thanks!PrashantWednesday, November 11, 2009 8:04 PM
Answers
-
Hi Prashs,
There is some problem with my sample, so here is a more detailed script:
# Get the job template file
Export-HpcJobTemplate -Name <jobtemplatename> -Path .\temp.xml -Scheduler <HN>
# Parse the xml file
[xml]$jt = Get-Content .\temp.xml
# Go through the xml, find nodegroups value which is splited by ","
# Then get all nodes which belongs to this group
# And don't forget to sort them by "-unique" to filter out duplicate
($jt.JobTemplate.TemplateItem | ?{$_.PropertyName -eq "NodeGroups"} | %{ $_.Default }).split(",") | %{get-hpcnode -groupname $_ -scheduler <HN>} | sort -property netbiosname -unique
Hope this helps?
Note, I didn't manage the error when there is no node group field in the template, which is the case for our default job template.
-yiding- Marked as answer by Don Pattee Friday, February 4, 2011 10:22 PM
Monday, December 14, 2009 6:24 AM
All replies
-
You can do that through PowerShell.
"Get-HpcJobTemplate -Name <jobtemplatename> -Path temp.xml -Scheduler <HN>"
...pass the xml file and find out all node groups...
"$allgroups | %{ get-hpcnode -groupname $_ } | sort -unique"Friday, November 13, 2009 9:56 PM -
Thanks for the reply Yidingz!!
Does this imply that there is no way to do this using the API?
Thanks!
PrashantMonday, November 23, 2009 3:27 PM -
I just checked and I don't see any PropId similar to JobTemplate. So you cannot create a filter this way.
Of course you can go by :
scheduler.Connect("clusterheadnode");
ISchedulernode mynode= scheduler.OpenNode(IdOfNode);
String groups =mynode.NodeGroups;
Do this for every node and voila.
However, it is quite brute force.
Johannes
JHMonday, November 23, 2009 4:11 PM -
@JohannesThis way I can get the nodes that are a part of a node group (which I can also get by _scheduler.GetNodesInNodeGroup(nodegroup);), but how do I know which node groups are a part of a particular job template?PrashantMonday, November 23, 2009 7:24 PM
-
@Johannes
Sorry for that you are right. I mixed up jobtemplate and nodegroup.This way I can get the nodes that are a part of a node group (which I can also get by _scheduler.GetNodesInNodeGroup(nodegroup);), but how do I know which node groups are a part of a particular job template?Prashant
Johannes
JHTuesday, November 24, 2009 6:45 AM -
@ YidingzCan you elaborate a bit more on your answer above?"Get-HpcJobTemplate -Name <jobtemplatename> -Path temp.xml -Scheduler <HN>"
...pass the xml file and find out all node groups...
"$allgroups | %{ get-hpcnode -groupname $_ } | sort -unique"Get-HpcJobTemplate doesn't seem to have a -Path option. Also, in the command sequence above where are we getting the node groups associated with a particular job template?Thanks!PrashantMonday, December 14, 2009 5:52 AM -
Hi Prashs,
There is some problem with my sample, so here is a more detailed script:
# Get the job template file
Export-HpcJobTemplate -Name <jobtemplatename> -Path .\temp.xml -Scheduler <HN>
# Parse the xml file
[xml]$jt = Get-Content .\temp.xml
# Go through the xml, find nodegroups value which is splited by ","
# Then get all nodes which belongs to this group
# And don't forget to sort them by "-unique" to filter out duplicate
($jt.JobTemplate.TemplateItem | ?{$_.PropertyName -eq "NodeGroups"} | %{ $_.Default }).split(",") | %{get-hpcnode -groupname $_ -scheduler <HN>} | sort -property netbiosname -unique
Hope this helps?
Note, I didn't manage the error when there is no node group field in the template, which is the case for our default job template.
-yiding- Marked as answer by Don Pattee Friday, February 4, 2011 10:22 PM
Monday, December 14, 2009 6:24 AM