1 package fr.in2p3.jsaga.engine.factories;
2
3 import fr.in2p3.jsaga.adaptor.ClientAdaptor;
4 import fr.in2p3.jsaga.adaptor.base.usage.U;
5 import fr.in2p3.jsaga.adaptor.base.usage.UAnd;
6 import fr.in2p3.jsaga.adaptor.base.usage.UOptional;
7 import fr.in2p3.jsaga.adaptor.base.usage.Usage;
8 import fr.in2p3.jsaga.adaptor.job.JobAdaptor;
9 import fr.in2p3.jsaga.adaptor.job.control.JobControlAdaptor;
10 import fr.in2p3.jsaga.adaptor.security.SecurityCredential;
11 import fr.in2p3.jsaga.engine.descriptors.AdaptorDescriptors;
12 import fr.in2p3.jsaga.engine.descriptors.JobAdaptorDescriptor;
13 import fr.in2p3.jsaga.impl.context.ContextImpl;
14 import org.ogf.saga.error.*;
15 import org.ogf.saga.url.URL;
16
17 import java.util.Map;
18
19
20
21
22
23
24
25
26
27
28
29
30
31 public class JobAdaptorFactory extends ServiceAdaptorFactory {
32 private JobAdaptorDescriptor m_descriptor;
33
34 public JobAdaptorFactory(AdaptorDescriptors descriptors) {
35 m_descriptor = descriptors.getJobDesc();
36 }
37
38 public JobControlAdaptor getJobControlAdaptor(URL url, ContextImpl context) throws NotImplementedException, IncorrectURLException, NoSuccessException {
39 if (url==null || url.getScheme()==null) {
40 throw new IncorrectURLException("No protocol found in URL: "+url);
41 }
42
43
44 String scheme = context.getSchemeFromAlias(url.getScheme());
45 Class clazz = m_descriptor.getClass(scheme);
46 try {
47 return (JobControlAdaptor) clazz.newInstance();
48 } catch (Exception e) {
49 throw new NoSuccessException(e);
50 }
51 }
52
53 public Map getAttribute(URL url, ContextImpl context) throws NotImplementedException, NoSuccessException {
54 String scheme = context.getSchemeFromAlias(url.getScheme());
55 try {
56 return getAttributes(url, context, m_descriptor.getDefaultsMap(scheme), ContextImpl.JOB_SERVICE_ATTRIBUTES);
57 } catch (BadParameterException e) {
58 throw new NoSuccessException(e);
59 }
60 }
61
62 public void connect(URL url, JobControlAdaptor jobAdaptor, Map attributes, ContextImpl context) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, IncorrectURLException, BadParameterException, TimeoutException, NoSuccessException {
63
64 SecurityCredential credential = getCredential(url, context, jobAdaptor);
65
66 this.checkAttributesValidity(attributes, jobAdaptor.getUsage());
67
68
69 connect(jobAdaptor, credential, url, attributes);
70 }
71
72 public static void connect(JobControlAdaptor jobAdaptor, SecurityCredential credential, URL url, Map attributes) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, IncorrectURLException, BadParameterException, TimeoutException, NoSuccessException {
73
74 if (url.getPort()<=0 && jobAdaptor.getDefaultPort() == ClientAdaptor.NO_DEFAULT) {
75 throw new BadParameterException("Missing PORT in URL:" + url.getString());
76 }
77 jobAdaptor.setSecurityCredential(credential);
78 jobAdaptor.connect(
79 url.getUserInfo(),
80 url.getHost(),
81 url.getPort()>0 ? url.getPort() : jobAdaptor.getDefaultPort(),
82 url.getPath(),
83 attributes);
84 }
85 public static void disconnect(JobControlAdaptor jobAdaptor) throws NoSuccessException {
86 jobAdaptor.disconnect();
87 }
88 }