View Javadoc

1   /*$Id: AbstractJobFactoryImpl.java,v 1.7 2005/04/25 12:13:54 clq2 Exp $
2    * Created on 11-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.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 $Log: AbstractJobFactoryImpl.java,v $
117 Revision 1.7  2005/04/25 12:13:54  clq2
118 jes-nww-776-again
119 
120 Revision 1.6.144.1  2005/04/11 13:55:53  nw
121 started using common-namegen
122 
123 Revision 1.6  2004/07/09 09:30:28  nw
124 merged in scripting workflow interpreter from branch
125 nww-x-workflow-extensions
126 
127 Revision 1.5  2004/07/01 11:19:05  nw
128 updated interface with cea - part of cea componentization
129 
130 Revision 1.4  2004/03/04 01:57:35  nw
131 major refactor.
132 upgraded to latest workflow object model.
133 removed internal facade
134 replaced community snippet with objects
135 
136 Revision 1.3  2004/03/03 01:13:41  nw
137 updated jes to work with regenerated workflow object model
138 
139 Revision 1.2  2004/02/27 00:46:03  nw
140 merged branch nww-itn05-bz#91
141 
142 Revision 1.1.2.4  2004/02/17 12:25:38  nw
143 improved javadocs for classes
144 
145 Revision 1.1.2.3  2004/02/17 10:58:38  nw
146 altered to implement cut down facade interface, matched with types
147 generated by wsdl2java
148 
149 Revision 1.1.2.2  2004/02/12 12:54:47  nw
150 worked in inversion of control pattern - basically means that
151 components have to be assembled, rather than self-configuring
152 from properties in config files. so easier to test each component in isolation
153 
154 Revision 1.1.2.1  2004/02/12 01:14:01  nw
155 castor implementation of jes object model
156  
157 */