1
2
3
4
5
6
7
8
9
10
11 package org.astrogrid.portal.workflow.intf;
12
13 import java.net.URL;
14
15 import org.apache.commons.logging.Log;
16 import org.apache.commons.logging.LogFactory;
17 import org.astrogrid.config.Config;
18 import org.astrogrid.config.PropertyNotFoundException;
19 import org.astrogrid.config.SimpleConfig;
20 import org.astrogrid.portal.workflow.impl.BasicWorkflowBuilder;
21 import org.astrogrid.portal.workflow.impl.FileApplicationRegistry;
22 import org.astrogrid.portal.workflow.impl.JesJobExecutionService;
23 import org.astrogrid.portal.workflow.impl.RegistryApplicationRegistry;
24 import org.astrogrid.portal.workflow.impl.RegistryV10ApplicationRegistry;
25 import org.astrogrid.portal.workflow.impl.VoSpaceClientWorkflowStore;
26
27 /*** Factory that creates a new workflow manager
28 * <p>
29 * After creation, a factory instance maintains a single instance of the manager
30 * <p>
31 * The composition of the created workflow manager depends on the keys set in the {@link org.astrogrid.config.Config} system. Refer to the documentation
32 * for this package for how to set keys.
33 * <p>
34 * The keys that control the configuration of the workflow manager are all defined in this class:
35 * <h2>Workflow Store</h2>
36 * Based on the VoSpaceClient delegate - configuration details given there. no futher configuration here.
37 * <h2>Application Registry</h2>
38 * <li>
39 * <li>{@link #WORKFLOW_APPLIST_KEY}
40 * <li>{@link #WORKFLOW_APPLIST_REGISTRY_ENDPOINT_KEY}
41 * <li>{@link #WORKFLOW_APPLIST_XML_URL_KEY}
42 * </ul>
43 * <h2>Job Execution Service</h2>
44 * <ul>
45 * <li>{@link #WORKFLOW_JES_ENDPOINT_KEY}
46 *
47 * </ul>
48 * @author Noel Winstanley nw@jb.man.ac.uk 24-Feb-2004
49 *
50 */
51 public class WorkflowManagerFactory {
52 private static Log log = LogFactory.getLog(WorkflowManagerFactory.class);
53 /*** Construct a new WorkflowManagerFactory
54 * will use default configuration object from {@link SimpleConfig}
55 */
56 public WorkflowManagerFactory() {
57 this(SimpleConfig.getSingleton());
58 }
59
60 /*** construct a workflow manager factory, which will use the passed in configuration object */
61 public WorkflowManagerFactory(Config conf) {
62 this.conf = conf;
63 }
64 private final Config conf;
65
66 /*** access the manager instance */
67 public synchronized WorkflowManager getManager() throws WorkflowInterfaceException{
68 if (theInstance == null) {
69 theInstance = createManager();
70 }
71 assert theInstance != null;
72 return theInstance;
73 }
74
75 private WorkflowManager theInstance;
76
77
78 /*** key to look under to determin implmenetation of workflow applicationRegistry to use
79 * <p>possible values: <tt>xml</tt> | <tt>registry</tt> | <tt><i>java.class.name</i></tt>
80 * <br> default value: <tt>registry</tt>
81 */
82 public static final String WORKFLOW_APPLIST_KEY = "workflow.applist";
83 /*** key to look under to determine url of xml file to use for xml-based application registry
84 * <p> default value: <tt>/application-list.xml</tt> on classpath*/
85 public static final String WORKFLOW_APPLIST_XML_URL_KEY = "workflow.applist.xml.url";
86 /*** default location to look for xml file for xml-based application registry */
87 public static final String WORKFLOW_APPLIST_XML_DEFAULT = "/application-list.xml";
88 private static final URL WORKFLOW_APPLIST_XML_DEFAULT_URL = WorkflowManagerFactory.class.getResource(WORKFLOW_APPLIST_XML_DEFAULT);
89 /*** key to look under to determine endpoint of registry-based application registry */
90 public static final String WORKFLOW_APPLIST_REGISTRY_ENDPOINT_KEY = "workflow.applist.registry.endpoint";
91 /*** key to look under to determine endpoint of jes controller service */
92 public static final String WORKFLOW_JES_ENDPOINT_KEY = "workflow.jes.endpoint";
93
94 /*** create workflow manager, based on properties in config */
95 private WorkflowManager createManager() throws WorkflowInterfaceException{
96 try {
97 WorkflowBuilder builder = new BasicWorkflowBuilder();
98 WorkflowStore store = buildStore();
99 ApplicationRegistry reg = buildAppReg();
100 JobExecutionService jes = buildJes();
101 return new WorkflowManager(builder,store,reg,jes);
102 } catch (Exception e) {
103 log.fatal("Failed to create Workflow Manager",e);
104 throw new WorkflowInterfaceException(e);
105 }
106 }
107
108 /***
109 * @return
110 */
111 private JobExecutionService buildJes() {
112 try {
113 String url = conf.getString(WORKFLOW_JES_ENDPOINT_KEY);
114 log.info(WORKFLOW_JES_ENDPOINT_KEY + " := " + url);
115 return new JesJobExecutionService(url);
116 } catch (PropertyNotFoundException e) {
117 log.info("no url found under " + WORKFLOW_JES_ENDPOINT_KEY + ", trying letting delegate configure itself");
118 return new JesJobExecutionService();
119 }
120 }
121
122 /***
123 * @return
124 */
125 private ApplicationRegistry buildAppReg() throws Exception {
126 try {
127 String option = conf.getString(WORKFLOW_APPLIST_KEY).trim();
128 log.info(WORKFLOW_APPLIST_KEY + " := " + option);
129 if ("xml".equalsIgnoreCase(option)) {
130 log.info("Creating xml-file backed application list");
131 URL applicationListDocument= conf.getUrl(WORKFLOW_APPLIST_XML_URL_KEY,WORKFLOW_APPLIST_XML_DEFAULT_URL);
132 log.info(WORKFLOW_APPLIST_XML_URL_KEY + " := " + applicationListDocument.toString());
133 return new FileApplicationRegistry(applicationListDocument);
134 } else if ("registry".equalsIgnoreCase(option)) {
135 return buildDefaultAppReg();
136 } else {
137 log.info("option unrecognized - assuming its a java classname. attempting to instantiate..");
138 Class clazz = Class.forName(option);
139 return (ApplicationRegistry)clazz.newInstance();
140 }
141 } catch (PropertyNotFoundException e) {
142 log.warn("no value for " + WORKFLOW_APPLIST_KEY + " falling back to default");
143 return buildDefaultAppReg();
144 }
145 }
146 /*** build default, astorgrid-registry based implementation */
147 private ApplicationRegistry buildDefaultAppReg() {
148 log.info("Creating registry backed application list");
149 try {
150 URL endpoint = conf.getUrl(WORKFLOW_APPLIST_REGISTRY_ENDPOINT_KEY);
151 log.info(WORKFLOW_APPLIST_REGISTRY_ENDPOINT_KEY + " := " + endpoint.toString());
152 if (conf.getString("org.astrogrid.registry.result.version","0.10").equals("0.9")) {
153 log.info("Creating v0.9 application registry");
154 return new RegistryApplicationRegistry(endpoint);
155 } else {
156 log.info("Creating v10 Application registry");
157 return new RegistryV10ApplicationRegistry(endpoint);
158 }
159 }catch (PropertyNotFoundException e) {
160 log.info("No registry endpoint specified, attempting to let registry delegate configure itself");
161 if (conf.getString("org.astrogrid.registry.result.version","0.10").equals("0.9")) {
162 log.info("Creating v0.9 application registry");
163 return new RegistryApplicationRegistry();
164 } else {
165 log.info("Creating v10 Application registry");
166 return new RegistryV10ApplicationRegistry();
167 }
168 }
169 }
170
171 /***
172 */
173 private WorkflowStore buildStore() throws Exception {
174 return new VoSpaceClientWorkflowStore();
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
218
219
220
221
222
223
224
225
226
227
228
229
230