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 2015/01/11 17:22:39 UTC
karaf-cellar git commit: [KARAF-1469] Allow to be able to define the
config excluded property
Repository: karaf-cellar
Updated Branches:
refs/heads/master 60a24ca29 -> 17ddbc51e
[KARAF-1469] Allow to be able to define the config excluded property
Project: http://git-wip-us.apache.org/repos/asf/karaf-cellar/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf-cellar/commit/17ddbc51
Tree: http://git-wip-us.apache.org/repos/asf/karaf-cellar/tree/17ddbc51
Diff: http://git-wip-us.apache.org/repos/asf/karaf-cellar/diff/17ddbc51
Branch: refs/heads/master
Commit: 17ddbc51e2ff73de1841e79e9631abd0a0ddfe11
Parents: 60a24ca
Author: Jean-Baptiste Onofré <jb...@apache.org>
Authored: Sun Jan 11 17:20:55 2015 +0100
Committer: Jean-Baptiste Onofré <jb...@apache.org>
Committed: Sun Jan 11 17:20:55 2015 +0100
----------------------------------------------------------------------
assembly/src/main/resources/node.cfg | 8 ++-
.../cellar/config/ConfigurationSupport.java | 21 +++++--
.../config/management/CellarConfigMBean.java | 4 ++
.../internal/CellarConfigMBeanImpl.java | 25 ++++++++
.../config/shell/PropExcludedCommand.java | 62 ++++++++++++++++++++
.../OSGI-INF/blueprint/shell-config.xml | 5 ++
6 files changed, 119 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/17ddbc51/assembly/src/main/resources/node.cfg
----------------------------------------------------------------------
diff --git a/assembly/src/main/resources/node.cfg b/assembly/src/main/resources/node.cfg
index 36028c9..2b0573d 100644
--- a/assembly/src/main/resources/node.cfg
+++ b/assembly/src/main/resources/node.cfg
@@ -37,4 +37,10 @@ handler.org.apache.karaf.cellar.dosgi.RemoteServiceCallHandler = true
handler.org.apache.karaf.cellar.event.ClusterEventHandler = true
# OBR event handler
handler.org.apache.karaf.cellar.obr.ObrBundleEventHandler = true
-handler.org.apache.karaf.cellar.obr.ObrUrlEventHandler = true
\ No newline at end of file
+handler.org.apache.karaf.cellar.obr.ObrUrlEventHandler = true
+
+#
+# Filtered config properties
+# Some config properties can be considered as local to a node, and should not be sync on the cluster.
+#
+config.filtered.properties = service.factoryPid, felix.fileinstall.filename, felix.fileinstall.dir, felix.fileinstall.tmpdir, org.ops4j.pax.url.mvn.defaultRepositories
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/17ddbc51/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java
----------------------------------------------------------------------
diff --git a/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java b/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java
index a3ee898..b627fc3 100644
--- a/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java
+++ b/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java
@@ -14,6 +14,7 @@
package org.apache.karaf.cellar.config;
import org.apache.karaf.cellar.core.CellarSupport;
+import org.apache.karaf.cellar.core.Configurations;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
@@ -28,8 +29,6 @@ import java.util.*;
*/
public class ConfigurationSupport extends CellarSupport {
- private static String[] EXCLUDED_PROPERTIES = {"service.factoryPid", "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;
@@ -118,9 +117,21 @@ public class ConfigurationSupport extends CellarSupport {
* @return true is the property is excluded, false else.
*/
public boolean isExcludedProperty(String propertyName) {
- for (int i = 0; i < EXCLUDED_PROPERTIES.length; i++) {
- if (EXCLUDED_PROPERTIES[i].equals(propertyName))
- return true;
+ try {
+ Configuration nodeConfiguration = configurationAdmin.getConfiguration(Configurations.NODE, null);
+ if (nodeConfiguration != null) {
+ Dictionary properties = nodeConfiguration.getProperties();
+ if (properties != null) {
+ String property = properties.get("config.filtered.properties").toString();
+ String[] excludedProperties = property.split(",");
+ for (int i = 0; i < excludedProperties.length; i++) {
+ if (excludedProperties[i].trim().equals(propertyName))
+ return true;
+ }
+ }
+ }
+ } catch (Exception e) {
+ LOGGER.warn("CELLAR CONFIG: can't check excluded properties", e);
}
return false;
}
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/17ddbc51/config/src/main/java/org/apache/karaf/cellar/config/management/CellarConfigMBean.java
----------------------------------------------------------------------
diff --git a/config/src/main/java/org/apache/karaf/cellar/config/management/CellarConfigMBean.java b/config/src/main/java/org/apache/karaf/cellar/config/management/CellarConfigMBean.java
index e01cd7d..5a9a1f8 100644
--- a/config/src/main/java/org/apache/karaf/cellar/config/management/CellarConfigMBean.java
+++ b/config/src/main/java/org/apache/karaf/cellar/config/management/CellarConfigMBean.java
@@ -82,4 +82,8 @@ public interface CellarConfigMBean {
*/
void deleteProperty(String group, String pid, String key) throws Exception;
+ String getExcludedProperties() throws Exception;
+
+ void setExcludedProperties(String excludedProperties) throws Exception;
+
}
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/17ddbc51/config/src/main/java/org/apache/karaf/cellar/config/management/internal/CellarConfigMBeanImpl.java
----------------------------------------------------------------------
diff --git a/config/src/main/java/org/apache/karaf/cellar/config/management/internal/CellarConfigMBeanImpl.java b/config/src/main/java/org/apache/karaf/cellar/config/management/internal/CellarConfigMBeanImpl.java
index 8424ccd..63baf56 100644
--- a/config/src/main/java/org/apache/karaf/cellar/config/management/internal/CellarConfigMBeanImpl.java
+++ b/config/src/main/java/org/apache/karaf/cellar/config/management/internal/CellarConfigMBeanImpl.java
@@ -20,6 +20,7 @@ import org.apache.karaf.cellar.core.control.SwitchStatus;
import org.apache.karaf.cellar.core.event.EventProducer;
import org.apache.karaf.cellar.core.event.EventType;
import org.apache.karaf.cellar.config.management.CellarConfigMBean;
+import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
import org.osgi.service.cm.ConfigurationEvent;
@@ -242,6 +243,30 @@ public class CellarConfigMBeanImpl extends StandardMBean implements CellarConfig
}
}
+ @Override
+ public String getExcludedProperties() throws Exception {
+ Configuration nodeConfiguration = configurationAdmin.getConfiguration(Configurations.NODE, null);
+ if (nodeConfiguration != null) {
+ Dictionary properties = nodeConfiguration.getProperties();
+ if (properties != null) {
+ return properties.get("config.filtered.properties").toString();
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public void setExcludedProperties(String excludedProperties) throws Exception {
+ Configuration nodeConfiguration = configurationAdmin.getConfiguration(Configurations.NODE, null);
+ if (nodeConfiguration != null) {
+ Dictionary properties = nodeConfiguration.getProperties();
+ if (properties == null)
+ properties = new Properties();
+ properties.put("config.filtered.properties", excludedProperties);
+ nodeConfiguration.update(properties);
+ }
+ }
+
public ClusterManager getClusterManager() {
return this.clusterManager;
}
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/17ddbc51/config/src/main/java/org/apache/karaf/cellar/config/shell/PropExcludedCommand.java
----------------------------------------------------------------------
diff --git a/config/src/main/java/org/apache/karaf/cellar/config/shell/PropExcludedCommand.java b/config/src/main/java/org/apache/karaf/cellar/config/shell/PropExcludedCommand.java
new file mode 100644
index 0000000..f65ff1b
--- /dev/null
+++ b/config/src/main/java/org/apache/karaf/cellar/config/shell/PropExcludedCommand.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.cellar.config.shell;
+
+import org.apache.karaf.cellar.core.Configurations;
+import org.apache.karaf.cellar.core.shell.CellarCommandSupport;
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+import java.util.Dictionary;
+import java.util.Properties;
+
+@Command(scope = "cluster", name = "config-property-excluded", description = "Display or set the config properties excluded from the cluster sync")
+public class PropExcludedCommand extends CellarCommandSupport {
+
+ @Argument(index = 0, name = "excluded-properties", description = "A list of comma separated properties excluded from the cluster sync", required = false, multiValued = false)
+ String excludedProperties;
+
+ private ConfigurationAdmin configurationAdmin;
+
+ @Override
+ protected Object doExecute() throws Exception {
+ Configuration nodeConfiguration = configurationAdmin.getConfiguration(Configurations.NODE, null);
+ if (excludedProperties == null || excludedProperties.isEmpty()) {
+ // display mode
+ if (nodeConfiguration != null) {
+ Dictionary properties = nodeConfiguration.getProperties();
+ if (properties != null) {
+ System.out.println(properties.get("config.filtered.properties"));
+ }
+ }
+ } else {
+ // set mode
+ if (nodeConfiguration != null) {
+ Dictionary properties = nodeConfiguration.getProperties();
+ if (properties == null)
+ properties = new Properties();
+ properties.put("config.filtered.properties", excludedProperties);
+ nodeConfiguration.update(properties);
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public void setConfigurationAdmin(ConfigurationAdmin configurationAdmin) {
+ this.configurationAdmin = configurationAdmin;
+ }
+}
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/17ddbc51/config/src/main/resources/OSGI-INF/blueprint/shell-config.xml
----------------------------------------------------------------------
diff --git a/config/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/config/src/main/resources/OSGI-INF/blueprint/shell-config.xml
index 1b5da82..66cc159 100644
--- a/config/src/main/resources/OSGI-INF/blueprint/shell-config.xml
+++ b/config/src/main/resources/OSGI-INF/blueprint/shell-config.xml
@@ -84,6 +84,11 @@
<ref component-id="clusterConfigCompleter"/>
</completers>
</command>
+ <command>
+ <action class="org.apache.karaf.cellar.config.shell.PropExcludedCommand">
+ <property name="configurationAdmin" ref="configurationAdmin"/>
+ </action>
+ </command>
</command-bundle>
<bean id="allGroupsCompleter" class="org.apache.karaf.cellar.core.shell.completer.AllGroupsCompleter">