Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 0FAF6200C73 for ; Wed, 10 May 2017 15:25:14 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 0DEB0160BA8; Wed, 10 May 2017 13:25:14 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D26C0160BC6 for ; Wed, 10 May 2017 15:25:12 +0200 (CEST) Received: (qmail 75985 invoked by uid 500); 10 May 2017 13:25:12 -0000 Mailing-List: contact commits-help@karaf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@karaf.apache.org Delivered-To: mailing list commits@karaf.apache.org Received: (qmail 75788 invoked by uid 99); 10 May 2017 13:25:11 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 May 2017 13:25:11 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id D10E1E01BC; Wed, 10 May 2017 13:25:11 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: jbonofre@apache.org To: commits@karaf.apache.org Message-Id: <323ff50dc1bc4c5c85ea3f34e26dc618@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: karaf-cellar git commit: [KARAF-4941] Improve resources sync when a node joins a cluster group Date: Wed, 10 May 2017 13:25:11 +0000 (UTC) archived-at: Wed, 10 May 2017 13:25:14 -0000 Repository: karaf-cellar Updated Branches: refs/heads/master f37f46a91 -> cce70103b [KARAF-4941] Improve resources sync when a node joins a cluster group Project: http://git-wip-us.apache.org/repos/asf/karaf-cellar/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf-cellar/commit/cce70103 Tree: http://git-wip-us.apache.org/repos/asf/karaf-cellar/tree/cce70103 Diff: http://git-wip-us.apache.org/repos/asf/karaf-cellar/diff/cce70103 Branch: refs/heads/master Commit: cce70103bb3a53ed7b72317f63ed4d0eb66b9772 Parents: f37f46a Author: Jean-Baptiste Onofré Authored: Wed May 10 15:24:39 2017 +0200 Committer: Jean-Baptiste Onofré Committed: Wed May 10 15:24:39 2017 +0200 ---------------------------------------------------------------------- assembly/src/main/resources/groups.cfg | 8 ++- .../karaf/cellar/bundle/BundleSynchronizer.java | 40 +++++++------- .../config/ConfigurationSynchronizer.java | 38 ++++++------- .../cellar/features/FeaturesSynchronizer.java | 57 ++++++++++++-------- .../http/balancer/ServletSynchronizer.java | 4 +- .../karaf/cellar/obr/ObrUrlSynchronizer.java | 2 +- 6 files changed, 78 insertions(+), 71 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/cce70103/assembly/src/main/resources/groups.cfg ---------------------------------------------------------------------- diff --git a/assembly/src/main/resources/groups.cfg b/assembly/src/main/resources/groups.cfg index ae294b0..31e3199 100644 --- a/assembly/src/main/resources/groups.cfg +++ b/assembly/src/main/resources/groups.cfg @@ -20,12 +20,16 @@ default.config.blacklist.inbound=org.apache.felix.fileinstall*, \ org.apache.karaf.management, \ org.apache.karaf.shell, \ org.ops4j.pax.web, \ - org.apache.aries.transaction + org.apache.aries.transaction, \ + org.apache.karaf.cellar.node.cfg, \ + org.apache.karaf.cellar.groups.cfg default.config.blacklist.outbound=org.apache.felix.fileinstall*, \ org.apache.karaf.management, \ org.apache.karaf.shell, \ org.ops4j.pax.web, \ - org.apache.aries.transaction + org.apache.aries.transaction, \ + org.apache.karaf.cellar.node.cfg, \ + org.apache.karaf.cellar.groups.cfg # # Filtering of the features in the default cluster group http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/cce70103/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 b722076..afde1c4 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 @@ -85,12 +85,9 @@ public class BundleSynchronizer extends BundleSupport implements Synchronizer { } if (policy.equalsIgnoreCase("cluster")) { LOGGER.debug("CELLAR BUNDLE: sync policy set as 'cluster' for cluster group {}", group.getName()); - if (clusterManager.listNodesByGroup(group).size() > 1) { - LOGGER.debug("CELLAR BUNDLE: updating node from the cluster (pull first)"); - pull(group); - } else { - LOGGER.debug("CELLAR BUNDLE: node is the only one in the cluster group, no pull"); - } + LOGGER.debug("CELLAR BUNDLE: updating node from the cluster (pull first)"); + pull(group); + LOGGER.debug("CELLAR BUNDLE: node is the only one in the cluster group, no pull"); LOGGER.debug("CELLAR BUNDLE: updating cluster from the local node (push after)"); push(group); } else if (policy.equalsIgnoreCase("node")) { @@ -101,12 +98,9 @@ public class BundleSynchronizer extends BundleSupport implements Synchronizer { pull(group); } else if (policy.equalsIgnoreCase("clusterOnly")) { LOGGER.debug("CELLAR BUNDLE: sync policy set as 'clusterOnly' for cluster group " + group.getName()); - if (clusterManager.listNodesByGroup(group).size() > 1) { - LOGGER.debug("CELLAR BUNDLE: updating node from the cluster (pull only)"); - pull(group); - } else { - LOGGER.debug("CELLAR BUNDLE: node is the only one in the cluster group, no pull"); - } + LOGGER.debug("CELLAR BUNDLE: updating node from the cluster (pull only)"); + pull(group); + LOGGER.debug("CELLAR BUNDLE: node is the only one in the cluster group, no pull"); } else if (policy.equalsIgnoreCase("nodeOnly")) { LOGGER.debug("CELLAR BUNDLE: sync policy set as 'nodeOnly' for cluster group " + group.getName()); LOGGER.debug("CELLAR BUNDLE: updating cluster from the local node (push only)"); @@ -189,15 +183,17 @@ public class BundleSynchronizer extends BundleSupport implements Synchronizer { } } } - // cleanup the local bundles not present on the cluster - for (Bundle bundle : bundleContext.getBundles()) { - String id = getId(bundle); - if (!clusterBundles.containsKey(id) && isAllowed(group, Constants.CATEGORY, bundle.getLocation(), EventType.INBOUND)) { - // the bundle is not present on the cluster, so it has to be uninstalled locally - try { - bundle.uninstall(); - } catch (Exception e) { - LOGGER.warn("Can't uninstall {}", id, e); + // cleanup the local bundles not present on the cluster if the node is not the first one in the cluster group + if (clusterManager.listNodesByGroup(group).size() > 1) { + for (Bundle bundle : bundleContext.getBundles()) { + String id = getId(bundle); + if (!clusterBundles.containsKey(id) && isAllowed(group, Constants.CATEGORY, bundle.getLocation(), EventType.INBOUND)) { + // the bundle is not present on the cluster, so it has to be uninstalled locally + try { + bundle.uninstall(); + } catch (Exception e) { + LOGGER.warn("Can't uninstall {}", id, e); + } } } } @@ -343,7 +339,7 @@ public class BundleSynchronizer extends BundleSupport implements Synchronizer { LOGGER.error("CELLAR BUNDLE: error while retrieving the sync policy", e); } - return "disabled"; + return "cluster"; } } http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/cce70103/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 7c7fe7c..17be5a0 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 @@ -82,12 +82,9 @@ public class ConfigurationSynchronizer extends ConfigurationSupport implements S } if (policy.equalsIgnoreCase("cluster")) { LOGGER.debug("CELLAR CONFIG: sync policy set as 'cluster' for cluster group {}", group.getName()); - if (clusterManager.listNodesByGroup(group).size() > 1) { - LOGGER.debug("CELLAR CONFIG: updating node from the cluster (pull first)"); - pull(group); - } else { - LOGGER.debug("CELLAR CONFIG: node is the first one in the cluster group, no pull"); - } + LOGGER.debug("CELLAR CONFIG: updating node from the cluster (pull first)"); + pull(group); + LOGGER.debug("CELLAR CONFIG: node is the first one in the cluster group, no pull"); LOGGER.debug("CELLAR CONFIG: updating cluster from the local node (push after)"); push(group); } else if (policy.equalsIgnoreCase("node")) { @@ -98,12 +95,9 @@ public class ConfigurationSynchronizer extends ConfigurationSupport implements S pull(group); } else if (policy.equalsIgnoreCase("clusterOnly")) { LOGGER.debug("CELLAR CONFIG: sync policy set as 'clusterOnly' for cluster group " + group.getName()); - if (clusterManager.listNodesByGroup(group).size() > 1) { - LOGGER.debug("CELLAR CONFIG: updating node from the cluster (pull only)"); - pull(group); - } else { - LOGGER.debug("CELLAR CONFIG: node is the first one in the cluster group, no pull"); - } + LOGGER.debug("CELLAR CONFIG: updating node from the cluster (pull only)"); + pull(group); + LOGGER.debug("CELLAR CONFIG: node is the first one in the cluster group, no pull"); } else if (policy.equalsIgnoreCase("nodeOnly")) { LOGGER.debug("CELLAR CONFIG: sync policy set as 'nodeOnly' for cluster group " + group.getName()); LOGGER.debug("CELLAR CONFIG: updating cluster from the local node (push only)"); @@ -152,16 +146,18 @@ public class ConfigurationSynchronizer extends ConfigurationSupport implements S } } else LOGGER.trace("CELLAR CONFIG: configuration with PID {} is marked BLOCKED INBOUND for cluster group {}", pid, groupName); } - // cleanup the local configurations not present on the cluster - try { - for (Configuration configuration : configurationAdmin.listConfigurations(null)) { - String pid = configuration.getPid(); - if (!clusterConfigurations.containsKey(pid) && isAllowed(group, Constants.CATEGORY, pid, EventType.INBOUND)) { - configuration.delete(); + // cleanup the local configurations not present on the cluster if the node is not the first one in the cluster + if (clusterManager.listNodesByGroup(group).size() > 1) { + try { + for (Configuration configuration : configurationAdmin.listConfigurations(null)) { + String pid = configuration.getPid(); + if (!clusterConfigurations.containsKey(pid) && isAllowed(group, Constants.CATEGORY, pid, EventType.INBOUND)) { + configuration.delete(); + } } + } catch (Exception e) { + LOGGER.warn("Can't get local configurations", e); } - } catch (Exception e) { - LOGGER.warn("Can't get local configurations", e); } } finally { Thread.currentThread().setContextClassLoader(originalClassLoader); @@ -274,7 +270,7 @@ public class ConfigurationSynchronizer extends ConfigurationSupport implements S LOGGER.error("CELLAR CONFIG: error while retrieving the sync policy", e); } - return "disabled"; + return "cluster"; } } http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/cce70103/features/src/main/java/org/apache/karaf/cellar/features/FeaturesSynchronizer.java ---------------------------------------------------------------------- diff --git a/features/src/main/java/org/apache/karaf/cellar/features/FeaturesSynchronizer.java b/features/src/main/java/org/apache/karaf/cellar/features/FeaturesSynchronizer.java index 88abe5f..331a7ce 100644 --- a/features/src/main/java/org/apache/karaf/cellar/features/FeaturesSynchronizer.java +++ b/features/src/main/java/org/apache/karaf/cellar/features/FeaturesSynchronizer.java @@ -83,12 +83,8 @@ public class FeaturesSynchronizer extends FeaturesSupport implements Synchronize } if (policy.equalsIgnoreCase("cluster")) { LOGGER.debug("CELLAR FEATURE: sync policy set as 'cluster' for cluster group {}", group.getName()); - if (clusterManager.listNodesByGroup(group).size() > 1) { - LOGGER.debug("CELLAR FEATURE: updating node from the cluster (pull first)"); - pull(group); - } else { - LOGGER.debug("CELLAR FEATURE: node is the first one in the cluster group, no pull"); - } + LOGGER.debug("CELLAR FEATURE: updating node from the cluster (pull first)"); + pull(group); LOGGER.debug("CELLAR FEATURE: updating cluster from the local node (push after)"); push(group); } else if (policy.equalsIgnoreCase("node")) { @@ -99,12 +95,8 @@ public class FeaturesSynchronizer extends FeaturesSupport implements Synchronize pull(group); } else if (policy.equalsIgnoreCase("clusterOnly")) { LOGGER.debug("CELLAR FEATURE: sync policy set as 'clusterOnly' for cluster group " + group.getName()); - if (clusterManager.listNodesByGroup(group).size() > 1) { - LOGGER.debug("CELLAR FEATURE: updating node from the cluster (pull only)"); - pull(group); - } else { - LOGGER.debug("CELLAR FEATURE: node is the first one in the cluster group, no pull"); - } + LOGGER.debug("CELLAR FEATURE: updating node from the cluster (pull only)"); + pull(group); } else if (policy.equalsIgnoreCase("nodeOnly")) { LOGGER.debug("CELLAR FEATURE: sync policy set as 'nodeOnly' for cluster group " + group.getName()); LOGGER.debug("CELLAR FEATURE: updating cluster from the local node (push only)"); @@ -139,23 +131,33 @@ public class FeaturesSynchronizer extends FeaturesSupport implements Synchronize if (!isRepositoryRegisteredLocally(url)) { LOGGER.debug("CELLAR FEATURE: adding repository {}", url); featuresService.addRepository(new URI(url)); - } // TODO uninstall local features repositories not on the cluster ? + } } catch (MalformedURLException e) { LOGGER.error("CELLAR FEATURE: failed to add repository URL {} (malformed)", url, e); } catch (Exception e) { LOGGER.error("CELLAR FEATURE: failed to add repository URL {}", url, e); } } - // cleanup the local features repositories not present on the cluster - try { - for (Repository repository : featuresService.listRepositories()) { - URI uri = repository.getURI(); - if (!clusterRepositories.containsKey(uri.toString())) { - featuresService.removeRepository(uri); + // cleanup the local features repositories not present on the cluster if the node is not the first one in the cluster group + if (clusterManager.listNodesByGroup(group).size() > 1) { + try { + for (Repository repository : featuresService.listRepositories()) { + URI uri = repository.getURI(); + boolean found = false; + for (String clusterRepository : clusterRepositories.keySet()) { + if (clusterRepository.equals(uri.toString())) { + found = true; + break; + } + } + if (!found) { + LOGGER.debug("CELLAR FEATURE: removing repository {}", uri); + featuresService.removeRepository(uri); + } } + } catch (Exception e) { + LOGGER.warn("Can't get local features repositories", e); } - } catch (Exception e) { - LOGGER.warn("Can't get local features repositories", e); } } @@ -184,7 +186,16 @@ public class FeaturesSynchronizer extends FeaturesSupport implements Synchronize } catch (Exception e) { LOGGER.error("CELLAR FEATURE: failed to install feature {}/{} ", new Object[]{state.getName(), state.getVersion()}, e); } - } // TODO uninstall local features not on the cluster ? + } + // if feature has to be uninstalled locally (and node is not the first one in the cluster group) + if (clusterManager.listNodesByGroup(group).size() > 1 && !clusterInstalled && locallyInstalled) { + try { + LOGGER.debug("CELLAR FEATURE: uninstalling feature {}/{}", state.getName(), state.getVersion()); + featuresService.uninstallFeature(state.getName(), state.getVersion()); + } catch (Exception e) { + LOGGER.error("CELLAR FEATURE: failed to uninstall feature {}/{}", new Object[]{state.getName(), state.getVersion()}, e); + } + } } else LOGGER.trace("CELLAR FEATURE: feature {} is marked BLOCKED INBOUND for cluster group {}", name, groupName); } } @@ -330,7 +341,7 @@ public class FeaturesSynchronizer extends FeaturesSupport implements Synchronize LOGGER.error("CELLAR FEATURE: error while retrieving the sync policy", e); } - return "disabled"; + return "cluster"; } } http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/cce70103/http/balancer/src/main/java/org/apache/karaf/cellar/http/balancer/ServletSynchronizer.java ---------------------------------------------------------------------- diff --git a/http/balancer/src/main/java/org/apache/karaf/cellar/http/balancer/ServletSynchronizer.java b/http/balancer/src/main/java/org/apache/karaf/cellar/http/balancer/ServletSynchronizer.java index e21c26b..e3fb6e6 100644 --- a/http/balancer/src/main/java/org/apache/karaf/cellar/http/balancer/ServletSynchronizer.java +++ b/http/balancer/src/main/java/org/apache/karaf/cellar/http/balancer/ServletSynchronizer.java @@ -183,10 +183,10 @@ public class ServletSynchronizer implements Synchronizer { return properties.get(propertyKey).toString(); } } catch (IOException e) { - LOGGER.error("CELLAR FEATURE: error while retrieving the sync policy", e); + LOGGER.error("CELLAR HTTP BALANCER: error while retrieving the sync policy", e); } - return "disabled"; + return "cluster"; } public void setClusterManager(ClusterManager clusterManager) { http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/cce70103/obr/src/main/java/org/apache/karaf/cellar/obr/ObrUrlSynchronizer.java ---------------------------------------------------------------------- diff --git a/obr/src/main/java/org/apache/karaf/cellar/obr/ObrUrlSynchronizer.java b/obr/src/main/java/org/apache/karaf/cellar/obr/ObrUrlSynchronizer.java index b6d75d5..726d33b 100644 --- a/obr/src/main/java/org/apache/karaf/cellar/obr/ObrUrlSynchronizer.java +++ b/obr/src/main/java/org/apache/karaf/cellar/obr/ObrUrlSynchronizer.java @@ -199,7 +199,7 @@ public class ObrUrlSynchronizer extends ObrSupport implements Synchronizer { LOGGER.error("CELLAR OBR: error while retrieving the sync policy", e); } - return "disabled"; + return "cluster"; } }