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
15
16
17
18
19
20
21
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
29 String[] fileTransfer = jobDesc.getVectorAttribute(JobDescription.FILETRANSFER);
30
31
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
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
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;
63
64
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 }