You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2016/04/15 08:54:07 UTC

[01/10] camel git commit: CAMEL-9851: Fixed NPE in consumer if path is empty

Repository: camel
Updated Branches:
  refs/heads/camel-2.16.x 7af24ce69 -> 025567f11
  refs/heads/camel-2.17.x dd45d2162 -> 365de1653
  refs/heads/master cbe6ad9da -> d5ae26727


CAMEL-9851: Fixed NPE in consumer if path is empty


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

Branch: refs/heads/master
Commit: 846335028bf5c3b6a47730e289cb2bc1e888dcce
Parents: cbe6ad9
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Apr 15 08:09:16 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Apr 15 08:09:16 2016 +0200

----------------------------------------------------------------------
 .../apache/camel/component/zookeeper/ZooKeeperConsumer.java  | 5 ++---
 .../camel/component/zookeeper/policy/ZooKeeperElection.java  | 8 +++-----
 2 files changed, 5 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/84633502/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ZooKeeperConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ZooKeeperConsumer.java b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ZooKeeperConsumer.java
index bb9507f..44b8f49 100644
--- a/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ZooKeeperConsumer.java
+++ b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ZooKeeperConsumer.java
@@ -34,7 +34,6 @@ import org.apache.camel.impl.DefaultConsumer;
 import org.apache.zookeeper.WatchedEvent;
 import org.apache.zookeeper.ZooKeeper;
 
