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