1 package org.kuali.ole.sys.context;
2
3 import org.apache.commons.lang.StringUtils;
4
5 /**
6 * BatchStepTriggerParameters provides parsing and error checking for the arguments needed by the BatchStepTrigger.
7 *
8 * stepName: args[0]: String- a comma delimited list of step names (no spaces)
9 * jobName: args[1]: String- the name of the job in which the steps are being executed
10 * stepIndex: args[2]: String- the index of the step in the job
11 * batchContainerDirectory: args[3]: String- the path to the directory in which the semaphore files are created.
12 * This value needs to match 'staging.directory.sys.batchContainer' in iu/build/configuration.properties
13 * sleepInterval: args[4]: String- the amount of time (in seconds) to wait before looking for the result file from BatchContainerStep
14 */
15 public class BatchStepTriggerParameters {
16
17 private String[] stepNames;
18 private String jobName;
19 private int stepIndex;
20 private long sleepInterval;
21
22 private BatchContainerDirectory batchContainerDirectory;
23
24 /**
25 * @param args
26 * stepName: args[0]: String- a comma delimited list of step names (no spaces)
27 * jobName: args[1]: String- the name of the job in which the steps are being executed
28 * stepIndex: args[2]: String- the index of the step in the job
29 * batchContainerDirectory: args[2]: String- the path to the directory in which the semaphore files are created.
30 * This value needs to match 'staging.directory.sys.batchContainer' in iu/build/configuration.properties
31 * sleepInterval: args[3]: String- the amount of time (in seconds) to wait before looking for the result file from BatchContainerStep
32 */
33 protected BatchStepTriggerParameters(String[] args) {
34 if (args.length < 1) {
35 System.err.println("ERROR: You must pass the name of the step to run on the command line.");
36 System.exit(8);
37 } else if (args.length < 2) {
38 System.err.println("ERROR: You must pass the name of the job to run on the command line.");
39 System.exit(8);
40 } else if (args.length < 3) {
41 System.err.println("ERROR: You must pass the index of the step in the job on the command line.");
42 System.exit(8);
43 } else if (args.length < 4) {
44 System.err.println("ERROR: You must pass the path of the directory in which to write and read result files on the command line.");
45 System.exit(8);
46 } else if (args.length < 5) {
47 System.err.println("ERROR: You must pass the amount of time (in seconds) to sleep while waiting for the step to run on the command line.");
48 System.exit(8);
49 }
50
51 if (args[0].indexOf(",") > 0) {
52 stepNames = StringUtils.split(args[0], ",");
53 }
54 else {
55 stepNames = new String[] { args[0] };
56 }
57
58 jobName = args[1];
59 stepIndex = Integer.parseInt(args[2]);
60 String directory = args[3];
61 sleepInterval = Long.parseLong(args[4]) * 1000;
62 batchContainerDirectory = new BatchContainerDirectory(directory);
63 }
64
65 /**
66 * @return a comma delimited list of step names (no spaces)
67 */
68 protected String[] getStepNames() {
69 return stepNames;
70 }
71
72 /**
73 * @return the name of the job in which the step(s) are being executed
74 */
75 protected String getJobName() {
76 return jobName;
77 }
78
79 /**
80 * @return the index of the step in the job
81 */
82 protected int getStepIndex() {
83 return stepIndex;
84 }
85
86 /**
87 * @return the amount of time to sleep (in seconds) while waiting for a result file from the BatchContainerStep
88 */
89 protected long getSleepInterval() {
90 return sleepInterval;
91 }
92
93 /**
94 * @return the directory in which the semaphore files are located
95 */
96 protected BatchContainerDirectory getBatchContainerDirectory() {
97 return batchContainerDirectory;
98 }
99 }