-
 /**
  * <code>ZooKeeperConsumer</code> uses various {@link ZooKeeperOperation} to
  * interact and consume data from a ZooKeeper cluster.
@@ -64,7 +63,7 @@ public class ZooKeeperConsumer extends DefaultConsumer {
         }
 
         initializeConsumer();
-        executor = getEndpoint().getCamelContext().getExecutorServiceManager().newFixedThreadPool(configuration.getPath(), "Camel-Zookeeper Ops executor", 1);
+        executor = getEndpoint().getCamelContext().getExecutorServiceManager().newFixedThreadPool(this, "Camel-Zookeeper OperationsExecutor", 1);
 
         OperationsExecutor opsService = new OperationsExecutor();
         executor.submit(opsService);
@@ -128,7 +127,6 @@ public class ZooKeeperConsumer extends DefaultConsumer {
 
         public void run() {
             while (isRunAllowed()) {
-
                 try {
                     current = operations.take();
                     if (log.isTraceEnabled()) {
@@ -169,6 +167,7 @@ public class ZooKeeperConsumer extends DefaultConsumer {
                     initializeConsumer();
                 }
             } catch (Exception e) {
+                // ignore
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/84633502/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/policy/ZooKeeperElection.java
----------------------------------------------------------------------
diff --git a/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/policy/ZooKeeperElection.java b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/policy/ZooKeeperElection.java
index 79e6a19..cdff74c 100644
--- a/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/policy/ZooKeeperElection.java
+++ b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/policy/ZooKeeperElection.java
@@ -146,15 +146,13 @@ public class ZooKeeperElection {
         producerTemplate.send(zep, e);
 
         if (e.isFailed()) {
-            LOG.error("Error setting up election node " + fullpath, e.getException());
+            LOG.warn("Error setting up election node " + fullpath, e.getException());
         } else {
             LOG.info("Candidate node '{}' has been created", fullpath);
             try {
-                if (zep != null) {
-                    camelContext.addRoutes(new ElectoralMonitorRoute(zep));
-                }
+                camelContext.addRoutes(new ElectoralMonitorRoute(zep));
             } catch (Exception ex) {
-                LOG.error("Error configuring ZookeeperElection", ex);
+                LOG.warn("Error configuring ZookeeperElection", ex);
             }
         }
         return zep;


[08/10] camel git commit: Fixed CS

Posted by da...@apache.org.
Fixed CS


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

Branch: refs/heads/master
Commit: d5ae26727707f971bf8d8fbabd897eb034b58bf2
Parents: 55052a9
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Apr 15 08:53:28 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Apr 15 08:53:28 2016 +0200

----------------------------------------------------------------------
 .../camel/component/zookeeper/operations/CreateOperation.java    | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/d5ae2672/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/CreateOperation.java
----------------------------------------------------------------------
diff --git a/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/CreateOperation.java b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/CreateOperation.java
index 730f6f2..75220e4 100644
--- a/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/CreateOperation.java
+++ b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/CreateOperation.java
@@ -18,14 +18,14 @@ package org.apache.camel.component.zookeeper.operations;
 
 import java.util.List;
 
+import static java.lang.String.format;
+
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.data.ACL;
 import org.apache.zookeeper.data.Stat;
 
-import static java.lang.String.format;
-
 /**
  * <code>CreateOperation</code> is a basic Zookeeper operation used to create
  * and set the data contained in a given node


[09/10] camel git commit: Fixed CS

Posted by da...@apache.org.
Fixed CS


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

Branch: refs/heads/camel-2.17.x
Commit: 365de16531bc648b3fd8ae4ddcd906a3685c8e19
Parents: 1eed481
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Apr 15 08:53:28 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Apr 15 08:53:44 2016 +0200

----------------------------------------------------------------------
 .../camel/component/zookeeper/operations/CreateOperation.java    | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/365de165/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/CreateOperation.java
----------------------------------------------------------------------
diff --git a/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/CreateOperation.java b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/CreateOperation.java
index 730f6f2..75220e4 100644
--- a/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/CreateOperation.java
+++ b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/CreateOperation.java
@@ -18,14 +18,14 @@ package org.apache.camel.component.zookeeper.operations;
 
 import java.util.List;
 
+import static java.lang.String.format;
+
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.data.ACL;
 import org.apache.zookeeper.data.Stat;
 
-import static java.lang.String.format;
-
 /**
  * <code>CreateOperation</code> is a basic Zookeeper operation used to create
  * and set the data contained in a given node


[05/10] camel git commit: CAMEL-9851: zookeeper create operation should create sub paths.

Posted by da...@apache.org.
CAMEL-9851: zookeeper create operation should create sub paths.


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

Branch: refs/heads/camel-2.17.x
Commit: 1eed481855aa248a3c474a2bf0ea03bf8b379877
Parents: 5f3cb2e
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Apr 15 08:51:31 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Apr 15 08:52:11 2016 +0200

----------------------------------------------------------------------
 .../zookeeper/operations/CreateOperation.java   |  6 +-
 .../zookeeper/operations/ZooKeeperHelper.java   | 58 ++++++++++++++++++++
 .../operations/CreateOperationTest.java         | 21 +++++++
 3 files changed, 83 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/1eed4818/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/CreateOperation.java
----------------------------------------------------------------------
diff --git a/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/CreateOperation.java b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/CreateOperation.java
index 5fb6587..730f6f2 100644
--- a/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/CreateOperation.java
+++ b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/CreateOperation.java
@@ -18,14 +18,14 @@ package org.apache.camel.component.zookeeper.operations;
 
 import java.util.List;
 
-import static java.lang.String.format;
-
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.data.ACL;
 import org.apache.zookeeper.data.Stat;
 
+import static java.lang.String.format;
+
 /**
  * <code>CreateOperation</code> is a basic Zookeeper operation used to create
  * and set the data contained in a given node
@@ -49,6 +49,8 @@ public class CreateOperation extends ZooKeeperOperation<String> {
     @Override
     public OperationResult<String> getResult() {
         try {
+            // ensure parent nodes is created first as persistent (cannot be ephemeral without children)
+            ZooKeeperHelper.mkdirs(connection, node, false, CreateMode.PERSISTENT);
             String created = connection.create(node, data, permissions, createMode);
             if (LOG.isDebugEnabled()) {
                 LOG.debug(format("Created node '%s' using mode '%s'", created, createMode));

http://git-wip-us.apache.org/repos/asf/camel/blob/1eed4818/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/ZooKeeperHelper.java
----------------------------------------------------------------------
diff --git a/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/ZooKeeperHelper.java b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/ZooKeeperHelper.java
new file mode 100644
index 0000000..0a022e1
--- /dev/null
+++ b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/ZooKeeperHelper.java
@@ -0,0 +1,58 @@
+/**
+ * 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.component.zookeeper.operations;
+
+import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.ZooDefs;
+import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.common.PathUtils;
+
+public final class ZooKeeperHelper {
+
+    private ZooKeeperHelper() {
+    }
+
+    public static void mkdirs(ZooKeeper zookeeper, String path, boolean makeLastNode, CreateMode createMode) throws Exception {
+        PathUtils.validatePath(path);
+
+        int pos = 1; // skip first slash, root is guaranteed to exist
+        do {
+            pos = path.indexOf("/", pos + 1);
+
+            if (pos == -1) {
+                if (makeLastNode) {
+                    pos = path.length();
+                } else {
+                    break;
+                }
+            }
+
+            String subPath = path.substring(0, pos);
+            if (zookeeper.exists(subPath, false) == null) {
+                try {
+                    zookeeper.create(subPath, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, createMode);
+                } catch (KeeperException.NodeExistsException e) {
+                    // ignore... someone else has created it since we checked
+                }
+            }
+
+        }
+        while (pos < path.length());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/1eed4818/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/operations/CreateOperationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/operations/CreateOperationTest.java b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/operations/CreateOperationTest.java
index e0137e1..48624c8 100644
--- a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/operations/CreateOperationTest.java
+++ b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/operations/CreateOperationTest.java
@@ -48,6 +48,27 @@ public class CreateOperationTest extends ZooKeeperTestSupport {
     }
 
     @Test
+    public void createBasicSubPath() throws Exception {
+        CreateOperation create = new CreateOperation(connection, "/sub/sub2");
+
+        OperationResult<String> result = create.get();
+        assertEquals("/sub/sub2", result.getResult());
+
+        verifyNodeContainsData("/sub/sub2", null);
+    }
+
+    @Test
+    public void createBasicSubPathWithData() throws Exception {
+        CreateOperation create = new CreateOperation(connection, "/sub/sub3");
+        create.setData(testPayload.getBytes());
+
+        OperationResult<String> result = create.get();
+        assertEquals("/sub/sub3", result.getResult());
+
+        verifyNodeContainsData("/sub/sub3", testPayloadBytes);
+    }
+
+    @Test
     public void createBasicWithData() throws Exception {
         CreateOperation create = new CreateOperation(connection, "/two");
         create.setData(testPayload.getBytes());


[04/10] camel git commit: CAMEL-9851: Fixed NPE in consumer if path is empty

Posted by da...@apache.org.
CAMEL-9851: Fixed NPE in consumer if path is empty


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

Branch: refs/heads/camel-2.17.x
Commit: 5f3cb2eb1d8d9a3aa886a9a30b91ffb1887927da
Parents: dd45d21
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Apr 15 08:09:16 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Apr 15 08:52:05 2016 +0200

----------------------------------------------------------------------
 .../apache/camel/component/zookeeper/ZooKeeperConsumer.java  | 5 ++---
 .../camel/component/zookeeper/policy/ZooKeeperElection.java  | 8 +++-----
 2 files changed, 5 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/5f3cb2eb/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ZooKeeperConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ZooKeeperConsumer.java b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ZooKeeperConsumer.java
index bb9507f..44b8f49 100644
--- a/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ZooKeeperConsumer.java
+++ b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ZooKeeperConsumer.java
@@ -34,7 +34,6 @@ import org.apache.camel.impl.DefaultConsumer;
 import org.apache.zookeeper.WatchedEvent;
 import org.apache.zookeeper.ZooKeeper;
 
-
 /**
  * <code>ZooKeeperConsumer</code> uses various {@link ZooKeeperOperation} to
  * interact and consume data from a ZooKeeper cluster.
@@ -64,7 +63,7 @@ public class ZooKeeperConsumer extends DefaultConsumer {
         }
 
         initializeConsumer();
-        executor = getEndpoint().getCamelContext().getExecutorServiceManager().newFixedThreadPool(configuration.getPath(), "Camel-Zookeeper Ops executor", 1);
+        executor = getEndpoint().getCamelContext().getExecutorServiceManager().newFixedThreadPool(this, "Camel-Zookeeper OperationsExecutor", 1);
 
         OperationsExecutor opsService = new OperationsExecutor();
         executor.submit(opsService);
@@ -128,7 +127,6 @@ public class ZooKeeperConsumer extends DefaultConsumer {
 
         public void run() {
             while (isRunAllowed()) {
-
                 try {
                     current = operations.take();
                     if (log.isTraceEnabled()) {
@@ -169,6 +167,7 @@ public class ZooKeeperConsumer extends DefaultConsumer {
                     initializeConsumer();
                 }
             } catch (Exception e) {
+                // ignore
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/5f3cb2eb/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/policy/ZooKeeperElection.java
----------------------------------------------------------------------
diff --git a/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/policy/ZooKeeperElection.java b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/policy/ZooKeeperElection.java
index 79e6a19..cdff74c 100644
--- a/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/policy/ZooKeeperElection.java
+++ b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/policy/ZooKeeperElection.java
@@ -146,15 +146,13 @@ public class ZooKeeperElection {
         producerTemplate.send(zep, e);
 
         if (e.isFailed()) {
-            LOG.error("Error setting up election node " + fullpath, e.getException());
+            LOG.warn("Error setting up election node " + fullpath, e.getException());
         } else {
             LOG.info("Candidate node '{}' has been created", fullpath);
             try {
-                if (zep != null) {
-                    camelContext.addRoutes(new ElectoralMonitorRoute(zep));
-                }
+                camelContext.addRoutes(new ElectoralMonitorRoute(zep));
             } catch (Exception ex) {
-                LOG.error("Error configuring ZookeeperElection", ex);
+                LOG.warn("Error configuring ZookeeperElection", ex);
             }
         }
         return zep;


[10/10] camel git commit: Fixed CS

Posted by da...@apache.org.
Fixed CS


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

Branch: refs/heads/camel-2.16.x
Commit: 025567f11816518287bbed834d3b47a1c5a40a6a
Parents: 72e20ff
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Apr 15 08:53:28 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Apr 15 08:53:57 2016 +0200

----------------------------------------------------------------------
 .../camel/component/zookeeper/operations/CreateOperation.java    | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/025567f1/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/CreateOperation.java
----------------------------------------------------------------------
diff --git a/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/CreateOperation.java b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/CreateOperation.java
index 730f6f2..75220e4 100644
--- a/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/CreateOperation.java
+++ b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/CreateOperation.java
@@ -18,14 +18,14 @@ package org.apache.camel.component.zookeeper.operations;
 
 import java.util.List;
 
+import static java.lang.String.format;
+
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.data.ACL;
 import org.apache.zookeeper.data.Stat;
 
-import static java.lang.String.format;
-
 /**
  * <code>CreateOperation</code> is a basic Zookeeper operation used to create
  * and set the data contained in a given node


[02/10] camel git commit: CAMEL-9851: zookeeper create operation should create sub paths.

Posted by da...@apache.org.
CAMEL-9851: zookeeper create operation should create sub paths.


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

Branch: refs/heads/master
Commit: f02727ea1623dc236602c0d1e4347e7bd4c29d55
Parents: 8463350
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Apr 15 08:51:31 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Apr 15 08:51:31 2016 +0200

----------------------------------------------------------------------
 .../zookeeper/operations/CreateOperation.java   |  6 +-
 .../zookeeper/operations/ZooKeeperHelper.java   | 58 ++++++++++++++++++++
 .../operations/CreateOperationTest.java         | 21 +++++++
 3 files changed, 83 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/f02727ea/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/CreateOperation.java
----------------------------------------------------------------------
diff --git a/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/CreateOperation.java b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/CreateOperation.java
index 5fb6587..730f6f2 100644
--- a/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/CreateOperation.java
+++ b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/CreateOperation.java
@@ -18,14 +18,14 @@ package org.apache.camel.component.zookeeper.operations;
 
 import java.util.List;
 
-import static java.lang.String.format;
-
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.data.ACL;
 import org.apache.zookeeper.data.Stat;
 
+import static java.lang.String.format;
+
 /**
  * <code>CreateOperation</code> is a basic Zookeeper operation used to create
  * and set the data contained in a given node
@@ -49,6 +49,8 @@ public class CreateOperation extends ZooKeeperOperation<String> {
     @Override
     public OperationResult<String> getResult() {
         try {
+            // ensure parent nodes is created first as persistent (cannot be ephemeral without children)
+            ZooKeeperHelper.mkdirs(connection, node, false, CreateMode.PERSISTENT);
             String created = connection.create(node, data, permissions, createMode);
             if (LOG.isDebugEnabled()) {
                 LOG.debug(format("Created node '%s' using mode '%s'", created, createMode));

http://git-wip-us.apache.org/repos/asf/camel/blob/f02727ea/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/ZooKeeperHelper.java
----------------------------------------------------------------------
diff --git a/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/ZooKeeperHelper.java b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/ZooKeeperHelper.java
new file mode 100644
index 0000000..0a022e1
--- /dev/null
+++ b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/ZooKeeperHelper.java
@@ -0,0 +1,58 @@
+/**
+ * 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.component.zookeeper.operations;
+
+import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.ZooDefs;
+import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.common.PathUtils;
+
+public final class ZooKeeperHelper {
+
+    private ZooKeeperHelper() {
+    }
+
+    public static void mkdirs(ZooKeeper zookeeper, String path, boolean makeLastNode, CreateMode createMode) throws Exception {
+        PathUtils.validatePath(path);
+
+        int pos = 1; // skip first slash, root is guaranteed to exist
+        do {
+            pos = path.indexOf("/", pos + 1);
+
+            if (pos == -1) {
+                if (makeLastNode) {
+                    pos = path.length();
+                } else {
+                    break;
+                }
+            }
+
+            String subPath = path.substring(0, pos);
+            if (zookeeper.exists(subPath, false) == null) {
+                try {
+                    zookeeper.create(subPath, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, createMode);
+                } catch (KeeperException.NodeExistsException e) {
+                    // ignore... someone else has created it since we checked
+                }
+            }
+
+        }
+        while (pos < path.length());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/f02727ea/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/operations/CreateOperationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/operations/CreateOperationTest.java b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/operations/CreateOperationTest.java
index e0137e1..48624c8 100644
--- a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/operations/CreateOperationTest.java
+++ b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/operations/CreateOperationTest.java
@@ -48,6 +48,27 @@ public class CreateOperationTest extends ZooKeeperTestSupport {
     }
 
     @Test
+    public void createBasicSubPath() throws Exception {
+        CreateOperation create = new CreateOperation(connection, "/sub/sub2");
+
+        OperationResult<String> result = create.get();
+        assertEquals("/sub/sub2", result.getResult());
+
+        verifyNodeContainsData("/sub/sub2", null);
+    }
+
+    @Test
+    public void createBasicSubPathWithData() throws Exception {
+        CreateOperation create = new CreateOperation(connection, "/sub/sub3");
+        create.setData(testPayload.getBytes());
+
+        OperationResult<String> result = create.get();
+        assertEquals("/sub/sub3", result.getResult());
+
+        verifyNodeContainsData("/sub/sub3", testPayloadBytes);
+    }
+
+    @Test
     public void createBasicWithData() throws Exception {
         CreateOperation create = new CreateOperation(connection, "/two");
         create.setData(testPayload.getBytes());


[06/10] camel git commit: CAMEL-9851: Fixed NPE in consumer if path is empty

Posted by da...@apache.org.
CAMEL-9851: Fixed NPE in consumer if path is empty


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

Branch: refs/heads/camel-2.16.x
Commit: 15ee2b73bb33468e017b08ec7927b02c51460948
Parents: 7af24ce
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Apr 15 08:09:16 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Apr 15 08:52:30 2016 +0200

----------------------------------------------------------------------
 .../apache/camel/component/zookeeper/ZooKeeperConsumer.java  | 5 ++---
 .../camel/component/zookeeper/policy/ZooKeeperElection.java  | 8 +++-----
 2 files changed, 5 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/15ee2b73/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ZooKeeperConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ZooKeeperConsumer.java b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ZooKeeperConsumer.java
index bb9507f..44b8f49 100644
--- a/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ZooKeeperConsumer.java
+++ b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ZooKeeperConsumer.java
@@ -34,7 +34,6 @@ import org.apache.camel.impl.DefaultConsumer;
 import org.apache.zookeeper.WatchedEvent;
 import org.apache.zookeeper.ZooKeeper;
 
-
 /**
  * <code>ZooKeeperConsumer</code> uses various {@link ZooKeeperOperation} to
  * interact and consume data from a ZooKeeper cluster.
@@ -64,7 +63,7 @@ public class ZooKeeperConsumer extends DefaultConsumer {
         }
 
         initializeConsumer();
-        executor = getEndpoint().getCamelContext().getExecutorServiceManager().newFixedThreadPool(configuration.getPath(), "Camel-Zookeeper Ops executor", 1);
+        executor = getEndpoint().getCamelContext().getExecutorServiceManager().newFixedThreadPool(this, "Camel-Zookeeper OperationsExecutor", 1);
 
         OperationsExecutor opsService = new OperationsExecutor();
         executor.submit(opsService);
@@ -128,7 +127,6 @@ public class ZooKeeperConsumer extends DefaultConsumer {
 
         public void run() {
             while (isRunAllowed()) {
-
                 try {
                     current = operations.take();
                     if (log.isTraceEnabled()) {
@@ -169,6 +167,7 @@ public class ZooKeeperConsumer extends DefaultConsumer {
                     initializeConsumer();
                 }
             } catch (Exception e) {
+                // ignore
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/15ee2b73/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/policy/ZooKeeperElection.java
----------------------------------------------------------------------
diff --git a/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/policy/ZooKeeperElection.java b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/policy/ZooKeeperElection.java
index 79e6a19..cdff74c 100644
--- a/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/policy/ZooKeeperElection.java
+++ b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/policy/ZooKeeperElection.java
@@ -146,15 +146,13 @@ public class ZooKeeperElection {
         producerTemplate.send(zep, e);
 
         if (e.isFailed()) {
-            LOG.error("Error setting up election node " + fullpath, e.getException());
+            LOG.warn("Error setting up election node " + fullpath, e.getException());
         } else {
             LOG.info("Candidate node '{}' has been created", fullpath);
             try {
-                if (zep != null) {
-                    camelContext.addRoutes(new ElectoralMonitorRoute(zep));
-                }
+                camelContext.addRoutes(new ElectoralMonitorRoute(zep));
             } catch (Exception ex) {
-                LOG.error("Error configuring ZookeeperElection", ex);
+                LOG.warn("Error configuring ZookeeperElection", ex);
             }
         }
         return zep;


[07/10] camel git commit: CAMEL-9851: zookeeper create operation should create sub paths.

Posted by da...@apache.org.
CAMEL-9851: zookeeper create operation should create sub paths.


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

Branch: refs/heads/camel-2.16.x
Commit: 72e20ff42abeeac753a157d651b381194968a3a8
Parents: 15ee2b7
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Apr 15 08:51:31 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Apr 15 08:52:36 2016 +0200

----------------------------------------------------------------------
 .../zookeeper/operations/CreateOperation.java   |  6 +-
 .../zookeeper/operations/ZooKeeperHelper.java   | 58 ++++++++++++++++++++
 .../operations/CreateOperationTest.java         | 21 +++++++
 3 files changed, 83 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/72e20ff4/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/CreateOperation.java
----------------------------------------------------------------------
diff --git a/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/CreateOperation.java b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/CreateOperation.java
index 5fb6587..730f6f2 100644
--- a/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/CreateOperation.java
+++ b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/CreateOperation.java
@@ -18,14 +18,14 @@ package org.apache.camel.component.zookeeper.operations;
 
 import java.util.List;
 
-import static java.lang.String.format;
-
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.data.ACL;
 import org.apache.zookeeper.data.Stat;
 
+import static java.lang.String.format;
+
 /**
  * <code>CreateOperation</code> is a basic Zookeeper operation used to create
  * and set the data contained in a given node
@@ -49,6 +49,8 @@ public class CreateOperation extends ZooKeeperOperation<String> {
     @Override
     public OperationResult<String> getResult() {
         try {
+            // ensure parent nodes is created first as persistent (cannot be ephemeral without children)
+            ZooKeeperHelper.mkdirs(connection, node, false, CreateMode.PERSISTENT);
             String created = connection.create(node, data, permissions, createMode);
             if (LOG.isDebugEnabled()) {
                 LOG.debug(format("Created node '%s' using mode '%s'", created, createMode));

http://git-wip-us.apache.org/repos/asf/camel/blob/72e20ff4/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/ZooKeeperHelper.java
----------------------------------------------------------------------
diff --git a/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/ZooKeeperHelper.java b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/ZooKeeperHelper.java
new file mode 100644
index 0000000..0a022e1
--- /dev/null
+++ b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/ZooKeeperHelper.java
@@ -0,0 +1,58 @@
+/**
+ * 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.component.zookeeper.operations;
+
+import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.ZooDefs;
+import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.common.PathUtils;
+
+public final class ZooKeeperHelper {
+
+    private ZooKeeperHelper() {
+    }
+
+    public static void mkdirs(ZooKeeper zookeeper, String path, boolean makeLastNode, CreateMode createMode) throws Exception {
+        PathUtils.validatePath(path);
+
+        int pos = 1; // skip first slash, root is guaranteed to exist
+        do {
+            pos = path.indexOf("/", pos + 1);
+
+            if (pos == -1) {
+                if (makeLastNode) {
+                    pos = path.length();
+                } else {
+                    break;
+                }
+            }
+
+            String subPath = path.substring(0, pos);
+            if (zookeeper.exists(subPath, false) == null) {
+                try {
+                    zookeeper.create(subPath, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, createMode);
+                } catch (KeeperException.NodeExistsException e) {
+                    // ignore... someone else has created it since we checked
+                }
+            }
+
+        }
+        while (pos < path.length());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/72e20ff4/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/operations/CreateOperationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/operations/CreateOperationTest.java b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/operations/CreateOperationTest.java
index e0137e1..48624c8 100644
--- a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/operations/CreateOperationTest.java
+++ b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/operations/CreateOperationTest.java
@@ -48,6 +48,27 @@ public class CreateOperationTest extends ZooKeeperTestSupport {
     }
 
     @Test
+    public void createBasicSubPath() throws Exception {
+        CreateOperation create = new CreateOperation(connection, "/sub/sub2");
+
+        OperationResult<String> result = create.get();
+        assertEquals("/sub/sub2", result.getResult());
+
+        verifyNodeContainsData("/sub/sub2", null);
+    }
+
+    @Test
+    public void createBasicSubPathWithData() throws Exception {
+        CreateOperation create = new CreateOperation(connection, "/sub/sub3");
+        create.setData(testPayload.getBytes());
+
+        OperationResult<String> result = create.get();
+        assertEquals("/sub/sub3", result.getResult());
+
+        verifyNodeContainsData("/sub/sub3", testPayloadBytes);
+    }
+
+    @Test
     public void createBasicWithData() throws Exception {
         CreateOperation create = new CreateOperation(connection, "/two");
         create.setData(testPayload.getBytes());


[03/10] camel git commit: Component docs

Posted by da...@apache.org.
Component docs


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

Branch: refs/heads/master
Commit: 55052a9fbfc5e31e675eb304af1a10178f83a82d
Parents: f02727e
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Apr 15 08:51:40 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Apr 15 08:51:40 2016 +0200

----------------------------------------------------------------------
 components/camel-hdfs2/src/main/docs/hdfs2.adoc | 4 ++++
 1 file changed, 4 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/55052a9f/components/camel-hdfs2/src/main/docs/hdfs2.adoc
----------------------------------------------------------------------
diff --git a/components/camel-hdfs2/src/main/docs/hdfs2.adoc b/components/camel-hdfs2/src/main/docs/hdfs2.adoc
index 2bfe7f7..45f85f4 100644
--- a/components/camel-hdfs2/src/main/docs/hdfs2.adoc
+++ b/components/camel-hdfs2/src/main/docs/hdfs2.adoc
@@ -55,9 +55,12 @@ Options
 ^^^^^^^
 
 
+
 // component options: START
 The HDFS2 component supports 1 options which are listed below.
 
+
+
 [width="100%",cols="2s,1m,8",options="header"]
 |=======================================================================
 | Name | Java Type | Description
@@ -65,6 +68,7 @@ The HDFS2 component supports 1 options which are listed below.
 |=======================================================================
 // component options: END
 
+
 // endpoint options: START
 The HDFS2 component supports 41 endpoint options which are listed below: