Repository: ignite
Updated Branches:
  refs/heads/ignite-zk ce7f0cbcf -> 4cd262ece


zk


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

Branch: refs/heads/ignite-zk
Commit: 4cd262ece7c29fcbdc612ffa9444001c1bc0596b
Parents: ce7f0cb
Author: sboikov <sboi...@gridgain.com>
Authored: Thu Nov 23 16:19:46 2017 +0300
Committer: sboikov <sboi...@gridgain.com>
Committed: Thu Nov 23 17:00:59 2017 +0300

----------------------------------------------------------------------
 .../discovery/zk/internal/ZkClusterNodes.java   |  5 +-
 .../discovery/zk/internal/ZkIgnitePaths.java    |  2 +-
 .../discovery/zk/internal/ZookeeperClient.java  | 58 +++++++++++++++++---
 .../ZookeeperClientFailedException.java         |  2 +-
 .../ZookeeperDiscoverySpiBasicTest.java         | 40 ++++++++++++++
 5 files changed, 96 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/4cd262ec/modules/core/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZkClusterNodes.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZkClusterNodes.java
 
b/modules/core/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZkClusterNodes.java
index e3e5f8b..7ca1360 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZkClusterNodes.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZkClusterNodes.java
@@ -42,7 +42,6 @@ public class ZkClusterNodes {
      * @return Remote nodes.
      */
     public Collection<ClusterNode> remoteNodes() {
-        // TODO ZK
         List<ClusterNode> nodes = new ArrayList<>();
 
         for (ClusterNode node : nodesById.values()) {
@@ -73,6 +72,10 @@ public class ZkClusterNodes {
         assert old == null : old;
     }
 
+    /**
+     * @param internalId Node internal ID.
+     * @return Removed node.
+     */
     ZookeeperClusterNode removeNode(int internalId) {
         ZookeeperClusterNode node = nodesByInternalId.remove(internalId);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/4cd262ec/modules/core/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZkIgnitePaths.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZkIgnitePaths.java
 
b/modules/core/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZkIgnitePaths.java
index 2936876..a98ea8d 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZkIgnitePaths.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZkIgnitePaths.java
@@ -104,7 +104,7 @@ class ZkIgnitePaths {
      * @return The given path if it was valid, for fluent chaining
      * @throws IllegalArgumentException if the path is invalid
      */
-    public static String validatePath(String path) throws 
IllegalArgumentException {
+    static String validatePath(String path) throws IllegalArgumentException {
         if (path == null) {
             throw new IllegalArgumentException("Path cannot be null");
         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/4cd262ec/modules/core/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperClient.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperClient.java
 
b/modules/core/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperClient.java
index 9125982..166db4c 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperClient.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperClient.java
@@ -167,7 +167,8 @@ public class ZookeeperClient implements Watcher {
                 }
 
                 if (newState != state) {
-                    log.info("Zookeeper client state changed [prevState=" + 
state + ", newState=" + newState + ']');
+                    if (log.isInfoEnabled())
+                        log.info("Zookeeper client state changed [prevState=" 
+ state + ", newState=" + newState + ']');
 
                     state = newState;
 
@@ -256,9 +257,19 @@ public class ZookeeperClient implements Watcher {
 
     }
 
+    /**
+     * @param path Path.
+     * @param data Data.
+     * @param createMode Create mode.
+     * @return Created path.
+     * @throws ZookeeperClientFailedException If connection to zk was lost.
+     * @throws InterruptedException If interrupted.
+     */
     String createIfNeeded(String path, byte[] data, CreateMode createMode)
         throws ZookeeperClientFailedException, InterruptedException
     {
+        assert !createMode.isSequential() : createMode;
+
         if (data == null)
             data = EMPTY_BYTES;
 
@@ -279,7 +290,17 @@ public class ZookeeperClient implements Watcher {
         }
     }
 
-    String createSequential(String checkPrefix, String dir, String childPath, 
byte[] data, CreateMode createMode)
+    /**
+     * @param checkPrefix Unique prefix to check in case of retry.
+     * @param parentPath Parent node path.
+     * @param childPath  Child path.
+     * @param data Node data.
+     * @param createMode Create mode.
+     * @return Create path.
+     * @throws ZookeeperClientFailedException If connection to zk was lost.
+     * @throws InterruptedException If interrupted.
+     */
+    String createSequential(String checkPrefix, String parentPath, String 
childPath, byte[] data, CreateMode createMode)
         throws ZookeeperClientFailedException, InterruptedException
     {
         assert createMode.isSequential() : createMode;
@@ -289,20 +310,20 @@ public class ZookeeperClient implements Watcher {
 
         boolean first = true;
 
-        String path = dir + "/" + childPath;
+        String path = parentPath + "/" + childPath;
 
         for (;;) {
             long connStartTime = this.connStartTime;
 
             try {
                 if (!first) {
-                    List<String> children = zk.getChildren(dir, false);
+                    List<String> children = zk.getChildren(parentPath, false);
 
                     for (int i = 0; i < children.size(); i++) {
                         String child = children.get(i);
 
                         if (children.get(i).startsWith(checkPrefix)) {
-                            String resPath = dir + "/" + child;
+                            String resPath = parentPath + "/" + child;
 
                             log.info("Check before retry, node already 
created: " + resPath);
 
@@ -349,6 +370,12 @@ public class ZookeeperClient implements Watcher {
         }
     }
 
+    /**
+     * @param path Path.
+     * @param ver Version.
+     * @throws ZookeeperClientFailedException If connection to zk was lost.
+     * @throws InterruptedException If interrupted.
+     */
     void deleteIfExists(String path, int ver)
         throws ZookeeperClientFailedException, InterruptedException
     {
@@ -360,7 +387,14 @@ public class ZookeeperClient implements Watcher {
         }
     }
 
-
+    /**
+     * @param parent Parent path.
+     * @param paths Children paths.
+     * @param ver Version.
+     * @throws KeeperException.NoNodeException If at least one of nodes does 
not exist.
+     * @throws ZookeeperClientFailedException If connection to zk was lost.
+     * @throws InterruptedException If interrupted.
+     */
     void deleteAll(@Nullable String parent, List<String> paths, int ver)
         throws KeeperException.NoNodeException, 
ZookeeperClientFailedException, InterruptedException
     {
@@ -397,7 +431,7 @@ public class ZookeeperClient implements Watcher {
      * @throws ZookeeperClientFailedException If connection to zk was lost.
      * @throws InterruptedException If interrupted.
      */
-    void delete(String path, int ver)
+    private void delete(String path, int ver)
         throws KeeperException.NoNodeException, 
ZookeeperClientFailedException, InterruptedException
     {
         for (;;) {
@@ -508,7 +542,7 @@ public class ZookeeperClient implements Watcher {
      * @param createMode Create mode.
      * @param cb Callback.
      */
-    void createAsync(String path, byte[] data, CreateMode createMode, 
AsyncCallback.StringCallback cb) {
+    private void createAsync(String path, byte[] data, CreateMode createMode, 
AsyncCallback.StringCallback cb) {
         if (data == null)
             data = EMPTY_BYTES;
 
@@ -525,7 +559,10 @@ public class ZookeeperClient implements Watcher {
     }
 
     /**
+     * @param prevConnStartTime Time when connection was established.
      * @param e Error.
+     * @throws ZookeeperClientFailedException If connection to zk was lost.
+     * @throws InterruptedException If interrupted.
      */
     private void onZookeeperError(long prevConnStartTime, Exception e)
         throws ZookeeperClientFailedException, InterruptedException
@@ -659,6 +696,11 @@ public class ZookeeperClient implements Watcher {
         /** */
         private final AsyncCallback.Children2Callback cb;
 
+        /**
+         * @param path Path.
+         * @param watcher Watcher.
+         * @param cb Callback.
+         */
         GetChildrenOperation(String path, Watcher watcher, 
AsyncCallback.Children2Callback cb) {
             this.path = path;
             this.watcher = watcher;

http://git-wip-us.apache.org/repos/asf/ignite/blob/4cd262ec/modules/core/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperClientFailedException.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperClientFailedException.java
 
b/modules/core/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperClientFailedException.java
index 99f2a6d..a61f478 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperClientFailedException.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperClientFailedException.java
@@ -20,7 +20,7 @@ package org.apache.ignite.spi.discovery.zk.internal;
 /**
  *
  */
-public class ZookeeperClientFailedException extends Exception {
+class ZookeeperClientFailedException extends Exception {
     /** */
     private static final long serialVersionUID = 0L;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/4cd262ec/modules/core/src/test/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoverySpiBasicTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoverySpiBasicTest.java
 
b/modules/core/src/test/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoverySpiBasicTest.java
index 9bdf670..a9f0d7f 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoverySpiBasicTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoverySpiBasicTest.java
@@ -44,6 +44,7 @@ import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.IgniteKernal;
 import org.apache.ignite.internal.IgnitionEx;
 import org.apache.ignite.internal.managers.discovery.DiscoveryLocalJoinData;
+import 
org.apache.ignite.internal.processors.cache.GridCacheAbstractFullApiSelfTest;
 import org.apache.ignite.internal.util.lang.GridAbsPredicate;
 import org.apache.ignite.internal.util.typedef.G;
 import org.apache.ignite.internal.util.typedef.internal.CU;
@@ -983,6 +984,45 @@ public class ZookeeperDiscoverySpiBasicTest extends 
GridCommonAbstractTest {
     }
 
     /**
+     * @throws Exception If failed.
+     */
+    public void testDeployService1() throws Exception {
+        startGridsMultiThreaded(3);
+
+        grid(0).services(grid(0).cluster()).deployNodeSingleton("test", new 
GridCacheAbstractFullApiSelfTest.DummyServiceImpl());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDeployService2() throws Exception {
+        client = false;
+
+        startGrid(0);
+
+        client = true;
+
+        startGrid(1);
+
+        grid(0).services(grid(0).cluster()).deployNodeSingleton("test", new 
GridCacheAbstractFullApiSelfTest.DummyServiceImpl());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDeployService3() throws Exception {
+        client = true;
+
+        startGrid(0);
+
+        client = false;
+
+        startGrid(1);
+
+        grid(0).services(grid(0).cluster()).deployNodeSingleton("test", new 
GridCacheAbstractFullApiSelfTest.DummyServiceImpl());
+    }
+
+    /**
      * @param restartZk If {@code true} in background restarts on of ZK 
servers.
      * @param closeClientSock If {@code true} in background closes zk clients' 
sockets.
      * @throws Exception If failed.

Reply via email to