You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by na...@apache.org on 2022/01/03 09:52:54 UTC

[ignite-extensions] branch master updated: IGNITE-16238 Add the TcpDiscoveryZookeeperIpFinder example. (#91)

This is an automated email from the ASF dual-hosted git repository.

namelchev pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite-extensions.git


The following commit(s) were added to refs/heads/master by this push:
     new 6699219  IGNITE-16238 Add the TcpDiscoveryZookeeperIpFinder example. (#91)
6699219 is described below

commit 669921912f1d527956722b5dc3fa04fdcb5899c3
Author: Nikita Amelchev <na...@apache.org>
AuthorDate: Mon Jan 3 12:52:50 2022 +0300

    IGNITE-16238 Add the TcpDiscoveryZookeeperIpFinder example. (#91)
---
 modules/zookeeper-ip-finder-ext/examples/pom.xml   | 52 +++++++++++++++
 .../src/main/java/ZookeeperIpFinderExample.java    | 74 ++++++++++++++++++++++
 modules/zookeeper-ip-finder-ext/pom.xml            |  2 +-
 parent/pom.xml                                     |  1 +
 pom.xml                                            |  6 ++
 5 files changed, 134 insertions(+), 1 deletion(-)

diff --git a/modules/zookeeper-ip-finder-ext/examples/pom.xml b/modules/zookeeper-ip-finder-ext/examples/pom.xml
new file mode 100644
index 0000000..d706f30
--- /dev/null
+++ b/modules/zookeeper-ip-finder-ext/examples/pom.xml
@@ -0,0 +1,52 @@
+<?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-examples</artifactId>
+    <version>${ignite-zookeeper-ip-finder-ext.version}</version>
+    <url>http://ignite.apache.org</url>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.ignite</groupId>
+            <artifactId>ignite-core</artifactId>
+            <version>${ignite.version}</version>
+        </dependency>
+
+        <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/examples/src/main/java/ZookeeperIpFinderExample.java b/modules/zookeeper-ip-finder-ext/examples/src/main/java/ZookeeperIpFinderExample.java
new file mode 100644
index 0000000..ff56ef2
--- /dev/null
+++ b/modules/zookeeper-ip-finder-ext/examples/src/main/java/ZookeeperIpFinderExample.java
@@ -0,0 +1,74 @@
+/*
+ * 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.
+ */
+
+import java.util.stream.Collectors;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.zk.TcpDiscoveryZookeeperIpFinder;
+
+/**
+ * This example demonstrates starting Ignite cluster with configured {@link TcpDiscoveryZookeeperIpFinder}
+ * to discover other nodes.
+ * <p>
+ * To start the example, you should:
+ * <ol>
+ *  <li>Start Apache ZooKeeper. See <a href="https://zookeeper.apache.org">Apache ZooKeeper</a>.</li>
+ *  <li>Make sure that the Apache ZooKeeper connection string is correct. See {@link ZK_CONNECT_STRING}.</li>
+ *  <li>Start example using {@link ZookeeperIpFinderExample}.</li>
+ * </ol>
+ */
+public class ZookeeperIpFinderExample {
+    /** The Apache ZooKeeper connection string. Comma separated host:port pairs, each corresponding to a zk server. */
+    private static final String ZK_CONNECT_STRING = "localhost:2181";
+
+    /**
+     * Start example.
+     *
+     * @param args Command line arguments, none required.
+     */
+    public static void main(String[] args) {
+        try (Ignite server1 = Ignition.start(configuration("server1"));
+             Ignite server2 =  Ignition.start(configuration("server2"))) {
+            System.out.println();
+            System.out.println("Zookeeper Ip Finder example started.");
+
+            System.out.println();
+            System.out.format(">>> Nodes identifiers [%s].\n",
+                server1.cluster().nodes().stream().map(ClusterNode::id).collect(Collectors.toList()));
+        }
+    }
+
+    /**
+     * Returns a new instance of Ignite configuration.
+     *
+     * @param igniteInstanceName Ignite instance name.
+     */
+    private static IgniteConfiguration configuration(String igniteInstanceName) {
+        IgniteConfiguration cfg = new IgniteConfiguration();
+
+        cfg.setDiscoverySpi(new TcpDiscoverySpi()
+            .setIpFinder(new TcpDiscoveryZookeeperIpFinder()
+                .setZkConnectionString(ZK_CONNECT_STRING)));
+
+        cfg.setIgniteInstanceName(igniteInstanceName);
+
+        return cfg;
+    }
+}
diff --git a/modules/zookeeper-ip-finder-ext/pom.xml b/modules/zookeeper-ip-finder-ext/pom.xml
index 03b5561..0cff919 100644
--- a/modules/zookeeper-ip-finder-ext/pom.xml
+++ b/modules/zookeeper-ip-finder-ext/pom.xml
@@ -33,7 +33,7 @@
     </parent>
 
     <artifactId>ignite-zookeeper-ip-finder-ext</artifactId>
-    <version>1.0.0-SNAPSHOT</version>
+    <version>${ignite-zookeeper-ip-finder-ext.version}</version>
     <url>http://ignite.apache.org</url>
 
     <dependencies>
diff --git a/parent/pom.xml b/parent/pom.xml
index 12ef2e1..0c0d7a9 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -44,6 +44,7 @@
         <ignite-spring-data-commons.version>1.2.0-SNAPSHOT</ignite-spring-data-commons.version>
         <ignite-spring-data-ext.version>1.1.0-SNAPSHOT</ignite-spring-data-ext.version>
         <ignite-spring-tx-ext.version>1.1.0-SNAPSHOT</ignite-spring-tx-ext.version>
+        <ignite-zookeeper-ip-finder-ext.version>1.0.0-SNAPSHOT</ignite-zookeeper-ip-finder-ext.version>
 
         <ignite.edition>apache-ignite</ignite.edition>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
diff --git a/pom.xml b/pom.xml
index c8909db..3e2bf79 100644
--- a/pom.xml
+++ b/pom.xml
@@ -71,6 +71,12 @@
     </modules>
 
     <profiles>
+        <profile>
+            <id>examples</id>
+            <modules>
+                <module>modules/zookeeper-ip-finder-ext/examples</module>
+            </modules>
+        </profile>
 
         <profile>
             <id>test</id>