You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2012/05/16 09:57:23 UTC
svn commit: r1339044 - in /karaf/cellar/trunk: ./ config/
config/src/main/java/org/apache/karaf/cellar/config/
config/src/main/resources/OSGI-INF/blueprint/
features/src/main/java/org/apache/karaf/cellar/features/
Author: jbonofre
Date: Wed May 16 07:57:22 2012
New Revision: 1339044
URL: http://svn.apache.org/viewvc?rev=1339044&view=rev
Log:
[KARAF-1480] Add creation of the cfg file
Modified:
karaf/cellar/trunk/config/pom.xml
karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationEventHandler.java
karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java
karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSynchronizer.java
karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/LocalConfigurationListener.java
karaf/cellar/trunk/config/src/main/resources/OSGI-INF/blueprint/blueprint.xml
karaf/cellar/trunk/features/src/main/java/org/apache/karaf/cellar/features/LocalFeaturesListener.java
karaf/cellar/trunk/pom.xml
Modified: karaf/cellar/trunk/config/pom.xml
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/config/pom.xml?rev=1339044&r1=1339043&r2=1339044&view=diff
==============================================================================
--- karaf/cellar/trunk/config/pom.xml (original)
+++ karaf/cellar/trunk/config/pom.xml Wed May 16 07:57:22 2012
@@ -50,6 +50,10 @@
<osgi.export>
org.apache.karaf.cellar.config*;version="${project.version}"
</osgi.export>
+ <osgi.private>
+ org.apache.felix.utils*;-split-package:=merge-first,
+ !*
+ </osgi.private>
</properties>
<dependencies>
@@ -59,6 +63,10 @@
<groupId>org.apache.karaf.cellar</groupId>
<artifactId>org.apache.karaf.cellar.core</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.utils</artifactId>
+ </dependency>
<!-- Configuration Admin -->
<dependency>
Modified: karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationEventHandler.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationEventHandler.java?rev=1339044&r1=1339043&r2=1339044&view=diff
==============================================================================
--- karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationEventHandler.java (original)
+++ karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationEventHandler.java Wed May 16 07:57:22 2012
@@ -69,7 +69,10 @@ public class ConfigurationEventHandler e
conf = configurationAdmin.getConfiguration(pid);
if (conf != null) {
if (event.getType() == ConfigurationEvent.CM_DELETED) {
- conf.delete();
+ if (conf.getProperties() != null) {
+ conf.delete();
+ deleteStorage(pid);
+ }
} else {
if (remoteDictionary != null) {
remoteDictionary.put(Constants.SYNC_PROPERTY, new Long(System.currentTimeMillis()).toString());
@@ -78,6 +81,7 @@ public class ConfigurationEventHandler e
localDictionary = new Properties();
filter(remoteDictionary, localDictionary);
conf.update(localDictionary);
+ persistConfiguration(configurationAdmin, pid, localDictionary);
}
}
}
Modified: karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java?rev=1339044&r1=1339043&r2=1339044&view=diff
==============================================================================
--- karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java (original)
+++ karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java Wed May 16 07:57:22 2012
@@ -14,17 +14,25 @@
package org.apache.karaf.cellar.config;
import org.apache.karaf.cellar.core.CellarSupport;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
-import java.util.Dictionary;
-import java.util.Enumeration;
-import java.util.Properties;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.util.*;
/**
* Configuration support.
*/
public class ConfigurationSupport extends CellarSupport {
- private static String[] EXCLUDED_PROPERTIES = { "felix.fileinstall.filename", "felix.fileinstall.dir", "felix.fileinstall.tmpdir", "org.ops4j.pax.url.mvn.defaultRepositories" };
+ private static String[] EXCLUDED_PROPERTIES = {"felix.fileinstall.filename", "felix.fileinstall.dir", "felix.fileinstall.tmpdir", "org.ops4j.pax.url.mvn.defaultRepositories"};
+
+ private static final String FELIX_FILEINSTALL_FILENAME = "felix.fileinstall.filename";
+
+ protected File storage;
/**
* Filter a dictionary, specially replace the karaf.home property with a relative value.
@@ -59,4 +67,55 @@ public class ConfigurationSupport extend
return false;
}
+ /**
+ * Persist a configuration to a storage.
+ *
+ * @param pid
+ * @throws Exception
+ */
+ protected void persistConfiguration(ConfigurationAdmin admin, String pid, Dictionary props) {
+ try {
+ if (pid.startsWith("org.apache.felix.fileinstall")) {
+ return;
+ }
+ File storageFile = new File(storage, pid + ".cfg");
+ Configuration cfg = admin.getConfiguration(pid, null);
+ if (cfg != null && cfg.getProperties() != null) {
+ Object val = cfg.getProperties().get(FELIX_FILEINSTALL_FILENAME);
+ if (val instanceof String) {
+ if (((String) val).startsWith("file:")) {
+ val = ((String) val).substring("file:".length());
+ }
+ storageFile = new File((String) val);
+ }
+ }
+ org.apache.felix.utils.properties.Properties p = new org.apache.felix.utils.properties.Properties(storageFile);
+ for (Enumeration keys = props.keys(); keys.hasMoreElements(); ) {
+ Object key = keys.nextElement();
+ if (!org.osgi.framework.Constants.SERVICE_PID.equals(key)
+ && !ConfigurationAdmin.SERVICE_FACTORYPID.equals(key)
+ && !FELIX_FILEINSTALL_FILENAME.equals(key)) {
+ p.put((String) key, (String) props.get(key));
+ }
+ }
+ storage.mkdirs();
+ p.save();
+ } catch (Exception e) {
+ // nothing to do
+ }
+ }
+
+ protected void deleteStorage(String pid) {
+ File cfgFile = new File(storage, pid + ".cfg");
+ cfgFile.delete();
+ }
+
+ public File getStorage() {
+ return storage;
+ }
+
+ public void setStorage(File storage) {
+ this.storage = storage;
+ }
+
}
Modified: karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSynchronizer.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSynchronizer.java?rev=1339044&r1=1339043&r2=1339044&view=diff
==============================================================================
--- karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSynchronizer.java (original)
+++ karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSynchronizer.java Wed May 16 07:57:22 2012
@@ -94,6 +94,7 @@ public class ConfigurationSynchronizer e
localDictionary = new Properties();
filter(remoteDictionary, localDictionary);
conf.update(localDictionary);
+ persistConfiguration(configurationAdmin, pid, localDictionary);
} catch (IOException ex) {
LOGGER.error("CELLAR CONFIG: failed to read distributed map", ex);
}
Modified: karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/LocalConfigurationListener.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/LocalConfigurationListener.java?rev=1339044&r1=1339043&r2=1339044&view=diff
==============================================================================
--- karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/LocalConfigurationListener.java (original)
+++ karaf/cellar/trunk/config/src/main/java/org/apache/karaf/cellar/config/LocalConfigurationListener.java Wed May 16 07:57:22 2012
@@ -88,8 +88,13 @@ public class LocalConfigurationListener
try {
if (event.getType() == ConfigurationEvent.CM_DELETED) {
+ // update the distributed map
configurationTable.remove(pid);
- // TODO broadcast the cluster event
+ // broadcast the cluster event
+ RemoteConfigurationEvent remoteConfigurationEvent = new RemoteConfigurationEvent(pid);
+ remoteConfigurationEvent.setType(ConfigurationEvent.CM_DELETED);
+ remoteConfigurationEvent.setSourceGroup(group);
+ eventProducer.produce(remoteConfigurationEvent);
} else {
Properties localProperties = new Properties();
filter(localDictionary, localProperties);
Modified: karaf/cellar/trunk/config/src/main/resources/OSGI-INF/blueprint/blueprint.xml
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/config/src/main/resources/OSGI-INF/blueprint/blueprint.xml?rev=1339044&r1=1339043&r2=1339044&view=diff
==============================================================================
--- karaf/cellar/trunk/config/src/main/resources/OSGI-INF/blueprint/blueprint.xml (original)
+++ karaf/cellar/trunk/config/src/main/resources/OSGI-INF/blueprint/blueprint.xml Wed May 16 07:57:22 2012
@@ -13,7 +13,9 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
+ xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0">
<!-- Local Configuration Listener -->
<bean id="configurationListener" class="org.apache.karaf.cellar.config.LocalConfigurationListener" init-method="init"
@@ -32,6 +34,7 @@
<property name="groupManager" ref="groupManager"/>
<property name="clusterManager" ref="clusterManager"/>
<property name="eventProducer" ref="eventProducer"/>
+ <property name="storage" value="${storage}"/>
</bean>
<service ref="synchronizer" interface="org.apache.karaf.cellar.core.Synchronizer"/>
@@ -40,6 +43,7 @@
init-method="init" destroy-method="destroy">
<property name="configurationAdmin" ref="configurationAdmin"/>
<property name="clusterManager" ref="clusterManager"/>
+ <property name="storage" value="${storage}"/>
</bean>
<service ref="eventHandler" interface="org.apache.karaf.cellar.core.event.EventHandler">
<service-properties>
@@ -52,4 +56,12 @@
<reference id="configurationAdmin" interface="org.osgi.service.cm.ConfigurationAdmin"/>
<reference id="eventProducer" interface="org.apache.karaf.cellar.core.event.EventProducer"/>
+ <ext:property-placeholder placeholder-prefix="$[" placeholder-suffix="]" />
+
+ <cm:property-placeholder persistent-id="org.apache.karaf.shell.config">
+ <cm:default-properties>
+ <cm:property name="storage" value="$[karaf.base]/etc/"/>
+ </cm:default-properties>
+ </cm:property-placeholder>
+
</blueprint>
Modified: karaf/cellar/trunk/features/src/main/java/org/apache/karaf/cellar/features/LocalFeaturesListener.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/features/src/main/java/org/apache/karaf/cellar/features/LocalFeaturesListener.java?rev=1339044&r1=1339043&r2=1339044&view=diff
==============================================================================
--- karaf/cellar/trunk/features/src/main/java/org/apache/karaf/cellar/features/LocalFeaturesListener.java (original)
+++ karaf/cellar/trunk/features/src/main/java/org/apache/karaf/cellar/features/LocalFeaturesListener.java Wed May 16 07:57:22 2012
@@ -103,54 +103,61 @@ public class LocalFeaturesListener exten
return;
}
- if (event != null && event.getRepository() != null) {
- Set<Group> groups = groupManager.listLocalGroups();
-
- if (groups != null && !groups.isEmpty()) {
- for (Group group : groups) {
- RemoteRepositoryEvent repositoryEvent = new RemoteRepositoryEvent(event.getRepository().getURI().toString(), event.getType());
- repositoryEvent.setSourceGroup(group);
- RepositoryEvent.EventType type = event.getType();
-
- // update the distributed map
- if (RepositoryEvent.EventType.RepositoryAdded.equals(type)){
- pushRepository(event.getRepository(), group);
- // update the feature map
- Map<FeatureInfo, Boolean> distributedFeatures = clusterManager.getMap(Constants.FEATURES + Configurations.SEPARATOR + group.getName());
- try {
- for (Feature feature : event.getRepository().getFeatures()) {
- // check the feature in the distributed map
- FeatureInfo featureInfo = null;
- for (FeatureInfo distributedFeature : distributedFeatures.keySet()) {
- if (distributedFeature.getName().equals(feature.getName()) && distributedFeature.getVersion().equals(feature.getVersion())) {
- featureInfo = distributedFeature;
- break;
+ ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+ if (event != null && event.getRepository() != null) {
+ Set<Group> groups = groupManager.listLocalGroups();
+
+ if (groups != null && !groups.isEmpty()) {
+ for (Group group : groups) {
+ RemoteRepositoryEvent repositoryEvent = new RemoteRepositoryEvent(event.getRepository().getURI().toString(), event.getType());
+ repositoryEvent.setSourceGroup(group);
+ RepositoryEvent.EventType type = event.getType();
+
+ // update the distributed map
+ if (RepositoryEvent.EventType.RepositoryAdded.equals(type)) {
+ pushRepository(event.getRepository(), group);
+ // update the feature map
+ Map<FeatureInfo, Boolean> distributedFeatures = clusterManager.getMap(Constants.FEATURES + Configurations.SEPARATOR + group.getName());
+ try {
+ for (Feature feature : event.getRepository().getFeatures()) {
+ // check the feature in the distributed map
+ FeatureInfo featureInfo = null;
+ for (FeatureInfo distributedFeature : distributedFeatures.keySet()) {
+ if (distributedFeature.getName().equals(feature.getName()) && distributedFeature.getVersion().equals(feature.getVersion())) {
+ featureInfo = distributedFeature;
+ break;
+ }
+ }
+ if (featureInfo == null) {
+ featureInfo = new FeatureInfo(feature.getName(), feature.getVersion());
+ distributedFeatures.put(featureInfo, false);
}
}
- if (featureInfo == null) {
- featureInfo = new FeatureInfo(feature.getName(), feature.getVersion());
- distributedFeatures.put(featureInfo, false);
- }
+ } catch (Exception e) {
+ LOGGER.warn("CELLAR FEATURES: can't update the distributed features map", e);
}
- } catch (Exception e) {
- LOGGER.warn("CELLAR FEATURES: can't update the distributed features map", e);
- }
- } else {
- removeRepository(event.getRepository(), group);
- // update the feature map
- Map<FeatureInfo, Boolean> distributedFeatures = clusterManager.getMap(Constants.FEATURES + Configurations.SEPARATOR + group.getName());
- try {
- for (Feature feature : event.getRepository().getFeatures()) {
- FeatureInfo info = new FeatureInfo(feature.getName(), feature.getVersion());
- distributedFeatures.remove(info);
+ } else {
+ removeRepository(event.getRepository(), group);
+ // update the feature map
+ Map<FeatureInfo, Boolean> distributedFeatures = clusterManager.getMap(Constants.FEATURES + Configurations.SEPARATOR + group.getName());
+ try {
+ for (Feature feature : event.getRepository().getFeatures()) {
+ FeatureInfo info = new FeatureInfo(feature.getName(), feature.getVersion());
+ distributedFeatures.remove(info);
+ }
+ } catch (Exception e) {
+ LOGGER.warn("CELLAR FEATURES: can't update the distributed features map", e);
}
- } catch (Exception e) {
- LOGGER.warn("CELLAR FEATURES: can't update the distributed features map", e);
}
+ // broadcast the cluster event
+ eventProducer.produce(repositoryEvent);
}
- eventProducer.produce(repositoryEvent);
}
}
+ } finally {
+ Thread.currentThread().setContextClassLoader(originalClassLoader);
}
}
Modified: karaf/cellar/trunk/pom.xml
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/pom.xml?rev=1339044&r1=1339043&r2=1339044&view=diff
==============================================================================
--- karaf/cellar/trunk/pom.xml (original)
+++ karaf/cellar/trunk/pom.xml Wed May 16 07:57:22 2012
@@ -37,6 +37,7 @@
<easymock.version>2.4</easymock.version>
<felix.bundlerepository.version>1.6.4</felix.bundlerepository.version>
<felix.configadmin.version>1.2.8</felix.configadmin.version>
+ <felix.utils.version>1.1.2</felix.utils.version>
<felix.webconsole.version>3.1.8</felix.webconsole.version>
<hazelcast.version>2.0.2</hazelcast.version>
<jclouds.version>1.4.0</jclouds.version>
@@ -194,6 +195,21 @@
<artifactId>org.apache.felix.webconsole</artifactId>
<version>${felix.webconsole.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.utils</artifactId>
+ <version>${felix.utils.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
<!-- Hazelcast -->
<dependency>