View Javadoc

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