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 2013/04/23 19:11:15 UTC
svn commit: r1471046 - in /karaf/cellar/branches/cellar-2.3.x:
bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/
bundle/src/main/resources/OSGI-INF/blueprint/
config/src/main/java/org/apache/karaf/cellar/config/
config/src/main/java/org/apache...
Author: jbonofre
Date: Tue Apr 23 17:11:14 2013
New Revision: 1471046
URL: http://svn.apache.org/r1471046
Log:
Code cleanup.
Added:
karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/ClusterConfigurationEvent.java
- copied, changed from r1471001, karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/RemoteConfigurationEvent.java
Removed:
karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/RemoteConfigurationEvent.java
Modified:
karaf/cellar/branches/cellar-2.3.x/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/InstallBundleCommand.java
karaf/cellar/branches/cellar-2.3.x/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/ListBundleCommand.java
karaf/cellar/branches/cellar-2.3.x/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StartBundleCommand.java
karaf/cellar/branches/cellar-2.3.x/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StopBundleCommand.java
karaf/cellar/branches/cellar-2.3.x/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/UninstallBundleCommand.java
karaf/cellar/branches/cellar-2.3.x/bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml
karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationEventHandler.java
karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java
karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSynchronizer.java
karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/LocalConfigurationListener.java
karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/ConfigCommandSupport.java
karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/DeleteCommand.java
karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/ListCommand.java
karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/PropAppendCommand.java
karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/PropDelCommand.java
karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/PropListCommand.java
karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/PropSetCommand.java
karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/completers/ClusterConfigCompleter.java
karaf/cellar/branches/cellar-2.3.x/config/src/main/resources/OSGI-INF/blueprint/blueprint.xml
karaf/cellar/branches/cellar-2.3.x/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarConfigMBeanImpl.java
Modified: karaf/cellar/branches/cellar-2.3.x/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/InstallBundleCommand.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/InstallBundleCommand.java?rev=1471046&r1=1471045&r2=1471046&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/InstallBundleCommand.java (original)
+++ karaf/cellar/branches/cellar-2.3.x/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/InstallBundleCommand.java Tue Apr 23 17:11:14 2013
@@ -34,7 +34,7 @@ import java.util.Map;
import java.util.jar.JarInputStream;
import java.util.jar.Manifest;
-@Command(scope = "cluster", name = "bundle-install", description = "Install a bundle in a cluster group.")
+@Command(scope = "cluster", name = "bundle-install", description = "Install a bundle in a cluster group")
public class InstallBundleCommand extends CellarCommandSupport {
@Argument(index = 0, name = "group", description = "The cluster group name", required = true, multiValued = false)
Modified: karaf/cellar/branches/cellar-2.3.x/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/ListBundleCommand.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/ListBundleCommand.java?rev=1471046&r1=1471045&r2=1471046&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/ListBundleCommand.java (original)
+++ karaf/cellar/branches/cellar-2.3.x/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/ListBundleCommand.java Tue Apr 23 17:11:14 2013
@@ -25,7 +25,7 @@ import org.osgi.framework.BundleEvent;
import java.util.Map;
-@Command(scope = "cluster", name = "bundle-list", description = "List the bundles in a cluster group.")
+@Command(scope = "cluster", name = "bundle-list", description = "List the bundles in a cluster group")
public class ListBundleCommand extends CellarCommandSupport {
protected static final String HEADER_FORMAT = " %-4s %-11s %s";
Modified: karaf/cellar/branches/cellar-2.3.x/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StartBundleCommand.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StartBundleCommand.java?rev=1471046&r1=1471045&r2=1471046&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StartBundleCommand.java (original)
+++ karaf/cellar/branches/cellar-2.3.x/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StartBundleCommand.java Tue Apr 23 17:11:14 2013
@@ -27,7 +27,7 @@ import org.osgi.framework.BundleEvent;
import java.util.Map;
-@Command(scope = "cluster", name = "bundle-start", description = "Start a bundle in a cluster group.")
+@Command(scope = "cluster", name = "bundle-start", description = "Start a bundle in a cluster group")
public class StartBundleCommand extends BundleCommandSupport {
private EventProducer eventProducer;
Modified: karaf/cellar/branches/cellar-2.3.x/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StopBundleCommand.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StopBundleCommand.java?rev=1471046&r1=1471045&r2=1471046&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StopBundleCommand.java (original)
+++ karaf/cellar/branches/cellar-2.3.x/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StopBundleCommand.java Tue Apr 23 17:11:14 2013
@@ -27,7 +27,7 @@ import org.osgi.framework.BundleEvent;
import java.util.Map;
-@Command(scope = "cluster", name = "bundle-stop", description = "Stop a bundle in a cluster group.")
+@Command(scope = "cluster", name = "bundle-stop", description = "Stop a bundle in a cluster group")
public class StopBundleCommand extends BundleCommandSupport {
private EventProducer eventProducer;
Modified: karaf/cellar/branches/cellar-2.3.x/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/UninstallBundleCommand.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/UninstallBundleCommand.java?rev=1471046&r1=1471045&r2=1471046&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/UninstallBundleCommand.java (original)
+++ karaf/cellar/branches/cellar-2.3.x/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/UninstallBundleCommand.java Tue Apr 23 17:11:14 2013
@@ -27,7 +27,7 @@ import org.osgi.framework.BundleEvent;
import java.util.Map;
-@Command(scope = "cluster", name = "bundle-uninstall", description = "Uninstall a bundle from a cluster group.")
+@Command(scope = "cluster", name = "bundle-uninstall", description = "Uninstall a bundle from a cluster group")
public class UninstallBundleCommand extends BundleCommandSupport {
private EventProducer eventProducer;
Modified: karaf/cellar/branches/cellar-2.3.x/bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml?rev=1471046&r1=1471045&r2=1471046&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml (original)
+++ karaf/cellar/branches/cellar-2.3.x/bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml Tue Apr 23 17:11:14 2013
@@ -16,7 +16,7 @@
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<!-- Local Bundle Listener -->
- <bean id="localBundleListener" class="org.apache.karaf.cellar.bundle.LocalBundleListener" init-method="init" destroy-method="destroy">
+ <bean id="localListener" class="org.apache.karaf.cellar.bundle.LocalBundleListener" init-method="init" destroy-method="destroy">
<property name="clusterManager" ref="clusterManager"/>
<property name="groupManager" ref="groupManager"/>
<property name="configurationAdmin" ref="configurationAdmin"/>
Copied: karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/ClusterConfigurationEvent.java (from r1471001, karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/RemoteConfigurationEvent.java)
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/ClusterConfigurationEvent.java?p2=karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/ClusterConfigurationEvent.java&p1=karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/RemoteConfigurationEvent.java&r1=1471001&r2=1471046&rev=1471046&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/RemoteConfigurationEvent.java (original)
+++ karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/ClusterConfigurationEvent.java Tue Apr 23 17:11:14 2013
@@ -16,13 +16,13 @@ package org.apache.karaf.cellar.config;
import org.apache.karaf.cellar.core.event.Event;
/**
- * Remote configuration event.
+ * Cluster configuration event.
*/
-public class RemoteConfigurationEvent extends Event {
+public class ClusterConfigurationEvent extends Event {
private int type;
- public RemoteConfigurationEvent(String id) {
+ public ClusterConfigurationEvent(String id) {
super(id);
}
Modified: karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationEventHandler.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationEventHandler.java?rev=1471046&r1=1471045&r2=1471046&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationEventHandler.java (original)
+++ karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationEventHandler.java Tue Apr 23 17:11:14 2013
@@ -15,7 +15,6 @@ package org.apache.karaf.cellar.config;
import org.apache.karaf.cellar.core.Configurations;
import org.apache.karaf.cellar.core.Group;
-import org.apache.karaf.cellar.core.Node;
import org.apache.karaf.cellar.core.control.BasicSwitch;
import org.apache.karaf.cellar.core.control.Switch;
import org.apache.karaf.cellar.core.control.SwitchStatus;
@@ -32,9 +31,9 @@ import java.util.Map;
import java.util.Properties;
/**
- * Configuration event handler.
+ * ConfigurationEventHandler handles received cluster configuration event.
*/
-public class ConfigurationEventHandler extends ConfigurationSupport implements EventHandler<RemoteConfigurationEvent> {
+public class ConfigurationEventHandler extends ConfigurationSupport implements EventHandler<ClusterConfigurationEvent> {
private static final transient Logger LOGGER = LoggerFactory.getLogger(ConfigurationEventHandler.class);
@@ -42,7 +41,7 @@ public class ConfigurationEventHandler e
private final Switch eventSwitch = new BasicSwitch(SWITCH_ID);
- public void handle(RemoteConfigurationEvent event) {
+ public void handle(ClusterConfigurationEvent event) {
// check if the handler is ON
if (this.getSwitch().getStatus().equals(SwitchStatus.OFF)) {
@@ -52,62 +51,62 @@ public class ConfigurationEventHandler e
// check if the group is local
if (!groupManager.isLocalGroup(event.getSourceGroup().getName())) {
- LOGGER.debug("CELLAR CONFIG: node is not part of the event cluster group");
+ LOGGER.debug("CELLAR CONFIG: node is not part of the event cluster group {}", event.getSourceGroup().getName());
return;
}
Group group = event.getSourceGroup();
String groupName = group.getName();
- Map<String, Properties> distributedConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
+ Map<String, Properties> clusterConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
String pid = event.getId();
if (isAllowed(event.getSourceGroup(), Constants.CATEGORY, pid, EventType.INBOUND)) {
- Properties distributedDictionary = distributedConfigurations.get(pid);
- Configuration conf;
+ Properties clusterDictionary = clusterConfigurations.get(pid);
+ Configuration localConfiguration;
try {
// update the local configuration
- conf = configurationAdmin.getConfiguration(pid, null);
+ localConfiguration = configurationAdmin.getConfiguration(pid, null);
if (event.getType() == ConfigurationEvent.CM_DELETED) {
- if (conf.getProperties() != null) {
+ if (localConfiguration.getProperties() != null) {
// delete the properties
- conf.delete();
+ localConfiguration.delete();
deleteStorage(pid);
}
} else {
- if (distributedDictionary != null) {
- Dictionary localDictionary = conf.getProperties();
+ if (clusterDictionary != null) {
+ Dictionary localDictionary = localConfiguration.getProperties();
if (localDictionary == null)
localDictionary = new Properties();
localDictionary = filter(localDictionary);
- if (!equals(distributedDictionary, localDictionary)) {
- conf.update((Dictionary) distributedDictionary);
- persistConfiguration(configurationAdmin, pid, distributedDictionary);
+ if (!equals(clusterDictionary, localDictionary)) {
+ localConfiguration.update((Dictionary) clusterDictionary);
+ persistConfiguration(configurationAdmin, pid, clusterDictionary);
}
}
}
} catch (IOException ex) {
- LOGGER.error("CELLAR CONFIG: failed to read distributed map", ex);
+ LOGGER.error("CELLAR CONFIG: failed to update local configuration", ex);
}
- } else LOGGER.warn("CELLAR CONFIG: configuration with PID {} is marked as BLOCKED INBOUND", pid);
+ } else LOGGER.warn("CELLAR CONFIG: configuration with PID {} is marked BLOCKED INBOUND for cluster group {}", pid, groupName);
}
- /**
- * Initialization Method.
- */
public void init() {
-
+ // nothing to do
}
- /**
- * Destruction Method.
- */
public void destroy() {
-
+ // nothing to do
}
+ /**
+ * Get the configuration event handler switch.
+ *
+ * @return the configuration event handler switch.
+ */
+ @Override
public Switch getSwitch() {
// load the switch status from the config
try {
@@ -126,8 +125,14 @@ public class ConfigurationEventHandler e
return eventSwitch;
}
- public Class<RemoteConfigurationEvent> getType() {
- return RemoteConfigurationEvent.class;
+ /**
+ * Get the cluster event type.
+ *
+ * @return the cluster configuration event type.
+ */
+ @Override
+ public Class<ClusterConfigurationEvent> getType() {
+ return ClusterConfigurationEvent.class;
}
}
Modified: karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java?rev=1471046&r1=1471045&r2=1471046&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java (original)
+++ karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java Tue Apr 23 17:11:14 2013
@@ -27,7 +27,7 @@ import java.util.Enumeration;
import java.util.Properties;
/**
- * Configuration support.
+ * Generic configuration support.
*/
public class ConfigurationSupport extends CellarSupport {
@@ -38,10 +38,10 @@ public class ConfigurationSupport extend
protected File storage;
/**
- * Reads a {@code Dictionary} object and creates a property object out of it.
+ * Read a {@code Dictionary} and create a corresponding {@code Properties}.
*
- * @param dictionary
- * @return
+ * @param dictionary the source dictionary.
+ * @return the corresponding properties.
*/
public Properties dictionaryToProperties(Dictionary dictionary) {
Properties properties = new Properties();
@@ -62,8 +62,8 @@ public class ConfigurationSupport extend
/**
* Returns true if dictionaries are equal.
*
- * @param source the first dictionary
- * @param target the second dictionary
+ * @param source the source dictionary.
+ * @param target the target dictionary.
* @return true if the two dictionaries are equal, false else.
*/
protected boolean equals(Dictionary source, Dictionary target) {
@@ -101,7 +101,6 @@ public class ConfigurationSupport extend
* @param dictionary the source dictionary.
* @return the filtered dictionary
*/
-
public Dictionary filter(Dictionary dictionary) {
Dictionary result = new Properties();
if (dictionary != null) {
@@ -118,10 +117,10 @@ public class ConfigurationSupport extend
}
/**
- * Returns true if property is Filtered.
+ * Check if a property is in the default excluded list.
*
- * @param propertyName
- * @return
+ * @param propertyName the property name to check.
+ * @return true if the property is excluded, false else.
*/
public boolean isExcludedProperty(String propertyName) {
for (int i = 0; i < EXCLUDED_PROPERTIES.length; i++) {
@@ -134,8 +133,9 @@ public class ConfigurationSupport extend
/**
* Persist a configuration to a storage.
*
- * @param pid
- * @throws Exception
+ * @param admin the configuration admin service.
+ * @param pid the configuration PID.
+ * @param props the properties to store, associated with the configuration PID.
*/
protected void persistConfiguration(ConfigurationAdmin admin, String pid, Dictionary props) {
try {
@@ -191,6 +191,11 @@ public class ConfigurationSupport extend
}
}
+ /**
+ * Delete the storage file of a configuration.
+ *
+ * @param pid the configuration PID.
+ */
protected void deleteStorage(String pid) {
File cfgFile = new File(storage, pid + ".cfg");
cfgFile.delete();
Modified: karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSynchronizer.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSynchronizer.java?rev=1471046&r1=1471045&r2=1471046&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSynchronizer.java (original)
+++ karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSynchronizer.java Tue Apr 23 17:11:14 2013
@@ -26,14 +26,13 @@ import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.Dictionary;
-import java.util.Enumeration;
-import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
/**
- * Configuration synchronizer.
+ * The ConfigurationSynchronizer is called when Cellar starts or when a node joins a cluster group.
+ * The purpose is to synchronize local configurations with the configurations in the cluster groups.
*/
public class ConfigurationSynchronizer extends ConfigurationSupport implements Synchronizer {
@@ -41,16 +40,10 @@ public class ConfigurationSynchronizer e
private EventProducer eventProducer;
- /**
- * Constructor
- */
public ConfigurationSynchronizer() {
-
+ // nothing to do
}
- /**
- * Registration method
- */
public void init() {
Set<Group> groups = groupManager.listLocalGroups();
if (groups != null && !groups.isEmpty()) {
@@ -63,45 +56,46 @@ public class ConfigurationSynchronizer e
}
}
- /**
- * Destruction method
- */
public void destroy() {
-
+ // nothing to do
}
/**
- * Gets the configuration from the distributed map.
+ * Pull the configurations from a cluster group to update the local ones.
+ *
+ * @param group the cluster group where to get the configurations.
*/
public void pull(Group group) {
if (group != null) {
String groupName = group.getName();
- Map<String, Properties> distributedConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
+ LOGGER.debug("CELLAR CONFIG: pulling configurations from cluster group {}", groupName);
+
+ Map<String, Properties> clusterConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
- for (String pid : distributedConfigurations.keySet()) {
- if (isAllowed(group, Constants.CATEGORY, pid, EventType.INBOUND)) {
- Dictionary remoteDictionary = distributedConfigurations.get(pid);
+ for (String clusterPID : clusterConfigurations.keySet()) {
+ if (isAllowed(group, Constants.CATEGORY, clusterPID, EventType.INBOUND)) {
+ Dictionary clusterDictionary = clusterConfigurations.get(clusterPID);
try {
// update the local configuration if needed
- Configuration conf = configurationAdmin.getConfiguration(pid, null);
- Dictionary localDictionary = conf.getProperties();
+ Configuration localConfiguration = configurationAdmin.getConfiguration(clusterPID, null);
+ Dictionary localDictionary = localConfiguration.getProperties();
if (localDictionary == null)
localDictionary = new Properties();
localDictionary = filter(localDictionary);
- if (!equals(localDictionary, remoteDictionary)) {
- conf.update(localDictionary);
- persistConfiguration(configurationAdmin, pid, localDictionary);
+ if (!equals(localDictionary, clusterDictionary)) {
+ localConfiguration.update(localDictionary);
+ persistConfiguration(configurationAdmin, clusterPID, localDictionary);
}
} catch (IOException ex) {
- LOGGER.error("CELLAR CONFIG: failed to read from the distributed map", ex);
+ LOGGER.error("CELLAR CONFIG: failed to update local configuration", ex);
}
}
- LOGGER.warn("CELLAR CONFIG: configuration with PID {} is marked as BLOCKED INBOUND", pid);
+ LOGGER.warn("CELLAR CONFIG: configuration with PID {} is marked BLOCKED INBOUND for cluster group {}", clusterPID, groupName);
}
} finally {
Thread.currentThread().setContextClassLoader(originalClassLoader);
@@ -110,7 +104,9 @@ public class ConfigurationSynchronizer e
}
/**
- * Publish local configuration to the cluster.
+ * Push local configurations to a cluster group.
+ *
+ * @param group the cluster group where to update the configurations.
*/
public void push(Group group) {
@@ -122,32 +118,32 @@ public class ConfigurationSynchronizer e
if (group != null) {
String groupName = group.getName();
- Map<String, Properties> distributedConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
+ Map<String, Properties> clusterConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
- Configuration[] configs;
+ Configuration[] localConfigurations;
try {
- configs = configurationAdmin.listConfigurations(null);
- for (Configuration conf : configs) {
+ localConfigurations = configurationAdmin.listConfigurations(null);
+ for (Configuration conf : localConfigurations) {
String pid = conf.getPid();
if (isAllowed(group, Constants.CATEGORY, pid, EventType.OUTBOUND)) {
Dictionary localDictionary = conf.getProperties();
localDictionary = filter(localDictionary);
- // update the distributed map
- distributedConfigurations.put(pid, dictionaryToProperties(localDictionary));
+ // update the configurations in the cluster group
+ clusterConfigurations.put(pid, dictionaryToProperties(localDictionary));
// broadcast the cluster event
- RemoteConfigurationEvent event = new RemoteConfigurationEvent(pid);
+ ClusterConfigurationEvent event = new ClusterConfigurationEvent(pid);
event.setSourceGroup(group);
eventProducer.produce(event);
} else
- LOGGER.warn("CELLAR CONFIG: configuration with PID {} is marked as BLOCKED OUTBOUND", pid);
+ LOGGER.warn("CELLAR CONFIG: configuration with PID {} is marked BLOCKED OUTBOUND for cluster group {}", pid, groupName);
}
} catch (IOException ex) {
- LOGGER.error("CELLAR CONFIG: failed to read from the distributed map (IO error)", ex);
+ LOGGER.error("CELLAR CONFIG: failed to update configuration (IO error)", ex);
} catch (InvalidSyntaxException ex) {
- LOGGER.error("CELLAR CONFIG: failed to read from the distributed map (invalid syntax error)", ex);
+ LOGGER.error("CELLAR CONFIG: failed to update configuration (invalid syntax error)", ex);
}
} finally {
Thread.currentThread().setContextClassLoader(originalClassLoader);
@@ -155,6 +151,13 @@ public class ConfigurationSynchronizer e
}
}
+ /**
+ * Check if configuration sync flag is enabled for a cluster group.
+ *
+ * @param group the cluster group.
+ * @return true if the configuration sync flag is enabled for the cluster group, false else.
+ */
+ @Override
public Boolean isSyncEnabled(Group group) {
Boolean result = Boolean.FALSE;
String groupName = group.getName();
Modified: karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/LocalConfigurationListener.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/LocalConfigurationListener.java?rev=1471046&r1=1471045&r2=1471046&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/LocalConfigurationListener.java (original)
+++ karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/LocalConfigurationListener.java Tue Apr 23 17:11:14 2013
@@ -15,25 +15,23 @@ package org.apache.karaf.cellar.config;
import org.apache.karaf.cellar.core.Configurations;
import org.apache.karaf.cellar.core.Group;
-import org.apache.karaf.cellar.core.Node;
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.osgi.framework.InvalidSyntaxException;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationEvent;
import org.osgi.service.cm.ConfigurationListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.IOException;
import java.util.Dictionary;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
/**
- * Local configuration listener.
+ * LocalConfigurationListener is listening for local configuration changes.
+ * When a local configuration change occurs, this listener updates the cluster group and broadcasts a cluster config event.
*/
public class LocalConfigurationListener extends ConfigurationSupport implements ConfigurationListener {
@@ -42,11 +40,11 @@ public class LocalConfigurationListener
private EventProducer eventProducer;
/**
- * Handle local configuration events.
- * If the event is a pending event stop it. Else broadcast it to the cluster.
+ * Callback method called when a local configuration changes.
*
- * @param event
+ * @param event the local configuration event.
*/
+ @Override
public void configurationEvent(ConfigurationEvent event) {
// check if the producer is ON
@@ -75,55 +73,47 @@ public class LocalConfigurationListener
// check if the pid is allowed for outbound.
if (isAllowed(group, Constants.CATEGORY, pid, EventType.OUTBOUND)) {
- // update the distributed map if needed
- Map<String, Properties> distributedConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + group.getName());
+ Map<String, Properties> clusterConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + group.getName());
- // broadcast the cluster event
try {
if (event.getType() == ConfigurationEvent.CM_DELETED) {
- // update the distributed map
- distributedConfigurations.remove(pid);
+ // update the configurations in the cluster group
+ clusterConfigurations.remove(pid);
// broadcast the cluster event
- RemoteConfigurationEvent remoteConfigurationEvent = new RemoteConfigurationEvent(pid);
- remoteConfigurationEvent.setType(ConfigurationEvent.CM_DELETED);
- remoteConfigurationEvent.setSourceNode(clusterManager.getNode());
- remoteConfigurationEvent.setSourceGroup(group);
- eventProducer.produce(remoteConfigurationEvent);
+ ClusterConfigurationEvent clusterConfigurationEvent = new ClusterConfigurationEvent(pid);
+ clusterConfigurationEvent.setType(ConfigurationEvent.CM_DELETED);
+ clusterConfigurationEvent.setSourceNode(clusterManager.getNode());
+ clusterConfigurationEvent.setSourceGroup(group);
+ eventProducer.produce(clusterConfigurationEvent);
} else {
localDictionary = filter(localDictionary);
- Properties distributedDictionary = distributedConfigurations.get(pid);
+ Properties distributedDictionary = clusterConfigurations.get(pid);
if (!equals(localDictionary, distributedDictionary)) {
- // update the distributed map
- distributedConfigurations.put(pid, dictionaryToProperties(localDictionary));
+ // update the configurations in the cluster group
+ clusterConfigurations.put(pid, dictionaryToProperties(localDictionary));
// broadcast the cluster event
- RemoteConfigurationEvent remoteConfigurationEvent = new RemoteConfigurationEvent(pid);
- remoteConfigurationEvent.setSourceGroup(group);
- remoteConfigurationEvent.setSourceNode(clusterManager.getNode());
- eventProducer.produce(remoteConfigurationEvent);
+ ClusterConfigurationEvent clusterConfigurationEvent = new ClusterConfigurationEvent(pid);
+ clusterConfigurationEvent.setSourceGroup(group);
+ clusterConfigurationEvent.setSourceNode(clusterManager.getNode());
+ eventProducer.produce(clusterConfigurationEvent);
}
}
} catch (Exception e) {
- LOGGER.error("CELLAR CONFIG: failed to push configuration with PID {} to the distributed map", pid, e);
+ LOGGER.error("CELLAR CONFIG: failed to update configuration with PID {} to the cluster group {}", pid, group.getName(), e);
}
- } else LOGGER.warn("CELLAR CONFIG: configuration with PID {} is marked as BLOCKED OUTBOUND", pid);
+ } else LOGGER.warn("CELLAR CONFIG: configuration with PID {} is marked BLOCKED OUTBOUND for cluster group {}", pid, group.getName());
}
}
}
- /**
- * Initialization Method.
- */
public void init() {
-
+ // nothing to do
}
- /**
- * Destruction Method.
- */
public void destroy() {
-
+ // nothing to do
}
public EventProducer getEventProducer() {
Modified: karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/ConfigCommandSupport.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/ConfigCommandSupport.java?rev=1471046&r1=1471045&r2=1471046&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/ConfigCommandSupport.java (original)
+++ karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/ConfigCommandSupport.java Tue Apr 23 17:11:14 2013
@@ -19,10 +19,19 @@ import org.apache.karaf.cellar.core.even
import org.apache.karaf.cellar.core.shell.CellarCommandSupport;
/**
- * Abstract config command support.
+ * Abstract cluster config command support.
*/
public abstract class ConfigCommandSupport extends CellarCommandSupport {
+ /**
+ * Check if a configuration is allowed.
+ *
+ * @param group the cluster group.
+ * @param category the configuration category constant.
+ * @param pid the configuration PID.
+ * @param type the cluster event type.
+ * @return true if the cluster event type is allowed, false else.
+ */
public boolean isAllowed(Group group, String category, String pid, EventType type) {
CellarSupport support = new CellarSupport();
support.setClusterManager(this.clusterManager);
Modified: karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/DeleteCommand.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/DeleteCommand.java?rev=1471046&r1=1471045&r2=1471046&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/DeleteCommand.java (original)
+++ karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/DeleteCommand.java Tue Apr 23 17:11:14 2013
@@ -15,8 +15,8 @@ package org.apache.karaf.cellar.config.s
import org.apache.felix.gogo.commands.Argument;
import org.apache.felix.gogo.commands.Command;
+import org.apache.karaf.cellar.config.ClusterConfigurationEvent;
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.karaf.cellar.core.control.SwitchStatus;
@@ -27,7 +27,7 @@ import org.osgi.service.cm.Configuration
import java.util.Map;
import java.util.Properties;
-@Command(scope = "cluster", name = "config-delete", description = "Delete a configuration from the cluster")
+@Command(scope = "cluster", name = "config-delete", description = "Delete a configuration from a cluster group")
public class DeleteCommand extends ConfigCommandSupport {
@Argument(index = 0, name = "group", description = "The cluster group name", required = true, multiValued = false)
@@ -55,22 +55,22 @@ public class DeleteCommand extends Confi
// check if the config pid is allowed
if (!isAllowed(group, Constants.CATEGORY, pid, EventType.OUTBOUND)) {
- System.err.println("Configuration PID " + pid + " is blocked outbound");
+ System.err.println("Configuration PID " + pid + " is blocked outbound for cluster group " + group.getName());
return null;
}
- Map<String, Properties> distributedConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
- if (distributedConfigurations != null) {
- // update the distributed map
- Properties properties = distributedConfigurations.remove(pid);
+ Map<String, Properties> clusterConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
+ if (clusterConfigurations != null) {
+ // update the configurations in the cluster group
+ clusterConfigurations.remove(pid);
// broadcast the cluster event
- RemoteConfigurationEvent event = new RemoteConfigurationEvent(pid);
+ ClusterConfigurationEvent event = new ClusterConfigurationEvent(pid);
event.setSourceGroup(group);
event.setType(ConfigurationEvent.CM_DELETED);
eventProducer.produce(event);
} else {
- System.out.println("Configuration distributed map not found for cluster group " + groupName);
+ System.out.println("No configuration found in cluster group " + groupName);
}
return null;
Modified: karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/ListCommand.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/ListCommand.java?rev=1471046&r1=1471045&r2=1471046&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/ListCommand.java (original)
+++ karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/ListCommand.java Tue Apr 23 17:11:14 2013
@@ -24,10 +24,7 @@ import java.util.Enumeration;
import java.util.Map;
import java.util.Properties;
-/**
- * List cluster config command.
- */
-@Command(scope = "cluster", name = "config-list", description = "List the configuration PIDs assigned to a group")
+@Command(scope = "cluster", name = "config-list", description = "List the configurations in a cluster group")
public class ListCommand extends ConfigCommandSupport {
@Argument(index = 0, name = "group", description = "The cluster group name", required = true, multiValued = false)
@@ -48,15 +45,15 @@ public class ListCommand extends ConfigC
return null;
}
- Map<String, Properties> distributedConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
+ Map<String, Properties> clusterConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
- if (distributedConfigurations != null && !distributedConfigurations.isEmpty()) {
- for (String pid : distributedConfigurations.keySet()) {
+ if (clusterConfigurations != null && !clusterConfigurations.isEmpty()) {
+ for (String pid : clusterConfigurations.keySet()) {
if (searchPid == null || (searchPid != null && searchPid.equals(pid))) {
System.out.println("----------------------------------------------------------------");
System.out.println("Pid: " + pid);
if (!minimal) {
- Properties properties = distributedConfigurations.get(pid);
+ Properties properties = clusterConfigurations.get(pid);
if (properties != null) {
System.out.println("Properties:");
for (Enumeration e = properties.keys(); e.hasMoreElements(); ) {
@@ -67,7 +64,7 @@ public class ListCommand extends ConfigC
}
}
}
- } else System.err.println("No configuration PID found for cluster group " + groupName);
+ } else System.err.println("No configuration found in cluster group " + groupName);
return null;
}
Modified: karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/PropAppendCommand.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/PropAppendCommand.java?rev=1471046&r1=1471045&r2=1471046&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/PropAppendCommand.java (original)
+++ karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/PropAppendCommand.java Tue Apr 23 17:11:14 2013
@@ -15,8 +15,8 @@ package org.apache.karaf.cellar.config.s
import org.apache.felix.gogo.commands.Argument;
import org.apache.felix.gogo.commands.Command;
+import org.apache.karaf.cellar.config.ClusterConfigurationEvent;
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.karaf.cellar.core.control.SwitchStatus;
@@ -26,7 +26,7 @@ import org.apache.karaf.cellar.core.even
import java.util.Map;
import java.util.Properties;
-@Command(scope = "cluster", name = "config-propappend", description = "Append to the property value for a configuration PID in a cluster group name")
+@Command(scope = "cluster", name = "config-propappend", description = "Append value to a property for a configuration in a cluster group")
public class PropAppendCommand extends ConfigCommandSupport {
@Argument(index = 0, name = "group", description = "The cluster group name", required = true, multiValued = false)
@@ -60,14 +60,14 @@ public class PropAppendCommand extends C
// check if the config pid is allowed
if (!isAllowed(group, Constants.CATEGORY, pid, EventType.OUTBOUND)) {
- System.err.println("Configuration PID " + pid + " is blocked outbound");
+ System.err.println("Configuration PID " + pid + " is blocked outbound for cluster group " + groupName);
return null;
}
- Map<String, Properties> distributedConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
- if (distributedConfigurations != null) {
- // update the distributed map
- Properties properties = distributedConfigurations.get(pid);
+ Map<String, Properties> clusterConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
+ if (clusterConfigurations != null) {
+ // update the configurations in the cluster group
+ Properties properties = clusterConfigurations.get(pid);
if (properties == null) {
properties = new Properties();
}
@@ -80,14 +80,14 @@ public class PropAppendCommand extends C
System.err.println("Append failed: current value is not a String");
return null;
}
- distributedConfigurations.put(pid, properties);
+ clusterConfigurations.put(pid, properties);
// broadcast the cluster event
- RemoteConfigurationEvent event = new RemoteConfigurationEvent(pid);
+ ClusterConfigurationEvent event = new ClusterConfigurationEvent(pid);
event.setSourceGroup(group);
eventProducer.produce(event);
} else {
- System.out.println("Configuration distributed map not found for cluster group " + groupName);
+ System.out.println("No configuration found in cluster group " + groupName);
}
return null;
}
Modified: karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/PropDelCommand.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/PropDelCommand.java?rev=1471046&r1=1471045&r2=1471046&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/PropDelCommand.java (original)
+++ karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/PropDelCommand.java Tue Apr 23 17:11:14 2013
@@ -15,8 +15,8 @@ package org.apache.karaf.cellar.config.s
import org.apache.felix.gogo.commands.Argument;
import org.apache.felix.gogo.commands.Command;
+import org.apache.karaf.cellar.config.ClusterConfigurationEvent;
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.karaf.cellar.core.control.SwitchStatus;
@@ -26,7 +26,7 @@ import org.apache.karaf.cellar.core.even
import java.util.Map;
import java.util.Properties;
-@Command(scope = "cluster", name = "config-propdel", description = "Delete a property from a configuration PID assigned to a cluster group")
+@Command(scope = "cluster", name = "config-propdel", description = "Delete a property from a configuration in a cluster group")
public class PropDelCommand extends ConfigCommandSupport {
@Argument(index = 0, name = "group", description = "The cluster group name", required = true, multiValued = false)
@@ -57,24 +57,24 @@ public class PropDelCommand extends Conf
// check if the configuration PID is allowed
if (!isAllowed(group, Constants.CATEGORY, pid, EventType.OUTBOUND)) {
- System.err.println("Configuration PID " + pid + " is blocked outbound");
+ System.err.println("Configuration PID " + pid + " is blocked outbound for cluster group " + groupName);
return null;
}
- Map<String, Properties> distributedConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
- if (distributedConfigurations != null) {
+ Map<String, Properties> clusterConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
+ if (clusterConfigurations != null) {
// update the distributed map
- Properties distributedDictionary = distributedConfigurations.get(pid);
- if (distributedDictionary != null) {
- distributedDictionary.remove(key);
- distributedConfigurations.put(pid, distributedDictionary);
+ Properties clusterDictionary = clusterConfigurations.get(pid);
+ if (clusterDictionary != null) {
+ clusterDictionary.remove(key);
+ clusterConfigurations.put(pid, clusterDictionary);
// broadcast the cluster event
- RemoteConfigurationEvent event = new RemoteConfigurationEvent(pid);
+ ClusterConfigurationEvent event = new ClusterConfigurationEvent(pid);
event.setSourceGroup(group);
eventProducer.produce(event);
}
} else {
- System.out.println("Configuration distributed map is not found for cluster group " + groupName);
+ System.out.println("No configuration found in cluster group " + groupName);
}
return null;
Modified: karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/PropListCommand.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/PropListCommand.java?rev=1471046&r1=1471045&r2=1471046&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/PropListCommand.java (original)
+++ karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/PropListCommand.java Tue Apr 23 17:11:14 2013
@@ -23,10 +23,7 @@ import org.apache.felix.gogo.commands.Co
import java.util.Map;
import java.util.Properties;
-/**
- * Config properties list cluster command.
- */
-@Command(scope = "cluster", name = "config-proplist", description = "List the configuration PIDs assigned to a cluster group")
+@Command(scope = "cluster", name = "config-proplist", description = "List the properties of a configuration in a cluster group")
public class PropListCommand extends CellarCommandSupport {
protected static final String OUTPUT_FORMAT = "%-40s %s";
@@ -45,21 +42,21 @@ public class PropListCommand extends Cel
return null;
}
- Map<String, Properties> distributedConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
+ Map<String, Properties> clusterConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
- if (distributedConfigurations != null && !distributedConfigurations.isEmpty()) {
- Properties properties = distributedConfigurations.get(pid);
+ if (clusterConfigurations != null && !clusterConfigurations.isEmpty()) {
+ Properties properties = clusterConfigurations.get(pid);
if (properties == null || properties.isEmpty()) {
- System.err.println("No configuration PID found for group " + groupName);
+ System.err.println("Configuration PID not found in cluster group " + groupName);
} else {
- System.out.println(String.format("Property list for configuration PID " + pid + " for group " + groupName));
+ System.out.println(String.format("Property list for configuration PID " + pid + " in cluster group " + groupName));
System.out.println(String.format(OUTPUT_FORMAT, "Key", "Value"));
for (Object key : properties.keySet()) {
String value = properties.getProperty((String) key);
System.out.println(String.format(OUTPUT_FORMAT, key, value));
}
}
- } else System.err.println("No configuration PID found for group " + groupName);
+ } else System.err.println("No configuration found in cluster group " + groupName);
return null;
}
Modified: karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/PropSetCommand.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/PropSetCommand.java?rev=1471046&r1=1471045&r2=1471046&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/PropSetCommand.java (original)
+++ karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/PropSetCommand.java Tue Apr 23 17:11:14 2013
@@ -13,8 +13,8 @@
*/
package org.apache.karaf.cellar.config.shell;
+import org.apache.karaf.cellar.config.ClusterConfigurationEvent;
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;
@@ -26,10 +26,7 @@ import org.apache.karaf.cellar.core.even
import java.util.Map;
import java.util.Properties;
-/**
- * Config properties set cluster command.
- */
-@Command(scope = "cluster", name = "config-propset", description = "Sets the a property value for a configuration PID assigned to a cluster group")
+@Command(scope = "cluster", name = "config-propset", description = "Set a property in a configuration in a cluster group")
public class PropSetCommand extends ConfigCommandSupport {
@Argument(index = 0, name = "group", description = "The cluster group name", required = true, multiValued = false)
@@ -63,26 +60,26 @@ public class PropSetCommand extends Conf
// check if the config pid is allowed
if (!isAllowed(group, Constants.CATEGORY, pid, EventType.OUTBOUND)) {
- System.err.println("Configuration PID " + pid + " is blocked outbound");
+ System.err.println("Configuration PID " + pid + " is blocked outbound for cluster group " + groupName);
return null;
}
- Map<String, Properties> distributedConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
- if (distributedConfigurations != null) {
- // update the distributed configuration
- Properties properties = distributedConfigurations.get(pid);
- if (properties == null) {
- properties = new Properties();
+ Map<String, Properties> clusterConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
+ if (clusterConfigurations != null) {
+ // update configurations in the cluster group
+ Properties clusterProperties = clusterConfigurations.get(pid);
+ if (clusterProperties == null) {
+ clusterProperties = new Properties();
}
- properties.put(key, value);
- distributedConfigurations.put(pid, properties);
+ clusterProperties.put(key, value);
+ clusterConfigurations.put(pid, clusterProperties);
// broadcast the cluster event
- RemoteConfigurationEvent event = new RemoteConfigurationEvent(pid);
+ ClusterConfigurationEvent event = new ClusterConfigurationEvent(pid);
event.setSourceGroup(group);
eventProducer.produce(event);
} else {
- System.out.println("Configuration distributed map not found for cluster group " + groupName);
+ System.out.println("No configuration found in cluster group " + groupName);
}
return null;
}
Modified: karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/completers/ClusterConfigCompleter.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/completers/ClusterConfigCompleter.java?rev=1471046&r1=1471045&r2=1471046&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/completers/ClusterConfigCompleter.java (original)
+++ karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/shell/completers/ClusterConfigCompleter.java Tue Apr 23 17:11:14 2013
@@ -26,32 +26,32 @@ import java.util.Map;
import java.util.Properties;
/**
- * Command completer on the cluster config.
+ * Command completer for configurations in cluster groups.
*/
public class ClusterConfigCompleter implements Completer {
protected ClusterManager clusterManager;
protected GroupManager groupManager;
+ @Override
public int complete(String buffer, int cursor, List<String> candidates) {
StringsCompleter delegate = new StringsCompleter();
try {
Map<String, Group> groups = groupManager.listGroups();
if (groups != null && !groups.isEmpty()) {
for (String groupName : groups.keySet()) {
- Map<String, Properties> configurationTable = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
- if (configurationTable != null && !configurationTable.isEmpty()) {
- for (String pid : configurationTable.keySet()) {
- if (delegate.getStrings() != null && !delegate.getStrings().contains(pid)) {
- delegate.getStrings().add(pid);
+ Map<String, Properties> clusterConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
+ if (clusterConfigurations != null && !clusterConfigurations.isEmpty()) {
+ for (String clusterConfiguration : clusterConfigurations.keySet()) {
+ if (delegate.getStrings() != null && !delegate.getStrings().contains(clusterConfiguration)) {
+ delegate.getStrings().add(clusterConfiguration);
}
}
}
}
}
-
} catch (Exception e) {
- // Ignore
+ // nothing to do
}
return delegate.complete(buffer, cursor, candidates);
}
Modified: karaf/cellar/branches/cellar-2.3.x/config/src/main/resources/OSGI-INF/blueprint/blueprint.xml
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/config/src/main/resources/OSGI-INF/blueprint/blueprint.xml?rev=1471046&r1=1471045&r2=1471046&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/config/src/main/resources/OSGI-INF/blueprint/blueprint.xml (original)
+++ karaf/cellar/branches/cellar-2.3.x/config/src/main/resources/OSGI-INF/blueprint/blueprint.xml Tue Apr 23 17:11:14 2013
@@ -18,14 +18,14 @@
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"
+ <bean id="localListener" class="org.apache.karaf.cellar.config.LocalConfigurationListener" init-method="init"
destroy-method="destroy">
<property name="clusterManager" ref="clusterManager"/>
<property name="groupManager" ref="groupManager"/>
<property name="configurationAdmin" ref="configurationAdmin"/>
<property name="eventProducer" ref="eventProducer"/>
</bean>
- <service ref="configurationListener" interface="org.osgi.service.cm.ConfigurationListener"/>
+ <service ref="localListener" interface="org.osgi.service.cm.ConfigurationListener"/>
<!-- Configuration Synchronizer -->
<bean id="synchronizer" class="org.apache.karaf.cellar.config.ConfigurationSynchronizer"
Modified: karaf/cellar/branches/cellar-2.3.x/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarConfigMBeanImpl.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarConfigMBeanImpl.java?rev=1471046&r1=1471045&r2=1471046&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarConfigMBeanImpl.java (original)
+++ karaf/cellar/branches/cellar-2.3.x/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarConfigMBeanImpl.java Tue Apr 23 17:11:14 2013
@@ -13,8 +13,8 @@
*/
package org.apache.karaf.cellar.management.internal;
+import org.apache.karaf.cellar.config.ClusterConfigurationEvent;
import org.apache.karaf.cellar.config.Constants;
-import org.apache.karaf.cellar.config.RemoteConfigurationEvent;
import org.apache.karaf.cellar.core.*;
import org.apache.karaf.cellar.core.control.SwitchStatus;
import org.apache.karaf.cellar.core.event.EventProducer;
@@ -86,7 +86,7 @@ public class CellarConfigMBeanImpl exten
Properties properties = distributedConfigurations.remove(pid);
// broadcast the cluster event
- RemoteConfigurationEvent event = new RemoteConfigurationEvent(pid);
+ ClusterConfigurationEvent event = new ClusterConfigurationEvent(pid);
event.setSourceGroup(group);
event.setType(ConfigurationEvent.CM_DELETED);
eventProducer.produce(event);
@@ -152,7 +152,7 @@ public class CellarConfigMBeanImpl exten
distributedConfigurations.put(pid, properties);
// broadcast the cluster event
- RemoteConfigurationEvent event = new RemoteConfigurationEvent(pid);
+ ClusterConfigurationEvent event = new ClusterConfigurationEvent(pid);
event.setSourceGroup(group);
eventProducer.produce(event);
} else {
@@ -199,7 +199,7 @@ public class CellarConfigMBeanImpl exten
distributedConfigurations.put(pid, properties);
// broadcast the cluster event
- RemoteConfigurationEvent event = new RemoteConfigurationEvent(pid);
+ ClusterConfigurationEvent event = new ClusterConfigurationEvent(pid);
event.setSourceGroup(group);
eventProducer.produce(event);
} else {
@@ -236,7 +236,7 @@ public class CellarConfigMBeanImpl exten
distributedDictionary.remove(key);
distributedConfigurations.put(pid, distributedDictionary);
// broadcast the cluster event
- RemoteConfigurationEvent event = new RemoteConfigurationEvent(pid);
+ ClusterConfigurationEvent event = new ClusterConfigurationEvent(pid);
event.setSourceGroup(group);
eventProducer.produce(event);
}