View Javadoc

1   package fr.in2p3.jsaga.impl;
2   
3   import fr.in2p3.jsaga.EngineProperties;
4   import fr.in2p3.jsaga.engine.config.ConfigurationException;
5   import fr.in2p3.jsaga.engine.descriptors.AdaptorDescriptors;
6   import fr.in2p3.jsaga.engine.factories.*;
7   import fr.in2p3.jsaga.engine.session.SessionConfiguration;
8   import fr.in2p3.jsaga.impl.buffer.BufferFactoryImpl;
9   import fr.in2p3.jsaga.impl.context.ContextFactoryImpl;
10  import fr.in2p3.jsaga.impl.file.FileFactoryImpl;
11  import fr.in2p3.jsaga.impl.job.JobFactoryImpl;
12  import fr.in2p3.jsaga.impl.logicalfile.LogicalFileFactoryImpl;
13  import fr.in2p3.jsaga.impl.monitoring.MonitoringFactoryImpl;
14  import fr.in2p3.jsaga.impl.namespace.NSFactoryImpl;
15  import fr.in2p3.jsaga.impl.resource.ResourceFactoryImpl;
16  import fr.in2p3.jsaga.impl.session.SessionFactoryImpl;
17  import fr.in2p3.jsaga.impl.task.TaskFactoryImpl;
18  import fr.in2p3.jsaga.impl.url.URLFactoryImpl;
19  import org.apache.log4j.Logger;
20  import org.apache.log4j.PropertyConfigurator;
21  import org.ogf.saga.bootstrap.SagaFactory;
22  import org.ogf.saga.buffer.BufferFactory;
23  import org.ogf.saga.context.ContextFactory;
24  import org.ogf.saga.error.NotImplementedException;
25  import org.ogf.saga.file.FileFactory;
26  import org.ogf.saga.isn.ISNFactory;
27  import org.ogf.saga.job.JobFactory;
28  import org.ogf.saga.logicalfile.LogicalFileFactory;
29  import org.ogf.saga.monitoring.MonitoringFactory;
30  import org.ogf.saga.namespace.NSFactory;
31  import org.ogf.saga.resource.ResourceFactory;
32  import org.ogf.saga.rpc.RPCFactory;
33  import org.ogf.saga.sd.SDFactory;
34  import org.ogf.saga.session.SessionFactory;
35  import org.ogf.saga.stream.StreamFactory;
36  import org.ogf.saga.task.TaskFactory;
37  import org.ogf.saga.url.URLFactory;
38  
39  import java.io.File;
40  import java.io.IOException;
41  import java.io.InputStream;
42  import java.net.URL;
43  import java.util.Properties;
44  
45  /* ***************************************************
46  * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
47  * ***             http://cc.in2p3.fr/             ***
48  * ***************************************************
49  * File:   SagaFactoryImpl
50  * Author: Sylvain Reynaud (sreynaud@in2p3.fr)
51  * Date:   17 sept. 2007
52  * ***************************************************
53  * Description:                                      */
54  /**
55   *
56   */
57  public class SagaFactoryImpl implements SagaFactory {
58      private SessionConfiguration m_config;
59  
60      // security
61      private SecurityAdaptorFactory m_securityAdaptorFactory;
62      // data
63      private DataAdaptorFactory m_dataAdaptorFactory;
64      // job
65      private JobAdaptorFactory m_jobAdaptorFactory;
66      private JobMonitorAdaptorFactory m_jobMonitorAdaptorFactory;
67      // Resource
68      private ResourceAdaptorFactory m_resourceAdaptorFactory;
69      
70      public SagaFactoryImpl() throws ConfigurationException {
71          // configure log4j
72          URL log4jCfgURL = EngineProperties.getURL(EngineProperties.LOG4J_CONFIGURATION);
73          if (log4jCfgURL != null) {
74              Properties prop = new Properties();
75              try {
76                  InputStream log4jCfgStream = log4jCfgURL.openStream();
77                  prop.load(log4jCfgStream);
78                  log4jCfgStream.close();
79              } catch (IOException e) {
80                  Logger.getLogger(SagaFactoryImpl.class).warn("Failed to load log4j properties, using defaults ["+e.getMessage()+"]");
81              }
82              PropertyConfigurator.configure(prop);
83          }
84          if (EngineProperties.getException() != null) {
85              Logger.getLogger(SagaFactoryImpl.class).warn("Failed to load engine properties, using defaults ["+EngineProperties.getException().getMessage()+"]");
86          }
87  
88          // configure adaptors factories
89          URL url = EngineProperties.getURL(EngineProperties.JSAGA_DEFAULT_CONTEXTS);
90          m_config = new SessionConfiguration(url);
91  
92          /* set javax.net.ssl.keyStore
93           * 1. Search for user value in configuration or property and setProperty
94           * 2. If no user value, check if file "~/.jsaga/.keystore" exists and setProperty
95           * 3. If it does not exist, do not setProperty
96           */
97          String keystore_path = EngineProperties.getProperty(EngineProperties.JAVAX_NET_SSL_KEYSTORE);
98          if (keystore_path == null) {
99          	File jsaga_keystore = new File(System.getProperty("user.home")+"/.jsaga/.keystore");
100         	if (jsaga_keystore.exists()) {
101         		System.setProperty(EngineProperties.JAVAX_NET_SSL_KEYSTORE, jsaga_keystore.getPath());
102         	}
103         }
104         /* set javax.net.ssl.keyStorePassword */
105         String keystore_pass = EngineProperties.getProperty(EngineProperties.JAVAX_NET_SSL_KEYSTOREPASSWORD);
106         if (keystore_pass != null) System.setProperty(EngineProperties.JAVAX_NET_SSL_KEYSTOREPASSWORD, keystore_pass);
107         
108         /* set javax.net.ssl.trustStore
109          * 1. Search for user value in configuration or property and setProperty
110          * 2. If no user value, check if file "~/.jsaga/.keystore" exists and setProperty
111          * 3. If it does not exist, do not setProperty
112          */
113         String truststore_path = EngineProperties.getProperty(EngineProperties.JAVAX_NET_SSL_TRUSTSTORE);
114         if (truststore_path == null) {
115         	File jsaga_keystore = new File(System.getProperty("user.home")+"/.jsaga/.keystore");
116         	if (jsaga_keystore.exists()) {
117         		System.setProperty(EngineProperties.JAVAX_NET_SSL_TRUSTSTORE, jsaga_keystore.getPath());
118         	}
119         }
120         /* set javax.net.ssl.trustStorePassword */
121         String truststore_pass = EngineProperties.getProperty(EngineProperties.JAVAX_NET_SSL_TRUSTSTOREPASSWORD);
122         if (truststore_pass != null) System.setProperty(EngineProperties.JAVAX_NET_SSL_TRUSTSTOREPASSWORD, truststore_pass);
123         
124         /* jsse.enableCBCProtection should be false Bug 5893 */
125         System.setProperty("jsse.enableCBCProtection", "false");
126         
127         AdaptorDescriptors descriptors = AdaptorDescriptors.getInstance();
128         m_securityAdaptorFactory = new SecurityAdaptorFactory(descriptors);
129         m_dataAdaptorFactory = new DataAdaptorFactory(descriptors);
130         m_jobAdaptorFactory = new JobAdaptorFactory(descriptors);
131         m_jobMonitorAdaptorFactory = new JobMonitorAdaptorFactory();
132         m_resourceAdaptorFactory = new ResourceAdaptorFactory(descriptors);
133     }
134 
135     public BufferFactory createBufferFactory() {
136         return new BufferFactoryImpl();
137     }
138 
139     public ContextFactory createContextFactory() {
140         return new ContextFactoryImpl(m_config, m_securityAdaptorFactory);
141     }
142 
143     public FileFactory createFileFactory() {
144         return new FileFactoryImpl(m_dataAdaptorFactory);
145     }
146 
147     public JobFactory createJobFactory() throws NotImplementedException {
148         return new JobFactoryImpl(m_jobAdaptorFactory, m_jobMonitorAdaptorFactory);
149     }
150 
151     public LogicalFileFactory createLogicalFileFactory() throws NotImplementedException {
152         return new LogicalFileFactoryImpl(m_dataAdaptorFactory);
153     }
154 
155     public MonitoringFactory createMonitoringFactory() throws NotImplementedException {
156         return new MonitoringFactoryImpl();
157     }
158 
159     public NSFactory createNamespaceFactory() throws NotImplementedException {
160         return new NSFactoryImpl(m_dataAdaptorFactory);
161     }
162 
163     public RPCFactory createRPCFactory() throws NotImplementedException {
164         throw new NotImplementedException("Not implemented by the SAGA engine");
165     }
166 
167     public SDFactory createSDFactory() throws NotImplementedException {
168         throw new NotImplementedException("Not implemented by the SAGA engine");
169     }
170 
171     public ISNFactory createISNFactory() throws NotImplementedException {
172         throw new NotImplementedException("Not implemented by the SAGA engine");
173     }
174 
175     public ResourceFactory createResourceFactory() throws NotImplementedException {
176         return new ResourceFactoryImpl(m_resourceAdaptorFactory);
177     }
178 
179     public SessionFactory createSessionFactory() {
180         return new SessionFactoryImpl(m_config);
181     }
182 
183     public StreamFactory createStreamFactory() throws NotImplementedException {
184         throw new NotImplementedException("Not implemented by the SAGA engine");
185     }
186 
187     public TaskFactory createTaskFactory() throws NotImplementedException {
188         return new TaskFactoryImpl();
189     }
190 
191     public URLFactory createURLFactory() {
192         return new URLFactoryImpl();
193     }
194 }