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/12/18 13:22:41 UTC
[06/50] [abbrv] git commit: Code cleanup.
Code cleanup.
git-svn-id: https://svn.apache.org/repos/asf/karaf/cellar/trunk@1471026 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/karaf-cellar/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf-cellar/commit/e08a2e87
Tree: http://git-wip-us.apache.org/repos/asf/karaf-cellar/tree/e08a2e87
Diff: http://git-wip-us.apache.org/repos/asf/karaf-cellar/diff/e08a2e87
Branch: refs/heads/master
Commit: e08a2e87156df21ca80a0d02e712a669c1105bd8
Parents: d8543b6
Author: jbonofre <jb...@13f79535-47bb-0310-9956-ffa450edef68>
Authored: Tue Apr 23 16:19:27 2013 +0000
Committer: jbonofre <jb...@13f79535-47bb-0310-9956-ffa450edef68>
Committed: Tue Apr 23 16:19:27 2013 +0000
----------------------------------------------------------------------
.../karaf/cellar/bundle/BundleSynchronizer.java | 4 +-
.../cellar/bundle/LocalBundleListener.java | 2 +-
.../bundle/shell/InstallBundleCommand.java | 2 +-
.../cellar/bundle/shell/ListBundleCommand.java | 2 +-
.../cellar/bundle/shell/StartBundleCommand.java | 2 +-
.../cellar/bundle/shell/StopBundleCommand.java | 2 +-
.../bundle/shell/UninstallBundleCommand.java | 2 +-
.../resources/OSGI-INF/blueprint/blueprint.xml | 2 +-
.../config/ClusterConfigurationEvent.java | 45 +++++++++++
.../config/ConfigurationEventHandler.java | 53 +++++++------
.../cellar/config/ConfigurationSupport.java | 30 +++++---
.../config/ConfigurationSynchronizer.java | 81 ++++++++++----------
.../config/LocalConfigurationListener.java | 59 ++++++--------
.../cellar/config/RemoteConfigurationEvent.java | 55 -------------
.../config/shell/ConfigCommandSupport.java | 11 ++-
.../cellar/config/shell/DeleteCommand.java | 16 ++--
.../karaf/cellar/config/shell/ListCommand.java | 12 +--
.../cellar/config/shell/PropAppendCommand.java | 20 ++---
.../cellar/config/shell/PropDelCommand.java | 21 ++---
.../cellar/config/shell/PropListCommand.java | 14 ++--
.../cellar/config/shell/PropSetCommand.java | 20 ++---
.../completers/ClusterConfigCompleter.java | 11 +--
.../resources/OSGI-INF/blueprint/blueprint.xml | 2 +-
.../internal/CellarConfigMBeanImpl.java | 10 +--
24 files changed, 242 insertions(+), 236 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/e08a2e87/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleSynchronizer.java
----------------------------------------------------------------------
diff --git a/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleSynchronizer.java b/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleSynchronizer.java
index be04ae9..4114ce5 100644
--- a/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleSynchronizer.java
+++ b/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleSynchronizer.java
@@ -34,8 +34,8 @@ import java.util.Map;
import java.util.Set;
/**
- * The BundleSynchronizer is called when Cellar starts or a node join a cluster group.
- * The purpose is synchronize bundles local state with the states in cluster groups.
+ * The BundleSynchronizer is called when Cellar starts or a node joins a cluster group.
+ * The purpose is to synchronize bundles local state with the states in the cluster groups.
*/
public class BundleSynchronizer extends BundleSupport implements Synchronizer {
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/e08a2e87/bundle/src/main/java/org/apache/karaf/cellar/bundle/LocalBundleListener.java
----------------------------------------------------------------------
diff --git a/bundle/src/main/java/org/apache/karaf/cellar/bundle/LocalBundleListener.java b/bundle/src/main/java/org/apache/karaf/cellar/bundle/LocalBundleListener.java
index 4209278..cba2f83 100644
--- a/bundle/src/main/java/org/apache/karaf/cellar/bundle/LocalBundleListener.java
+++ b/bundle/src/main/java/org/apache/karaf/cellar/bundle/LocalBundleListener.java
@@ -30,7 +30,7 @@ import java.util.Set;
/**
* LocalBundleListener is listening for local bundles changes.
- * When a local bundle change occurs, this listener updates the cluster and broadcast a cluster bundle event.
+ * When a local bundle change occurs, this listener updates the cluster and broadcasts a cluster bundle event.
*/
public class LocalBundleListener extends BundleSupport implements SynchronousBundleListener {
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/e08a2e87/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/InstallBundleCommand.java
----------------------------------------------------------------------
diff --git a/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/InstallBundleCommand.java b/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/InstallBundleCommand.java
index 903cfab..81ebc46 100644
--- a/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/InstallBundleCommand.java
+++ b/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/InstallBundleCommand.java
@@ -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 bundles in a cluster group")
public class InstallBundleCommand extends CellarCommandSupport {
@Argument(index = 0, name = "group", description = "The cluster group name", required = true, multiValued = false)
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/e08a2e87/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/ListBundleCommand.java
----------------------------------------------------------------------
diff --git a/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/ListBundleCommand.java b/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/ListBundleCommand.java
index e836ccb..eaf1ace 100644
--- a/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/ListBundleCommand.java
+++ b/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/ListBundleCommand.java
@@ -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";
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/e08a2e87/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StartBundleCommand.java
----------------------------------------------------------------------
diff --git a/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StartBundleCommand.java b/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StartBundleCommand.java
index a695477..beee496 100644
--- a/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StartBundleCommand.java
+++ b/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StartBundleCommand.java
@@ -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;
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/e08a2e87/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StopBundleCommand.java
----------------------------------------------------------------------
diff --git a/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StopBundleCommand.java b/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StopBundleCommand.java
index 86d9c6f..2f94b07 100644
--- a/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StopBundleCommand.java
+++ b/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StopBundleCommand.java
@@ -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;
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/e08a2e87/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/UninstallBundleCommand.java
----------------------------------------------------------------------
diff --git a/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/UninstallBundleCommand.java b/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/UninstallBundleCommand.java
index 3f58c0f..d48a360 100644
--- a/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/UninstallBundleCommand.java
+++ b/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/UninstallBundleCommand.java
@@ -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;
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/e08a2e87/bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml
----------------------------------------------------------------------
diff --git a/bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml
index efd5e20..20ab5a5 100644
--- a/bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ b/bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -18,7 +18,7 @@
http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<!-- Local Bundle Listener -->
- <bean id="localBundleListener" class="org.apache.karaf.cellar.bundle.LocalBundleListener" init-method="init"
+ <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"/>
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/e08a2e87/config/src/main/java/org/apache/karaf/cellar/config/ClusterConfigurationEvent.java
----------------------------------------------------------------------
diff --git a/config/src/main/java/org/apache/karaf/cellar/config/ClusterConfigurationEvent.java b/config/src/main/java/org/apache/karaf/cellar/config/ClusterConfigurationEvent.java
new file mode 100644
index 0000000..d3eb7ee
--- /dev/null
+++ b/config/src/main/java/org/apache/karaf/cellar/config/ClusterConfigurationEvent.java
@@ -0,0 +1,45 @@
+/*
+ * 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;
+
+import org.apache.karaf.cellar.core.event.Event;
+
+/**
+ * Cluster configuration event.
+ */
+public class ClusterConfigurationEvent extends Event {
+
+ private int type;
+
+ public ClusterConfigurationEvent(String id) {
+ super(id);
+ }
+
+ public int getType() {
+ return type;
+ }
+
+ public void setType(int type) {
+ this.type = type;
+ }
+
+ @Override
+ public String toString() {
+ return "ClusterConfigurationEvent [type=" + type + ", id=" + id
+ + ", sourceNode=" + sourceNode + ", sourceGroup=" + sourceGroup
+ + ", destination=" + destination + ", force=" + force
+ + ", postPublish=" + postPublish + "]";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/e08a2e87/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationEventHandler.java
----------------------------------------------------------------------
diff --git a/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationEventHandler.java b/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationEventHandler.java
index e355dc3..1ebfde6 100644
--- a/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationEventHandler.java
+++ b/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationEventHandler.java
@@ -31,9 +31,9 @@ import java.util.Map;
import java.util.Properties;
/**
- * Configuration event handler.
+ * ConfigurationEventHandler handles received configuration cluster 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);
@@ -41,7 +41,8 @@ public class ConfigurationEventHandler extends ConfigurationSupport implements E
private final Switch eventSwitch = new BasicSwitch(SWITCH_ID);
- public void handle(RemoteConfigurationEvent event) {
+ @Override
+ public void handle(ClusterConfigurationEvent event) {
// check if the handler is ON
if (this.getSwitch().getStatus().equals(SwitchStatus.OFF)) {
@@ -57,20 +58,20 @@ public class ConfigurationEventHandler extends ConfigurationSupport implements 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);
+ Properties clusterDictionary = clusterConfigurations.get(pid);
Configuration conf;
try {
conf = configurationAdmin.getConfiguration(pid, null);
@@ -81,37 +82,37 @@ public class ConfigurationEventHandler extends ConfigurationSupport implements E
deleteStorage(pid);
}
} else {
- if (distributedDictionary != null) {
+ if (clusterDictionary != null) {
Dictionary localDictionary = conf.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)) {
+ conf.update((Dictionary) clusterDictionary);
+ persistConfiguration(configurationAdmin, pid, clusterDictionary);
}
}
}
} catch (IOException ex) {
- LOGGER.error("CELLAR CONFIG: failed to read remote distributed map", ex);
+ LOGGER.error("CELLAR CONFIG: failed to read cluster configuration", ex);
}
- } else LOGGER.warn("CELLAR CONFIG: configuration with pid {} is marked as BLOCKED INBOUND", pid);
+ } else LOGGER.warn("CELLAR CONFIG: configuration 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 cluster configuration event handler switch.
+ *
+ * @return the cluster configuration event handler switch.
+ */
+ @Override
public Switch getSwitch() {
// load the switch status from the config
try {
@@ -125,13 +126,19 @@ public class ConfigurationEventHandler extends ConfigurationSupport implements E
}
}
} catch (Exception e) {
- // ignore
+ // nothing to do
}
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;
}
}
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/e08a2e87/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 3113bd4..fa6f986 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
@@ -24,7 +24,7 @@ import java.net.URL;
import java.util.*;
/**
- * Configuration support.
+ * Generic configuration support.
*/
public class ConfigurationSupport extends CellarSupport {
@@ -35,10 +35,10 @@ public class ConfigurationSupport extends CellarSupport {
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();
@@ -59,8 +59,8 @@ public class ConfigurationSupport extends CellarSupport {
/**
* 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) {
@@ -98,7 +98,6 @@ public class ConfigurationSupport extends CellarSupport {
* @param dictionary the source dictionary.
* @return the filtered dictionary
*/
-
public Dictionary filter(Dictionary dictionary) {
Dictionary result = new Properties();
if (dictionary != null) {
@@ -115,10 +114,10 @@ public class ConfigurationSupport extends CellarSupport {
}
/**
- * 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 is the property is excluded, false else.
*/
public boolean isExcludedProperty(String propertyName) {
for (int i = 0; i < EXCLUDED_PROPERTIES.length; i++) {
@@ -131,8 +130,10 @@ public class ConfigurationSupport extends CellarSupport {
/**
* Persist a configuration to a storage.
*
- * @param pid
- * @throws Exception
+ * @param admin the configuration admin service.
+ * @param pid the configuration PID to store.
+ * @param props the properties to store, linked to the configuration PID.
+ * @throws Exception in case of store failure.
*/
protected void persistConfiguration(ConfigurationAdmin admin, String pid, Dictionary props) {
try {
@@ -188,6 +189,11 @@ public class ConfigurationSupport extends CellarSupport {
}
}
+ /**
+ * Delete the storage of a configuration.
+ *
+ * @param pid the configuration PID to delete.
+ */
protected void deleteStorage(String pid) {
File cfgFile = new File(storage, pid + ".cfg");
cfgFile.delete();
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/e08a2e87/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSynchronizer.java
----------------------------------------------------------------------
diff --git a/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSynchronizer.java b/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSynchronizer.java
index 3cd4fd1..a30b459 100644
--- a/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSynchronizer.java
+++ b/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSynchronizer.java
@@ -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 extends ConfigurationSupport implements S
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,44 +56,45 @@ public class ConfigurationSynchronizer extends ConfigurationSupport implements S
}
}
- /**
- * Destruction method
- */
public void destroy() {
-
+ // nothing to do
}
/**
- * Gets the configuration from the distributed map.
+ * Pull the configuration 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 clusterConfiguration : clusterConfigurations.keySet()) {
+ if (isAllowed(group, Constants.CATEGORY, clusterConfiguration, EventType.INBOUND)) {
+ Dictionary clusterDictionary = clusterConfigurations.get(clusterConfiguration);
try {
// update the local configuration if needed
- Configuration conf = configurationAdmin.getConfiguration(pid, null);
- Dictionary localDictionary = conf.getProperties();
+ Configuration localConfiguration = configurationAdmin.getConfiguration(clusterConfiguration, 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, clusterConfiguration, localDictionary);
}
} catch (IOException ex) {
- LOGGER.error("CELLAR CONFIG: failed to read distributed map", ex);
+ LOGGER.error("CELLAR CONFIG: failed to read 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 {}", clusterConfiguration, groupName);
}
} finally {
Thread.currentThread().setContextClassLoader(originalClassLoader);
@@ -109,7 +103,9 @@ public class ConfigurationSynchronizer extends ConfigurationSupport implements S
}
/**
- * 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) {
@@ -121,33 +117,34 @@ public class ConfigurationSynchronizer extends ConfigurationSupport implements S
if (group != null) {
String groupName = group.getName();
- Map<String, Properties> distributedConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
+ LOGGER.debug("CELLAR CONFIG: pushing configurations to 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());
- Configuration[] configs;
+ Configuration[] localConfigurations;
try {
- configs = configurationAdmin.listConfigurations(null);
- for (Configuration conf : configs) {
- String pid = conf.getPid();
+ localConfigurations = configurationAdmin.listConfigurations(null);
+ for (Configuration localConfiguration : localConfigurations) {
+ String pid = localConfiguration.getPid();
// check if the pid is marked as local.
if (isAllowed(group, Constants.CATEGORY, pid, EventType.OUTBOUND)) {
- Dictionary localDictionary = conf.getProperties();
+ Dictionary localDictionary = localConfiguration.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 the distributed map (IO error)", ex);
+ LOGGER.error("CELLAR CONFIG: failed to read configuration (IO error)", ex);
} catch (InvalidSyntaxException ex) {
- LOGGER.error("CELLAR CONFIG: failed to read the distributed map (invalid filter syntax)", ex);
+ LOGGER.error("CELLAR CONFIG: failed to read configuration (invalid filter syntax)", ex);
}
} finally {
Thread.currentThread().setContextClassLoader(originalClassLoader);
@@ -155,6 +152,12 @@ public class ConfigurationSynchronizer extends ConfigurationSupport implements S
}
}
+ /**
+ * 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;
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/e08a2e87/config/src/main/java/org/apache/karaf/cellar/config/LocalConfigurationListener.java
----------------------------------------------------------------------
diff --git a/config/src/main/java/org/apache/karaf/cellar/config/LocalConfigurationListener.java b/config/src/main/java/org/apache/karaf/cellar/config/LocalConfigurationListener.java
index e16a7c6..de4e105 100644
--- a/config/src/main/java/org/apache/karaf/cellar/config/LocalConfigurationListener.java
+++ b/config/src/main/java/org/apache/karaf/cellar/config/LocalConfigurationListener.java
@@ -15,22 +15,20 @@ 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.*;
/**
- * 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 {
@@ -39,11 +37,11 @@ public class LocalConfigurationListener extends ConfigurationSupport implements
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
@@ -72,56 +70,47 @@ public class LocalConfigurationListener extends ConfigurationSupport implements
// 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 {} in 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() {
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/e08a2e87/config/src/main/java/org/apache/karaf/cellar/config/RemoteConfigurationEvent.java
----------------------------------------------------------------------
diff --git a/config/src/main/java/org/apache/karaf/cellar/config/RemoteConfigurationEvent.java b/config/src/main/java/org/apache/karaf/cellar/config/RemoteConfigurationEvent.java
deleted file mode 100644
index def8443..0000000
--- a/config/src/main/java/org/apache/karaf/cellar/config/RemoteConfigurationEvent.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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;
-
-import org.apache.karaf.cellar.core.event.Event;
-
-/**
- * Remote configuration event.
- */
-public class RemoteConfigurationEvent extends Event {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- private int type;
-
- public RemoteConfigurationEvent(String id) {
- super(id);
- }
-
- public int getType() {
- return type;
- }
-
- public void setType(int type) {
- this.type = type;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "RemoteConfigurationEvent [type=" + type + ", id=" + id
- + ", sourceNode=" + sourceNode + ", sourceGroup=" + sourceGroup
- + ", destination=" + destination + ", force=" + force
- + ", postPublish=" + postPublish + "]";
- }
-
-
-
-}
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/e08a2e87/config/src/main/java/org/apache/karaf/cellar/config/shell/ConfigCommandSupport.java
----------------------------------------------------------------------
diff --git a/config/src/main/java/org/apache/karaf/cellar/config/shell/ConfigCommandSupport.java b/config/src/main/java/org/apache/karaf/cellar/config/shell/ConfigCommandSupport.java
index 5b3c185..631a749 100644
--- a/config/src/main/java/org/apache/karaf/cellar/config/shell/ConfigCommandSupport.java
+++ b/config/src/main/java/org/apache/karaf/cellar/config/shell/ConfigCommandSupport.java
@@ -19,10 +19,19 @@ import org.apache.karaf.cellar.core.event.EventType;
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);
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/e08a2e87/config/src/main/java/org/apache/karaf/cellar/config/shell/DeleteCommand.java
----------------------------------------------------------------------
diff --git a/config/src/main/java/org/apache/karaf/cellar/config/shell/DeleteCommand.java b/config/src/main/java/org/apache/karaf/cellar/config/shell/DeleteCommand.java
index 2fb0c2f..220dc41 100644
--- a/config/src/main/java/org/apache/karaf/cellar/config/shell/DeleteCommand.java
+++ b/config/src/main/java/org/apache/karaf/cellar/config/shell/DeleteCommand.java
@@ -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.karaf.cellar.core.control.SwitchStatus;
@@ -27,7 +27,7 @@ import org.osgi.service.cm.ConfigurationEvent;
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,17 +55,17 @@ public class DeleteCommand extends ConfigCommandSupport {
// 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.remove(pid);
+ Map<String, Properties> clusterConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
+ if (clusterConfigurations != null) {
+ // update configurations in the cluster group
+ clusterConfigurations.remove(pid);
// broadcast a cluster event
- RemoteConfigurationEvent event = new RemoteConfigurationEvent(pid);
+ ClusterConfigurationEvent event = new ClusterConfigurationEvent(pid);
event.setSourceGroup(group);
event.setType(ConfigurationEvent.CM_DELETED);
eventProducer.produce(event);
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/e08a2e87/config/src/main/java/org/apache/karaf/cellar/config/shell/ListCommand.java
----------------------------------------------------------------------
diff --git a/config/src/main/java/org/apache/karaf/cellar/config/shell/ListCommand.java b/config/src/main/java/org/apache/karaf/cellar/config/shell/ListCommand.java
index 652ed40..8ef55bf 100644
--- a/config/src/main/java/org/apache/karaf/cellar/config/shell/ListCommand.java
+++ b/config/src/main/java/org/apache/karaf/cellar/config/shell/ListCommand.java
@@ -24,7 +24,7 @@ import java.util.Enumeration;
import java.util.Map;
import java.util.Properties;
-@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)
@@ -45,15 +45,15 @@ public class ListCommand extends ConfigCommandSupport {
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(); ) {
@@ -64,7 +64,7 @@ public class ListCommand extends ConfigCommandSupport {
}
}
}
- } else System.err.println("No configuration PID found for cluster group " + groupName);
+ } else System.err.println("No configuration PID found in cluster group " + groupName);
return null;
}
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/e08a2e87/config/src/main/java/org/apache/karaf/cellar/config/shell/PropAppendCommand.java
----------------------------------------------------------------------
diff --git a/config/src/main/java/org/apache/karaf/cellar/config/shell/PropAppendCommand.java b/config/src/main/java/org/apache/karaf/cellar/config/shell/PropAppendCommand.java
index 2793a30..8cbcba0 100644
--- a/config/src/main/java/org/apache/karaf/cellar/config/shell/PropAppendCommand.java
+++ b/config/src/main/java/org/apache/karaf/cellar/config/shell/PropAppendCommand.java
@@ -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.karaf.cellar.core.control.SwitchStatus;
@@ -26,7 +26,7 @@ import org.apache.karaf.cellar.core.event.EventType;
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 to the property value for a configuration PID 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 ConfigCommandSupport {
// 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 ConfigCommandSupport {
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;
}
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/e08a2e87/config/src/main/java/org/apache/karaf/cellar/config/shell/PropDelCommand.java
----------------------------------------------------------------------
diff --git a/config/src/main/java/org/apache/karaf/cellar/config/shell/PropDelCommand.java b/config/src/main/java/org/apache/karaf/cellar/config/shell/PropDelCommand.java
index 8f5d073..d416949 100644
--- a/config/src/main/java/org/apache/karaf/cellar/config/shell/PropDelCommand.java
+++ b/config/src/main/java/org/apache/karaf/cellar/config/shell/PropDelCommand.java
@@ -16,7 +16,7 @@ package org.apache.karaf.cellar.config.shell;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.cellar.config.Constants;
-import org.apache.karaf.cellar.config.RemoteConfigurationEvent;
+import org.apache.karaf.cellar.config.ClusterConfigurationEvent;
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.event.EventType;
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,25 @@ public class PropDelCommand extends ConfigCommandSupport {
// 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) {
- // update the distributed map
- Properties distributedDictionary = 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 distributedDictionary = clusterConfigurations.get(pid);
if (distributedDictionary != null) {
distributedDictionary.remove(key);
- distributedConfigurations.put(pid, distributedDictionary);
+ clusterConfigurations.put(pid, distributedDictionary);
+
// 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;
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/e08a2e87/config/src/main/java/org/apache/karaf/cellar/config/shell/PropListCommand.java
----------------------------------------------------------------------
diff --git a/config/src/main/java/org/apache/karaf/cellar/config/shell/PropListCommand.java b/config/src/main/java/org/apache/karaf/cellar/config/shell/PropListCommand.java
index f629bbc..8d8d800 100644
--- a/config/src/main/java/org/apache/karaf/cellar/config/shell/PropListCommand.java
+++ b/config/src/main/java/org/apache/karaf/cellar/config/shell/PropListCommand.java
@@ -23,7 +23,7 @@ import org.apache.karaf.shell.commands.Command;
import java.util.Map;
import java.util.Properties;
-@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 configurations in a cluster group")
public class PropListCommand extends CellarCommandSupport {
protected static final String OUTPUT_FORMAT = "%-40s %s";
@@ -43,14 +43,14 @@ public class PropListCommand extends CellarCommandSupport {
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 " + 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 + " for cluster group " + groupName));
System.out.println(String.format(OUTPUT_FORMAT, "Key", "Value"));
for (Object key : properties.keySet()) {
@@ -58,7 +58,7 @@ public class PropListCommand extends CellarCommandSupport {
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;
}
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/e08a2e87/config/src/main/java/org/apache/karaf/cellar/config/shell/PropSetCommand.java
----------------------------------------------------------------------
diff --git a/config/src/main/java/org/apache/karaf/cellar/config/shell/PropSetCommand.java b/config/src/main/java/org/apache/karaf/cellar/config/shell/PropSetCommand.java
index 8c6fce8..a3f8d4c 100644
--- a/config/src/main/java/org/apache/karaf/cellar/config/shell/PropSetCommand.java
+++ b/config/src/main/java/org/apache/karaf/cellar/config/shell/PropSetCommand.java
@@ -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.karaf.cellar.core.control.SwitchStatus;
@@ -26,7 +26,7 @@ import org.apache.karaf.cellar.core.event.EventType;
import java.util.Map;
import java.util.Properties;
-@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 value for 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)
@@ -60,26 +60,26 @@ public class PropSetCommand extends ConfigCommandSupport {
// 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);
+ 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();
}
properties.put(key, value);
- 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;
}
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/e08a2e87/config/src/main/java/org/apache/karaf/cellar/config/shell/completers/ClusterConfigCompleter.java
----------------------------------------------------------------------
diff --git a/config/src/main/java/org/apache/karaf/cellar/config/shell/completers/ClusterConfigCompleter.java b/config/src/main/java/org/apache/karaf/cellar/config/shell/completers/ClusterConfigCompleter.java
index e1a3c22..6481149 100644
--- a/config/src/main/java/org/apache/karaf/cellar/config/shell/completers/ClusterConfigCompleter.java
+++ b/config/src/main/java/org/apache/karaf/cellar/config/shell/completers/ClusterConfigCompleter.java
@@ -26,22 +26,23 @@ import java.util.Map;
import java.util.Properties;
/**
- * Command completer on the cluster config.
+ * Command completer for the configuration from the cluster.
*/
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()) {
+ Map<String, Properties> clusterConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
+ if (clusterConfigurations != null && !clusterConfigurations.isEmpty()) {
+ for (String pid : clusterConfigurations.keySet()) {
if (delegate.getStrings() != null && !delegate.getStrings().contains(pid)) {
delegate.getStrings().add(pid);
}
@@ -51,7 +52,7 @@ public class ClusterConfigCompleter implements Completer {
}
} catch (Exception e) {
- // Ignore
+ // nothing to do
}
return delegate.complete(buffer, cursor, candidates);
}
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/e08a2e87/config/src/main/resources/OSGI-INF/blueprint/blueprint.xml
----------------------------------------------------------------------
diff --git a/config/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/config/src/main/resources/OSGI-INF/blueprint/blueprint.xml
index e5048e6..3610f4c 100644
--- a/config/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ b/config/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -28,7 +28,7 @@
">
<!-- 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"/>
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/e08a2e87/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarConfigMBeanImpl.java
----------------------------------------------------------------------
diff --git a/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarConfigMBeanImpl.java b/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarConfigMBeanImpl.java
index f5da71f..5be849a 100644
--- a/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarConfigMBeanImpl.java
+++ b/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarConfigMBeanImpl.java
@@ -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 extends StandardMBean implements CellarConfig
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);
@@ -153,7 +153,7 @@ public class CellarConfigMBeanImpl extends StandardMBean implements CellarConfig
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 {
@@ -200,7 +200,7 @@ public class CellarConfigMBeanImpl extends StandardMBean implements CellarConfig
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 {
@@ -237,7 +237,7 @@ public class CellarConfigMBeanImpl extends StandardMBean implements CellarConfig
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);
}