View Javadoc

1   /*
2    * $Id: CommonExecutionConnectorServiceSoapBindingImpl.java,v 1.13 2006/06/13 20:33:13 clq2 Exp $
3    * 
4    * Created on 25-Mar-2004 by Paul Harrison (pah@jb.man.ac.uk)
5    *
6    * Copyright 2004 AstroGrid. All rights reserved.
7    *
8    * This software is published under the terms of the AstroGrid 
9    * Software License version 1.2, a copy of which has been included 
10   * with this distribution in the LICENSE.txt file.  
11   *
12   */ 
13  
14  package org.astrogrid.applications.service.v1.cea;
15  
16  import org.apache.commons.logging.Log;
17  import org.apache.commons.logging.LogFactory;
18  
19  import org.astrogrid.applications.component.CEAComponentManagerFactory;
20  import org.astrogrid.applications.manager.ExecutionController;
21  import org.astrogrid.applications.manager.QueryService;
22  import org.astrogrid.common.bean.Axis2Castor;
23  import org.astrogrid.common.bean.Castor2Axis;
24  import org.astrogrid.jes.types.v1.cea.axis.ExecutionSummaryType;
25  import org.astrogrid.jes.types.v1.cea.axis.JobIdentifierType;
26  import org.astrogrid.jes.types.v1.cea.axis.MessageType;
27  import org.astrogrid.jes.types.v1.cea.axis.ResultListType;
28  import org.astrogrid.security.AxisServiceSecurityGuard;
29  import org.astrogrid.workflow.beans.v1.Tool;
30  import org.astrogrid.workflow.beans.v1.axis._tool;
31  
32  import org.apache.axis.description.ServiceDesc;
33  import org.apache.axis.types.URI;
34  import org.apache.axis.utils.XMLUtils;
35  
36  import java.rmi.RemoteException;
37  
38  /***
39   * This is the main implementation of the CommonExecutionConnectorService. This is the class that should be referenced in the Axis wsdd file.
40   * Its main task is to convert between axis and castor object representations, and then delegate to the appropriate component in the componentManager 
41   * <p>
42   * Catches all exceptions, propagates them as {@link org.astrogrid.applications.service.v1.cea.CeaFault} messages back to the caller.
43   * @author Paul Harrison (pah@jb.man.ac.uk) 25-Mar-2004
44   * @author Noel Winstanley
45   * @version $Name: HEAD $
46   * @since iteration5
47   */
48  public class CommonExecutionConnectorServiceSoapBindingImpl implements CommonExecutionConnector {
49      /***
50       * Logger for this class
51       */
52      private static final Log logger = LogFactory.getLog(CommonExecutionConnectorServiceSoapBindingImpl.class);
53  
54  
55        
56        protected  final ExecutionController cec;
57        protected final QueryService query;
58  
59     /***
60      * 
61      */
62     public CommonExecutionConnectorServiceSoapBindingImpl() {
63        try {
64            //TODO need to get this service description into pico
65           ServiceDesc servicedesc = org.apache.axis.MessageContext.getCurrentContext().getService().getServiceDescription();
66   
67           cec = CEAComponentManagerFactory.getInstance().getExecutionController();
68          
69           //nController(servicedesc);
70        }
71        catch (Throwable e) {         
72           logger.fatal("problem instatiating applicationController", e);
73           //we're stuffed - no point continuing.
74           throw new RuntimeException("Could not instantiate application controller",e);
75        }
76        try {
77            query = CEAComponentManagerFactory.getInstance().getQueryService();
78        } catch (Throwable e) {
79            logger.fatal("problem instantiating querier",e);
80            throw new RuntimeException("Could not instantiate query service",e);
81        }
82        
83     }
84  
85     /*** 
86      * @see org.astrogrid.applications.service.v1.cea.CommonExecutionConnector#execute(org.astrogrid.workflow.beans.v1.axis._tool, org.astrogrid.jes.types.v1.cea.axis.JobIdentifierType, java.lang.String)
87      */
88     public String init(_tool tool, JobIdentifierType jobstepID)
89        throws RemoteException, CeaFault {           
90           try {           
91               Tool ctool = Axis2Castor.convert(tool); 
92              return cec.init(ctool, jobstepID.toString());
93           }
94           catch (Exception e) {
95             logger.error("init(_tool tool = " + tool + ") - Throwable caught:", e);
96             throw CeaFault.makeFault(e);
97           }
98           catch(Throwable e) {
99              logger.error("init(_tool tool = " + tool + ") - Exception caught:", e);
100             throw CeaFault.makeFault(new Exception("an Throwable occurred in init-"+e.getMessage(), e));
101          }
102    }
103 
104    /***
105     * @see org.astrogrid.applications.service.v1.cea.CommonExecutionConnector#execute(java.lang.String)
106     */
107    public boolean execute(String arg0) throws RemoteException, CeaFault {
108        try {
109            this.cacheSecurityGuard();
110            return cec.execute(arg0);
111        } catch (Exception e) {
112         logger.error("execute("+ arg0 + ")", e);
113 
114            throw CeaFault.makeFault(e);
115        } catch (Throwable e) {
116         logger.error("execute("+ arg0 +")", e);
117            throw CeaFault.makeFault(new Exception("a throwable occurred in execute-"+e.getMessage(),e)); 
118        }
119    }
120 
121    /*** 
122     * @see org.astrogrid.applications.service.v1.cea.CommonExecutionConnector#abort(java.lang.String)
123     */
124    public boolean abort(String executionId) throws RemoteException, CeaFault {
125       try {
126             return cec.abort(executionId);
127       } catch (Exception e) {
128         logger.error("abort(" + executionId + ")", e);
129           throw CeaFault.makeFault(e);
130       } catch (Throwable t) {
131         logger.error("abort(" + executionId+")", t);
132           throw CeaFault.makeFault(new Exception("a throwable occurred in abort",t));
133    }
134    }
135 
136 
137    /*** 
138     * @see org.astrogrid.applications.service.v1.cea.CommonExecutionConnector#queryExecutionStatus(java.lang.String)
139     */
140    public MessageType queryExecutionStatus(String executionId)
141       throws RemoteException, CeaFault {
142          try {
143             org.astrogrid.applications.beans.v1.cea.castor.MessageType mess = query.queryExecutionStatus(executionId);
144             return  Castor2Axis.convert(mess);
145          }
146          catch (Exception e) {
147             logger.error("queryExecutionStatus(" + executionId+")", e);
148             throw CeaFault.makeFault(e);
149          }
150          catch(Throwable e)
151          {
152             logger.error("queryExecutionStatus(" + executionId+")", e);
153             throw CeaFault.makeFault(new Exception("an Throwable occurred in query status-"+e.getMessage(), e));
154          }
155    }
156      
157 /***
158  * @see org.astrogrid.applications.service.v1.cea.CommonExecutionConnector#registerResultsListener(java.lang.String, org.apache.axis.types.URI)
159  */
160 public boolean registerResultsListener(String arg0, URI arg1) throws RemoteException, CeaFault {
161     try {
162         return query.registerResultsListener(arg0,new java.net.URI(arg1.toString()));
163     } catch (Exception e) {
164         logger.error("registerResultsListener(" + arg0 + ", " + arg1+")", e);
165         throw CeaFault.makeFault(e);
166     } catch (Throwable e) {
167         logger.error("registerResultsListener(" + arg0 + ", " + arg1 +")", e);
168         throw CeaFault.makeFault(new Exception("a throwable occurred in registerResultsListener-"+e.getMessage(),e));
169     }
170 }
171 
172 /***
173  * @see org.astrogrid.applications.service.v1.cea.CommonExecutionConnector#registerProgressListener(java.lang.String, org.apache.axis.types.URI)
174  */
175 public boolean registerProgressListener(String arg0, URI arg1) throws RemoteException, CeaFault {
176     try {
177         return query.registerProgressListener(arg0,new java.net.URI(arg1.toString()));
178     } catch (Exception e) {
179         logger.error("registerProgressListener(" + arg0 + ", " + arg1+")", e);
180         throw CeaFault.makeFault(e);
181     } catch (Throwable e) {
182         logger.error("registerProgressListener(" + arg0 + ", " + arg1 +")", e);
183 
184         throw CeaFault.makeFault(new Exception("a throwable occurred in registerProgressListener-"+e.getMessage(),e));
185     }
186 }
187 
188 /***
189  * @see org.astrogrid.applications.service.v1.cea.CommonExecutionConnector#getExecutionSummary(java.lang.String)
190  */
191 public ExecutionSummaryType getExecutionSummary(String arg0) throws RemoteException, CeaFault {
192     try {
193         return Castor2Axis.convert(query.getSummary(arg0));
194     } catch (Exception e) {
195         logger.error("getExecutionSummary("+arg0+")", e);
196         throw CeaFault.makeFault(e);
197     } catch (Throwable e) {
198         logger.error("getExecutionSummary("+arg0+")", e);
199         throw CeaFault.makeFault(new Exception("a throwable occurred in getExecutionSummary-"+e.getMessage(),e));
200     }
201 }
202 /***
203  * @see org.astrogrid.applications.service.v1.cea.CommonExecutionConnector#getResults(java.lang.String)
204  */
205 public ResultListType getResults(String arg0) throws RemoteException, CeaFault {
206     try {
207         return Castor2Axis.convert(query.getResults(arg0));
208     } catch (Exception e) {
209         logger.error("getResults("+arg0+")", e);
210         throw CeaFault.makeFault(e);
211     } catch (Throwable e) {
212         logger.error("getResults("+arg0+")", e);
213 
214         throw CeaFault.makeFault(new Exception("a throwable occurred in getResults-"+e.getMessage(),e));
215     }
216 }
217    
218 /*** 
219   * @see org.astrogrid.applications.service.v1.cea.CommonExecutionConnector#returnRegistryEntry()
220   */
221  public String returnRegistryEntry() throws RemoteException, CeaFault
222  {
223      try {
224          return XMLUtils.DocumentToString(CEAComponentManagerFactory.getInstance().getMetadataService().returnRegistryEntry());
225      } catch (Exception e) {
226 		 logger.error("returnRegistryEntry()", e);
227          throw CeaFault.makeFault(e);       
228      } catch (Throwable e) {
229 		 logger.error("returnRegistryEntry()", e);
230          throw CeaFault.makeFault(new Exception("A throwable occured in return registry entry-"+e.getMessage(),e));
231      }
232   }
233  
234  private void cacheSecurityGuard() {
235    AxisServiceSecurityGuard g = AxisServiceSecurityGuard.getInstanceFromContext();
236    CeaSecurityGuard.setInstanceInContext(g);
237  }
238 
239 
240 }