Skip to Content
Author's profile photo Former Member

Script to Extract job Chain details

Below script will help to extract all job chain parameter details .

import com.redwood.scheduler.api.model.*;
import java.util.*;

{
   String P_PARAMETERS = “SAP_SYSTEMS,CLIENT,ABAP_PROGRAM_NAME,ABAP_VARIANT_NAME,JOBNAME,NAME,EXT_COMMAND_NAME,EXT_COMMAND_PARAMETERS,EXT_PROGRAM_NAME,EXT_PROGRAM_PARAMETERS”;
   chains = new ArrayList();

   String query = “select jc.* from JobChain jc,JobDefinition jd”
                + ” where jc.JobDefinition = jd.UniqueId”
                + ” and jd.UniqueId = jd.MasterJobDefinition”
                + ” and jd.UniqueId not in (select distinct JobChainCall.JobDefinition from JobChainCall)”;

   for (Iterator it = jcsSession.executeObjectQuery(query, null); it.hasNext();)
   {
     JobChain jc = (JobChain)it.next();
     JobDefinition jd = jc.getJobDefinition();
     listChain(P_PARAMETERS, “”, jd);
  }
}

List chains;
Partition  partition;

  public void listChain(String P_PARAMETERS, String ident, JobDefinition jd)
  {
     jcsOut.print(ident + ” ” + jd.getPartition().getName() + “.” + jd.getName());
     String paramList = null;
     String[] paramArray = P_PARAMETERS.split(“,”);
     String paramValue = “”;
     for (int i = 0; i < paramArray.length; i++)
     {
       if (jd.getJobDefinitionParameterByName(paramArray[i]) != null)
       {
         if (paramList == null)
         {
           paramList = “”;
         }
         paramValue = jd.getJobDefinitionParameterByName(paramArray[i]).getDefaultExpression();
         if (paramValue == null)
         {
            paramValue = “”;
         }
         paramList = paramList + “(” + paramArray[i] + “=” + paramValue + “) “;
       }
     }
     if (paramList != null)
     {
       jcsOut.print(” ” + paramList);
     }
     jcsOut.println(“”);
     showEvents(ident, jd);
     showChain(P_PARAMETERS, ident, jd);
     jcsOut.println(“”);
     jcsOut.println(“”);
     jcsOut.println(“”);
  } 

  public void showEvents(String ident, JobDefinition jd)
  {
    boolean hasEvents = false;
    int raiseAantal = 0;
    int waitAantal = 0;
    // wait events
    for (Iterator it = jd.getJobDefinitionWaitEvents(); it.hasNext();)
    {
      JobDefinitionWaitEvent re = (JobDefinitionWaitEvent)it.next();
      jcsOut.println(ident + ” <== ” + re.getEventDefinition().getName());
      hasEvents = true;
      waitAantal++;
    }
    // raise events
    for (Iterator it = jd.getJobDefinitionRaiseEvents(); it.hasNext();)
    {
      JobDefinitionRaiseEvent re = (JobDefinitionRaiseEvent)it.next();
      jcsOut.println(ident + ” ==> ” + re.getEventDefinition().getName());
      hasEvents = true;
      raiseAantal++;
    }
  }

  public boolean isParameterDefined(JobChainCall jc, String pName)
  {
    JobDefinitionParameter p = jc.getJobDefinition().getJobDefinitionParameterByName(pName);
    return (p != null);
  }

  public String getParameterValue(JobChainCall jc, String pName)
  {
    String valueParam = null;
    JobDefinitionParameter p = jc.getJobDefinition().getJobDefinitionParameterByName(pName);
    if (p != null)
    {
    if (jc.getJobChainCallInReferenceParameterByLocalJobDefinitionParameter(p) != null)
    {
      valueParam = “ref(” + jc.getJobChainCallInReferenceParameterByLocalJobDefinitionParameter(p).getSourceJobDefinitionParameter().getName() + “)”;
    }
    else
    {
      if (jc.getJobChainCallInExpressionParameterByLocalJobDefinitionParameter(p) != null)
      {
         valueParam = “expr(” + jc.getJobChainCallInExpressionParameterByLocalJobDefinitionParameter(p).getExpression() + “)”;
      }
      else
      {
        if (jc.getJobDefinition().getJobDefinitionParameterByName(pName).getDefaultExpression() != null)
        {
           valueParam = jc.getJobDefinition().getJobDefinitionParameterByName(pName).getDefaultExpression();
        }
        else
        {
           valueParam = “”;
        }
      }
     }
    }
    return valueParam;
  }

  public String buildParamList(String P_PARAMETERS, JobDefinition jd, JobChainCall ja)
  {
    String paramList  = null;
    String[] paramArray = P_PARAMETERS.split(“,”);
    for (int i = 0; i < paramArray.length; i++)
    {
      if (isParameterDefined(ja, paramArray[i]))
      {
        if (paramList == null)
        {
           paramList = “”;
        }
        paramList = paramList + “(” + paramArray[i] + “=” + getParameterValue(ja, paramArray[i]) + “) “;
      }
    }
    return paramList;
  }

  public void showChain(String P_PARAMETERS, String ident, JobDefinition jd)
  {
    String paramList = null;
    JobChain jc = jcsSession.getJobChainByJobDefinition(jd);
    if (jc != null)
    {
      for (Iterator it = jc.getJobChainSteps(); it.hasNext();)
      {
         JobChainStep js = (JobChainStep) it.next();

         jcsOut.println(ident + ” | “);
         if (it.hasNext())
         {
           jcsOut.println(ident + ” | ” + ” (step) “+ js.getName());
         }
         else
         {
           jcsOut.println(ident + ” + ” + ” (step) ” + js.getName());
         }
         for (Iterator it2 = js.getJobChainCalls(); it2.hasNext();)
         {
           JobChainCall ja = (JobChainCall) it2.next();
           paramList = null;
           JobChain jcc = jcsSession.getJobChainByJobDefinition(ja.getJobDefinition());
           paramList = buildParamList(P_PARAMETERS, jd, ja);
           paramList = paramList;

           String indent2 = ” |  “;
           if (jcc == null)
           {
              jcsOut.print(ident + ” +- ” + ja.getJobDefinition().getPartition().getName() + “.” + ja.getJobDefinition().getName());
              if (paramList != null)
              {
                 jcsOut.print(” ” + paramList);
              }
              if (ja.getJobDefinition().getTimeWindow() != null) {
                 jcsOut.print(” [” + ja.getJobDefinition().getTimeWindow().getName() + “]”);
              }
              jcsOut.println(“”);
              showEvents(ident + indent2, ja.getJobDefinition());
           }
           else
           {
              if (!chains.contains(ja.getJobDefinition().getPartition().getName() + “.” + ja.getJobDefinition().getName()))
              {
                chains.add(ja.getJobDefinition().getPartition().getName() + “.” + ja.getJobDefinition().getName());
                jcsOut.print(ident + ” +- ” + ” ” + ja.getJobDefinition().getPartition().getName() + “.” + ja.getJobDefinition().getName());
                if (paramList != null)
                {
                   jcsOut.print(” ” + paramList);
                }
                if (ja.getJobDefinition().getTimeWindow() != null) {
                   jcsOut.print(” [” + ja.getJobDefinition().getTimeWindow().getName() + “]”);
                }
                jcsOut.println(“”);
                showEvents(ident + indent2, ja.getJobDefinition());
                showChain(P_PARAMETERS, ident + indent2, ja.getJobDefinition());
              }
              else
              {
                jcsOut.print(ident + ” +- ” + ” *** ” + ja.getJobDefinition().getPartition().getName() + “.” + ja.getJobDefinition().getName() + ” ***”);
                if (paramList != null)
                {
                   jcsOut.print(” ” + paramList);
                }
                if (ja.getJobDefinition().getTimeWindow() != null) {
                   jcsOut.print(” [” + ja.getJobDefinition().getTimeWindow().getName() + “]”);
                }
                jcsOut.println(“”);
              }
           }
           if (it2.hasNext())
           {
             jcsOut.println(ident + ” |”);
           }
        }
     }
   }
  }

