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