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/02 08:07:28 UTC
svn commit: r1332925 - in /karaf/cellar/branches/cellar-2.2.x:
config/src/main/java/org/apache/karaf/cellar/config/
config/src/main/java/org/apache/karaf/cellar/config/shell/
config/src/main/resources/OSGI-INF/blueprint/
config/src/test/java/org/apache...
Author: jbonofre
Date: Wed May 2 06:07:28 2012
New Revision: 1332925
URL: http://svn.apache.org/viewvc?rev=1332925&view=rev
Log:
[KARAF-1405] Update local configuration in the handler and produce an event in the cluster:config-propset command
[KARAF-1190] Remove property filtering
Modified:
karaf/cellar/branches/cellar-2.2.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationEventHandler.java
karaf/cellar/branches/cellar-2.2.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java
karaf/cellar/branches/cellar-2.2.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSynchronizer.java
karaf/cellar/branches/cellar-2.2.x/config/src/main/java/org/apache/karaf/cellar/config/LocalConfigurationListener.java
karaf/cellar/branches/cellar-2.2.x/config/src/main/java/org/apache/karaf/cellar/config/shell/PropSetCommand.java
karaf/cellar/branches/cellar-2.2.x/config/src/main/resources/OSGI-INF/blueprint/shell-config.xml
karaf/cellar/branches/cellar-2.2.x/config/src/test/java/org/apache/karaf/cellar/config/ConfigurationSupportTest.java
karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastGroupManager.java
Modified: karaf/cellar/branches/cellar-2.2.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationEventHandler.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.2.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationEventHandler.java?rev=1332925&r1=1332924&r2=1332925&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.2.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationEventHandler.java (original)
+++ karaf/cellar/branches/cellar-2.2.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationEventHandler.java Wed May 2 06:07:28 2012
@@ -50,7 +50,7 @@ public class ConfigurationEventHandler e
*/
public void handle(RemoteConfigurationEvent event) {
- if (event == null || event.getSourceGroup() == null || node == null || node.equals(event.getSourceNode()))
+ if (event == null || event.getSourceGroup() == null)
return;
// check if the handler is ON
@@ -70,27 +70,19 @@ public class ConfigurationEventHandler e
Map<String, Properties> configurationTable = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
- if (eventSwitch.getStatus().equals(SwitchStatus.ON)) {
- String pid = event.getId();
- //Check if the pid is marked as local.
- if (isAllowed(event.getSourceGroup(), Constants.CATEGORY, pid, EventType.INBOUND)) {
- Properties dictionary = configurationTable.get(pid);
- Configuration conf;
- try {
- conf = configurationAdmin.getConfiguration(pid);
- //Update the configurationTable.
- if (conf != null && dictionary != null) {
- Dictionary existingConfiguration = filterDictionary(conf.getProperties());
- if (!dictionariesEqual(dictionary, existingConfiguration)) {
- conf.update(preparePull(dictionary));
- }
- LOGGER.debug("CELLAR CONFIG: local configuration updated");
- }
- } catch (IOException ex) {
- LOGGER.error("CELLAR CONFIG: failed to read distributed map", ex);
- }
- } else LOGGER.warn("CELLAR CONFIG: configuration with PID {} is marked as BLOCKED INBOUND", pid);
- }
+ String pid = event.getId();
+ //Check if the pid is marked as local.
+ if (isAllowed(event.getSourceGroup(), Constants.CATEGORY, pid, EventType.INBOUND)) {
+ Properties dictionary = configurationTable.get(pid);
+ Configuration conf;
+ try {
+ // update the local configuration
+ conf = configurationAdmin.getConfiguration(pid);
+ conf.update(preparePull(dictionary));
+ } catch (IOException ex) {
+ LOGGER.error("CELLAR CONFIG: failed to read distributed map", ex);
+ }
+ } else LOGGER.warn("CELLAR CONFIG: configuration with PID {} is marked as BLOCKED INBOUND", pid);
}
/**
Modified: karaf/cellar/branches/cellar-2.2.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.2.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java?rev=1332925&r1=1332924&r2=1332925&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.2.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java (original)
+++ karaf/cellar/branches/cellar-2.2.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java Wed May 2 06:07:28 2012
@@ -28,8 +28,6 @@ public class ConfigurationSupport extend
private static String RELATIVE_HOME = "${" + HOME_PLACEHOLDER + "}";
private static String HOME = System.getProperty("karaf.home");
- private static String[] FILTERED_PROPERTIES = {"service.pid", "service.factoryPid", "felix.fileinstall.filename"};
-
/**
* Reads a {@code Dictionary} object and creates a property object out of it.
*
@@ -105,78 +103,4 @@ public class ConfigurationSupport extend
return result;
}
- public Dictionary filterDictionary(Dictionary dictionary) {
- Dictionary result = new Properties();
- if (dictionary != null) {
- Enumeration enumaration = dictionary.keys();
- while (enumaration.hasMoreElements()) {
- String key = (String) enumaration.nextElement();
- if (!isPropertyFiltered(key)) {
- String value = String.valueOf(dictionary.get(key));
- result.put(key, value);
- }
- }
- }
- return result;
- }
-
- /**
- * Returns true if dictionaries are equal.
- *
- * @param dict1
- * @param dict2
- * @return
- */
- protected boolean dictionariesEqual(Dictionary dict1, Dictionary dict2) {
- return subDictionary(dict1, dict2) && subDictionary(dict2, dict1);
- }
-
- /**
- * Returns true if target contains all source key/value pairs.
- *
- * @param source
- * @param target
- * @return
- */
- public boolean subDictionary(Dictionary source, Dictionary target) {
- if (source == null && target == null) {
- return true;
- } else if (source == null || target == null) {
- return false;
- } else if (source.isEmpty() && target.isEmpty()) {
- return true;
- } else {
- Enumeration keys = source.keys();
- while (keys.hasMoreElements()) {
- String key = (String) keys.nextElement();
- String value1 = (String) source.get(key);
- String value2 = (String) target.get(key);
-
- if (value1 == null && value2 == null)
- continue;
- else if (value1 == null)
- return false;
- else if (value2 == null)
- return false;
- else if (value1.equals(value2))
- continue;
- }
- return true;
- }
- }
-
- /**
- * Returns true if property is Filtered.
- *
- * @param propertyName
- * @return
- */
- public boolean isPropertyFiltered(String propertyName) {
- for (int i = 0; i < FILTERED_PROPERTIES.length; i++) {
- if (FILTERED_PROPERTIES[i].equals(propertyName))
- return true;
- }
- return false;
- }
-
}
Modified: karaf/cellar/branches/cellar-2.2.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSynchronizer.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.2.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSynchronizer.java?rev=1332925&r1=1332924&r2=1332925&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.2.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSynchronizer.java (original)
+++ karaf/cellar/branches/cellar-2.2.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSynchronizer.java Wed May 2 06:07:28 2012
@@ -93,7 +93,6 @@ public class ConfigurationSynchronizer e
//Mark the remote configuration event.
conf.update(preparePull(dictionary));
}
- LOGGER.debug("CELLAR CONFIG: read from the distributed map");
} catch (IOException ex) {
LOGGER.error("CELLAR CONFIG: failed to read from the distributed map", ex);
}
@@ -130,7 +129,7 @@ public class ConfigurationSynchronizer e
String pid = conf.getPid();
// check if the pid is marked as local.
if (isAllowed(group, Constants.CATEGORY, pid, EventType.OUTBOUND)) {
- Properties source = dictionaryToProperties(preparePush(filterDictionary(conf.getProperties())));
+ Properties source = dictionaryToProperties(preparePush(conf.getProperties()));
Properties target = configurationTable.get(pid);
if (target != null) {
boolean requiresUpdate = false;
@@ -154,7 +153,6 @@ public class ConfigurationSynchronizer e
configurationTable.put(pid, source);
eventProducer.produce(event);
}
- LOGGER.debug("CELLAR CONFIG: publishing PID {} to the distributed map", pid);
} else LOGGER.warn("CELLAR CONFIG: configuration with PID {} is marked as BLOCKED OUTBOUND", pid);
}
} catch (IOException ex) {
Modified: karaf/cellar/branches/cellar-2.2.x/config/src/main/java/org/apache/karaf/cellar/config/LocalConfigurationListener.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.2.x/config/src/main/java/org/apache/karaf/cellar/config/LocalConfigurationListener.java?rev=1332925&r1=1332924&r2=1332925&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.2.x/config/src/main/java/org/apache/karaf/cellar/config/LocalConfigurationListener.java (original)
+++ karaf/cellar/branches/cellar-2.2.x/config/src/main/java/org/apache/karaf/cellar/config/LocalConfigurationListener.java Wed May 2 06:07:28 2012
@@ -87,7 +87,7 @@ public class LocalConfigurationListener
try {
Configuration[] configurations = configurationAdmin.listConfigurations("(service.pid=" + pid + ")");
for (Configuration configuration : configurations) {
- Properties properties = dictionaryToProperties(preparePush(filterDictionary(configuration.getProperties())));
+ Properties properties = dictionaryToProperties(preparePush(configuration.getProperties()));
configurationTable.put(configuration.getPid(), properties);
}
} catch (IOException e) {
Modified: karaf/cellar/branches/cellar-2.2.x/config/src/main/java/org/apache/karaf/cellar/config/shell/PropSetCommand.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.2.x/config/src/main/java/org/apache/karaf/cellar/config/shell/PropSetCommand.java?rev=1332925&r1=1332924&r2=1332925&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.2.x/config/src/main/java/org/apache/karaf/cellar/config/shell/PropSetCommand.java (original)
+++ karaf/cellar/branches/cellar-2.2.x/config/src/main/java/org/apache/karaf/cellar/config/shell/PropSetCommand.java Wed May 2 06:07:28 2012
@@ -14,10 +14,13 @@
package org.apache.karaf.cellar.config.shell;
import org.apache.karaf.cellar.config.Constants;
+import org.apache.karaf.cellar.config.RemoteConfigurationEvent;
import org.apache.karaf.cellar.core.Configurations;
import org.apache.karaf.cellar.core.Group;
import org.apache.felix.gogo.commands.Argument;
import org.apache.felix.gogo.commands.Command;
+import org.apache.karaf.cellar.core.control.SwitchStatus;
+import org.apache.karaf.cellar.core.event.EventProducer;
import java.util.Map;
import java.util.Properties;
@@ -40,25 +43,49 @@ public class PropSetCommand extends Conf
@Argument(index = 3, name = "value", description = "The property value.", required = true, multiValued = false)
String value;
+ private EventProducer eventProducer;
+
@Override
protected Object doExecute() throws Exception {
+ // check if the group exists
Group group = groupManager.findGroupByName(groupName);
if (group == null) {
- System.err.println("Cluster group " + groupName + " doesn't exist.");
+ System.err.println("Cluster group " + groupName + " doesn't exist");
return null;
}
+
+ // check if the producer is ON
+ if (eventProducer.getSwitch().getStatus().equals(SwitchStatus.OFF)) {
+ System.err.println("Cluster event producer is OFF");
+ return null;
+ }
+
Map<String, Properties> configurationMap = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
if (configurationMap != null) {
+ // update the distributed map
Properties properties = configurationMap.get(pid);
if (properties == null) {
properties = new Properties();
}
properties.put(key, value);
configurationMap.put(pid, properties);
+
+ // broadcast the cluster event
+ RemoteConfigurationEvent event = new RemoteConfigurationEvent(pid);
+ event.setSourceGroup(group);
+ eventProducer.produce(event);
} else {
System.out.println("Configuration distributed map not found for cluster group " + groupName);
}
return null;
}
+ public EventProducer getEventProducer() {
+ return eventProducer;
+ }
+
+ public void setEventProducer(EventProducer eventProducer) {
+ this.eventProducer = eventProducer;
+ }
+
}
Modified: karaf/cellar/branches/cellar-2.2.x/config/src/main/resources/OSGI-INF/blueprint/shell-config.xml
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.2.x/config/src/main/resources/OSGI-INF/blueprint/shell-config.xml?rev=1332925&r1=1332924&r2=1332925&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.2.x/config/src/main/resources/OSGI-INF/blueprint/shell-config.xml (original)
+++ karaf/cellar/branches/cellar-2.2.x/config/src/main/resources/OSGI-INF/blueprint/shell-config.xml Wed May 2 06:07:28 2012
@@ -39,6 +39,7 @@
<action class="org.apache.karaf.cellar.config.shell.PropSetCommand">
<property name="clusterManager" ref="clusterManager"/>
<property name="groupManager" ref="groupManager"/>
+ <property name="eventProducer" ref="eventProducer"/>
</action>
<completers>
<ref component-id="allGroupCompleter"/>
Modified: karaf/cellar/branches/cellar-2.2.x/config/src/test/java/org/apache/karaf/cellar/config/ConfigurationSupportTest.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.2.x/config/src/test/java/org/apache/karaf/cellar/config/ConfigurationSupportTest.java?rev=1332925&r1=1332924&r2=1332925&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.2.x/config/src/test/java/org/apache/karaf/cellar/config/ConfigurationSupportTest.java (original)
+++ karaf/cellar/branches/cellar-2.2.x/config/src/test/java/org/apache/karaf/cellar/config/ConfigurationSupportTest.java Wed May 2 06:07:28 2012
@@ -27,25 +27,6 @@ public class ConfigurationSupportTest {
ConfigurationSupport support = new ConfigurationSupport();
@Test
- public void testFilterDictionary() {
- Dictionary result = null;
- Dictionary source = new Properties();
- Dictionary expectedResult = new Properties();
-
- source.put("key1", "value1");
- source.put("key2", "value2");
-
- expectedResult.put("key1", "value1");
- expectedResult.put("key2", "value2");
- result = support.filterDictionary(source);
-
- source.put("service.pid", "value3");
- result = support.filterDictionary(source);
-
- Assert.assertEquals(expectedResult, result);
- }
-
- @Test
public void testConvertStrings() throws Exception {
String absolutePath = "/somewehre/karaf/etc";
String home = "/somewehre/karaf";
Modified: karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastGroupManager.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastGroupManager.java?rev=1332925&r1=1332924&r2=1332925&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastGroupManager.java (original)
+++ karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastGroupManager.java Wed May 2 06:07:28 2012
@@ -490,7 +490,6 @@ public class HazelcastGroupManager imple
public void configurationEvent(ConfigurationEvent configurationEvent) {
String pid = configurationEvent.getPid();
if(pid.equals(GROUPS)) {
- LOGGER.info("Local group configuration has been updated, updating distributed group configuration");
Map groupConfiguration = instance.getMap(GROUPS_CONFIG);
try {