View Javadoc

1   package fr.in2p3.jsaga.impl.job.staging.mgr;
2   
3   import fr.in2p3.jsaga.adaptor.job.control.JobControlAdaptor;
4   import fr.in2p3.jsaga.adaptor.job.control.interactive.StreamableJobAdaptor;
5   import fr.in2p3.jsaga.adaptor.job.control.staging.StagingJobAdaptorOnePhase;
6   import fr.in2p3.jsaga.adaptor.job.control.staging.StagingJobAdaptorTwoPhase;
7   import fr.in2p3.jsaga.impl.job.streaming.mgr.StreamingManagerThroughSandboxOnePhase;
8   import fr.in2p3.jsaga.impl.job.streaming.mgr.StreamingManagerThroughSandboxTwoPhase;
9   
10  import org.ogf.saga.error.*;
11  import org.ogf.saga.job.JobDescription;
12  
13  /* ***************************************************
14   * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
15   * ***             http://cc.in2p3.fr/             ***
16   * ***************************************************
17   * File:   DataStagingManagerFactory
18   * Author: Sylvain Reynaud (sreynaud@in2p3.fr)
19   * Date:   9 mars 2010
20   * ***************************************************
21   * Description:                                      */
22  /**
23   *
24   */
25  public class DataStagingManagerFactory {
26      public static DataStagingManager create(JobControlAdaptor adaptor, JobDescription jobDesc, String uniqId) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, TimeoutException, NoSuccessException {
27          try {
28              // get FileTransfer
29              String[] fileTransfer = jobDesc.getVectorAttribute(JobDescription.FILETRANSFER);
30  
31              // create data staging manager
32              if (adaptor instanceof StagingJobAdaptorOnePhase) {
33                  return new DataStagingManagerThroughSandboxOnePhase((StagingJobAdaptorOnePhase) adaptor, uniqId);
34              } else if (adaptor instanceof StagingJobAdaptorTwoPhase) {
35             		return new DataStagingManagerThroughSandboxTwoPhase((StagingJobAdaptorTwoPhase) adaptor, uniqId);
36              } else if (adaptor instanceof StreamableJobAdaptor) {
37                  return new DataStagingManagerThroughStream(fileTransfer);
38              } else {
39                  throw new NotImplementedException("Adaptor can not handle attribute FileTransfer: "+adaptor.getClass());
40              }
41          } catch (DoesNotExistException e) {
42          	// If job is interactive and adaptor does not implement streaming, we use the streaming manager
43          	try {
44  				if ("true".equalsIgnoreCase(jobDesc.getAttribute(JobDescription.INTERACTIVE))) {
45  					if (adaptor instanceof StagingJobAdaptorTwoPhase) {
46  						return new StreamingManagerThroughSandboxTwoPhase((StagingJobAdaptorTwoPhase) adaptor, uniqId);
47  					} else if (adaptor instanceof StagingJobAdaptorOnePhase) {
48  						return new StreamingManagerThroughSandboxOnePhase((StagingJobAdaptorOnePhase) adaptor, uniqId);
49  					}
50  				}
51  			} catch (IncorrectStateException e1) {
52  			} catch (DoesNotExistException e1) {
53  			}
54              // create data staging manager
55              return new DataStagingManagerDummy();
56          } catch (IncorrectStateException e) {
57              throw new NoSuccessException(e);
58          }
59      }
60  
61      public static DataStagingManager create(JobControlAdaptor adaptor) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, TimeoutException, NoSuccessException {
62          String uniqId = null;   //todo: remove this
63  
64          // create data staging manager
65          if (adaptor instanceof StagingJobAdaptorOnePhase) {
66              return new DataStagingManagerThroughSandboxOnePhase((StagingJobAdaptorOnePhase) adaptor, uniqId);
67          } else if (adaptor instanceof StagingJobAdaptorTwoPhase) {
68              return new DataStagingManagerThroughSandboxTwoPhase((StagingJobAdaptorTwoPhase) adaptor, uniqId);
69          } else {
70              return new DataStagingManagerDummy();
71          }
72      }
73  }