use of org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi in project ignite by apache.
the class ZookeeperDiscovery method ZookeeperDiscoveryConfigurationExample.
void ZookeeperDiscoveryConfigurationExample() {
// tag::cfg[]
ZookeeperDiscoverySpi zkDiscoverySpi = new ZookeeperDiscoverySpi();
zkDiscoverySpi.setZkConnectionString("127.0.0.1:34076,127.0.0.1:43310,127.0.0.1:36745");
zkDiscoverySpi.setSessionTimeout(30_000);
zkDiscoverySpi.setZkRootPath("/ignite");
zkDiscoverySpi.setJoinTimeout(10_000);
IgniteConfiguration cfg = new IgniteConfiguration();
// Override default discovery SPI.
cfg.setDiscoverySpi(zkDiscoverySpi);
// Start the node.
Ignite ignite = Ignition.start(cfg);
// end::cfg[]
ignite.close();
}
use of org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi in project ignite by apache.
the class ZookeeperDiscoverySpiTestBase method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(final String igniteInstanceName) throws Exception {
if (testSockNio)
System.setProperty(ZOOKEEPER_CLIENT_CNXN_SOCKET, ZkTestClientCnxnSocketNIO.class.getName());
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
if (nodeId != null)
cfg.setNodeId(nodeId);
if (!dfltConsistenId)
cfg.setConsistentId(igniteInstanceName);
ZookeeperDiscoverySpi zkSpi = new ZookeeperDiscoverySpi();
if (joinTimeout != 0)
zkSpi.setJoinTimeout(joinTimeout);
zkSpi.setSessionTimeout(sesTimeout > 0 ? sesTimeout : 10_000);
zkSpi.setClientReconnectDisabled(clientReconnectDisabled);
// Set authenticator for basic sanity tests.
if (auth != null) {
zkSpi.setAuthenticator(auth.apply());
zkSpi.setInternalListener(new IgniteDiscoverySpiInternalListener() {
@Override
public void beforeJoin(ClusterNode locNode, IgniteLogger log) {
ZookeeperClusterNode locNode0 = (ZookeeperClusterNode) locNode;
Map<String, Object> attrs = new HashMap<>(locNode0.getAttributes());
attrs.put(ATTR_SECURITY_CREDENTIALS, new SecurityCredentials(null, null, igniteInstanceName));
locNode0.setAttributes(attrs);
}
@Override
public boolean beforeSendCustomEvent(DiscoverySpi spi, IgniteLogger log, DiscoverySpiCustomMessage msg) {
return false;
}
});
}
spis.put(igniteInstanceName, zkSpi);
if (USE_TEST_CLUSTER) {
assert zkCluster != null;
zkSpi.setZkConnectionString(getTestClusterZkConnectionString());
if (zkRootPath != null)
zkSpi.setZkRootPath(zkRootPath);
} else
zkSpi.setZkConnectionString(getRealClusterZkConnectionString());
cfg.setDiscoverySpi(zkSpi);
cfg.setCacheConfiguration(getCacheConfiguration());
if (userAttrs != null)
cfg.setUserAttributes(userAttrs);
Map<IgnitePredicate<? extends Event>, int[]> lsnrs = new HashMap<>();
if (cfg.isClientMode()) {
UUID currNodeId = cfg.getNodeId();
lsnrs.put(new IgnitePredicate<Event>() {
/**
* Last remembered uuid before node reconnected.
*/
private UUID nodeId = currNodeId;
@Override
public boolean apply(Event evt) {
if (evt.type() == EVT_CLIENT_NODE_RECONNECTED) {
evts.remove(nodeId);
nodeId = evt.node().id();
}
return true;
}
}, new int[] { EVT_CLIENT_NODE_RECONNECTED });
}
lsnrs.put(new IgnitePredicate<Event>() {
/**
*/
@IgniteInstanceResource
private Ignite ignite;
@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
@Override
public boolean apply(Event evt) {
try {
DiscoveryEvent discoveryEvt = (DiscoveryEvent) evt;
UUID locId = ((IgniteKernal) ignite).context().localNodeId();
Map<T2<Integer, Long>, DiscoveryEvent> nodeEvts = evts.get(locId);
if (nodeEvts == null) {
Object old = evts.put(locId, nodeEvts = new LinkedHashMap<>());
assertNull(old);
// If the current node has failed, the local join will never happened.
if (evt.type() != EVT_NODE_FAILED || discoveryEvt.eventNode().consistentId().equals(ignite.configuration().getConsistentId())) {
synchronized (nodeEvts) {
DiscoveryLocalJoinData locJoin = ((IgniteEx) ignite).context().discovery().localJoin();
if (locJoin.event().node().order() == 1)
clusterNum.incrementAndGet();
nodeEvts.put(new T2<>(clusterNum.get(), locJoin.event().topologyVersion()), locJoin.event());
}
}
}
synchronized (nodeEvts) {
DiscoveryEvent old = nodeEvts.put(new T2<>(clusterNum.get(), discoveryEvt.topologyVersion()), discoveryEvt);
assertNull(old);
}
} catch (Throwable e) {
error("Unexpected error [evt=" + evt + ", err=" + e + ']', e);
err = true;
}
return true;
}
}, new int[] { EVT_NODE_JOINED, EVT_NODE_FAILED, EVT_NODE_LEFT });
if (!isMultiJvm())
cfg.setLocalEventListeners(lsnrs);
if (persistence) {
DataStorageConfiguration memCfg = new DataStorageConfiguration().setDefaultDataRegionConfiguration(new DataRegionConfiguration().setMaxSize(100 * 1024 * 1024).setPersistenceEnabled(true)).setPageSize(1024).setWalMode(WALMode.LOG_ONLY);
cfg.setDataStorageConfiguration(memCfg);
}
if (testCommSpi)
cfg.setCommunicationSpi(new ZkTestCommunicationSpi());
if (failCommSpi)
cfg.setCommunicationSpi(new PeerToPeerCommunicationFailureSpi());
if (blockCommSpi) {
cfg.setCommunicationSpi(new TcpBlockCommunicationSpi(igniteInstanceName.contains("block")).setUsePairedConnections(true));
cfg.setNetworkTimeout(500);
}
if (commFailureRslvr != null)
cfg.setCommunicationFailureResolver(commFailureRslvr.apply());
cfg.setIncludeEventTypes(EventType.EVTS_ALL);
return cfg;
}
use of org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi in project ignite by apache.
the class ZookeeperDiscoverySpiSaslAuthAbstractTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String instanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(instanceName);
ZookeeperDiscoverySpi zkSpi = new ZookeeperDiscoverySpi();
if (joinTimeout != 0)
zkSpi.setJoinTimeout(joinTimeout);
zkSpi.setSessionTimeout(sesTimeout > 0 ? sesTimeout : 10_000);
zkSpi.setZkConnectionString(hostPort);
cfg.setDiscoverySpi(zkSpi);
return cfg;
}
use of org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi in project ignite by apache.
the class ZookeeperDiscoveryCommunicationFailureTest method communicationFailureResolve_KillNodes.
/**
* @param startNodes Number of nodes to start.
* @param killNodes Nodes to kill by resolve process.
* @throws Exception If failed.
*/
private void communicationFailureResolve_KillNodes(int startNodes, Collection<Long> killNodes) throws Exception {
testCommSpi = true;
commFailureRslvr = TestNodeKillCommunicationFailureResolver.factory(killNodes);
startGrids(startNodes);
ZkTestCommunicationSpi commSpi = ZkTestCommunicationSpi.testSpi(ignite(0));
commSpi.checkRes = new BitSet(startNodes);
ZookeeperDiscoverySpi spi = null;
UUID killNodeId = null;
for (Ignite node : G.allGrids()) {
ZookeeperDiscoverySpi spi0 = spi(node);
if (!killNodes.contains(node.cluster().localNode().order()))
spi = spi0;
else
killNodeId = node.cluster().localNode().id();
}
assertNotNull(spi);
assertNotNull(killNodeId);
try {
spi.resolveCommunicationFailure(spi.getNode(killNodeId), new Exception("test"));
fail("Exception is not thrown");
} catch (IgniteSpiException e) {
assertTrue("Unexpected exception: " + e, e.getCause() instanceof ClusterTopologyCheckedException);
}
int expNodes = startNodes - killNodes.size();
waitForTopology(expNodes);
for (Ignite node : G.allGrids()) assertFalse(killNodes.contains(node.cluster().localNode().order()));
startGrid(startNodes);
waitForTopology(expNodes + 1);
}
use of org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi in project ignite by apache.
the class ZookeeperDiscoveryCommunicationFailureTest method testNoOpCommunicationErrorResolve_3.
/**
* Tests case when one node fails before sending communication status.
*
* @throws Exception If failed.
*/
@Test
public void testNoOpCommunicationErrorResolve_3() throws Exception {
sesTimeout = 2000;
commFailureRslvr = NoOpCommunicationFailureResolver.FACTORY;
startGridsMultiThreaded(3);
sesTimeout = 10_000;
testSockNio = true;
sesTimeout = 5000;
startGrid(3);
IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Object>() {
@Override
public Object call() {
ZookeeperDiscoverySpi spi = spi(ignite(0));
spi.resolveCommunicationFailure(ignite(1).cluster().localNode(), new Exception("test"));
return null;
}
});
U.sleep(1000);
ZkTestClientCnxnSocketNIO nio = ZkTestClientCnxnSocketNIO.forNode(ignite(3));
nio.closeSocket(true);
try {
stopGrid(3);
fut.get();
} finally {
nio.allowConnect();
}
waitForTopology(3);
}
Aggregations