1 package fr.in2p3.jsaga.impl.job.streaming.mgr;
2
3 import java.io.File;
4
5 import org.ogf.saga.error.AuthenticationFailedException;
6 import org.ogf.saga.error.AuthorizationFailedException;
7 import org.ogf.saga.error.BadParameterException;
8 import org.ogf.saga.error.DoesNotExistException;
9 import org.ogf.saga.error.IncorrectStateException;
10 import org.ogf.saga.error.NoSuccessException;
11 import org.ogf.saga.error.NotImplementedException;
12 import org.ogf.saga.error.PermissionDeniedException;
13 import org.ogf.saga.error.TimeoutException;
14 import org.ogf.saga.file.Directory;
15 import org.ogf.saga.job.JobDescription;
16
17 import fr.in2p3.jsaga.adaptor.job.control.staging.StagingJobAdaptorOnePhase;
18 import fr.in2p3.jsaga.impl.job.instance.AbstractSyncJobImpl;
19 import fr.in2p3.jsaga.impl.job.staging.mgr.DataStagingManagerThroughSandboxOnePhase;
20 import fr.in2p3.jsaga.impl.job.streaming.LocalFileFactory;
21
22
23
24
25
26
27
28
29
30
31
32 public class StreamingManagerThroughSandboxOnePhase extends
33 DataStagingManagerThroughSandboxOnePhase implements
34 StreamingManagerThroughSandbox {
35
36 private String m_uuid;
37
38 public StreamingManagerThroughSandboxOnePhase(
39 StagingJobAdaptorOnePhase adaptor, String uniqId)
40 throws NotImplementedException, BadParameterException,
41 NoSuccessException {
42 super(adaptor, uniqId);
43 this.m_uuid = uniqId;
44 }
45
46 @Override
47 public JobDescription modifyJobDescription(JobDescription jobDesc)
48 throws NotImplementedException, AuthenticationFailedException,
49 AuthorizationFailedException, PermissionDeniedException,
50 BadParameterException, TimeoutException, NoSuccessException {
51
52 try {
53 JobDescription newJobDesc = (JobDescription) jobDesc.clone();
54
55 newJobDesc.setAttribute(JobDescription.INTERACTIVE, JobDescription.FALSE);
56
57
58 newJobDesc.setVectorAttribute(JobDescription.FILETRANSFER, new String[]{
59 LocalFileFactory.getLocalInputFile(m_uuid) + " > " + getWorker("input"),
60 LocalFileFactory.getLocalOutputFile(m_uuid) + " < " + getWorker("output"),
61 LocalFileFactory.getLocalErrorFile(m_uuid) + " < " + getWorker("error")
62 });
63
64
65 newJobDesc.setAttribute(JobDescription.INPUT, getWorker("input").toString());
66 newJobDesc.setAttribute(JobDescription.OUTPUT, getWorker("output").toString());
67 newJobDesc.setAttribute(JobDescription.ERROR, getWorker("error").toString());
68
69 return newJobDesc;
70 } catch (CloneNotSupportedException e) {
71 throw new NoSuccessException(e);
72 } catch (Exception e) {
73 throw new NoSuccessException(e);
74 }
75 }
76
77 @Override
78 public Directory cleanup(AbstractSyncJobImpl job, String nativeJobId) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, DoesNotExistException, TimeoutException, IncorrectStateException, NoSuccessException {
79 try {
80 File input = LocalFileFactory.getLocalInputFile(m_uuid);
81 input.delete();
82 } catch (Exception e) {
83 }
84 try {
85 File output = LocalFileFactory.getLocalOutputFile(m_uuid);
86 output.delete();
87 } catch (Exception e) {
88 }
89 try {
90 File error = LocalFileFactory.getLocalErrorFile(m_uuid);
91 error.delete();
92 } catch (Exception e) {
93 }
94 return super.cleanup(job, nativeJobId);
95 }
96
97 protected String getWorker(String suffix) {
98 return "worker-"+m_uuid+"."+suffix;
99 }
100
101 }