1 package fr.in2p3.jsaga.impl.job.streaming;
2
3 import java.io.File;
4 import java.io.FileNotFoundException;
5 import java.io.FileOutputStream;
6 import java.io.IOException;
7 import java.io.InputStream;
8 import java.io.OutputStream;
9 import java.util.Map;
10
11 import org.ogf.saga.error.AuthenticationFailedException;
12 import org.ogf.saga.error.AuthorizationFailedException;
13 import org.ogf.saga.error.BadParameterException;
14 import org.ogf.saga.error.IncorrectStateException;
15 import org.ogf.saga.error.IncorrectURLException;
16 import org.ogf.saga.error.NoSuccessException;
17 import org.ogf.saga.error.NotImplementedException;
18 import org.ogf.saga.error.PermissionDeniedException;
19 import org.ogf.saga.error.TimeoutException;
20 import fr.in2p3.jsaga.adaptor.base.defaults.Default;
21 import fr.in2p3.jsaga.adaptor.base.usage.Usage;
22 import fr.in2p3.jsaga.adaptor.job.BadResource;
23 import fr.in2p3.jsaga.adaptor.job.control.JobControlAdaptor;
24 import fr.in2p3.jsaga.adaptor.job.control.description.JobDescriptionTranslator;
25 import fr.in2p3.jsaga.adaptor.job.control.interactive.JobIOHandler;
26 import fr.in2p3.jsaga.adaptor.job.control.interactive.StreamableJobBatch;
27 import fr.in2p3.jsaga.adaptor.job.control.staging.StagingJobAdaptor;
28 import fr.in2p3.jsaga.adaptor.job.monitor.JobMonitorAdaptor;
29 import fr.in2p3.jsaga.adaptor.security.SecurityCredential;
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 public class GenericStreamableJobAdaptor implements StreamableJobBatch {
45
46 private StagingJobAdaptor m_adaptor;
47
48 public GenericStreamableJobAdaptor(StagingJobAdaptor adaptor) {
49 m_adaptor = adaptor;
50 }
51
52 public JobIOHandler submit(String jobDesc, boolean checkMatch,
53 String uniqId, InputStream stdin) throws PermissionDeniedException,
54 TimeoutException, NoSuccessException {
55 File input = LocalFileFactory.getLocalInputFile(uniqId);
56 OutputStream out;
57 try {
58 out = new FileOutputStream(input);
59 if (stdin != null) {
60 int n;
61 byte[] buffer = new byte[1024];
62 while ((n = stdin.read(buffer)) != -1) {
63 out.write(buffer, 0, n);
64 }
65 } else {
66 out.write(' ');
67 }
68 out.close();
69 } catch (FileNotFoundException e) {
70 e.printStackTrace();
71 } catch (IOException e) {
72 throw new NoSuccessException("Standard input could not be written to local file: " + input);
73 }
74 String jobId = m_adaptor.submit(jobDesc, checkMatch, uniqId);
75 return new GenericJobIOHandler(jobId, uniqId);
76 }
77
78
79
80
81
82 public JobDescriptionTranslator getJobDescriptionTranslator()
83 throws NoSuccessException {
84 return m_adaptor.getJobDescriptionTranslator();
85 }
86
87 public JobMonitorAdaptor getDefaultJobMonitor() {
88 return m_adaptor.getDefaultJobMonitor();
89 }
90
91 public String submit(String jobDesc, boolean checkMatch, String uniqId)
92 throws PermissionDeniedException, TimeoutException,
93 NoSuccessException, BadResource {
94 return m_adaptor.submit(jobDesc, checkMatch, uniqId);
95 }
96
97 public void cancel(String nativeJobId) throws PermissionDeniedException,
98 TimeoutException, NoSuccessException {
99 m_adaptor.cancel(nativeJobId);
100 }
101
102 public Class[] getSupportedSecurityCredentialClasses() {
103 return m_adaptor.getSupportedSecurityCredentialClasses();
104 }
105
106 public void setSecurityCredential(SecurityCredential credential) {
107 m_adaptor.setSecurityCredential(credential);
108 }
109
110 public int getDefaultPort() {
111 return m_adaptor.getDefaultPort();
112 }
113
114 public void connect(String userInfo, String host, int port,
115 String basePath, Map attributes) throws NotImplementedException,
116 AuthenticationFailedException, AuthorizationFailedException,
117 IncorrectURLException, BadParameterException, TimeoutException,
118 NoSuccessException {
119 m_adaptor.connect(userInfo, host, port, basePath, attributes);
120 }
121
122 public void disconnect() throws NoSuccessException {
123 m_adaptor.disconnect();
124 }
125
126 public String getType() {
127 return m_adaptor.getType();
128 }
129
130 public Usage getUsage() {
131 return m_adaptor.getUsage();
132 }
133
134 public Default[] getDefaults(Map attributes) throws IncorrectStateException {
135 return m_adaptor.getDefaults(attributes);
136 }
137
138 }