1
2
3
4
5
6
7
8
9
10
11 package org.astrogrid.jes.jobscheduler.dispatcher;
12
13 import org.astrogrid.applications.delegate.CEADelegateException;
14 import org.astrogrid.applications.delegate.CommonExecutionConnectorClient;
15 import org.astrogrid.applications.delegate.DelegateFactory;
16 import org.astrogrid.component.descriptor.ComponentDescriptor;
17 import org.astrogrid.jes.JesException;
18 import org.astrogrid.jes.delegate.JesDelegateFactory;
19 import org.astrogrid.jes.delegate.JobMonitor;
20 import org.astrogrid.jes.jobscheduler.Dispatcher;
21 import org.astrogrid.jes.jobscheduler.Locator;
22 import org.astrogrid.jes.types.v1.cea.axis.JobIdentifierType;
23 import org.astrogrid.jes.util.JesUtil;
24 import org.astrogrid.workflow.beans.v1.Tool;
25 import org.astrogrid.workflow.beans.v1.Workflow;
26
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29
30 import java.net.URI;
31 import java.net.URLConnection;
32
33 import junit.framework.Test;
34 import junit.framework.TestCase;
35 import junit.framework.TestSuite;
36
37 /*** Implementation of a Dispactcher that calls an application controller web service to execute job steps.
38 * @author Noel Winstanley nw@jb.man.ac.uk 25-Feb-2004
39 *
40 */
41 public class ApplicationControllerDispatcher implements Dispatcher, ComponentDescriptor {
42 private static final Log logger =
43 LogFactory.getLog(ApplicationControllerDispatcher.class);
44 /*** Configuration component for Application Controller Dispatcher
45 * @author Noel Winstanley nw@jb.man.ac.uk 07-Mar-2004
46 *
47 */
48 public interface Endpoints {
49 URI monitorEndpoint();
50 URI resultListenerEndpoint();
51 }
52 /*** Construct a new ApplicationControllerDispatcher
53 * @param locator tool locator component to use to resolve endpoints
54 * @param endpoint configuration component that specifies the endpoint of the JobMonitor service. This is used by the ApplicationController to
55 * return execution information back to the JES server.
56 */
57 public ApplicationControllerDispatcher(Locator locator, Endpoints endpoint) {
58 this.locator = locator;
59 this.monitorURI = endpoint.monitorEndpoint();
60 this.resultListenerURI = endpoint.resultListenerEndpoint();
61 assert monitorURI != null;
62 assert resultListenerURI != null;
63 logger.info("monitor URL set to " + monitorURI.toString());
64 logger.info("result URL set to " + resultListenerURI.toString());
65 }
66 /*** tool locator component */
67 protected final Locator locator;
68 /*** endpoint of local jobmonitor service - used as a callback */
69 protected final URI monitorURI;
70 /*** endpoint of local result listener servuce - again, used as a callback */
71 protected final URI resultListenerURI;
72
73
74 public void dispatchStep(Workflow job, Tool tool,String stepId) throws JesException {
75
76 String toolLocation = locator.locateTool(tool);
77 CommonExecutionConnectorClient appController = DelegateFactory.createDelegate(toolLocation);
78
79 JobIdentifierType id = JesUtil.createJobId(job.getJobExecutionRecord().getJobId(), stepId);
80 logger.debug( "Calling application controller at " + toolLocation + " for "
81 + tool.getName() + ", "+ id.getValue());
82 try {
83 String applicationId = appController.init(tool,id);
84 appController.registerResultsListener(applicationId,resultListenerURI);
85 appController.registerProgressListener(applicationId,monitorURI);
86 appController.execute(applicationId);
87
88 }
89 catch (CEADelegateException e) {
90 throw new JesException("Failed to communicate with application controller", e);
91 }
92
93 }
94
95 /***
96 * @see org.astrogrid.jes.component.ComponentDescriptor#getName()
97 */
98 public String getName() {
99 return "ApplicationController Dispatcher";
100 }
101
102 /***
103 * @see org.astrogrid.jes.component.ComponentDescriptor#getDescription()
104 */
105 public String getDescription() {
106 return "Dispatcher that executes job steps by calling application controllers"
107 + " Configured to tell application controllers to call back to:\n"
108 + monitorURI.toString();
109 }
110
111 /***
112 * @see org.astrogrid.jes.component.ComponentDescriptor#getInstallationTest()
113 */
114 public Test getInstallationTest() {
115 TestSuite suite = new TestSuite("Tests for ApplicationControllerDispatcher");
116 suite.addTest(new InstallationTest("testCanConnectMonitorURL"));
117 suite.addTest(new InstallationTest("testCanCallMonitorURL"));
118 return suite;
119 }
120
121 protected class InstallationTest extends TestCase {
122 public InstallationTest(String s) {
123 super(s);
124 }
125 public void testCanConnectMonitorURL() throws Exception {
126 URLConnection conn = monitorURI.toURL().openConnection();
127 assertNotNull(conn);
128 conn.connect();
129
130 }
131 public void testCanCallMonitorURL() throws Exception {
132 JobMonitor mon = JesDelegateFactory.createJobMonitor(monitorURI.toString());
133 assertNotNull(mon);
134
135 mon.monitorJob(null, null);
136 }
137 }
138
139
140
141 }
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217