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

  • Question

  • 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

    Thursday, July 21, 2011 11:03 AM

Answers

  • 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
    Thursday, July 28, 2011 10:36 PM

All replies

  • 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
    Thursday, July 28, 2011 10:36 PM
  • thank you very much!!!!!!!!!

    Ben

    Sunday, July 31, 2011 7:25 AM