camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject camel git commit: CAMEL-10986: camel-zookeeper-master - Make it install in karaf
Date Fri, 10 Mar 2017 22:08:35 GMT
Repository: camel
Updated Branches:
  refs/heads/master 16d6fc385 -> 03aab77c8


CAMEL-10986: camel-zookeeper-master - Make it install in karaf


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/03aab77c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/03aab77c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/03aab77c

Branch: refs/heads/master
Commit: 03aab77c8ec61e729e9783b9af481154f991a884
Parents: 16d6fc3
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Fri Mar 10 23:07:34 2017 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Fri Mar 10 23:07:34 2017 +0100

----------------------------------------------------------------------
 components/camel-zookeeper-master/pom.xml       | 10 +++-
 .../group/internal/ZooKeeperGroup.java          | 63 ++++++--------------
 .../features/src/main/resources/features.xml    | 12 ++++
 .../itest/karaf/CamelZookeeperMasterTest.java   | 34 +++++++++++
 4 files changed, 74 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/03aab77c/components/camel-zookeeper-master/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-zookeeper-master/pom.xml b/components/camel-zookeeper-master/pom.xml
index 493a266..a1e89a3 100644
--- a/components/camel-zookeeper-master/pom.xml
+++ b/components/camel-zookeeper-master/pom.xml
@@ -31,7 +31,15 @@
   <description>Camel Zookeeper Master Support</description>
 
   <properties>
-    <camel.osgi.export.pkg>org.apache.camel.component.zookeepermaster.*</camel.osgi.export.pkg>
+    <camel.osgi.import>
+      !com.google.common.base;,
+      !org.apache.camel.component.zookeepermaster.group,
+      *
+    </camel.osgi.import>
+    <camel.osgi.export.pkg>
+      org.apache.camel.component.zookeepermaster,
+      org.apache.camel.component.zookeepermaster.group
+    </camel.osgi.export.pkg>
     <camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=zookeeper-master</camel.osgi.export.service>
   </properties>
 

http://git-wip-us.apache.org/repos/asf/camel/blob/03aab77c/components/camel-zookeeper-master/src/main/java/org/apache/camel/component/zookeepermaster/group/internal/ZooKeeperGroup.java
----------------------------------------------------------------------
diff --git a/components/camel-zookeeper-master/src/main/java/org/apache/camel/component/zookeepermaster/group/internal/ZooKeeperGroup.java
b/components/camel-zookeeper-master/src/main/java/org/apache/camel/component/zookeepermaster/group/internal/ZooKeeperGroup.java
index 6e58f50..f297e43 100644
--- a/components/camel-zookeeper-master/src/main/java/org/apache/camel/component/zookeepermaster/group/internal/ZooKeeperGroup.java
+++ b/components/camel-zookeeper-master/src/main/java/org/apache/camel/component/zookeepermaster/group/internal/ZooKeeperGroup.java
@@ -24,6 +24,7 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -31,6 +32,7 @@ import java.util.Set;
 import java.util.TreeMap;
 import java.util.UUID;
 import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
@@ -38,15 +40,10 @@ import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.stream.Collectors;
 
 import com.fasterxml.jackson.databind.DeserializationFeature;
 import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Function;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
 import org.apache.camel.component.zookeepermaster.group.Group;
 import org.apache.camel.component.zookeepermaster.group.GroupListener;
 import org.apache.camel.component.zookeepermaster.group.NodeState;
