Author: [email protected]
Date: Wed Mar 2 15:34:55 2011
New Revision: 856
Log:
[AMDATU-258] Fixes for war deployment. Using relative paths cannot be supported
in WAR deployment so refactored relative paths to absolute path in case a
system property "amdatu.dir" is provided.
Added:
branches/0.2/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/module/AmdatuContainerConfig.java
Modified:
branches/0.2/amdatu-authentication/oauth-consumerregistry-fs/src/main/java/org/amdatu/authentication/oauth/consumerregistry/fs/service/FSConsumerRegistryImpl.java
branches/0.2/amdatu-cassandra/cassandra-application/src/main/java/org/amdatu/cassandra/application/CassandraConfigurationService.java
branches/0.2/amdatu-cassandra/cassandra-application/src/main/java/org/amdatu/cassandra/application/service/CassandraConfigurationServiceImpl.java
branches/0.2/amdatu-cassandra/cassandra-application/src/main/resources/conf/log4j.properties
branches/0.2/amdatu-cassandra/cassandra-persistencemanager/src/main/java/org/amdatu/cassandra/persistencemanager/service/CassandraPersistenceManagerFactoryImpl.java
branches/0.2/amdatu-core/config-filebased/src/main/resources/conf/org.amdatu.core.cassandra.application.cfg
branches/0.2/amdatu-core/config-templates/src/main/java/org/amdatu/core/config/templates/service/ConfigTemplateManagerImpl.java
branches/0.2/amdatu-core/tenantstore-fs/src/main/java/org/amdatu/core/tenantstore/fs/service/FSTenantStorageProvider.java
branches/0.2/amdatu-core/useradminstore-fs/src/main/java/org/amdatu/core/useradminstore/fs/service/FSUserAdminStorageProvider.java
branches/0.2/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/module/OAuthModuleImpl.java
branches/0.2/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/service/ShindigRegistrationServiceImpl.java
branches/0.2/amdatu-release/pom.xml
branches/0.2/amdatu-release/src/main/java/org/amdatu/webapp/FrameworkService.java
branches/0.2/amdatu-release/src/main/java/org/amdatu/webapp/ProvisionActivator.java
branches/0.2/amdatu-release/src/main/java/org/amdatu/webapp/StartupListener.java
branches/0.2/amdatu-release/src/main/webapp/framework.properties
branches/0.2/amdatu-semanticweb/sesame/src/main/java/org/amdatu/semanticweb/sesame/service/SesameServiceImpl.java
branches/0.2/pom.xml
Modified:
branches/0.2/amdatu-authentication/oauth-consumerregistry-fs/src/main/java/org/amdatu/authentication/oauth/consumerregistry/fs/service/FSConsumerRegistryImpl.java
==============================================================================
---
branches/0.2/amdatu-authentication/oauth-consumerregistry-fs/src/main/java/org/amdatu/authentication/oauth/consumerregistry/fs/service/FSConsumerRegistryImpl.java
(original)
+++
branches/0.2/amdatu-authentication/oauth-consumerregistry-fs/src/main/java/org/amdatu/authentication/oauth/consumerregistry/fs/service/FSConsumerRegistryImpl.java
Wed Mar 2 15:34:55 2011
@@ -66,8 +66,14 @@
public synchronized void setDataDirectory(File dataDirectory) throws
ConsumerRegistryStorageException {
if (!dataDirectory.isAbsolute()) {
- File userDirectory = new File(System.getProperty("user.dir"));
- dataDirectory = new File(userDirectory, dataDirectory.getPath());
+ // If amdatu.dir is provided as System property, use this as base
directory instead of the current directory
+ File baseDirectory;
+ if (System.getProperty("amdatu.dir") != null) {
+ baseDirectory = new File(System.getProperty("amdatu.dir"));
+ } else {
+ baseDirectory = new File(System.getProperty("user.dir"));
+ }
+ dataDirectory = new File(baseDirectory, dataDirectory.getPath());
}
if (!((dataDirectory.exists() && dataDirectory.canRead() &&
dataDirectory.canWrite()) || dataDirectory.mkdirs())) {
throw new ConsumerRegistryStorageException("Unable to access data
directory: "
Modified:
branches/0.2/amdatu-cassandra/cassandra-application/src/main/java/org/amdatu/cassandra/application/CassandraConfigurationService.java
==============================================================================
---
branches/0.2/amdatu-cassandra/cassandra-application/src/main/java/org/amdatu/cassandra/application/CassandraConfigurationService.java
(original)
+++
branches/0.2/amdatu-cassandra/cassandra-application/src/main/java/org/amdatu/cassandra/application/CassandraConfigurationService.java
Wed Mar 2 15:34:55 2011
@@ -43,6 +43,26 @@
* Configuration key for the working directory to use for Cassandra
*/
public static final String CONFIG_WORKDIR = "workdir";
+
+ /**
+ * Configuration key for the commit log directory to use for Cassandra
+ */
+ public static final String COMMITLOG_DIR = "commitlogdir";
+
+ /**
+ * Configuration key for the datafile directory to use for Cassandra
+ */
+ public static final String DATAFILE_DIR = "datafiledir";
+
+ /**
+ * Configuration key for the saved caches directory to use for Cassandra
+ */
+ public static final String SAVEDCACHES_DIR = "savedcachesdir";
+
+ /**
+ * Configuration key for the log4j log directory to use for Cassandra
+ */
+ public static final String LOG4JLOG_DIR = "log4j.systemlog";
/**
* Configuration key for the default replication factor
Modified:
branches/0.2/amdatu-cassandra/cassandra-application/src/main/java/org/amdatu/cassandra/application/service/CassandraConfigurationServiceImpl.java
==============================================================================
---
branches/0.2/amdatu-cassandra/cassandra-application/src/main/java/org/amdatu/cassandra/application/service/CassandraConfigurationServiceImpl.java
(original)
+++
branches/0.2/amdatu-cassandra/cassandra-application/src/main/java/org/amdatu/cassandra/application/service/CassandraConfigurationServiceImpl.java
Wed Mar 2 15:34:55 2011
@@ -64,7 +64,8 @@
*/
public void init() {
m_logService.log(LogService.LOG_DEBUG, "Preparing Cassandra
configuration");
-
+ m_logService.log(LogService.LOG_INFO, "Cassandra work directory=" +
m_workDir.getAbsolutePath());
+
// Initialize storage configuration
// Load the URL of the storage-conf.xml and write it file using the
config template
// manager, which automatically replaces configuration entries in that
file
@@ -87,7 +88,7 @@
File log4jPropertiesFile = new File(m_workDir,
CassandraConfigurationService.LOG4J_CONF_TARGET);
url = bundle.getResource(LOG4J_CONF_SOURCE);
try {
- m_configTemplateManager.writeConfiguration(url,
log4jPropertiesFile);
+ m_configTemplateManager.writeConfiguration(url,
log4jPropertiesFile, new CassandraCallbackHandler());
PropertyConfigurator.configure(log4jPropertiesFile.getAbsolutePath());
System.setProperty("log4j.configuration",
log4jPropertiesFile.toURI().toString());
log4jPropertiesFile.deleteOnExit();
@@ -99,7 +100,7 @@
// cassandra-foreground must be set to true, otherwise Cassandra will
close System err and out streams such
// that entries will not be visible in the console anymore.
System.setProperty("cassandra-foreground", "true");
-
+
// Disable Hector statistics gathering
System.setProperty("com.prettyprint.cassandra.load_hector_log4j",
"true");
@@ -107,13 +108,12 @@
}
@SuppressWarnings("rawtypes")
- public void updated(Dictionary dictionary) throws
ConfigurationException {
+ public void updated(Dictionary dictionary) throws ConfigurationException {
if (dictionary != null) {
if (dictionary.get(CONFIG_WORKDIR) == null) {
throw new ConfigurationException("Missing configuration key",
CONFIG_WORKDIR);
}
- File workBaseDir = new File(System.getProperty("user.dir"),
"work");
- m_workDir = new File(workBaseDir, (String)
dictionary.get(CONFIG_WORKDIR));
+ m_workDir = relativeToAbsolute((String)
dictionary.get(CONFIG_WORKDIR));
m_defaultReplicationFactor =
Integer.parseInt(dictionary.get(DEFAULT_REPLICATION_FACTOR).toString());
m_readConsistencyLevel =
ConsistencyLevel.valueOf(dictionary.get(READ_CONSISTENCY_LEVEL).toString());
m_writeConsistencyLevel =
ConsistencyLevel.valueOf(dictionary.get(WRITE_CONSISTENCY_LEVEL).toString());
@@ -127,7 +127,24 @@
}
}
+ private File relativeToAbsolute(String workDir) {
+ File file = new File(workDir);
+ if (!file.isAbsolute()) {
+ // If amdatu.dir is provided as System property, use that as base
directory. Otherwise use the current
+ // directory as base directory
+ if (System.getProperty("amdatu.dir") != null) {
+ return new File(new File(System.getProperty("amdatu.dir"),
"work"), workDir);
+ } else {
+ return new File(new File(System.getProperty("user.dir"),
"work"), workDir);
+ }
+ } else {
+ return file;
+ }
+ }
+
class CassandraCallbackHandler implements ConfigTemplateCallbackHandler {
+ private String m_amdatuDir = System.getProperty("amdatu.dir");
+
public String getValue(String pid, String property, Object
configValue) {
if (CassandraConfigurationService.PID.equals(pid) &&
CassandraConfigurationService.SEEDS.equals(property)) {
// We must convert the comma separated list of IP addresses to
the cassandra yaml format
@@ -137,11 +154,20 @@
result += EOL + "- " + seed;
}
return result;
+ } else if (CassandraConfigurationService.PID.equals(pid) &&
m_amdatuDir != null) {
+ if
(CassandraConfigurationService.CONFIG_WORKDIR.equals(property)
+ ||
CassandraConfigurationService.COMMITLOG_DIR.equals(property)
+ ||
CassandraConfigurationService.DATAFILE_DIR.equals(property)
+ ||
CassandraConfigurationService.SAVEDCACHES_DIR.equals(property)
+ ||
CassandraConfigurationService.LOG4JLOG_DIR.equals(property)) {
+ // If amdatu.dir is provided as a system property, convert
the directories to absolute directories
+ String dir = m_amdatuDir + File.separator +
configValue.toString();
+ dir = dir.replace("\\", "/");
+ return dir;
+ }
}
- else {
- // Return the value as-is
- return configValue.toString();
- }
+ // Return the value as-is
+ return configValue.toString();
}
}
Modified:
branches/0.2/amdatu-cassandra/cassandra-application/src/main/resources/conf/log4j.properties
==============================================================================
---
branches/0.2/amdatu-cassandra/cassandra-application/src/main/resources/conf/log4j.properties
(original)
+++
branches/0.2/amdatu-cassandra/cassandra-application/src/main/resources/conf/log4j.properties
Wed Mar 2 15:34:55 2011
@@ -31,7 +31,7 @@
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%5p [%t] %d{ISO8601} %F (line %L)
%m%n
# Edit the next line to point to your logs directory
-log4j.appender.R.File=work/cassandra/system.log
+log4j.appender.R.File=${org.amdatu.core.cassandra.application/log4j.systemlog}
# Application logging options
#log4j.logger.com.facebook=DEBUG
Modified:
branches/0.2/amdatu-cassandra/cassandra-persistencemanager/src/main/java/org/amdatu/cassandra/persistencemanager/service/CassandraPersistenceManagerFactoryImpl.java
==============================================================================
---
branches/0.2/amdatu-cassandra/cassandra-persistencemanager/src/main/java/org/amdatu/cassandra/persistencemanager/service/CassandraPersistenceManagerFactoryImpl.java
(original)
+++
branches/0.2/amdatu-cassandra/cassandra-persistencemanager/src/main/java/org/amdatu/cassandra/persistencemanager/service/CassandraPersistenceManagerFactoryImpl.java
Wed Mar 2 15:34:55 2011
@@ -34,9 +34,10 @@
// Instances injected by the Felix dependency manager
private volatile DependencyManager m_dependencyManager;
private volatile LogService m_logService;
+
+
public void createCassandraPersistenceManager(String keyspaceId) {
- m_logService.log(LogService.LOG_DEBUG, "Launching
CassandraPersistenceManager for keyspace '" + keyspaceId + "'");
Dictionary<String, String> serviceProperties = new Hashtable<String,
String>();
serviceProperties.put(CassandraPersistenceManager.KEYSPACE_AWARE_KEY,
keyspaceId);
Modified:
branches/0.2/amdatu-core/config-filebased/src/main/resources/conf/org.amdatu.core.cassandra.application.cfg
==============================================================================
---
branches/0.2/amdatu-core/config-filebased/src/main/resources/conf/org.amdatu.core.cassandra.application.cfg
(original)
+++
branches/0.2/amdatu-core/config-filebased/src/main/resources/conf/org.amdatu.core.cassandra.application.cfg
Wed Mar 2 15:34:55 2011
@@ -10,7 +10,7 @@
# Directory in which the caches are saved
savedcachesdir=work/cassandra/saved_caches
-
+log4j.systemlog=work/cassandra/system.log
###############################
# Cassandra clustering related properties
Modified:
branches/0.2/amdatu-core/config-templates/src/main/java/org/amdatu/core/config/templates/service/ConfigTemplateManagerImpl.java
==============================================================================
---
branches/0.2/amdatu-core/config-templates/src/main/java/org/amdatu/core/config/templates/service/ConfigTemplateManagerImpl.java
(original)
+++
branches/0.2/amdatu-core/config-templates/src/main/java/org/amdatu/core/config/templates/service/ConfigTemplateManagerImpl.java
Wed Mar 2 15:34:55 2011
@@ -75,9 +75,17 @@
}
private void initializeWorkDir() {
- File workBaseDir = new File(System.getProperty("user.dir"), "work");
+
+ // If amdatu.dir is provided as System property, use this as base
directory instead of the current directory
+ File workBaseDir;
+ if (System.getProperty("amdatu.dir") != null) {
+ workBaseDir = new File(System.getProperty("amdatu.dir"), "work");
+ } else {
+ workBaseDir = new File(System.getProperty("user.dir"), "work");
+ }
m_workDir = new File(workBaseDir, m_workDirName);
m_workDir.mkdirs();
+ m_logService.log(LogService.LOG_INFO, "ConfigTemplateManager work
directory=" + m_workDir.getAbsolutePath());
}
/**
Modified:
branches/0.2/amdatu-core/tenantstore-fs/src/main/java/org/amdatu/core/tenantstore/fs/service/FSTenantStorageProvider.java
==============================================================================
---
branches/0.2/amdatu-core/tenantstore-fs/src/main/java/org/amdatu/core/tenantstore/fs/service/FSTenantStorageProvider.java
(original)
+++
branches/0.2/amdatu-core/tenantstore-fs/src/main/java/org/amdatu/core/tenantstore/fs/service/FSTenantStorageProvider.java
Wed Mar 2 15:34:55 2011
@@ -74,8 +74,14 @@
public void setDataDirectory(File dataDirectory) throws
TenantStorageException {
if (!dataDirectory.isAbsolute()) {
- File userDirectory = new File(System.getProperty("user.dir"));
- dataDirectory = new File(userDirectory, dataDirectory.getPath());
+ // If amdatu.dir is provided as System property, use this as base
directory instead of the current directory
+ File baseDirectory;
+ if (System.getProperty("amdatu.dir") != null) {
+ baseDirectory = new File(System.getProperty("amdatu.dir"));
+ } else {
+ baseDirectory = new File(System.getProperty("user.dir"));
+ }
+ dataDirectory = new File(baseDirectory, dataDirectory.getPath());
}
if (!((dataDirectory.exists() && dataDirectory.canRead() &&
dataDirectory.canWrite()) || dataDirectory
.mkdirs())) {
Modified:
branches/0.2/amdatu-core/useradminstore-fs/src/main/java/org/amdatu/core/useradminstore/fs/service/FSUserAdminStorageProvider.java
==============================================================================
---
branches/0.2/amdatu-core/useradminstore-fs/src/main/java/org/amdatu/core/useradminstore/fs/service/FSUserAdminStorageProvider.java
(original)
+++
branches/0.2/amdatu-core/useradminstore-fs/src/main/java/org/amdatu/core/useradminstore/fs/service/FSUserAdminStorageProvider.java
Wed Mar 2 15:34:55 2011
@@ -93,8 +93,14 @@
public synchronized void setDataDirectory(File dataDirectory) throws
StorageException {
if (!dataDirectory.isAbsolute()) {
- File userDirectory = new File(System.getProperty("user.dir"));
- dataDirectory = new File(userDirectory, dataDirectory.getPath());
+ // If amdatu.dir is provided as System property, use this as base
directory instead of the current directory
+ File baseDirectory;
+ if (System.getProperty("amdatu.dir") != null) {
+ baseDirectory = new File(System.getProperty("amdatu.dir"));
+ } else {
+ baseDirectory = new File(System.getProperty("user.dir"));
+ }
+ dataDirectory = new File(baseDirectory, dataDirectory.getPath());
}
if (!((dataDirectory.exists() && dataDirectory.canRead() &&
dataDirectory.canWrite()) || dataDirectory
.mkdirs())) {
Added:
branches/0.2/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/module/AmdatuContainerConfig.java
==============================================================================
--- (empty file)
+++
branches/0.2/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/module/AmdatuContainerConfig.java
Wed Mar 2 15:34:55 2011
@@ -0,0 +1,74 @@
+/*
+ Copyright (C) 2010 Amdatu.org
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.amdatu.opensocial.shindig.module;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.shindig.auth.BlobCrypterSecurityTokenCodec;
+import org.apache.shindig.config.ContainerConfig;
+
+public class AmdatuContainerConfig implements ContainerConfig {
+ private ContainerConfig m_containerConfig;
+
+ public AmdatuContainerConfig(ContainerConfig containerConfig) {
+ m_containerConfig = containerConfig;
+ }
+
+ public Collection<String> getContainers() {
+ return m_containerConfig.getContainers();
+ }
+
+ public Map<String, Object> getProperties(String container) {
+ return m_containerConfig.getProperties(container);
+ }
+
+ public Object getProperty(String container, String name) {
+ return m_containerConfig.getProperty(container, name);
+ }
+
+ public String getString(String container, String name) {
+ if
(name.equals(BlobCrypterSecurityTokenCodec.SECURITY_TOKEN_KEY_FILE)) {
+ // The gadget security token file is a relative path, so we should
make it absolute
+ // to make this work in WAR mode
+ String keyFile = m_containerConfig.getString(container, name);
+ if (System.getProperty("amdatu.dir") != null) {
+ keyFile = System.getProperty("amdatu.dir") + File.separator +
keyFile;
+ }
+ return keyFile;
+ }
+ return m_containerConfig.getString(container, name);
+ }
+
+ public int getInt(String container, String name) {
+ return m_containerConfig.getInt(container, name);
+ }
+
+ public boolean getBool(String container, String name) {
+ return m_containerConfig.getBool(container, name);
+ }
+
+ public <T> List<T> getList(String container, String name) {
+ return m_containerConfig.getList(container, name);
+ }
+
+ public <T> Map<String, T> getMap(String container, String name) {
+ return m_containerConfig.getMap(container, name);
+ }
+}
Modified:
branches/0.2/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/module/OAuthModuleImpl.java
==============================================================================
---
branches/0.2/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/module/OAuthModuleImpl.java
(original)
+++
branches/0.2/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/module/OAuthModuleImpl.java
Wed Mar 2 15:34:55 2011
@@ -22,9 +22,12 @@
import org.amdatu.opensocial.shindig.OAuthModule;
import org.apache.commons.lang.StringUtils;
+import org.apache.shindig.auth.DefaultSecurityTokenCodec;
+import org.apache.shindig.auth.SecurityTokenCodec;
import org.apache.shindig.common.crypto.BasicBlobCrypter;
import org.apache.shindig.common.crypto.BlobCrypter;
import org.apache.shindig.common.crypto.Crypto;
+import org.apache.shindig.config.ContainerConfig;
import org.apache.shindig.gadgets.http.HttpFetcher;
import org.apache.shindig.gadgets.oauth.OAuthFetcherConfig;
import org.apache.shindig.gadgets.oauth.OAuthRequest;
@@ -60,6 +63,7 @@
// Used for persistent storage of OAuth access tokens.
bind(OAuthStore.class).toInstance(m_gadgetStore);
bind(OAuthRequest.class).toProvider(OAuthRequestProvider.class);
+ bind(SecurityTokenCodec.class).to(AmdatuSecurityTokenCodec.class);
}
@Singleton
@@ -98,4 +102,13 @@
return new OAuthRequest(config, fetcher);
}
}
+
+ // Overrules SecurityTokenCodec to be able to customize container
properties which
+ // is necessary in some cases (i.e. security token key file)
+ public static class AmdatuSecurityTokenCodec extends
DefaultSecurityTokenCodec {
+ @Inject
+ public AmdatuSecurityTokenCodec(ContainerConfig config) {
+ super(new AmdatuContainerConfig(config));
+ }
+ }
}
\ No newline at end of file
Modified:
branches/0.2/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/service/ShindigRegistrationServiceImpl.java
==============================================================================
---
branches/0.2/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/service/ShindigRegistrationServiceImpl.java
(original)
+++
branches/0.2/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/service/ShindigRegistrationServiceImpl.java
Wed Mar 2 15:34:55 2011
@@ -149,7 +149,12 @@
// We need to copy the security token key from the bundle to a fixed
location on disk
// since the Shindig implementation requires this (uses new File(...)
to load it).
URL tokenUrl =
m_bundleContext.getBundle().getResource("/conf/securitytokenkey.txt");
- String confDir = System.getProperty("user.dir") + File.separator +
"conf";
+ String confDir;
+ if (System.getProperty("amdatu.dir") != null) {
+ confDir = System.getProperty("amdatu.dir") + File.separator +
"conf";
+ } else {
+ confDir = System.getProperty("user.dir") + File.separator + "conf";
+ }
new File(confDir).mkdir();
String targetFile = confDir + File.separator + "securitytokenkey.txt";
InputStream is = null;
Modified: branches/0.2/amdatu-release/pom.xml
==============================================================================
--- branches/0.2/amdatu-release/pom.xml (original)
+++ branches/0.2/amdatu-release/pom.xml Wed Mar 2 15:34:55 2011
@@ -558,8 +558,8 @@
<contextPath>/</contextPath>
<systemProperties>
<systemProperty>
- <name>amdatu.work.dir</name>
- <value>c:/temp/amdatu-work</value>
+ <name>amdatu.dir</name>
+ <value>${project.build.directory}/amdatu-war</value>
</systemProperty>
</systemProperties>
</configuration>
Modified:
branches/0.2/amdatu-release/src/main/java/org/amdatu/webapp/FrameworkService.java
==============================================================================
---
branches/0.2/amdatu-release/src/main/java/org/amdatu/webapp/FrameworkService.java
(original)
+++
branches/0.2/amdatu-release/src/main/java/org/amdatu/webapp/FrameworkService.java
Wed Mar 2 15:34:55 2011
@@ -17,10 +17,11 @@
package org.amdatu.webapp;
import java.io.File;
-import java.io.FilePermission;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.io.IOException;
-import java.security.AccessControlContext;
-import java.security.AccessController;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@@ -31,8 +32,9 @@
import org.apache.felix.framework.Felix;
import org.apache.felix.framework.util.FelixConstants;
-public final class FrameworkService
-{
+public final class FrameworkService {
+ private static final String AMDATU_DIR = "amdatu.dir";
+
private final ServletContext m_servletContext;
private Felix m_felix;
@@ -73,70 +75,89 @@
}
private Map<String, Object> createConfig() throws Exception {
- String amdatuWorkDir = System.getProperty("amdatu.work.dir");
- if (amdatuWorkDir == null || amdatuWorkDir.isEmpty()) {
- System.out.println("No amdatu.work.dir system property defined
which is required");
- throw new IllegalArgumentException("No amdatu.work.dir system
property defined which is requied");
- }
- System.setProperty("user.dir", amdatuWorkDir);
- System.out.println("***** Current directory set to " + amdatuWorkDir);
-
+ // Load and set framework properties
Properties props = new Properties();
props.load(m_servletContext.getResourceAsStream("/WEB-INF/framework.properties"));
HashMap<String, Object> map = new HashMap<String, Object>();
for (Object key : props.keySet()) {
map.put(key.toString(), props.get(key));
}
-
- // Check that we can create and remove a temp dir/temp file
- System.out.println("R/W access to " + amdatuWorkDir + ": " + new
File(amdatuWorkDir).canRead() + "/" + new File(amdatuWorkDir).canWrite());
-
- System.out.println("security manager:
"+System.getProperty("java.security.manager"));
- System.out.println("security manager: "+System.getSecurityManager());
- System.out.println("security policy: "+System.getProperty("policy"));
- //checkDir("work");
- //checkDir("work/test");
- //checkDir("work/test/a");
- AccessControlContext acc = AccessController.getContext();
- System.out.println("AccessControlContext="+acc);
- System.out.println(acc.getDomainCombiner());
- acc.checkPermission(new FilePermission(amdatuWorkDir, "write"));
-
- map.put("felix.cache.rootdir", amdatuWorkDir); // No constant for this
one
- // map.put("felix.cm.dir", amdatuWorkDir + File.separator +
"configadmin");
- //map.put("felix.fileinstall.tmpdir", amdatuWorkDir + File.separator +
"fileinstall");
- // map.put(FelixConstants.FRAMEWORK_STORAGE, amdatuWorkDir +
File.separator + "cache");
- String deployDir = m_servletContext.getRealPath("/amdatu/deploy/");
- map.put("felix.fileinstall.dir", deployDir);
- System.out.println("Deploy directory = " + deployDir);
-
+
+ // Check if a system property amdatu.dir was provided. If not, set the
current directory
+ // as amdatu.dir. The amdatu.dir is used by all Amdatu components that
use relative
+ // directories for file storage (i.e. for Cassandra commitlog files
and felix-deploy cache).
+ String amdatuDir = System.getProperty(AMDATU_DIR);
+ if (amdatuDir == null || amdatuDir.isEmpty()) {
+ // amdatu.dir was not provided as system property, maybe as
framework property?
+ if (map.containsKey(AMDATU_DIR)) {
+ amdatuDir = map.get(AMDATU_DIR).toString();
+ System.out.println(AMDATU_DIR + "=" + amdatuDir + " (provided
as framework property)");
+ } else {
+ amdatuDir = System.getProperty("user.dir");
+ System.out.println(AMDATU_DIR + "=" + amdatuDir + " (set to
current working directory)");
+ }
+ } else {
+ System.out.println(AMDATU_DIR + "=" + amdatuDir + " (provided as
system property)");
+ }
+ System.setProperty(AMDATU_DIR, amdatuDir);
+
+ // Ensure that the Amdatu directory exists
+ new File(amdatuDir).mkdirs();
+
+ // Convert the relative paths in framework.properties to absolute
paths by prefixing it
+ // with the AMDATU_WORK_DIR
+ System.out.println("Setting framework directory properties:");
+ relativeToAbsolute(amdatuDir, map, "felix.cache.rootdir");
+ relativeToAbsolute(amdatuDir, map, "felix.cm.dir");
+ relativeToAbsolute(amdatuDir, map, "felix.fileinstall.dir");
+ relativeToAbsolute(amdatuDir, map, "felix.fileinstall.tmpdir");
+
+ // Now when Amdatu is booted for the very first time, the target
deploy directory used
+ // by fileinstall will be empty. So we must copy the files included in
the WAR to this
+ // directory
+ File deployDir = new File(map.get("felix.fileinstall.dir").toString());
+ if (!deployDir.exists()) {
+ deployDir.mkdirs();
+ String sourceDir = m_servletContext.getRealPath("/amdatu/deploy");
+ System.out.println("Config Admin deploy directory does not exist,
copying initial configuration files from "
+ + sourceDir + " to " + deployDir.getAbsolutePath());
+ String[] files = new File(sourceDir).list();
+ for (String file : files) {
+ String target = deployDir.getAbsolutePath() + File.separator +
new File(file).getName();
+ copyFile(new File(sourceDir + File.separator + file), new
File(target));
+ }
+ }
+
map.put(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP, Arrays.asList(new
ProvisionActivator(m_servletContext)));
return map;
}
+ private void relativeToAbsolute(String amdatuDir, Map<String, Object> map
, String propName) {
+ String newDir = amdatuDir + File.separator +
map.get(propName).toString();
+ map.put(propName, newDir);
+ System.out.println(" " + propName + "=" + newDir);
+ }
+
private void log(String message, Throwable cause) {
m_servletContext.log(message, cause);
}
-
- private void checkDir(String tempDir) throws IOException {
- String temp = "temp.tmp";
- File tempDirFile = new File(tempDir);
- if (!tempDirFile.mkdirs()) {
- System.out.println("ERROR: Could not create temp dir '" +
tempDirFile.getAbsolutePath() + "'");
- } else if (!new File(tempDir).exists()) {
- System.out.println("ERROR: Could create temp dir '" + tempDir +
"', but dir still does not exist");
- } else {
- File tempFile = new File(tempDir + "/" + temp);
- if (!tempFile.createNewFile() || !new File(tempDir + "/" +
temp).exists()) {
- System.out.println("ERROR: Could not create temp file '" +
tempDir + "/" + temp + "'");
- } else {
- System.out.println("INFO: Could create temp dir and file '" +
tempDir + "/" + temp + "'");
- /* if (!tempFile.delete()) {
- System.out.println("ERROR: Could not delete temp file");
- }
- if (!tempDirFile.delete()) {
- System.out.println("ERROR: Could not delete temp dir");
- }*/
+
+ private void copyFile(File source, File target) throws IOException {
+ InputStream in = null;
+ OutputStream out = null;
+ try {
+ in = new FileInputStream(source);
+ out = new FileOutputStream(target);
+ byte[] buf = new byte[1024];
+ int len;
+ while ((len = in.read(buf)) > 0) {
+ out.write(buf, 0, len);
+ }
+ } finally {
+ try {
+ if (in != null) in.close();
+ } finally {
+ if (out != null) out.close();
}
}
}
Modified:
branches/0.2/amdatu-release/src/main/java/org/amdatu/webapp/ProvisionActivator.java
==============================================================================
---
branches/0.2/amdatu-release/src/main/java/org/amdatu/webapp/ProvisionActivator.java
(original)
+++
branches/0.2/amdatu-release/src/main/java/org/amdatu/webapp/ProvisionActivator.java
Wed Mar 2 15:34:55 2011
@@ -23,6 +23,7 @@
import javax.servlet.ServletContext;
+import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
@@ -36,7 +37,7 @@
public void start(BundleContext context) throws Exception {
System.out.println("Provisioning OSGi bundles");
m_servletContext.setAttribute(BundleContext.class.getName(), context);
- /*ArrayList<Bundle> installed = new ArrayList<Bundle>();
+ ArrayList<Bundle> installed = new ArrayList<Bundle>();
for (URL url : findBundles()) {
this.m_servletContext.log("Installing bundle [" + url + "]");
System.out.println("Installing bundle [" + url + "]");
@@ -46,7 +47,7 @@
for (Bundle bundle : installed) {
bundle.start();
- }*/
+ }
}
public void stop(BundleContext context) throws Exception{
Modified:
branches/0.2/amdatu-release/src/main/java/org/amdatu/webapp/StartupListener.java
==============================================================================
---
branches/0.2/amdatu-release/src/main/java/org/amdatu/webapp/StartupListener.java
(original)
+++
branches/0.2/amdatu-release/src/main/java/org/amdatu/webapp/StartupListener.java
Wed Mar 2 15:34:55 2011
@@ -23,7 +23,6 @@
private FrameworkService m_frameworkService;
public void contextInitialized(ServletContextEvent event) {
- System.out.println("Starting felix!!!");
m_frameworkService = new FrameworkService(event.getServletContext());
m_frameworkService.start();
}
Modified: branches/0.2/amdatu-release/src/main/webapp/framework.properties
==============================================================================
--- branches/0.2/amdatu-release/src/main/webapp/framework.properties
(original)
+++ branches/0.2/amdatu-release/src/main/webapp/framework.properties Wed Mar
2 15:34:55 2011
@@ -1,23 +1,27 @@
-
-org.osgi.framework.system.packages.extra=sun.misc,com.sun.management
-
-org.osgi.framework.storage=felix-deploy
-
+# Directory properties. Relative here, but converted to absolute directories
+# in FrameworkService. These paths are prefixed by the value of amdatu.dir,
+# which can be passed as system property or as framework property. If not
+# provided, the current working directory is used.
felix.cache.rootdir=work/cache
-
felix.cm.dir=work/configadmin
+felix.fileinstall.tmpdir=work/fileinstall
+felix.fileinstall.dir=deploy
+
+# Felix storage properties
+org.osgi.framework.storage=felix-deploy
+org.osgi.framework.storage.clean = onFirstInit
# Config of file install
felix.fileinstall.poll=3000
-felix.fileinstall.dir=deploy
felix.fileinstall.debug=1
felix.fileinstall.bundles.new.start=true
felix.fileinstall.filter=.*
-felix.fileinstall.tmpdir=work/fileinstall
felix.fileinstall.disableConfigSave=true
-org.osgi.framework.storage.clean = onFirstInit
+# Extra exported system packages
+org.osgi.framework.system.packages.extra=sun.misc,com.sun.management
+# System packages
org.osgi.framework.system.packages = \
org.osgi.framework; version=1.5.0, \
org.osgi.framework.hooks.service, \
Modified:
branches/0.2/amdatu-semanticweb/sesame/src/main/java/org/amdatu/semanticweb/sesame/service/SesameServiceImpl.java
==============================================================================
---
branches/0.2/amdatu-semanticweb/sesame/src/main/java/org/amdatu/semanticweb/sesame/service/SesameServiceImpl.java
(original)
+++
branches/0.2/amdatu-semanticweb/sesame/src/main/java/org/amdatu/semanticweb/sesame/service/SesameServiceImpl.java
Wed Mar 2 15:34:55 2011
@@ -187,13 +187,21 @@
return subjects;
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings("rawtypes")
public void updated(Dictionary dictionary) throws ConfigurationException {
if (dictionary != null) {
m_repositoryDir = (String) dictionary.get(DATA_DIRECTORY);
if (m_repositoryDir == null || "".equals(m_repositoryDir)) {
throw new ConfigurationException(DATA_DIRECTORY, "Missing
mandatory data directory configuration");
}
+ if (!new File(m_repositoryDir).isAbsolute()) {
+ // Convert to absolute directory
+ if (System.getProperty("amdatu.dir") != null) {
+ m_repositoryDir = System.getProperty("amdatu.dir") +
File.separator + m_repositoryDir;
+ } else {
+ m_repositoryDir = System.getProperty("user.dir") +
File.separator + m_repositoryDir;
+ }
+ }
}
}
Modified: branches/0.2/pom.xml
==============================================================================
--- branches/0.2/pom.xml (original)
+++ branches/0.2/pom.xml Wed Mar 2 15:34:55 2011
@@ -86,7 +86,7 @@
<org.osgi.version>4.2.0</org.osgi.version>
<org.apache.felix.configadmin.version>1.2.4</org.apache.felix.configadmin.version>
<org.apache.felix.log.version>1.0.0</org.apache.felix.log.version>
-
<org.apache.felix.file.install.version>3.1.4</org.apache.felix.file.install.version>
+
<org.apache.felix.file.install.version>3.1.10</org.apache.felix.file.install.version>
<org.apache.felix.scr.version>1.6.0</org.apache.felix.scr.version>
<org.apache.felix.http.version>2.0.4</org.apache.felix.http.version>
<pax.swissbox.version>1.3.0</pax.swissbox.version>
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits