Skip to content
Permalink
Browse files
IGNITE-16238 Add the TcpDiscoveryZookeeperIpFinder example. (#91)
  • Loading branch information
NSAmelchev committed Jan 3, 2022
1 parent 2b9f8f6 commit 669921912f1d527956722b5dc3fa04fdcb5899c3
Showing 5 changed files with 134 additions and 1 deletion.
@@ -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>
@@ -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;
}
}
@@ -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>
@@ -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>
@@ -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>

0 comments on commit 6699219

Please sign in to comment.