locked
Find a job owner by job id in c# RRS feed

  • Question

  • hey,

    Can someone help me?

    How do I Find a job owner by job ID in order to allow the user to cancel a job via API?

    (i Need to check the user trying to caccek the job against the AD)

    (With c#)

    thanks,

    Ben

    Tuesday, March 15, 2011 2:17 PM

All replies

  • hey,

    Can someone help me?

    How do I Find a job owner by job ID in order to allow the user to cancel a job via API?

    (i Need to check the user trying to cancel the job against the AD)

    (With c#)

    thanks,

    Ben

    Tuesday, March 15, 2011 2:19 PM
  • Here's the sample, which you may find useful. Let me know if this is what you need.

    using System;
    
    using Microsoft.Hpc.Scheduler;
    
    namespace GetOwnerByJobId
    {
      class Program
      {
        static void Main(string[] args)
        {
          const string ClusterHeadnode = "LUKASZTCLUSTER";
          const int JobIdToFind = 345;
    
          using (IScheduler scheduler = new Scheduler())
          {
            scheduler.Connect(ClusterHeadnode);
    
            ISchedulerJob job = scheduler.OpenJob(JobIdToFind);
    
            Console.WriteLine("Job: {0} Owner: {1}", job.Id, job.Owner);
          }
        }
      }
    }
    
    

     

    Wednesday, March 16, 2011 4:04 PM
  • Hi Ben,

    Lukasz's solution to find the job owner works out perfectly.

    However, as per your requirement of checking if the person who is cancelling the job is authorized to do it, I feel its really not essential to access the AD.

    What you can do is, just use the Environment.UserName property which gives you the username of the user logged into the OS and use this for your validation.

    Please let me know if this was helpful.

    Thanks,

    Sridutt

    Friday, May 6, 2011 6:29 AM