1
2
3
4
5
6
7
8
9
10
11 package org.astrogrid.jes.impl.workflow;
12
13 import org.astrogrid.community.beans.v1.Account;
14 import org.astrogrid.jes.job.JobException;
15 import org.astrogrid.jes.job.JobFactory;
16 import org.astrogrid.workflow.beans.v1.Workflow;
17 import org.astrogrid.workflow.beans.v1.execution.JobExecutionRecord;
18 import org.astrogrid.workflow.beans.v1.execution.JobURN;
19
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22
23 import java.net.InetAddress;
24 import java.util.Random;
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() {
35 super();
36 }
37 /***
38 * @see org.astrogrid.jes.job.JobFactory#begin()
39 * @deprecated - not transactional any more.
40 */
41 public void begin() {
42 }
43 /***
44 * @see org.astrogrid.jes.job.JobFactory#end(boolean)
45 * @tdeprecated - not transactional any more.
46 */
47 public boolean end(boolean bCommit) throws JobException {
48 return true;
49 }
50 /***
51 * Build a new initialized job object.
52 */
53 protected Workflow buildJob(Workflow job) throws JobException {
54 JobURN jobURN = generateUniqueJobURN(job);
55 JobExecutionRecord exec = new JobExecutionRecord();
56 exec.setJobId(jobURN);
57 job.setJobExecutionRecord(exec);
58 return job;
59
60 }
61
62 /*** handy helper to get id string for a workflow
63 *
64 */
65 protected String id(Workflow w) {
66 return w.getJobExecutionRecord().getJobId().getContent();
67 }
68
69 /*** stuff for generating a unique job urn */
70 protected static String hostname;
71 static {
72 hostname = null;
73 try {
74 hostname = InetAddress.getLocalHost().toString();
75 } catch (Exception e) {
76 hostname="unavailable";
77 }
78 }
79 private static Random rand = new Random();
80 /*** generates a new job urn
81 *
82 * @param job
83 * @return string in format <code>jes:<i>userid</i>:<i>community</i>:<i>jes-server-hostname</i>:<i>currentTime</i>:<i>randomNumber</i></code>
84 * @throws JobException
85 */
86 protected JobURN generateUniqueJobURN( Workflow job ) throws JobException {
87
88 StringBuffer
89 buffer = new StringBuffer(128);
90 Account acc = job.getCredentials().getAccount();
91 buffer
92 .append("jes:")
93 .append(hostname)
94 .append('/')
95 .append( acc.getName() )
96 .append( '@' )
97 .append( acc.getCommunity() )
98 .append( '/' )
99 .append( System.currentTimeMillis())
100 .append( ':' )
101 .append(Math.abs( rand.nextInt()));
102 JobURN urn = new JobURN();
103 urn.setContent(buffer.toString().trim());
104 return urn;
105
106 }
107 protected static final Log log = LogFactory.getLog("job factory");
108
109 }
110
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