/** * @throws Exception Thrown in case of any errors. */ @Test public void testGetNode() throws Exception { try { ignite.cluster().node(null); assert false : "Null nodeId can't be entered."; } catch (NullPointerException ignored) { // No-op. } }
/** * Sends optional message. If message is {@code null} - it's no-op. * * @param nodeId ID of the node to send message to. * @param respMsg Message to send. * @throws IgniteException Thrown in case of any errors. */ private void send(UUID nodeId, @Nullable Object respMsg) throws IgniteException { assert nodeId != null; if (respMsg != null) { ClusterNode node = ignite.cluster().node(nodeId); if (node != null) ignite.message(ignite.cluster().forNode(node)).send(null, respMsg); // Can still fail. else throw new IgniteException("Failed to send message since destination node has " + "left topology (ignoring) [nodeId=" +nodeId + ", respMsg=" + respMsg + ']'); } }
/** * Activates grid if necessary and wait for partition map exchange. */ private void afterGridStarted() throws InterruptedException { G.allGrids().stream() .filter(g -> !g.cluster().node().isClient()) .findAny() .filter(g -> !g.cluster().active()) .ifPresent(g -> g.cluster().active(true)); awaitPartitionMapExchange(); }
/** * Tries to set the global cleanup node id to current node. * * @param grid Grid. * @param metaCache Meta cache. * * @return True if successfully set the flag indicating that current node performs the cleanup; otherwise false. */ private boolean trySetGlobalCleanupFlag(Ignite grid, final Cache<CleanupNodeId, UUID> metaCache) { final UUID localNodeId = grid.cluster().localNode().id(); while (true) { // Get the node performing cleanup. UUID nodeId = metaCache.get(CLEANUP_NODE_ID); if (nodeId == null) { if (metaCache.putIfAbsent(CLEANUP_NODE_ID, localNodeId)) return true; // Successfully reserved cleanup to local node. // Failed putIfAbsent: someone else may have started cleanup. Retry the check. continue; } if (nodeId.equals(localNodeId)) return false; // Current node already performs cleanup. if (grid.cluster().node(nodeId) != null) return false; // Another node already performs cleanup and is alive. // Node that performs cleanup has disconnected. if (metaCache.replace(CLEANUP_NODE_ID, nodeId, localNodeId)) return true; // Successfully replaced disconnected node id with our id. // Replace failed: someone else started cleanup. return false; } }
ClusterNode node = ignite(0).cluster().node();
ClusterMetrics metrics = ignite.cluster().node(nodeId).metrics();
/** * @throws Exception If failed. */ @Test public void testDefaultCommunicationFailureResolver1() throws Exception { testCommSpi = true; sesTimeout = 5000; startGrids(3); ZkTestCommunicationSpi.testSpi(ignite(0)).initCheckResult(3, 0, 1); ZkTestCommunicationSpi.testSpi(ignite(1)).initCheckResult(3, 0, 1); ZkTestCommunicationSpi.testSpi(ignite(2)).initCheckResult(3, 2); UUID killedId = nodeId(2); assertNotNull(ignite(0).cluster().node(killedId)); ZookeeperDiscoverySpi spi = spi(ignite(0)); spi.resolveCommunicationFailure(spi.getNode(ignite(1).cluster().localNode().id()), new Exception("test")); waitForTopology(2); assertNull(ignite(0).cluster().node(killedId)); }
/** * Sends optional message. If message is {@code null} - it's no-op. * * @param nodeId ID of the node to send message to. * @param respMsg Message to send. * @throws IgniteException Thrown in case of any errors. */ private void send(UUID nodeId, @Nullable Object respMsg) throws IgniteException { assert nodeId != null; if (respMsg != null) { ClusterNode node = ignite.cluster().node(nodeId); if (node != null) ignite.message(ignite.cluster().forNode(node)).send(null, respMsg); // Can still fail. else throw new IgniteException("Failed to send message since destination node has " + "left topology (ignoring) [nodeId=" +nodeId + ", respMsg=" + respMsg + ']'); } }
/** * Tries to set the global cleanup node id to current node. * * @param grid Grid. * @param metaCache Meta cache. * * @return True if successfully set the flag indicating that current node performs the cleanup; otherwise false. */ private boolean trySetGlobalCleanupFlag(Ignite grid, final Cache<CleanupNodeId, UUID> metaCache) { final UUID localNodeId = grid.cluster().localNode().id(); while (true) { // Get the node performing cleanup. UUID nodeId = metaCache.get(CLEANUP_NODE_ID); if (nodeId == null) { if (metaCache.putIfAbsent(CLEANUP_NODE_ID, localNodeId)) return true; // Successfully reserved cleanup to local node. // Failed putIfAbsent: someone else may have started cleanup. Retry the check. continue; } if (nodeId.equals(localNodeId)) return false; // Current node already performs cleanup. if (grid.cluster().node(nodeId) != null) return false; // Another node already performs cleanup and is alive. // Node that performs cleanup has disconnected. if (metaCache.replace(CLEANUP_NODE_ID, nodeId, localNodeId)) return true; // Successfully replaced disconnected node id with our id. // Replace failed: someone else started cleanup. return false; } }