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 + ” |”);
}
}
}
}
}

New NetWeaver Information at SAP.com

Very Helpfull

 

 

User Rating: Be the first one !