none
How to get the list of active jobs ID for a specific Node Group using C# API RRS feed

  • Question

  • In my application I need to get the list of active jobs ID for a specific Node Group that the user chooses.

    how can i get it using C#?

    Thanks ,

    Ben

    Monday, October 24, 2011 2:38 PM

Answers

  • Since nodegroups cannot be used as a filter criteria, this must be implemented on the client side.

    Assuming "active" means "running" we get:

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;


    using Microsoft.Hpc.Scheduler;
    using
    Microsoft.Hpc.Scheduler.Properties;   

    namespace Sample
    {
        class Program
       
    {
           
    static void Main(string[] args)
            {
                IScheduler scheduler = new Scheduler();

                scheduler.Connect("localhost");

                IFilterCollection filter = scheduler.CreateFilterCollection();
                FilterProperty filStateRunning = new FilterProperty(FilterOperator.Equal, JobPropertyIds.State, JobState.Running);

                filter.Add(filStateRunning);

                // now fetch the list of all jobs that satisfy the filter
                ISchedulerCollection jobs = scheduler.GetJobList(filter, null /* no sort order specified */);

                // build this list of jobs in desired nodegroup.
                List<ISchedulerJob> jobsInNodegroup = new List<ISchedulerJob>;

                // walk the filtered collection, look for jobs in desired nodegroup
                foreach (object obj in jobs)
                {
                    if (obj is ISchedulerJob)
                    {
                        ISchedulerJob job = obj as ISchedulerJob;

                        if (job.NodeGroups.Contains("ComputeNodes")) //<<-- put desired nodegroup here
                        {
                            jobsInNodegroup.Add(job);
                        }
                    }
                }

                // use "jobsInnodegroup" here
            }
        }
    }

     

    • Proposed as answer by DarylMsft Tuesday, November 1, 2011 10:00 PM
    • Edited by DarylMsft Tuesday, November 1, 2011 10:16 PM formating battles
    • Marked as answer by Ben.Alterzon Thursday, November 3, 2011 12:48 PM
    Tuesday, November 1, 2011 10:00 PM

All replies

  • You might start by reviewing IScheduler.GetJobList() (http://msdn.microsoft.com/en-us/library/microsoft.hpc.scheduler.ischeduler.getjoblist(VS.85).aspx).

    Filtering by nodegroup membership might take some work but with GetJobList() you should be able to get the information you seek.

     

     

    daryl

    Thursday, October 27, 2011 9:57 PM
  • Hi Daryl,

    I would appreciate if I can get an example.

    Thanks,

    Ben

    Sunday, October 30, 2011 2:27 PM
  • Since nodegroups cannot be used as a filter criteria, this must be implemented on the client side.

    Assuming "active" means "running" we get:

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;


    using Microsoft.Hpc.Scheduler;
    using
    Microsoft.Hpc.Scheduler.Properties;   

    namespace Sample
    {
        class Program
       
    {
           
    static void Main(string[] args)
            {
                IScheduler scheduler = new Scheduler();

                scheduler.Connect("localhost");

                IFilterCollection filter = scheduler.CreateFilterCollection();
                FilterProperty filStateRunning = new FilterProperty(FilterOperator.Equal, JobPropertyIds.State, JobState.Running);

                filter.Add(filStateRunning);

                // now fetch the list of all jobs that satisfy the filter
                ISchedulerCollection jobs = scheduler.GetJobList(filter, null /* no sort order specified */);

                // build this list of jobs in desired nodegroup.
                List<ISchedulerJob> jobsInNodegroup = new List<ISchedulerJob>;

                // walk the filtered collection, look for jobs in desired nodegroup
                foreach (object obj in jobs)
                {
                    if (obj is ISchedulerJob)
                    {
                        ISchedulerJob job = obj as ISchedulerJob;

                        if (job.NodeGroups.Contains("ComputeNodes")) //<<-- put desired nodegroup here
                        {
                            jobsInNodegroup.Add(job);
                        }
                    }
                }

                // use "jobsInnodegroup" here
            }
        }
    }

     

    • Proposed as answer by DarylMsft Tuesday, November 1, 2011 10:00 PM
    • Edited by DarylMsft Tuesday, November 1, 2011 10:16 PM formating battles
    • Marked as answer by Ben.Alterzon Thursday, November 3, 2011 12:48 PM
    Tuesday, November 1, 2011 10:00 PM