none
How to get the activity log for a specific job using C# API RRS feed

  • Question

  • In my application I need to get the activity log for a specific job that the user chooses.

    how can i get it using C#?

    Thanks ,

    Ben

    Wednesday, September 14, 2011 4:35 PM

Answers


  • Hi Ben,

    It looks like you need to add '/scheduler' parameter to 'job view' cmdline. If this parameter is not provided, by default commandline client tools try to connect to scheduler with hostname specified in CCP_SCHEDULER environment variable. If this variable doesn't exist, they will try to connect to localhost.

    I think your code will look like this (one line modification):

    si.Arguments = "view " + jobId 
       + " /history /scheduler:"+headNodeName;
     
    
    

    Also I see in the code above, that you are openning connection to the scheduler, but this is not needed.

    Regards,
    Łukasz

    • Marked as answer by Ben.Alterzon Thursday, October 6, 2011 1:33 PM
    Thursday, September 22, 2011 7:06 PM

All replies

  • Hi Ben,

    What kind of information do you want to have in your activity log?

    Regards,
    Łukasz

    Wednesday, September 14, 2011 4:59 PM
  • Hi Lukasz,

    I would like to have the information that is found in the activity log that I can see using the job managment interface.

    (when I mark a job, I can see the activity log in the bottom window-"activity log" tab)

    the users want to have all the information in the activity log(time and text).

    and they want it in my c# application. 

    Thanks for your reply,

    Ben

    Thursday, September 15, 2011 6:10 AM
  • Hi Ben,

    If you want to get exactly the same content as from Job Manager GUI, probably the best solution will be to capture the output of 'job view <job_id_here> /history' CLI command by executing it with System.Diagnostics.Process class.

    If you want to do it purely with use of Windows HPC Scheduler .NET APIs you'll have to take a look at combining information available via the following methods:

    IScheduler.OpenJobHistoryEnumerator() : http://msdn.microsoft.com/en-us/library/microsoft.hpc.scheduler.ischeduler.openjobhistoryenumerator(VS.85).aspx

    ISchedulerJob.OpenJobAllocationHistoryEnumerator(): http://msdn.microsoft.com/en-us/library/hh203992(v=VS.85).aspx

    plus information delivered via properties of ISchedulerJob like Owner and CreateTime.

    Please let me know if you have any questions.

    Thanks,
    Łukasz

     

    Friday, September 16, 2011 9:55 PM
  • Hi Lukasz,

    if you can give me an example of how to ,capture the output of 'job view <job_id_here> /history' CLI

    command by executing it with System.Diagnostics.Process class, it will be great because I could not find

    the function that retrives the same activity log from the Job Manager GUI.

    thanks for your help,

    Ben

    Sunday, September 18, 2011 3:14 PM
  • Hi Ben,

    Here's the example:

    using System;
    using System.Diagnostics;
    using System.IO;
    
    namespace JobHistory
    {
        class Program
        {
            static void Main(string[] args)
            {
                ProcessStartInfo si = new ProcessStartInfo();
    
                si.FileName = "job";
                si.Arguments = "view " + args[0] + " /history";
                
                si.RedirectStandardOutput = true;
                si.UseShellExecute = false;
    
                string output = null;
    
                using (Process p = Process.Start(si))
                {
                    using (StreamReader reader = p.StandardOutput)
                    {
                        output = reader.ReadToEnd();
                    }
    
                    p.WaitForExit();
                }
    
                Console.WriteLine(output);
            }
        }
    }
    
    

    It's based on what you can find here: http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx

    Job ID has to be passed here as an commandline argument. I also suggest adding some error handling when integrating with your solution.

    Finally, here's output of this example for a job, which was requeued several times:

    9/12/2011 12:57:08 PM  Created by REDMOND\lutom
    9/12/2011 12:57:22 PM  Submitted
    9/12/2011 12:57:22 PM  Started
    9/12/2011 12:57:22 PM  Started on LUKASZTCN01 with 4 cores
    9/12/2011 12:57:24 PM  Ended on LUKASZTCN01
    9/12/2011 12:57:24 PM  Job Failed
    9/12/2011 12:57:43 PM  Started
    9/12/2011 12:57:43 PM  Started on LUKASZTCN01 with 4 cores
    9/12/2011 12:57:45 PM  Ended on LUKASZTCN01
    9/12/2011 12:57:45 PM  Job Failed
    9/12/2011 12:58:13 PM  Started
    9/12/2011 12:58:13 PM  Started on LUKASZTCN01 with 4 cores
    9/12/2011 12:58:15 PM  Ended on LUKASZTCN01
    9/12/2011 12:58:15 PM  Job Failed
    9/12/2011 12:58:31 PM  Started
    9/12/2011 12:58:31 PM  Started on LUKASZTCN01 with 4 cores
    9/12/2011 12:58:33 PM  Ended on LUKASZTCN01
    9/12/2011 12:58:33 PM  Job Failed
    9/16/2011 2:35:45 PM  Started
    9/16/2011 2:35:45 PM  Started on LUKASZTCN01 with 4 cores
    9/16/2011 2:35:48 PM  Ended on LUKASZTCN01
    9/16/2011 2:35:48 PM  Job Failed

    Regards,
    Łukasz

    Monday, September 19, 2011 4:31 PM
  • Hi Lukasz,

    It doesn't work.

    I don't get anything in the output variable.

    In my code I am passing the job Id not as a commandline argument.

    In my code:

    public class HpcDataAccess

    {

        public HpcActivityLog GetJobActivityLog(int jobId)

        {

                HpcActivityLog hpcActivityLog = new HpcActivityLog();

                scheduler _scheduler = new scheduler ();

                try

                {

                 _scheduler.connect(headNodeName);

                 IschedulerJob hpcJob = _scheduler.OpenJob(jobId);

                ProcessStartInfo si = new ProcessStartInfo();

                si.FileName = "job";
                si.Arguments = "view " + jobId + " /history";
               
                si.RedirectStandardOutput = true;
                si.UseShellExecute = false;

                string output = null;

                using (Process p = Process.Start(si))
                {
                    using (StreamReader reader = p.StandardOutput)
                    {
                        output = reader.ReadToEnd();
                    }

                    p.WaitForExit();
                }
                 hpcActivityLog.Add(new HpcActivityOutput(output);

                 return hpcActivityLog ;
                //Console.WriteLine(output);

          }

          catch{

          exeption handling

          }

          finaly{

          _scheduler.dispose();

          }

    }


    Regard,

    Ben

    Wednesday, September 21, 2011 5:01 PM
  • Hi Ben,

    Maybe you could try to also redirect Standard Error output to see if there are any errors there. This may give us some idea about what's going wrong.

    Regards,
    Łukasz

    Wednesday, September 21, 2011 8:56 PM
  • Hi Lukasz,

    from the Error output I got :

    "no connection could be made because the target machine actively refused it 127.0.0.1:5800\r\n"

    does it mean anything to you?

    Thanks,

    Ben

    Thursday, September 22, 2011 10:17 AM

  • Hi Ben,

    It looks like you need to add '/scheduler' parameter to 'job view' cmdline. If this parameter is not provided, by default commandline client tools try to connect to scheduler with hostname specified in CCP_SCHEDULER environment variable. If this variable doesn't exist, they will try to connect to localhost.

    I think your code will look like this (one line modification):

    si.Arguments = "view " + jobId 
       + " /history /scheduler:"+headNodeName;
     
    
    

    Also I see in the code above, that you are openning connection to the scheduler, but this is not needed.

    Regards,
    Łukasz

    • Marked as answer by Ben.Alterzon Thursday, October 6, 2011 1:33 PM
    Thursday, September 22, 2011 7:06 PM
  • Thanks a lot Lukasz,

    works great.

    Regards,

    Ben

    Thursday, October 6, 2011 1:33 PM