IGNITE-16182 Migrate TcpDiscoveryZookeeperIpFinder to ignite-extensions. (#88)
diff --git a/modules/zookeeper-ip-finder-ext/README.txt b/modules/zookeeper-ip-finder-ext/README.txt
new file mode 100644
index 0000000..87b8d3a
--- /dev/null
+++ b/modules/zookeeper-ip-finder-ext/README.txt
@@ -0,0 +1,35 @@
+Apache Ignite ZooKeeper Ip Finder Module
+------------------------------
+
+Apache Ignite ZooKeeper Ip Finder module provides a TCP Discovery IP Finder that uses a ZooKeeper
+directory to locate other Ignite nodes to connect to.
+
+Depending on how you use Ignite, you can an extension using one of the following methods:
+
+- If you use the binary distribution, move the lib/optional/{module-dir} to the lib directory before starting the node.
+- Add libraries from lib/optional/{module-dir} to the classpath of your application.
+- Add a module as a Maven dependency to your project.
+
+Importing Apache Ignite ZooKeeper IpFinder Module In Maven Project
+---------------------------------------------------------
+
+If you are using Maven to manage dependencies of your project, you can add the ZooKeeper
+module dependency like this (replace '${ignite-zookeeper-ip-finder-ext.version}' with actual Ignite version you
+are interested in):
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
+ http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ ...
+ <dependencies>
+ ...
+ <dependency>
+ <groupId>org.apache.ignite</groupId>
+ <artifactId>ignite-zookeeper-ip-finder-ext</artifactId>
+ <version>${ignite-zookeeper-ip-finder-ext.version}</version>
+ </dependency>
+ ...
+ </dependencies>
+ ...
+</project>
diff --git a/modules/zookeeper-ip-finder-ext/assembly/zookeeper-ip-finder-ext.xml b/modules/zookeeper-ip-finder-ext/assembly/zookeeper-ip-finder-ext.xml
new file mode 100644
index 0000000..80a55c9
--- /dev/null
+++ b/modules/zookeeper-ip-finder-ext/assembly/zookeeper-ip-finder-ext.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ 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.
+-->
+
+<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2
+ http://maven.apache.org/xsd/assembly-1.1.2.xsd">
+ <id>zookeeper-ip-finder-ext</id>
+
+ <includeBaseDirectory>false</includeBaseDirectory>
+
+ <formats>
+ <format>zip</format>
+ </formats>
+
+ <fileSets>
+ <fileSet>
+ <directory>${project.build.directory}</directory>
+ <outputDirectory>/libs/optional/ignite-zookeeper-ip-finder-ext</outputDirectory>
+ <includes>
+ <include>${project.build.finalName}.${project.packaging}</include>
+ </includes>
+ </fileSet>
+ <fileSet>
+ <directory>${project.build.directory}/libs</directory>
+ <outputDirectory>/libs/optional/ignite-zookeeper-ip-finder-ext</outputDirectory>
+ </fileSet>
+ </fileSets>
+</assembly>
diff --git a/modules/zookeeper-ip-finder-ext/licenses/apache-2.0.txt b/modules/zookeeper-ip-finder-ext/licenses/apache-2.0.txt
new file mode 100644
index 0000000..d645695
--- /dev/null
+++ b/modules/zookeeper-ip-finder-ext/licenses/apache-2.0.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ 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.
diff --git a/modules/zookeeper-ip-finder-ext/modules/core/src/test/config/log4j-test.xml b/modules/zookeeper-ip-finder-ext/modules/core/src/test/config/log4j-test.xml
new file mode 100755
index 0000000..3061bd4
--- /dev/null
+++ b/modules/zookeeper-ip-finder-ext/modules/core/src/test/config/log4j-test.xml
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ 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.
+-->
+
+<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN"
+ "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
+<!--
+ Log4j configuration.
+-->
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+ <!--
+ Logs System.out messages to console.
+ -->
+ <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+ <!-- Log to STDOUT. -->
+ <param name="Target" value="System.out"/>
+
+ <!-- Log from DEBUG and higher. -->
+ <param name="Threshold" value="DEBUG"/>
+
+ <!-- The default pattern: Date Priority [Category] Message\n -->
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="[%d{ISO8601}][%-5p][%t][%c{1}] %m%n"/>
+ </layout>
+
+ <!-- Do not log beyond INFO level. -->
+ <filter class="org.apache.log4j.varia.LevelRangeFilter">
+ <param name="levelMin" value="DEBUG"/>
+ <param name="levelMax" value="INFO"/>
+ </filter>
+ </appender>
+
+ <!--
+ Logs all System.err messages to console.
+ -->
+ <appender name="CONSOLE_ERR" class="org.apache.log4j.ConsoleAppender">
+ <!-- Log to STDERR. -->
+ <param name="Target" value="System.err"/>
+
+ <!-- Log from WARN and higher. -->
+ <param name="Threshold" value="WARN"/>
+
+ <!-- The default pattern: Date Priority [Category] Message\n -->
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="[%d{ISO8601}][%-5p][%t][%c{1}] %m%n"/>
+ </layout>
+ </appender>
+
+ <!--
+ Logs all output to specified file.
+ -->
+ <appender name="FILE" class="org.apache.log4j.RollingFileAppender">
+ <param name="Threshold" value="DEBUG"/>
+ <param name="File" value="ignite/work/log/ignite.log"/>
+ <param name="Append" value="true"/>
+ <param name="MaxFileSize" value="10MB"/>
+ <param name="MaxBackupIndex" value="10"/>
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="[%d{ISO8601}][%-5p][%t][%c{1}] %m%n"/>
+ </layout>
+ </appender>
+
+ <!-- Disable all open source debugging. -->
+ <category name="org">
+ <level value="INFO"/>
+ </category>
+
+ <category name="org.eclipse.jetty">
+ <level value="INFO"/>
+ </category>
+
+ <!-- Default settings. -->
+ <root>
+ <!-- Print at info by default. -->
+ <level value="INFO"/>
+
+ <!-- Append to file and console. -->
+ <appender-ref ref="FILE"/>
+ <appender-ref ref="CONSOLE"/>
+ <appender-ref ref="CONSOLE_ERR"/>
+ </root>
+</log4j:configuration>
diff --git a/modules/zookeeper-ip-finder-ext/modules/core/src/test/config/tests.properties b/modules/zookeeper-ip-finder-ext/modules/core/src/test/config/tests.properties
new file mode 100644
index 0000000..0faf5b8
--- /dev/null
+++ b/modules/zookeeper-ip-finder-ext/modules/core/src/test/config/tests.properties
@@ -0,0 +1,22 @@
+#
+# 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.
+#
+
+# Local address to bind to.
+local.ip=127.0.0.1
+
+# TCP communication port
+comm.tcp.port=30010
diff --git a/modules/zookeeper-ip-finder-ext/pom.xml b/modules/zookeeper-ip-finder-ext/pom.xml
new file mode 100644
index 0000000..03b5561
--- /dev/null
+++ b/modules/zookeeper-ip-finder-ext/pom.xml
@@ -0,0 +1,207 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ 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.
+-->
+
+<!--
+ POM file.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.ignite</groupId>
+ <artifactId>ignite-extensions-parent</artifactId>
+ <version>1</version>
+ <relativePath>../../parent</relativePath>
+ </parent>
+
+ <artifactId>ignite-zookeeper-ip-finder-ext</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <url>http://ignite.apache.org</url>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.ignite</groupId>
+ <artifactId>ignite-core</artifactId>
+ <version>${ignite.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.curator</groupId>
+ <artifactId>curator-framework</artifactId>
+ <version>${curator.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.curator</groupId>
+ <artifactId>curator-recipes</artifactId>
+ <version>${curator.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.curator</groupId>
+ <artifactId>curator-x-discovery</artifactId>
+ <version>${curator.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.curator</groupId>
+ <artifactId>curator-client</artifactId>
+ <version>${curator.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ <version>${guava16.version}</version>
+ </dependency>
+
+ <!-- Do not remove org.codehaus.jackson:jackson-core-asl it is required by Apache Curator at runtime -->
+ <dependency>
+ <groupId>org.codehaus.jackson</groupId>
+ <artifactId>jackson-core-asl</artifactId>
+ <version>${jackson1.version}</version>
+ </dependency>
+
+ <!-- Do not remove org.codehaus.jackson:jackson-mapper-asl it is required by Apache Curator at runtime -->
+ <dependency>
+ <groupId>org.codehaus.jackson</groupId>
+ <artifactId>jackson-mapper-asl</artifactId>
+ <version>${jackson1.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.zookeeper</groupId>
+ <artifactId>zookeeper</artifactId>
+ <version>${zookeeper.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.zookeeper</groupId>
+ <artifactId>zookeeper-jute</artifactId>
+ <version>${zookeeper.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>${slf4j.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>${slf4j.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.curator</groupId>
+ <artifactId>curator-test</artifactId>
+ <version>${curator.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.ignite</groupId>
+ <artifactId>ignite-spring</artifactId>
+ <version>${ignite.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.ignite</groupId>
+ <artifactId>ignite-core</artifactId>
+ <version>${ignite.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.ignite</groupId>
+ <artifactId>ignite-tools</artifactId>
+ <version>${ignite.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${project.build.directory}/libs</outputDirectory>
+ <includeScope>runtime</includeScope>
+ <excludeArtifactIds>ignite-core,ignite-spring,ignite-shmem</excludeArtifactIds>
+ <excludeTransitive>false</excludeTransitive>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>zookeeper-ip-finder-ext</id>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ <phase>package</phase>
+ <configuration>
+ <appendAssemblyId>false</appendAssemblyId>
+ <descriptors>
+ <descriptor>assembly/zookeeper-ip-finder-ext.xml</descriptor>
+ </descriptors>
+ <finalName>ignite-zookeeper-ip-finder-ext</finalName>
+ <attach>false</attach>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ <!-- Generate the OSGi MANIFEST.MF for this bundle. -->
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <version>2.8.2</version>
+ <configuration>
+ <skip>false</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/modules/zookeeper-ip-finder-ext/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/zk/TcpDiscoveryZookeeperIpFinder.java b/modules/zookeeper-ip-finder-ext/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/zk/TcpDiscoveryZookeeperIpFinder.java
new file mode 100644
index 0000000..ad0821b
--- /dev/null
+++ b/modules/zookeeper-ip-finder-ext/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/zk/TcpDiscoveryZookeeperIpFinder.java
@@ -0,0 +1,398 @@
+/*
+ * 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.ignite.spi.discovery.tcp.ipfinder.zk;
+
+import java.net.InetSocketAddress;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+import com.google.common.collect.Sets;
+import org.apache.curator.RetryPolicy;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.framework.imps.CuratorFrameworkState;
+import org.apache.curator.retry.ExponentialBackoffRetry;
+import org.apache.curator.x.discovery.ServiceDiscovery;
+import org.apache.curator.x.discovery.ServiceDiscoveryBuilder;
+import org.apache.curator.x.discovery.ServiceInstance;
+import org.apache.curator.x.discovery.UriSpec;
+import org.apache.curator.x.discovery.details.JsonInstanceSerializer;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.IgniteSystemProperties;
+import org.apache.ignite.SystemProperty;
+import org.apache.ignite.internal.util.tostring.GridToStringExclude;
+import org.apache.ignite.internal.util.typedef.internal.A;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.resources.LoggerResource;
+import org.apache.ignite.spi.IgniteSpiException;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinderAdapter;
+import org.codehaus.jackson.map.annotate.JsonRootName;
+
+/**
+ * This TCP Discovery IP Finder uses Apache ZooKeeper (ZK) to locate peer nodes when bootstrapping in order to join
+ * the cluster. It uses the Apache Curator library to interact with ZooKeeper in a simple manner. Specifically,
+ * it uses the {@link ServiceDiscovery} recipe, which makes use of ephemeral nodes in ZK to register services.
+ *
+ * <p>
+ * There are several ways to instantiate the TcpDiscoveryZookeeperIpFinder:
+ * <li>
+ * <ul>By providing an instance of {@link CuratorFramework} directly, in which case no ZK Connection String
+ * is required.</ul>
+ * <ul>By providing a ZK Connection String through {@link #setZkConnectionString(String)}, and optionally
+ * a {@link RetryPolicy} through the setter. If the latter is not provided, a default
+ * {@link ExponentialBackoffRetry} policy is used, with a base sleep time of 1000ms and 10 retries.</ul>
+ * <ul>By providing a ZK Connection String through system property {@link #PROP_ZK_CONNECTION_STRING}. If this
+ * property is set, it overrides the ZK Connection String passed in as a property, but it does not override
+ * the {@link CuratorFramework} if provided.</ul>
+ * </li>
+ *
+ * You may customise the base path for services, as well as the service name. By default {@link #BASE_PATH} and
+ * {@link #SERVICE_NAME} are use respectively. You can also choose to enable or disable duplicate registrations. See
+ * {@link #setAllowDuplicateRegistrations(boolean)} for more details.
+ *
+ * @see <a href="http://zookeeper.apache.org">Apache ZooKeeper</a>
+ * @see <a href="http://curator.apache.org">Apache Curator</a>
+ */
+public class TcpDiscoveryZookeeperIpFinder extends TcpDiscoveryIpFinderAdapter {
+ /** System property name to provide the ZK Connection String. */
+ @SystemProperty(value = "Zookeeper connection string", type = String.class)
+ public static final String PROP_ZK_CONNECTION_STRING = "IGNITE_ZK_CONNECTION_STRING";
+
+ /** Default base path for service registrations. */
+ private static final String BASE_PATH = "/services";
+
+ /** Default service name for service registrations. */
+ private static final String SERVICE_NAME = "ignite";
+
+ /** Default URI Spec to use with the {@link ServiceDiscoveryBuilder}. */
+ private static final UriSpec URI_SPEC = new UriSpec("{address}:{port}");
+
+ /** Init guard. */
+ @GridToStringExclude
+ private final AtomicBoolean initGuard = new AtomicBoolean();
+
+ /** Init guard. */
+ @GridToStringExclude
+ private final AtomicBoolean closeGuard = new AtomicBoolean();
+
+ /** Logger. */
+ @LoggerResource
+ private IgniteLogger log;
+
+ /** The Curator framework in use, either injected or constructed by this component. */
+ private CuratorFramework curator;
+
+ /** The ZK Connection String if provided by the user. */
+ private String zkConnectionString;
+
+ /** Retry policy to use. */
+ private RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 10);
+
+ /** Base path to use, by default {#link #BASE_PATH}. */
+ private String basePath = BASE_PATH;
+
+ /** Service name to use, by default {#link #SERVICE_NAME}. */
+ private String serviceName = SERVICE_NAME;
+
+ /** Whether to allow or not duplicate registrations. See setter doc. */
+ private boolean allowDuplicateRegistrations;
+
+ /** The Service Discovery recipe. */
+ private ServiceDiscovery<IgniteInstanceDetails> discovery;
+
+ /** Map of the {#link ServiceInstance}s we have registered. */
+ private Map<InetSocketAddress, ServiceInstance<IgniteInstanceDetails>> ourInstances = new ConcurrentHashMap<>();
+
+ /** Constructor. */
+ public TcpDiscoveryZookeeperIpFinder() {
+ setShared(true);
+ }
+
+ /** Initializes this IP Finder by creating the appropriate Curator objects. */
+ private void init() {
+ if (!initGuard.compareAndSet(false, true))
+ return;
+
+ String sysPropZkConnString = IgniteSystemProperties.getString(PROP_ZK_CONNECTION_STRING);
+
+ if (sysPropZkConnString != null && !sysPropZkConnString.trim().isEmpty())
+ zkConnectionString = sysPropZkConnString;
+
+ if (log.isInfoEnabled())
+ log.info("Initializing ZooKeeper IP Finder.");
+
+ if (curator == null) {
+ A.notNullOrEmpty(zkConnectionString, String.format("ZooKeeper URL (or system property %s) cannot be null " +
+ "or empty if a CuratorFramework object is not provided explicitly", PROP_ZK_CONNECTION_STRING));
+ curator = CuratorFrameworkFactory.newClient(zkConnectionString, retryPolicy);
+ }
+
+ if (curator.getState() == CuratorFrameworkState.LATENT)
+ curator.start();
+
+ A.ensure(curator.getState() == CuratorFrameworkState.STARTED, "CuratorFramework can't be started.");
+
+ discovery = ServiceDiscoveryBuilder.builder(IgniteInstanceDetails.class)
+ .client(curator)
+ .basePath(basePath)
+ .serializer(new JsonInstanceSerializer<>(IgniteInstanceDetails.class))
+ .build();
+ }
+
+ /** {@inheritDoc} */
+ @Override public void onSpiContextDestroyed() {
+ if (!closeGuard.compareAndSet(false, true)) {
+ U.warn(log, "ZooKeeper IP Finder can't be closed more than once.");
+
+ return;
+ }
+
+ if (log.isInfoEnabled())
+ log.info("Destroying ZooKeeper IP Finder.");
+
+ super.onSpiContextDestroyed();
+
+ if (curator != null)
+ curator.close();
+
+ }
+
+ /** {@inheritDoc} */
+ @Override public Collection<InetSocketAddress> getRegisteredAddresses() throws IgniteSpiException {
+ init();
+
+ if (log.isDebugEnabled())
+ log.debug("Getting registered addresses from ZooKeeper IP Finder.");
+
+ Collection<ServiceInstance<IgniteInstanceDetails>> serviceInstances;
+
+ try {
+ serviceInstances = discovery.queryForInstances(serviceName);
+ }
+ catch (Exception e) {
+ log.warning("Error while getting registered addresses from ZooKeeper IP Finder.", e);
+ return Collections.emptyList();
+ }
+
+ Set<InetSocketAddress> answer = new HashSet<>();
+
+ for (ServiceInstance<IgniteInstanceDetails> si : serviceInstances)
+ answer.add(new InetSocketAddress(si.getAddress(), si.getPort()));
+
+ if (log.isInfoEnabled())
+ log.info("ZooKeeper IP Finder resolved addresses: " + answer);
+
+ return answer;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void registerAddresses(Collection<InetSocketAddress> addrs) throws IgniteSpiException {
+ init();
+
+ if (log.isInfoEnabled())
+ log.info("Registering addresses with ZooKeeper IP Finder: " + addrs);
+
+ Set<InetSocketAddress> registrationsToIgnore = Sets.newHashSet();
+ if (!allowDuplicateRegistrations) {
+ try {
+ for (ServiceInstance<IgniteInstanceDetails> sd : discovery.queryForInstances(serviceName))
+ registrationsToIgnore.add(new InetSocketAddress(sd.getAddress(), sd.getPort()));
+ }
+ catch (Exception e) {
+ log.warning("Error while finding currently registered services to avoid duplicate registrations", e);
+ throw new IgniteSpiException(e);
+ }
+ }
+
+ for (InetSocketAddress addr : addrs) {
+ if (registrationsToIgnore.contains(addr))
+ continue;
+
+ try {
+ ServiceInstance<IgniteInstanceDetails> si = ServiceInstance.<IgniteInstanceDetails>builder()
+ .name(serviceName)
+ .uriSpec(URI_SPEC)
+ .address(addr.getAddress().getHostAddress())
+ .port(addr.getPort())
+ .build();
+
+ ourInstances.put(addr, si);
+
+ discovery.registerService(si);
+
+ }
+ catch (Exception e) {
+ log.warning(String.format("Error while registering an address from ZooKeeper IP Finder " +
+ "[message=%s,addresses=%s]", e.getMessage(), addr), e);
+ }
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public void unregisterAddresses(Collection<InetSocketAddress> addrs) throws IgniteSpiException {
+
+ // if curator is not STARTED, we have nothing to unregister, because we are using ephemeral nodes,
+ // which means that our addresses will only be registered in ZK as long as our connection is alive
+ if (curator.getState() != CuratorFrameworkState.STARTED)
+ return;
+
+ if (log.isInfoEnabled())
+ log.info("Unregistering addresses with ZooKeeper IP Finder: " + addrs);
+
+ for (InetSocketAddress addr : addrs) {
+ ServiceInstance<IgniteInstanceDetails> si = ourInstances.get(addr);
+ if (si == null) {
+ log.warning("Asked to unregister address from ZooKeeper IP Finder, but no match was found in local " +
+ "instance map for: " + addrs);
+ continue;
+ }
+
+ try {
+ discovery.unregisterService(si);
+ }
+ catch (Exception e) {
+ log.warning("Error while unregistering an address from ZooKeeper IP Finder: " + addr, e);
+ }
+ }
+ }
+
+ /**
+ * @param curator A {@link CuratorFramework} instance to use. It can already be in <tt>STARTED</tt> state.
+ * @return {@code this} for chaining.
+ */
+ public TcpDiscoveryZookeeperIpFinder setCurator(CuratorFramework curator) {
+ this.curator = curator;
+
+ return this;
+ }
+
+ /**
+ * @return The ZooKeeper connection string, only if set explicitly. Else, it returns null.
+ */
+ public String getZkConnectionString() {
+ return zkConnectionString;
+ }
+
+ /**
+ * @param zkConnectionString ZooKeeper connection string in case a {@link CuratorFramework} is not being set
+ * explicitly.
+ * @return {@code this} for chaining.
+ */
+ public TcpDiscoveryZookeeperIpFinder setZkConnectionString(String zkConnectionString) {
+ this.zkConnectionString = zkConnectionString;
+
+ return this;
+ }
+
+ /**
+ * @return Retry policy in use if, and only if, it was set explicitly. Else, it returns null.
+ */
+ public RetryPolicy getRetryPolicy() {
+ return retryPolicy;
+ }
+
+ /**
+ * @param retryPolicy {@link RetryPolicy} to use in case a ZK Connection String is being injected, or if using a
+ * system property.
+ * @return {@code this} for chaining.
+ */
+ public TcpDiscoveryZookeeperIpFinder setRetryPolicy(RetryPolicy retryPolicy) {
+ this.retryPolicy = retryPolicy;
+
+ return this;
+ }
+
+ /**
+ * @return Base path for service registration in ZK. Default value: {@link #BASE_PATH}.
+ */
+ public String getBasePath() {
+ return basePath;
+ }
+
+ /**
+ * @param basePath Base path for service registration in ZK. If not passed, {@link #BASE_PATH} will be used.
+ * @return {@code this} for chaining.
+ */
+ public TcpDiscoveryZookeeperIpFinder setBasePath(String basePath) {
+ this.basePath = basePath;
+
+ return this;
+ }
+
+ /**
+ * @return Service name being used, in Curator terms. See {@link #setServiceName(String)} for more information.
+ */
+ public String getServiceName() {
+ return serviceName;
+ }
+
+ /**
+ * @param serviceName Service name to use, as defined by Curator's {#link ServiceDiscovery} recipe. In physical ZK
+ * terms, it represents the node under {@link #basePath}, under which services will be registered.
+ * @return {@code this} for chaining.
+ */
+ public TcpDiscoveryZookeeperIpFinder setServiceName(String serviceName) {
+ this.serviceName = serviceName;
+
+ return this;
+ }
+
+ /**
+ * @return The value of this flag. See {@link #setAllowDuplicateRegistrations(boolean)} for more details.
+ */
+ public boolean isAllowDuplicateRegistrations() {
+ return allowDuplicateRegistrations;
+ }
+
+ /**
+ * @param allowDuplicateRegistrations Whether to register each node only once, or if duplicate registrations are
+ * allowed. Nodes will attempt to register themselves, plus those they know about. By default, duplicate
+ * registrations are not allowed, but you might want to set this property to <tt>true</tt> if you have multiple
+ * network interfaces or if you are facing troubles.
+ * @return {@code this} for chaining.
+ */
+ public TcpDiscoveryZookeeperIpFinder setAllowDuplicateRegistrations(boolean allowDuplicateRegistrations) {
+ this.allowDuplicateRegistrations = allowDuplicateRegistrations;
+
+ return this;
+ }
+
+ /** {@inheritDoc} */
+ @Override public TcpDiscoveryZookeeperIpFinder setShared(boolean shared) {
+ super.setShared(shared);
+
+ return this;
+ }
+
+ /**
+ * Empty DTO for storing service instances details. Currently acting as a placeholder because Curator requires a
+ * payload type when registering and discovering nodes. May be enhanced in the future with further information to
+ * assist discovery.
+ *
+ * @author Raul Kripalani
+ */
+ @JsonRootName("ignite_instance_details")
+ private class IgniteInstanceDetails {
+
+ }
+
+}
diff --git a/modules/zookeeper-ip-finder-ext/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/zk/package-info.java b/modules/zookeeper-ip-finder-ext/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/zk/package-info.java
new file mode 100644
index 0000000..fcfc7b9
--- /dev/null
+++ b/modules/zookeeper-ip-finder-ext/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/zk/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+
+/**
+ * Contains TCP Discovery IP Finder uses Apache ZooKeeper (ZK) to locate peer nodes.
+ */
+
+package org.apache.ignite.spi.discovery.tcp.ipfinder.zk;
diff --git a/modules/zookeeper-ip-finder-ext/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/zk/ZookeeperIpFinderTest.java b/modules/zookeeper-ip-finder-ext/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/zk/ZookeeperIpFinderTest.java
new file mode 100644
index 0000000..897c045
--- /dev/null
+++ b/modules/zookeeper-ip-finder-ext/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/zk/ZookeeperIpFinderTest.java
@@ -0,0 +1,409 @@
+/*
+ * 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.ignite.spi.discovery.tcp.ipfinder.zk;
+
+import java.util.Collection;
+import java.util.UUID;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.retry.ExponentialBackoffRetry;
+import org.apache.curator.retry.RetryNTimes;
+import org.apache.curator.test.InstanceSpec;
+import org.apache.curator.test.TestingCluster;
+import org.apache.curator.utils.CloseableUtils;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.events.Event;
+import org.apache.ignite.events.EventType;
+import org.apache.ignite.lang.IgniteBiPredicate;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.WithSystemProperty;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.Timeout;
+
+/**
+ * Test for {@link TcpDiscoveryZookeeperIpFinder}.
+ *
+ * @author Raul Kripalani
+ */
+@WithSystemProperty(key = "zookeeper.jmx.log4j.disable", value = "true") // disable JMX for tests
+public class ZookeeperIpFinderTest extends GridCommonAbstractTest {
+ /** Per test timeout */
+ @Rule
+ public Timeout globalTimeout = new Timeout((int)GridTestUtils.DFLT_TEST_TIMEOUT);
+
+ /** ZK Cluster size. */
+ private static final int ZK_CLUSTER_SIZE = 3;
+
+ /** ZK Path size. */
+ private static final String SERVICES_IGNITE_ZK_PATH = "/services/ignite";
+
+ /** The ZK cluster instance, from curator-test. */
+ private TestingCluster zkCluster;
+
+ /** A Curator client to perform assertions on the embedded ZK instances. */
+ private CuratorFramework zkCurator;
+
+ /** Whether to allow duplicate registrations for the current test method or not. */
+ private boolean allowDuplicateRegistrations = false;
+
+ /** Constructor that does not start any grids. */
+ public ZookeeperIpFinderTest() {
+ super(false);
+ }
+
+ /**
+ * Before test.
+ *
+ * @throws Exception
+ */
+ @Override public void beforeTest() throws Exception {
+ super.beforeTest();
+
+ // remove stale system properties
+ System.getProperties().remove(TcpDiscoveryZookeeperIpFinder.PROP_ZK_CONNECTION_STRING);
+
+ // start the ZK cluster
+ zkCluster = new TestingCluster(ZK_CLUSTER_SIZE);
+
+ zkCluster.start();
+
+ // start the Curator client so we can perform assertions on the ZK state later
+ zkCurator = CuratorFrameworkFactory.newClient(zkCluster.getConnectString(), new RetryNTimes(10, 1000));
+ zkCurator.start();
+ }
+
+ /**
+ * After test.
+ *
+ * @throws Exception
+ */
+ @Override public void afterTest() throws Exception {
+ super.afterTest();
+
+ if (zkCurator != null)
+ CloseableUtils.closeQuietly(zkCurator);
+
+ if (zkCluster != null)
+ CloseableUtils.closeQuietly(zkCluster);
+
+ stopAllGrids();
+ }
+
+ /**
+ * Enhances the default configuration with the {#TcpDiscoveryZookeeperIpFinder}.
+ *
+ * @param igniteInstanceName Ignite instance name.
+ * @return Ignite configuration.
+ * @throws Exception If failed.
+ */
+ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+ IgniteConfiguration configuration = super.getConfiguration(igniteInstanceName);
+
+ TcpDiscoverySpi tcpDisco = (TcpDiscoverySpi)configuration.getDiscoverySpi();
+ TcpDiscoveryZookeeperIpFinder zkIpFinder = new TcpDiscoveryZookeeperIpFinder();
+ zkIpFinder.setAllowDuplicateRegistrations(allowDuplicateRegistrations);
+
+ // first node => configure with zkUrl; second node => configure with CuratorFramework; third and subsequent
+ // shall be configured through system property
+ if (igniteInstanceName.equals(getTestIgniteInstanceName(0)))
+ zkIpFinder.setZkConnectionString(zkCluster.getConnectString());
+
+ else if (igniteInstanceName.equals(getTestIgniteInstanceName(1))) {
+ zkIpFinder.setCurator(CuratorFrameworkFactory.newClient(zkCluster.getConnectString(),
+ new ExponentialBackoffRetry(100, 5)));
+ }
+
+ tcpDisco.setIpFinder(zkIpFinder);
+
+ return configuration;
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testOneIgniteNodeIsAlone() throws Exception {
+ startGrid(0);
+
+ assertEquals(1, grid(0).cluster().metrics().getTotalNodes());
+
+ stopAllGrids();
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testTwoIgniteNodesFindEachOther() throws Exception {
+ // start one node
+ startGrid(0);
+
+ // set up an event listener to expect one NODE_JOINED event
+ CountDownLatch latch = expectJoinEvents(grid(0), 1);
+
+ // start the other node
+ startGrid(1);
+
+ // assert the nodes see each other
+ assertEquals(2, grid(0).cluster().metrics().getTotalNodes());
+ assertEquals(2, grid(1).cluster().metrics().getTotalNodes());
+
+ // assert the event listener got as many events as expected
+ latch.await(1, TimeUnit.SECONDS);
+
+ stopAllGrids();
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testThreeNodesWithThreeDifferentConfigMethods() throws Exception {
+ // start one node
+ startGrid(0);
+
+ // set up an event listener to expect one NODE_JOINED event
+ CountDownLatch latch = expectJoinEvents(grid(0), 2);
+
+ // start the 2nd node
+ startGrid(1);
+
+ // start the 3rd node, first setting the system property
+ System.setProperty(TcpDiscoveryZookeeperIpFinder.PROP_ZK_CONNECTION_STRING, zkCluster.getConnectString());
+ startGrid(2);
+
+ // wait until all grids are started
+ waitForRemoteNodes(grid(0), 2);
+
+ // assert the nodes see each other
+ assertEquals(3, grid(0).cluster().metrics().getTotalNodes());
+ assertEquals(3, grid(1).cluster().metrics().getTotalNodes());
+ assertEquals(3, grid(2).cluster().metrics().getTotalNodes());
+
+ // assert the event listener got as many events as expected
+ latch.await(1, TimeUnit.SECONDS);
+
+ stopAllGrids();
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testFourNodesStartingAndStopping() throws Exception {
+ // start one node
+ startGrid(0);
+
+ // set up an event listener to expect one NODE_JOINED event
+ CountDownLatch latch = expectJoinEvents(grid(0), 3);
+
+ // start the 2nd node
+ startGrid(1);
+
+ // start the 3rd & 4th nodes, first setting the system property
+ System.setProperty(TcpDiscoveryZookeeperIpFinder.PROP_ZK_CONNECTION_STRING, zkCluster.getConnectString());
+ startGrid(2);
+ startGrid(3);
+
+ // wait until all grids are started
+ waitForRemoteNodes(grid(0), 3);
+
+ // assert the nodes see each other
+ assertEquals(4, grid(0).cluster().metrics().getTotalNodes());
+ assertEquals(4, grid(1).cluster().metrics().getTotalNodes());
+ assertEquals(4, grid(2).cluster().metrics().getTotalNodes());
+ assertEquals(4, grid(3).cluster().metrics().getTotalNodes());
+
+ // assert the event listener got as many events as expected
+ latch.await(1, TimeUnit.SECONDS);
+
+ // stop the first grid
+ stopGrid(0);
+
+ // make sure that nodes were synchronized; they should only see 3 now
+ assertEquals(3, grid(1).cluster().metrics().getTotalNodes());
+ assertEquals(3, grid(2).cluster().metrics().getTotalNodes());
+ assertEquals(3, grid(3).cluster().metrics().getTotalNodes());
+
+ // stop all remaining grids
+ stopGrid(1);
+ stopGrid(2);
+ stopGrid(3);
+
+ // check that the nodes are gone in ZK
+ assertEquals(0, zkCurator.getChildren().forPath(SERVICES_IGNITE_ZK_PATH).size());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testFourNodesWithDuplicateRegistrations() throws Exception {
+ allowDuplicateRegistrations = true;
+
+ // start 4 nodes
+ System.setProperty(TcpDiscoveryZookeeperIpFinder.PROP_ZK_CONNECTION_STRING, zkCluster.getConnectString());
+ startGrids(4);
+
+ // wait until all grids are started
+ waitForRemoteNodes(grid(0), 3);
+
+ // each node will register itself + the node that it connected to to join the cluster
+ assertEquals(7, zkCurator.getChildren().forPath(SERVICES_IGNITE_ZK_PATH).size());
+
+ // stop all grids
+ stopAllGrids();
+
+ // check that all nodes are gone in ZK
+ assertEquals(0, zkCurator.getChildren().forPath(SERVICES_IGNITE_ZK_PATH).size());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testFourNodesWithNoDuplicateRegistrations() throws Exception {
+ allowDuplicateRegistrations = false;
+
+ // start 4 nodes
+ System.setProperty(TcpDiscoveryZookeeperIpFinder.PROP_ZK_CONNECTION_STRING, zkCluster.getConnectString());
+ startGrids(4);
+
+ // wait until all grids are started
+ waitForRemoteNodes(grid(0), 3);
+
+ // each node will only register itself
+ assertEquals(4, zkCurator.getChildren().forPath(SERVICES_IGNITE_ZK_PATH).size());
+
+ // stop all grids
+ stopAllGrids();
+
+ // check that all nodes are gone in ZK
+ assertEquals(0, zkCurator.getChildren().forPath(SERVICES_IGNITE_ZK_PATH).size());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testFourNodesRestartLastSeveralTimes() throws Exception {
+ allowDuplicateRegistrations = false;
+
+ // start 4 nodes
+ System.setProperty(TcpDiscoveryZookeeperIpFinder.PROP_ZK_CONNECTION_STRING, zkCluster.getConnectString());
+ startGrids(4);
+
+ // wait until all grids are started
+ waitForRemoteNodes(grid(0), 3);
+
+ // each node will only register itself
+ assertEquals(4, zkCurator.getChildren().forPath(SERVICES_IGNITE_ZK_PATH).size());
+
+ // repeat 5 times
+ for (int i = 0; i < 5; i++) {
+ // stop last grid
+ stopGrid(2);
+
+ // check that the node has unregistered itself and its party
+ assertEquals(3, zkCurator.getChildren().forPath(SERVICES_IGNITE_ZK_PATH).size());
+
+ // start the node again
+ startGrid(2);
+
+ // check that the node back in ZK
+ assertEquals(4, zkCurator.getChildren().forPath(SERVICES_IGNITE_ZK_PATH).size());
+ }
+
+ stopAllGrids();
+
+ assertEquals(0, zkCurator.getChildren().forPath(SERVICES_IGNITE_ZK_PATH).size());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testFourNodesKillRestartZookeeper() throws Exception {
+ allowDuplicateRegistrations = false;
+
+ // start 4 nodes
+ System.setProperty(TcpDiscoveryZookeeperIpFinder.PROP_ZK_CONNECTION_STRING, zkCluster.getConnectString());
+ startGrids(4);
+
+ // wait until all grids are started
+ waitForRemoteNodes(grid(0), 3);
+
+ // each node will only register itself
+ assertEquals(4, zkCurator.getChildren().forPath(SERVICES_IGNITE_ZK_PATH).size());
+
+ // remember ZK server configuration and stop the cluster
+ Collection<InstanceSpec> instances = zkCluster.getInstances();
+ zkCluster.stop();
+ Thread.sleep(1000);
+
+ // start the cluster with the previous configuration
+ zkCluster = new TestingCluster(instances);
+ zkCluster.start();
+
+ // block the client until connected
+ zkCurator.blockUntilConnected();
+
+ // Check that the nodes have registered again with the previous configuration.
+ assertEquals(4, zkCurator.getChildren().forPath(SERVICES_IGNITE_ZK_PATH).size());
+
+ // Block the clients until connected.
+ for (int i = 0; i < 4; i++) {
+ TcpDiscoverySpi spi = (TcpDiscoverySpi)grid(i).configuration().getDiscoverySpi();
+
+ TcpDiscoveryZookeeperIpFinder zkIpFinder = (TcpDiscoveryZookeeperIpFinder)spi.getIpFinder();
+
+ CuratorFramework curator = GridTestUtils.getFieldValue(zkIpFinder, "curator");
+
+ curator.blockUntilConnected();
+ }
+
+ // stop all grids
+ stopAllGrids();
+
+ assertEquals(0, zkCurator.getChildren().forPath(SERVICES_IGNITE_ZK_PATH).size());
+ }
+
+ /**
+ * @param ignite Node.
+ * @param joinEvtCnt Expected events number.
+ * @return Events latch.
+ */
+ private CountDownLatch expectJoinEvents(Ignite ignite, int joinEvtCnt) {
+ final CountDownLatch latch = new CountDownLatch(joinEvtCnt);
+
+ ignite.events().remoteListen(new IgniteBiPredicate<UUID, Event>() {
+ @Override public boolean apply(UUID uuid, Event evt) {
+ latch.countDown();
+ return true;
+ }
+ }, null, EventType.EVT_NODE_JOINED);
+
+ return latch;
+ }
+}
diff --git a/modules/zookeeper-ip-finder-ext/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/zk/ZookeeperIpFinderTestSuite.java b/modules/zookeeper-ip-finder-ext/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/zk/ZookeeperIpFinderTestSuite.java
new file mode 100644
index 0000000..a5b6d8f
--- /dev/null
+++ b/modules/zookeeper-ip-finder-ext/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/zk/ZookeeperIpFinderTestSuite.java
@@ -0,0 +1,32 @@
+/*
+ * 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.ignite.spi.discovery.tcp.ipfinder.zk;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * Zookeeper IP Finder tests.
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ ZookeeperIpFinderTest.class
+})
+public class ZookeeperIpFinderTestSuite {
+
+}
diff --git a/pom.xml b/pom.xml
index 11a6c08..c8909db 100644
--- a/pom.xml
+++ b/pom.xml
@@ -67,6 +67,7 @@
<module>modules/aws-ext</module>
<module>modules/azure-ext</module>
<module>modules/gce-ext</module>
+ <module>modules/zookeeper-ip-finder-ext</module>
</modules>
<profiles>