how to get the list of active job owners(by using c# and hpc api)?

Answered how to get the list of active job owners(by using c# and hpc api)?

  • Thursday, July 21, 2011 11:03 AM
     
     

    hi ,

    i would like to get via web application, using c# and hpc api, the list of all the job owners that are active(that mean that there jobs are running or queued.

    thank in advanced for your help,

    Ben

All Replies

  • Thursday, July 28, 2011 10:36 PM
     
     Answered Has Code

    Hi Ben,

    Here is some short, console example:

    using System;
    using System.Collections.Generic;
    
    using Microsoft.Hpc.Scheduler;
    using Microsoft.Hpc.Scheduler.Properties;
    
    namespace ConsoleApplication1
    {
      class Program
      {
        static void Main(string[] args)
        {
          using (IScheduler scheduler = new Scheduler())
          {
            // Connect to scheduler
            scheduler.Connect("LOCALHOST");
    
            // Specify, that we only want job owner to be returned
            IPropertyIdCollection properties = new PropertyIdCollection();
            properties.Add(JobPropertyIds.Owner);
    
            // We need to filter jobs by eliminating states we don't need
            // (filters in the collection are combined with AND operator)
            IFilterCollection filters = scheduler.CreateFilterCollection();
            filters.Add(FilterOperator.NotEqual, JobPropertyIds.State, JobState.Canceled);
            filters.Add(FilterOperator.NotEqual, JobPropertyIds.State, JobState.Finished);
            filters.Add(FilterOperator.NotEqual, JobPropertyIds.State, JobState.Failed);
            filters.Add(FilterOperator.NotEqual, JobPropertyIds.State, JobState.Configuring);
    
            // HashSet to store only unique user names
            HashSet<string> users = new HashSet<string>();
    
            // Enumerate returned jobs and store owner names
            using (ISchedulerRowEnumerator rows = scheduler.OpenJobEnumerator(properties, filters, null))
            {
              foreach (PropertyRow row in rows)
              {
                users.Add(row[JobPropertyIds.Owner].Value.ToString());
              }
            }
    
            // Print result
            foreach (string user in users)
              Console.WriteLine(user);
          }
        }
      }
    }
    
    

    Thanks,
    Łukasz

    • Marked As Answer by Ben.Alterzon Sunday, July 31, 2011 7:25 AM
    •  
  • Sunday, July 31, 2011 7:25 AM
     
     

    thank you very much!!!!!!!!!

    Ben