01: /*
02: * Copyright 2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.kuali.kfs.context;
17:
18: import java.util.Arrays;
19:
20: import org.apache.commons.lang.StringUtils;
21: import org.kuali.kfs.KFSConstants;
22: import org.kuali.kfs.batch.BatchSpringContext;
23: import org.kuali.kfs.batch.Job;
24: import org.kuali.kfs.service.ParameterService;
25:
26: public class BatchStepRunner {
27: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
28: .getLogger(BatchStepRunner.class);
29:
30: public static void main(String[] args) {
31: if (args.length < 1) {
32: System.err
33: .println("ERROR: You must pass the name of the step to run on the command line.");
34: System.exit(8);
35: }
36: try {
37: Log4jConfigurer.configureLogging(false);
38: SpringContext.initializeApplicationContext();
39: String[] stepNames;
40: if (args[0].indexOf(",") > 0) {
41: stepNames = StringUtils.split(args[0], ",");
42: } else {
43: stepNames = new String[] { args[0] };
44: }
45: ParameterService parameterService = SpringContext
46: .getBean(ParameterService.class);
47: String jobName = args.length >= 2 ? args[1]
48: : KFSConstants.BATCH_STEP_RUNNER_JOB_NAME;
49: LOG.info("Executing job: " + jobName + " steps: "
50: + Arrays.toString(stepNames));
51: for (int i = 0; i < stepNames.length; ++i) {
52: if (!Job.runStep(parameterService, jobName, i,
53: BatchSpringContext.getStep(stepNames[i]))) {
54: System.exit(4);
55: }
56: }
57: LOG.info("Finished executing job: " + jobName + " steps: "
58: + Arrays.toString(stepNames));
59: System.exit(0);
60: } catch (Throwable t) {
61: System.err.println("ERROR: Exception caught: ");
62: t.printStackTrace(System.err);
63: System.exit(8);
64: }
65: }
66: }
|