none
Problem filtering job status (c#) RRS feed

  • Question

  • Hi,

    I am trying to use C# to get job status from Windows HPC Server 2008 scheduler.
    I want to use filter to get all "Active" jobs only, but I am having problem setting up the filter :(
    I am pretty sure the problem in the way I add filter options, but I have no idea on how to solve it.
    Could someone help me to solve this problem?

    Thank you

    Scheduler scheduler = new Scheduler();
    scheduler.Connect("hpcs2008");
    
    IFilterCollection filters = null;
    
    filters = scheduler.CreateFilterCollection();
    filters.Add(FilterOperator.Equal, PropId.Job_State, JobState.Canceling);
    filters.Add(FilterOperator.HasBitSet, PropId.Job_State, JobState.Configuring);
    filters.Add(FilterOperator.HasBitSet, PropId.Job_State, JobState.Finishing);
    filters.Add(FilterOperator.HasBitSet, PropId.Job_State, JobState.Queued);
    filters.Add(FilterOperator.HasBitSet, PropId.Job_State, JobState.Running);
    filters.Add(FilterOperator.HasBitSet, PropId.Job_State, JobState.Submitted);
    filters.Add(FilterOperator.HasBitSet, PropId.Job_State, JobState.Validating);
    
    
    foreach (int jobId in scheduler.GetJobIdList(filters, null))
     {
    str += jobId.ToString() + " ";
    str += scheduler.OpenJob(jobId).State.ToString() + " ";
    str += scheduler.OpenJob(jobId).UserName.ToString() + " ";
     ...
     }
    


    Tuesday, November 10, 2009 8:10 AM

Answers

  • Hi Johannes,

    Thank you for the reply.
    Your guess is correct, so I will try your method.
    By the way, could you tell me how to create an array of filter like your code?

    The reason why I used multiple filters is because I looked at the following msdn page, and I though HasBitSet could be used as OR operator.
    Maybe I just misunderstood it?

    I must apologize, I haven't had such a close look to your code or the API either to recognize the bitmask. I will definitively have a look into it, as it would be much more elegant.

    You basically have the code above. Here the complete code snippet :
    Please mind any bugs, as its just a quick hack until know.

                    scheduler.Connect(ClusterToQuery);
    
    // allocate IFilterCollection Array
                    IFilterCollection[] FinishedJobsIFC = new IFilterCollection[FiltersToApply];
    // allocate ISchedulerCollection Array
                    ISchedulerCollection[] FinishedJobsISC = new ISchedulerCollection[FiltersToApply];
                    for (int Id = 0; Id < FiltersToApply; Id++)
                    {
    // Assign SchedulerCollection
                        FinishedJobsIFC[Id] = scheduler.CreateFilterCollection();
    
                    }
    
    // Define 3 differenct filters
                    FinishedJobsIFC[0].Add(FilterOperator.Equal, PropId.Job_State, JobState.Failed);
                    FinishedJobsIFC[1].Add(FilterOperator.Equal, PropId.Job_State, JobState.Canceled);
                    FinishedJobsIFC[2].Add(FilterOperator.Equal, PropId.Job_State, JobState.Finished);
    
    
                    // Apply filter and generate ISchedulerCollections
                    int num = 0;
                    foreach (IFilterCollection applyFilter in FinishedJobsIFC)
                    {
                        FinishedJobsISC[num] = scheduler.GetJobList(applyFilter, null);
                        num++;
                    }



    JH
    Thursday, November 19, 2009 9:56 AM

All replies

  • Hi,

    I have posted this thread a week ago, but I haven't get any reply yet...

    I am hoping if someone could help me solve this problem.

    Thank you.
    Tuesday, November 17, 2009 2:25 AM
  • Hi,

    basically I don't know what to answer as you  don't describe your problem.

    You want to filter and get all active jobs, thats okay.
    But:
    1. Is the code compiling?
    2. What is the code actually doing?

    Just a lucky guess, but the way I understand a filter is that it gives you all items that match that criteria.
    Multiple filters give you items that match ALL criteria
    So let's walk through, first you get all jobs in status canceling. Then these jobs are filtered for jobs which are in canceling AND configuring state.
    What finally comes out is no job because no job is in all states at the same time!
    You need multiple filters which only hold one filter operator, unless you really want multiple filters:

    FinishedJobsIFC[0].Add(FilterOperator.Equal, PropId.Job_State, JobState.Failed);
    FinishedJobsIFC[1].Add(FilterOperator.Equal, PropId.Job_State, JobState.Canceled);
    FinishedJobsIFC[2].Add(FilterOperator.Equal, PropId.Job_State, JobState.Finished);
    // Apply filter and generate ISchedulerCollection
    int num = 0;
    foreach (IFilterCollection applyFilter in FinishedJobsIFC) {
    FinishedJobsISC[num] = scheduler.GetJobList(applyFilter, null);
    num++; }

    Perhaps someone can comment If I'm totally mistaken. But my small test code just showed the behavior I described above.


    Hope that helps,

    Johannes

    JH
    • Edited by Johannes_de Tuesday, November 17, 2009 6:33 AM pretty printing
    Tuesday, November 17, 2009 6:32 AM
  • Hi Johannes,

    Thank you for the reply.
    Your guess is correct, so I will try your method.
    By the way, could you tell me how to create an array of filter like your code?

    The reason why I used multiple filters is because I looked at the following msdn page, and I though HasBitSet could be used as OR operator.
    Maybe I just misunderstood it?

    HasBitSet Include the object in the result if the property value has one or more bits set. For example, you can use this operator to test if the state of the job is failed or canceled by using the bitwise OR to set the filter value to both states. This enumeration member represents a value of 6.


    Thank you
    Thursday, November 19, 2009 2:42 AM
  • Hi Johannes,

    Thank you for the reply.
    Your guess is correct, so I will try your method.
    By the way, could you tell me how to create an array of filter like your code?

    The reason why I used multiple filters is because I looked at the following msdn page, and I though HasBitSet could be used as OR operator.
    Maybe I just misunderstood it?

    I must apologize, I haven't had such a close look to your code or the API either to recognize the bitmask. I will definitively have a look into it, as it would be much more elegant.

    You basically have the code above. Here the complete code snippet :
    Please mind any bugs, as its just a quick hack until know.

                    scheduler.Connect(ClusterToQuery);
    
    // allocate IFilterCollection Array
                    IFilterCollection[] FinishedJobsIFC = new IFilterCollection[FiltersToApply];
    // allocate ISchedulerCollection Array
                    ISchedulerCollection[] FinishedJobsISC = new ISchedulerCollection[FiltersToApply];
                    for (int Id = 0; Id < FiltersToApply; Id++)
                    {
    // Assign SchedulerCollection
                        FinishedJobsIFC[Id] = scheduler.CreateFilterCollection();
    
                    }
    
    // Define 3 differenct filters
                    FinishedJobsIFC[0].Add(FilterOperator.Equal, PropId.Job_State, JobState.Failed);
                    FinishedJobsIFC[1].Add(FilterOperator.Equal, PropId.Job_State, JobState.Canceled);
                    FinishedJobsIFC[2].Add(FilterOperator.Equal, PropId.Job_State, JobState.Finished);
    
    
                    // Apply filter and generate ISchedulerCollections
                    int num = 0;
                    foreach (IFilterCollection applyFilter in FinishedJobsIFC)
                    {
                        FinishedJobsISC[num] = scheduler.GetJobList(applyFilter, null);
                        num++;
                    }



    JH
    Thursday, November 19, 2009 9:56 AM
  • Hi Johannes,

    Thank you for the code.

    I have tried your code and they seems to work fine.

    Please post a message if you have figured easier way out :)

    Thank you
    Tuesday, November 24, 2009 2:14 AM
  • these simply code seems to work fine, i used OR (|) operator between jobstate enums.

    ISortCollection sort = scheduler.CreateSortCollection();
    sort.Add(SortProperty.SortOrder.Descending, PropId.Job_CreateTime);
    sort.Add(SortProperty.SortOrder.Descending, PropId.Job_SubmitTime);
    sort.Add(SortProperty.SortOrder.Descending, PropId.Job_StartTime);

    IFilterCollection filters = scheduler.CreateFilterCollection();
    filters.Add(FilterOperator.Equal, PropId.Job_UserName, MasterPage.User_Username); filters.Add(FilterOperator.HasBitSet, PropId.Job_State, JobState.Configuring | JobState.Validating | JobState.Submitted | JobState.Queued); ISchedulerCollection jobs = scheduler.GetJobList(filters, sort);
    ListJobs(jobs);

    Sunday, April 18, 2010 1:18 PM