Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
IGNITE-16238 Add the TcpDiscoveryZookeeperIpFinder example. (#91)
- Loading branch information
Showing
5 changed files
with
134 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters