View Javadoc

1   /*$Id: ApplicationControllerDispatcher.java,v 1.19 2004/08/13 09:07:58 nw Exp $
2    * Created on 25-Feb-2004
3    *
4    * Copyright (C) AstroGrid. All rights reserved.
5    *
6    * This software is published under the terms of the AstroGrid 
7    * Software License version 1.2, a copy of which has been included 
8    * with this distribution in the LICENSE.txt file.  
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          // call, with null parameters. will be ignored by other end - if it gets there. we're checking it gets there..
135          mon.monitorJob(null, null);
136       }
137    }
138 
139 
140 
141 }
142 
143 /* 
144 $Log: ApplicationControllerDispatcher.java,v $
145 Revision 1.19  2004/08/13 09:07:58  nw
146 tidied imports
147 
148 Revision 1.18  2004/08/09 17:31:11  nw
149 adjusted interface, to work better with dynamically-generated states.
150 
151 Revision 1.17  2004/08/03 16:31:25  nw
152 simplified interface to dispatcher and locator components.
153 removed redundant implementations.
154 
155 Revision 1.16  2004/07/30 15:42:34  nw
156 merged in branch nww-itn06-bz#441 (groovy scripting)
157 
158 Revision 1.15.20.1  2004/07/30 15:10:04  nw
159 removed policy-based implementation,
160 adjusted tests, etc to use groovy implementation
161 
162 Revision 1.15  2004/07/09 09:30:28  nw
163 merged in scripting workflow interpreter from branch
164 nww-x-workflow-extensions
165 
166 Revision 1.14  2004/07/02 09:07:58  nw
167 added in results listener
168 
169 Revision 1.13  2004/07/01 21:15:00  nw
170 added results-listener interface to jes
171 
172 Revision 1.12  2004/07/01 11:19:05  nw
173 updated interface with cea - part of cea componentization
174 
175 Revision 1.11  2004/05/27 09:49:42  nw
176 improved exception reporting 'when applications go bad'
177 
178 Revision 1.10  2004/04/08 14:43:26  nw
179 added delete and abort job functionality
180 
181 Revision 1.9  2004/03/24 08:05:08  pah
182 call the new CommonExecutionConnector Delegate
183 
184 Revision 1.8  2004/03/15 23:45:07  nw
185 improved javadoc
186 
187 Revision 1.7  2004/03/15 01:30:45  nw
188 factored component descriptor out into separate package
189 
190 Revision 1.6  2004/03/12 15:32:14  nw
191 improved logging
192 
193 Revision 1.5  2004/03/07 21:04:39  nw
194 merged in nww-itn05-pico - adds picocontainer
195 
196 Revision 1.4.4.1  2004/03/07 20:41:06  nw
197 added component descriptor interface impl,
198 refactored any primitive types passed into constructor
199 
200 Revision 1.4  2004/03/05 16:16:23  nw
201 worked now object model through jes.
202 implemented basic scheduling policy
203 removed internal facade
204 
205 Revision 1.3  2004/03/04 01:57:35  nw
206 major refactor.
207 upgraded to latest workflow object model.
208 removed internal facade
209 replaced community snippet with objects
210 
211 Revision 1.2  2004/02/27 00:46:03  nw
212 merged branch nww-itn05-bz#91
213 
214 Revision 1.1.2.1  2004/02/27 00:27:07  nw
215 rearranging code
216  
217 */