1 package fr.in2p3.jsaga.adaptor.data;
2
3 import fr.in2p3.jsaga.adaptor.base.defaults.Default;
4 import fr.in2p3.jsaga.adaptor.base.usage.Usage;
5 import fr.in2p3.jsaga.adaptor.data.optimise.DataCopy;
6 import fr.in2p3.jsaga.adaptor.data.optimise.DataCopyMonitor;
7 import fr.in2p3.jsaga.adaptor.data.optimise.DataRename;
8 import fr.in2p3.jsaga.adaptor.data.read.FileAttributes;
9 import fr.in2p3.jsaga.adaptor.data.read.FileReaderStreamFactory;
10 import fr.in2p3.jsaga.adaptor.data.write.FileWriterStreamFactory;
11 import fr.in2p3.jsaga.adaptor.security.SecurityCredential;
12 import org.globus.ftp.FeatureList;
13 import org.globus.ftp.exception.ServerException;
14 import org.ogf.saga.error.*;
15 import org.ogf.saga.task.Task;
16
17 import java.io.*;
18 import java.util.Map;
19
20
21
22
23
24
25
26
27
28
29
30
31
32 public class GsiftpDataAdaptor implements DataCopy, DataRename, FileReaderStreamFactory, FileWriterStreamFactory
33 {
34 private GsiftpDataAdaptorAbstract m_adaptor;
35
36 public GsiftpDataAdaptor() {
37 m_adaptor = new GsiftpDefaultDataAdaptor();
38 }
39
40 public String getType() {
41 return "gsiftp";
42 }
43
44 public Usage getUsage() {
45 return m_adaptor.getUsage();
46 }
47
48 public Default[] getDefaults(Map attributes) throws IncorrectStateException {
49 return m_adaptor.getDefaults(attributes);
50 }
51
52 public Class[] getSupportedSecurityCredentialClasses() {
53 return m_adaptor.getSupportedSecurityCredentialClasses();
54 }
55
56 public void setSecurityCredential(SecurityCredential credential) {
57 m_adaptor.setSecurityCredential(credential);
58 }
59
60 public int getDefaultPort() {
61 return m_adaptor.getDefaultPort();
62 }
63
64 public void connect(String userInfo, String host, int port, String basePath, Map attributes) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, BadParameterException, TimeoutException, NoSuccessException {
65
66 m_adaptor.connect(userInfo, host, port, null, attributes);
67
68
69 FeatureList fl;
70 try {
71 fl = m_adaptor.m_client.getFeatureList();
72 } catch (IOException e) {
73 throw new NoSuccessException(e);
74 } catch (ServerException e) {
75 throw new NoSuccessException(e);
76 }
77
78
79 GsiftpDataAdaptorAbstract sav = m_adaptor;
80 if (fl.contains(FeatureList.PARALLEL) && fl.contains(FeatureList.SIZE) && fl.contains(FeatureList.ERET) && fl.contains(FeatureList.ESTO)) {
81
82 if (fl.contains(FeatureList.DCAU) && fl.contains(FeatureList.MDTM) && fl.contains("REST STREAM")) {
83
84 if (fl.contains("SPAS") && fl.contains("SPOR")) {
85
86 m_adaptor = new Gsiftp2DataAdaptor();
87 } else {
88
89 m_adaptor = new Gsiftp1DataAdaptor();
90 }
91 } else if (fl.contains(FeatureList.SBUF) && fl.contains("EOF")) {
92
93
94 m_adaptor = new GsiftpDCacheDataAdaptor();
95 }
96 } else {
97 throw new NotImplementedException("Unsupported server implementation");
98 }
99 m_adaptor.m_client = sav.m_client;
100 m_adaptor.m_credential = sav.m_credential;
101 }
102
103 public void disconnect() throws NoSuccessException {
104 m_adaptor.disconnect();
105 }
106
107 public boolean exists(String absolutePath, String additionalArgs) throws PermissionDeniedException, TimeoutException, NoSuccessException {
108 return m_adaptor.exists(absolutePath, additionalArgs);
109 }
110
111 public InputStream getInputStream(String absolutePath, String additionalArgs) throws PermissionDeniedException, BadParameterException, DoesNotExistException, TimeoutException, NoSuccessException {
112 return m_adaptor.getInputStream(absolutePath, additionalArgs);
113 }
114
115 public OutputStream getOutputStream(String parentAbsolutePath, String fileName, boolean exclusive, boolean append, String additionalArgs) throws PermissionDeniedException, BadParameterException, AlreadyExistsException, ParentDoesNotExist, TimeoutException, NoSuccessException {
116 return m_adaptor.getOutputStream(parentAbsolutePath, fileName, exclusive, append, additionalArgs);
117 }
118
119 public void copy(String sourceAbsolutePath, String targetHost, int targetPort, String targetAbsolutePath, boolean overwrite, String additionalArgs, DataCopyMonitor progressMonitor) throws AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, AlreadyExistsException, DoesNotExistException, ParentDoesNotExist, TimeoutException, NoSuccessException {
120 m_adaptor.copy(sourceAbsolutePath, targetHost, targetPort, targetAbsolutePath, overwrite, additionalArgs, progressMonitor);
121 }
122
123 public void copyFrom(String sourceHost, int sourcePort, String sourceAbsolutePath, String targetAbsolutePath, boolean overwrite, String additionalArgs) throws AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
124 m_adaptor.copyFrom(sourceHost, sourcePort, sourceAbsolutePath, targetAbsolutePath, overwrite, additionalArgs);
125 }
126
127 public void rename(String sourceAbsolutePath, String targetAbsolutePath, boolean overwrite, String additionalArgs) throws PermissionDeniedException, BadParameterException, DoesNotExistException, AlreadyExistsException, TimeoutException, NoSuccessException {
128 m_adaptor.rename(sourceAbsolutePath, targetAbsolutePath, overwrite, additionalArgs);
129 }
130
131 public void removeFile(String parentAbsolutePath, String fileName, String additionalArgs) throws PermissionDeniedException, BadParameterException, DoesNotExistException, TimeoutException, NoSuccessException {
132 m_adaptor.removeFile(parentAbsolutePath, fileName, additionalArgs);
133 }
134
135 public FileAttributes getAttributes(String absolutePath, String additionalArgs) throws PermissionDeniedException, DoesNotExistException, TimeoutException, NoSuccessException {
136 return m_adaptor.getAttributes(absolutePath, additionalArgs);
137 }
138
139 public FileAttributes[] listAttributes(String absolutePath, String additionalArgs) throws PermissionDeniedException, DoesNotExistException, TimeoutException, NoSuccessException {
140 return m_adaptor.listAttributes(absolutePath, additionalArgs);
141 }
142
143 public void makeDir(String parentAbsolutePath, String directoryName, String additionalArgs) throws PermissionDeniedException, BadParameterException, AlreadyExistsException, ParentDoesNotExist, TimeoutException, NoSuccessException {
144 m_adaptor.makeDir(parentAbsolutePath, directoryName, additionalArgs);
145 }
146
147 public void removeDir(String parentAbsolutePath, String directoryName, String additionalArgs) throws PermissionDeniedException, BadParameterException, DoesNotExistException, TimeoutException, NoSuccessException {
148 m_adaptor.removeDir(parentAbsolutePath, directoryName, additionalArgs);
149 }
150 }