1
2
3
4
5
6
7
8
9
10
11 package org.astrogrid.jes.impl.workflow;
12
13 import org.astrogrid.common.namegen.NameGen;
14 import org.astrogrid.community.beans.v1.Account;
15 import org.astrogrid.jes.job.JobException;
16 import org.astrogrid.jes.job.JobFactory;
17 import org.astrogrid.workflow.beans.v1.Workflow;
18 import org.astrogrid.workflow.beans.v1.execution.JobExecutionRecord;
19 import org.astrogrid.workflow.beans.v1.execution.JobURN;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23
24 import java.net.InetAddress;
25
26 /*** Abstract base class for implementations of job factory.
27 * @author Noel Winstanley nw@jb.man.ac.uk 11-Feb-2004
28 *
29 */
30 public abstract class AbstractJobFactoryImpl implements JobFactory {
31 /*** Construct a new JobFactoryImpl
32 *
33 */
34 public AbstractJobFactoryImpl(NameGen nameGen) {
35 this.nameGen = nameGen;
36 }
37 protected final NameGen nameGen;
38 /***
39 * @see org.astrogrid.jes.job.JobFactory#begin()
40 * @deprecated - not transactional any more.
41 */
42 public void begin() {
43 }
44 /***
45 * @see org.astrogrid.jes.job.JobFactory#end(boolean)
46 * @tdeprecated - not transactional any more.
47 */
48 public boolean end(boolean bCommit) throws JobException {
49 return true;
50 }
51 /***
52 * Build a new initialized job object.
53 */
54 protected Workflow buildJob(Workflow job) throws JobException {
55 JobURN jobURN = generateUniqueJobURN(job);
56 JobExecutionRecord exec = new JobExecutionRecord();
57 exec.setJobId(jobURN);
58 job.setJobExecutionRecord(exec);
59 return job;
60
61 }
62
63 /*** handy helper to get id string for a workflow
64 *
65 */
66 protected String id(Workflow w) {
67 return w.getJobExecutionRecord().getJobId().getContent();
68 }
69
70 /*** stuff for generating a unique job urn */
71 protected static String hostname;
72 static {
73 hostname = null;
74 try {
75 hostname = InetAddress.getLocalHost().toString();
76 } catch (Exception e) {
77 hostname="unavailable";
78 }
79 }
80
81 /*** generates a new job urn
82 *
83 * @param job
84 * @return string in format <code>jes:<i>userid</i>:<i>community</i>:<i>jes-server-hostname</i>:<i>currentTime</i>:<i>randomNumber</i></code>
85 * @throws JobException
86 */
87 protected JobURN generateUniqueJobURN( Workflow job ) throws JobException {
88
89 StringBuffer
90 buffer = new StringBuffer(128);
91 Account acc = job.getCredentials().getAccount();
92 try {
93 buffer
94 .append("jes:")
95 .append(hostname)
96 .append('/')
97 .append( acc.getName() )
98 .append( '@' )
99 .append( acc.getCommunity() )
100 .append( '/' )
101 .append(nameGen.next());
102 } catch (Exception e) {
103 throw new JobException("Failure in name generator");
104 }
105 JobURN urn = new JobURN();
106 urn.setContent(buffer.toString().trim());
107 return urn;
108
109 }
110 protected static final Log log = LogFactory.getLog("job factory");
111
112 }
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157