1 package fr.in2p3.jsaga.adaptor.job;
2
3 import fr.in2p3.jsaga.adaptor.ClientAdaptor;
4 import fr.in2p3.jsaga.adaptor.security.SecurityCredential;
5 import fr.in2p3.jsaga.adaptor.security.impl.GSSCredentialSecurityCredential;
6 import org.globus.common.CoGProperties;
7 import org.globus.gram.*;
8 import org.globus.gram.internal.GRAMProtocolErrorConstants;
9 import org.ietf.jgss.GSSCredential;
10 import org.ietf.jgss.GSSException;
11 import org.ogf.saga.error.*;
12
13 import java.net.MalformedURLException;
14 import java.util.Map;
15
16
17
18
19
20
21
22
23
24
25
26 public abstract class GatekeeperJobAdaptorAbstract implements ClientAdaptor {
27 protected GSSCredential m_credential;
28 protected String m_serverUrl;
29 protected static final String IP_ADDRESS = "IPAddress";
30 protected static final String TCP_PORT_RANGE = "TcpPortRange";
31
32 public Class[] getSupportedSecurityCredentialClasses() {
33 return new Class[]{GSSCredentialSecurityCredential.class};
34 }
35
36 public void setSecurityCredential(SecurityCredential credential) {
37 m_credential = ((GSSCredentialSecurityCredential) credential).getGSSCredential();
38 }
39
40 public int getDefaultPort() {
41 return 2119;
42 }
43
44 public void connect(String userInfo, String host, int port, String basePath, Map attributes) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, BadParameterException, TimeoutException, NoSuccessException {
45 if(basePath.indexOf("=") > -1)
46 m_serverUrl = host+":"+port+":"+basePath;
47 else
48 m_serverUrl = host+":"+port+basePath;
49
50 if (attributes!=null && attributes.containsKey(IP_ADDRESS)) {
51 String value = ((String) attributes.get(IP_ADDRESS));
52 CoGProperties loadedCogProperties= CoGProperties.getDefault();
53 loadedCogProperties.setIPAddress(value);
54 CoGProperties.setDefault(loadedCogProperties);
55 }
56
57 if (attributes!=null && attributes.containsKey(TCP_PORT_RANGE)) {
58 String value = ((String) attributes.get(TCP_PORT_RANGE));
59 CoGProperties loadedCogProperties= CoGProperties.getDefault();
60 loadedCogProperties.setProperty("tcp.port.range", value);
61 CoGProperties.setDefault(loadedCogProperties);
62 }
63 if("true".equalsIgnoreCase((String) attributes.get(JobAdaptor.CHECK_AVAILABILITY))) {
64 try {
65 Gram.ping(m_credential, m_serverUrl);
66 } catch (GramException e) {
67 switch(e.getErrorCode()) {
68 case GRAMProtocolErrorConstants.ERROR_PROTOCOL_FAILED:
69 Throwable cause = e.getException();
70 if (cause!=null && cause.getMessage()!=null && cause.getMessage().startsWith("Authentication failed")) {
71 throw new AuthenticationFailedException(cause);
72 } else {
73 throw new NoSuccessException(e);
74 }
75 case GRAMProtocolErrorConstants.ERROR_AUTHORIZATION:
76 throw new AuthorizationFailedException(e);
77 case GRAMProtocolErrorConstants.INVALID_JOB_CONTACT:
78 case GRAMProtocolErrorConstants.ERROR_CONNECTION_FAILED:
79 throw new TimeoutException(e);
80 default:
81 throw new NoSuccessException(e);
82 }
83 } catch (GSSException e) {
84 throw new AuthenticationFailedException(e);
85 }
86 }
87 }
88
89 public void disconnect() throws NoSuccessException {
90 m_serverUrl = null;
91 }
92
93
94 protected GramJob getGramJobById(String nativeJobId) throws NoSuccessException {
95 GramJob job = new GramJob(m_credential, null);
96 try {
97 job.setID(nativeJobId);
98 } catch (MalformedURLException e) {
99 throw new NoSuccessException(e);
100 }
101 return job;
102 }
103 }