@@ -85,7 +82,7 @@ public class ZooKeeperGroup<T extends NodeState> implements Group<T>
{
     private final EnsurePath ensurePath;
     private final BlockingQueue<Operation> operations = new LinkedBlockingQueue<Operation>();
     private final ListenerContainer<GroupListener<T>> listeners = new ListenerContainer<GroupListener<T>>();
-    private final ConcurrentMap<String, ChildData<T>> currentData = Maps.newConcurrentMap();
+    private final ConcurrentMap<String, ChildData<T>> currentData = new ConcurrentHashMap<>();
     private final AtomicBoolean started = new AtomicBoolean();
     private final AtomicBoolean connected = new AtomicBoolean();
     private final SequenceComparator sequenceComparator = new SequenceComparator();
@@ -166,7 +163,7 @@ public class ZooKeeperGroup<T extends NodeState> implements Group<T>
{
      * Start the cache. The cache is not started automatically. You must call this method.
      */
     public void start() {
-        LOG.info("Starting ZK Group for path \"" + path + "\"");
+        LOG.info("Starting ZK Group for path: {}", path);
         if (started.compareAndSet(false, true)) {
             connected.set(client.getZookeeperClient().isConnected());
 
@@ -406,7 +403,9 @@ public class ZooKeeperGroup<T extends NodeState> implements Group<T>
{
      * @return list of children and data
      */
     public List<ChildData> getCurrentData() {
-        return ImmutableList.copyOf(Sets.<ChildData>newTreeSet(currentData.values()));
+        List<ChildData> answer = new ArrayList<>();
+        answer.addAll(currentData.values());
+        return answer;
     }
 
     /**
@@ -484,17 +483,14 @@ public class ZooKeeperGroup<T extends NodeState> implements Group<T>
{
     }
 
     void callListeners(final GroupListener.GroupEvent event) {
-        listeners.forEach(new Function<GroupListener<T>, Void>() {
-                @Override
-                public Void apply(GroupListener<T> listener) {
-                    try {
-                        listener.groupEvent(ZooKeeperGroup.this, event);
-                    } catch (Exception e) {
-                        handleException(e);
-                    }
-                    return null;
-                }
+        listeners.forEach(listener -> {
+            try {
+                listener.groupEvent(ZooKeeperGroup.this, event);
+            } catch (Exception e) {
+                handleException(e);
             }
+            return null;
+        }
         );
     }
 
@@ -517,7 +513,6 @@ public class ZooKeeperGroup<T extends NodeState> implements Group<T>
{
         }
     }
 
-    @VisibleForTesting
     protected void remove(String fullPath) {
         ChildData data = currentData.remove(fullPath);
         if (data != null) {
@@ -525,17 +520,6 @@ public class ZooKeeperGroup<T extends NodeState> implements Group<T>
{
         }
     }
 
-    private void internalRebuildNode(String fullPath) throws Exception {
-        try {
-            Stat stat = new Stat();
-            byte[] bytes = client.getData().storingStatIn(stat).forPath(fullPath);
-            currentData.put(fullPath, new ChildData<T>(fullPath, stat, bytes, decode(bytes)));
-        } catch (KeeperException.NoNodeException ignore) {
-            // node no longer exists - remove it
-            currentData.remove(fullPath);
-        }
-    }
-
     private void handleStateChange(ConnectionState newState) {
         switch (newState) {
         case SUSPENDED:
@@ -563,16 +547,9 @@ public class ZooKeeperGroup<T extends NodeState> implements Group<T>
{
     }
 
     private void processChildren(List<String> children, RefreshMode mode) throws Exception
{
-        List<String> fullPaths = Lists.newArrayList(Lists.transform(
-            children,
-                new Function<String, String>() {
-                    @Override
-                    public String apply(String child) {
-                        return ZKPaths.makePath(path, child);
-                    }
-                }
-            ));
-        Set<String> removedNodes = Sets.newHashSet(currentData.keySet());
+        List<String> fullPaths = children.stream().map(c -> ZKPaths.makePath(path,
c)).collect(Collectors.toList());
+
+        Set<String> removedNodes = new HashSet<>(currentData.keySet());
         removedNodes.removeAll(fullPaths);
 
         for (String fullPath : removedNodes) {
@@ -637,7 +614,7 @@ public class ZooKeeperGroup<T extends NodeState> implements Group<T>
{
         if (!operations.contains(operation)) {
             operations.offer(operation);
         }
-//        operations.remove(operation);   // avoids herding for refresh operations
+        // operations.remove(operation);   // avoids herding for refresh operations
     }
 
     public static <T> Map<String, T> members(ObjectMapper mapper, CuratorFramework
curator, String path, Class<T> clazz) throws Exception {
@@ -655,14 +632,12 @@ public class ZooKeeperGroup<T extends NodeState> implements Group<T>
{
         return id;
     }
 
-    @VisibleForTesting
     void setId(String id) {
         this.id = id;
     }
 
     /**
      * Returns an indication that the sequential, ephemeral node may be registered more than
once for this group
-     * @return
      */
     public boolean isUnstable() {
         return unstable.get();

http://git-wip-us.apache.org/repos/asf/camel/blob/03aab77c/platforms/karaf/features/src/main/resources/features.xml
----------------------------------------------------------------------
diff --git a/platforms/karaf/features/src/main/resources/features.xml b/platforms/karaf/features/src/main/resources/features.xml
index a805df4..cb52f64 100644
--- a/platforms/karaf/features/src/main/resources/features.xml
+++ b/platforms/karaf/features/src/main/resources/features.xml
@@ -2056,5 +2056,17 @@
     <bundle dependency='true'>mvn:com.google.guava/guava/${zookeeper-guava-version}</bundle>
     <bundle>mvn:org.apache.camel/camel-zookeeper/${project.version}</bundle>
   </feature>
+  <feature name='camel-zookeeper-master' version='${project.version}' resolver='(obr)'
start-level='50'>
+    <feature version='${project.version}'>camel-core</feature>
+    <bundle dependency='true'>mvn:org.apache.zookeeper/zookeeper/${zookeeper-version}</bundle>
+    <bundle dependency='true'>mvn:org.apache.curator/curator-framework/${curator-version}</bundle>
+    <bundle dependency='true'>mvn:org.apache.curator/curator-client/${curator-version}</bundle>
+    <bundle dependency='true'>mvn:org.apache.curator/curator-recipes/${curator-version}</bundle>
+    <bundle dependency='true'>mvn:com.google.guava/guava/${zookeeper-guava-version}</bundle>
+    <bundle dependency='true'>mvn:com.fasterxml.jackson.core/jackson-core/${jackson2-version}</bundle>
+    <bundle dependency='true'>mvn:com.fasterxml.jackson.core/jackson-databind/${jackson2-version}</bundle>
+    <bundle dependency='true'>mvn:com.fasterxml.jackson.core/jackson-annotations/${jackson2-version}</bundle>
+    <bundle>mvn:org.apache.camel/camel-zookeeper-master/${project.version}</bundle>
+  </feature>
 
 </features>

http://git-wip-us.apache.org/repos/asf/camel/blob/03aab77c/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelZookeeperMasterTest.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelZookeeperMasterTest.java
b/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelZookeeperMasterTest.java
new file mode 100644
index 0000000..58617a6
--- /dev/null
+++ b/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelZookeeperMasterTest.java
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.camel.itest.karaf;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+
+@RunWith(PaxExam.class)
+public class CamelZookeeperMasterTest extends BaseKarafTest {
+
+    public static final String COMPONENT = extractName(CamelZookeeperMasterTest.class);
+
+    @Test
+    public void test() throws Exception {
+        testComponent(COMPONENT);
+    }
+
+
+}


Mime
View raw message