1 package org.kuali.ole.sys.context;
2
3
4 import java.util.concurrent.Executor;
5 import java.util.concurrent.Executors;
6
7 import org.kuali.ole.sys.batch.BatchSpringContext;
8
9 import org.kuali.ole.sys.batch.BatchContainerStep;
10
11
12
13
14 public class BatchStepLauncher implements Runnable {
15 private static final String LOG_PREFIX = BatchStepLauncher.class.getName() +": ";
16 private static final String batchContainerStep = "batchContainerStep";
17
18 private static BatchStepTriggerParameters batchStepTriggerParms;
19
20
21
22
23
24
25
26
27
28
29
30 public static void main(String[] args) {
31
32
33 checkArguments(args);
34
35
36 startBatchContainer();
37
38
39
40 confirmStartUp();
41
42
43 executeSteps(args);
44
45
46 }
47
48
49
50
51 public void run() {
52 String[] args = new String[2];
53 args[0] = batchContainerStep;
54 args[1] = (batchStepTriggerParms != null ? batchStepTriggerParms.getJobName(): "unknown");
55
56 BatchStepRunner.main(args);
57 }
58
59
60
61
62
63
64 private static void checkArguments(String[] args) {
65 logToOut("checking arguments");
66
67 batchStepTriggerParms = new BatchStepTriggerParameters(args);
68
69 logToOut("received valid arguments");
70 }
71
72
73
74
75 private static void startBatchContainer() {
76 logToOut("starting the batch container");
77 Executor executor = Executors.newCachedThreadPool();
78
79 BatchStepLauncher batchStepLauncher = new BatchStepLauncher();
80 executor.execute(batchStepLauncher);
81 }
82
83
84
85
86 private static void confirmStartUp() {
87 logToOut("confirming batch container start up");
88
89 while (!batchStepTriggerParms.getBatchContainerDirectory().isBatchContainerRunning()) {
90 logToOut("waiting for the batch container to start up");
91 try {
92 Thread.sleep(batchStepTriggerParms.getSleepInterval());
93 }
94 catch (InterruptedException e) {
95 throw new RuntimeException("BatchStepLauncher encountered interrupt exception while trying to wait for the batch container to start up", e);
96 }
97 }
98
99 logToOut("batch container is running");
100 }
101
102
103
104
105
106
107 private static void executeSteps(String[] args) {
108 logToOut("executing step(s)");
109
110 BatchStepTrigger.main(args);
111
112 logToOut("finished executing step(s)");
113 }
114
115
116
117
118
119 private static void removeBatchContainerSemaphore() {
120 logToOut("removing batch container semaphore file");
121
122 if (batchStepTriggerParms.getBatchContainerDirectory().isBatchContainerRunning()) {
123 batchStepTriggerParms.getBatchContainerDirectory().removeBatchContainerSemaphore();
124 }
125
126 logToOut("batch container semaphore file has been removed");
127 }
128
129
130
131
132
133
134 private static void logToOut(String statement) {
135 System.out.println(LOG_PREFIX + statement);
136 }
137 }