Assigned Tags

      7 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Jonas Nielsen
      Jonas Nielsen

      Thank you very much for this, works perfect!

      Question: Could the output be exported to Excel in any way?

      Author's profile photo Zameer Ahamad
      Zameer Ahamad

      Hi Gurbakhshinder,

      Kindly let me know how to run this script in CPS.

      Whether we have to run in report section or anywhere else.

      I am having following query posting below scn thread.

      JD Parameter export information from job chains

      Please can you help me on this to get it done.

      Appreciate your help.

      Regards

      Zameer Ahamad

      Author's profile photo Zameer Ahamad
      Zameer Ahamad

      Hi Experts,

      Please anyone can look into my request.

      We need to pull the report in excel or csv for the job definition which contains multiple times in single chain and it is having parameters with different values.

      Is it able to get all the details through any script or report to know all the values for the particular job definition parameters.

      Author's profile photo Kshitish Mohanty
      Kshitish Mohanty

      Thanks Expert, the script is working perfectly in V9. However this is extracting whole chain detail existing in CPS.Can this be customized as follows:

      1- Can it be customized for only a single process chain?

      2-  Can it be customized to showcase all the ABAp parameter defined for each jobs defined inside the chain.

      3- Would be great if you can provide a script to extract the forecast report from cronacle which will include the queue, application and partition.

      Thanks a lot in advance!

      Author's profile photo Former Member
      Former Member

      Hi ,

       

      Could anyone please let us know how to run this script in CPS because we are not able to find redwood script in definition. Also when we ran this script on shell in Scripting but still no luck.

      Thanks in Advance !!

      Akash

       

       

       

       

      Author's profile photo Sharath Menon
      Sharath Menon

      Hi

      This does not work on redwood 8.0

      It popped 100 + errors showing that " is an illegal character

      Reg

      Sharath

      Author's profile photo Puneet Aggarwal
      Puneet Aggarwal

      Hi ,

      This works perfectly !

       

      But is there any way we can pull independent (single) job defination other than Job chains/step ?

      Along with their respective schedules, events, program and variants.

       

      Thanks,

      Puneet