View Javadoc

1   package fr.in2p3.jsaga.impl.job.service;
2   
3   import fr.in2p3.jsaga.adaptor.job.control.JobControlAdaptor;
4   import fr.in2p3.jsaga.adaptor.job.control.description.JobDescriptionTranslator;
5   import fr.in2p3.jsaga.adaptor.job.monitor.JobMonitorAdaptor;
6   import fr.in2p3.jsaga.adaptor.security.SecurityCredential;
7   import fr.in2p3.jsaga.engine.factories.JobAdaptorFactory;
8   import fr.in2p3.jsaga.engine.factories.JobMonitorAdaptorFactory;
9   import fr.in2p3.jsaga.engine.job.monitor.JobMonitorService;
10  import org.apache.log4j.Logger;
11  import org.ogf.saga.error.*;
12  import org.ogf.saga.job.*;
13  import org.ogf.saga.session.Session;
14  import org.ogf.saga.task.TaskMode;
15  import org.ogf.saga.url.URL;
16  
17  import java.util.List;
18  import java.util.Map;
19  
20  /* ***************************************************
21  * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
22  * ***             http://cc.in2p3.fr/             ***
23  * ***************************************************
24  * File:   JobServiceImpl
25  * Author: Sylvain Reynaud (sreynaud@in2p3.fr)
26  * Date:   26 oct. 2007
27  * ***************************************************
28  * Description:                                      */
29  /**
30   *
31   */
32  public class JobServiceImpl extends AbstractAsyncJobServiceImpl implements JobService {
33      private static Logger s_logger = Logger.getLogger(JobServiceImpl.class);
34  
35      /** constructor */
36      public JobServiceImpl(Session session, URL rm, JobControlAdaptor controlAdaptor, JobMonitorService monitorService, JobDescriptionTranslator translator) {
37          super(session, rm, controlAdaptor, monitorService, translator);
38      }
39  
40      ///////////////////////////////////////// interface JobService /////////////////////////////////////////
41  
42      public synchronized Job createJob(JobDescription jd) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, TimeoutException, NoSuccessException {
43          // can not hang...
44          return super.createJobSync(jd);
45      }
46  
47      public Job runJob(String commandLine, String host, boolean interactive) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, TimeoutException, NoSuccessException {
48          float timeout = this.getTimeout("runJob");
49          if (timeout == WAIT_FOREVER) {
50              return super.runJobSync(commandLine, host, interactive);
51          } else {
52              throw new NotImplementedException("Instead you should set timeout for: "+Job.class+"#run");
53          }
54      }
55      public Job runJob(String commandLine, String host) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, TimeoutException, NoSuccessException {
56          return this.runJob(commandLine, host, DEFAULT_INTERACTIVE);
57      }
58      public Job runJob(String commandLine, boolean interactive) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, TimeoutException, NoSuccessException {
59          return this.runJob(commandLine, DEFAULT_HOST, interactive);
60      }
61      public Job runJob(String commandLine) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, TimeoutException, NoSuccessException {
62          return this.runJob(commandLine, DEFAULT_HOST, DEFAULT_INTERACTIVE);
63      }
64  
65      public List<String> list() throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, TimeoutException, NoSuccessException {
66          float timeout = this.getTimeout("list");
67          if (timeout == WAIT_FOREVER) {
68              return super.listSync();
69          } else {
70              try {
71                  return (List<String>) getResult(super.list(TaskMode.ASYNC), timeout);
72              }
73              catch (IncorrectURLException e) {throw new NoSuccessException(e);}
74              catch (BadParameterException e) {throw new NoSuccessException(e);}
75              catch (IncorrectStateException e) {throw new NoSuccessException(e);}
76              catch (AlreadyExistsException e) {throw new NoSuccessException(e);}
77              catch (DoesNotExistException e) {throw new NoSuccessException(e);}
78              catch (SagaIOException e) {throw new NoSuccessException(e);}
79          }
80      }
81  
82      public Job getJob(String jobId) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, DoesNotExistException, TimeoutException, NoSuccessException {
83          // can not hang...
84          return super.getJobSync(jobId);
85      }
86  
87      public JobSelf getSelf() throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, TimeoutException, NoSuccessException {
88          throw new NotImplementedException("Not implemented by the SAGA engine", this);
89      }
90  
91      public void disconnect() throws NoSuccessException {
92      	m_controlAdaptor.disconnect();
93      	m_monitorService.disconnect();
94      }
95      ////////////////////////////////////////// private methods //////////////////////////////////////////
96  
97      public synchronized void resetAdaptors(SecurityCredential security) {
98          m_monitorService.startReset();
99          // retrieve service attributes
100         Map attributes = m_monitorService.getAttributes();
101         try {
102             // reset control adaptor
103             JobAdaptorFactory.disconnect(m_controlAdaptor);
104             JobAdaptorFactory.connect(m_controlAdaptor, security, m_resourceManager, attributes);
105 
106             // reset monitor adaptor
107             JobMonitorAdaptor monitorAdaptor = m_monitorService.getAdaptor();
108             URL monitorURL = m_monitorService.getURL();
109             JobMonitorAdaptorFactory.disconnect(monitorAdaptor);
110             JobMonitorAdaptorFactory.connect(monitorAdaptor, security, monitorURL, attributes);
111         } catch (SagaException e) {
112             s_logger.warn("Failed to reconnect to job service", e);
113             m_monitorService.failReset(e);
114         } finally {
115             m_monitorService.stopReset();
116         }
117     }
118 
119     private float getTimeout(String methodName) throws NoSuccessException {
120         return getTimeout(JobService.class, methodName, m_resourceManager.getScheme());
121     }
122 }