use of org.kuali.kfs.kns.bo.Step in project cu-kfs by CU-CommunityApps.
the class BatchStepRunner method main.
public static void main(String[] args) {
if (args.length < 1) {
System.err.println("ERROR: You must pass the name of the step to run on the command line.");
System.exit(8);
}
try {
SpringContextForBatchRunner.initializeKfs();
/*
* CU Customization to initialize PojoPropertyUtilsBean for batch processing
*/
PojoPlugin.initBeanUtils();
String[] stepNames;
if (args[0].indexOf(",") > 0) {
stepNames = StringUtils.split(args[0], ",");
} else {
stepNames = new String[] { args[0] };
}
ParameterService parameterService = SpringContext.getBean(ParameterService.class);
DateTimeService dateTimeService = SpringContext.getBean(DateTimeService.class);
String jobName = args.length >= 2 ? args[1] : KFSConstants.BATCH_STEP_RUNNER_JOB_NAME;
Date jobRunDate = dateTimeService.getCurrentDate();
LOG.info("Executing job: " + jobName + " steps: " + Arrays.toString(stepNames));
for (int i = 0; i < stepNames.length; ++i) {
Step step = BatchSpringContext.getStep(stepNames[i]);
if (step != null) {
Step unProxiedStep = (Step) ProxyUtils.getTargetIfProxied(step);
Class<?> stepClass = unProxiedStep.getClass();
ModuleService module = getModuleService(stepClass);
String nestedDiagnosticContext = getReportsDirectory() + File.separator + StringUtils.substringAfter(module.getModuleConfiguration().getNamespaceCode(), "-").toLowerCase(Locale.US) + File.separator + step.getName() + "-" + dateTimeService.toDateTimeStringForFilename(dateTimeService.getCurrentDate());
boolean ndcSet = false;
try {
ThreadContext.put(KFSConstants.BATCH_LOGGER_THREAD_CONTEXT_KEY, nestedDiagnosticContext);
ndcSet = true;
} catch (Exception ex) {
LOG.warn("Could not initialize custom logging for step: " + step.getName(), ex);
}
try {
if (!Job.runStep(parameterService, jobName, i, step, jobRunDate)) {
System.exit(4);
}
} finally {
if (ndcSet) {
ThreadContext.remove(KFSConstants.BATCH_LOGGER_THREAD_CONTEXT_KEY);
}
}
} else {
throw new IllegalArgumentException("Unable to find step: " + stepNames[i]);
}
}
LOG.info("Finished executing job: " + jobName + " steps: " + Arrays.toString(stepNames));
System.exit(0);
} catch (Throwable t) {
System.err.println("ERROR: Exception caught: ");
t.printStackTrace(System.err);
System.exit(8);
}
}
Aggregations