@Override public boolean apply(ClusterNode n) { return cctx.discovery().cacheAffinityNode(n, cctx.name()) && (prj == null || prj.node(n.id()) != null) && (part == null || owners.contains(n)); } });
/** {@inheritDoc} */ @Override public boolean isValid(int timeout) throws SQLException { ensureNotClosed(); if (timeout < 0) throw new SQLException("Invalid timeout: " + timeout); try { JdbcConnectionValidationTask task = new JdbcConnectionValidationTask(cacheName, nodeId == null ? ignite : null); if (nodeId != null) { ClusterGroup grp = ignite.cluster().forServers().forNodeId(nodeId); if (grp.nodes().isEmpty()) throw new SQLException("Failed to establish connection with node (is it a server node?): " + nodeId); assert grp.nodes().size() == 1; if (grp.node().isDaemon()) throw new SQLException("Failed to establish connection with node (is it a server node?): " + nodeId); return ignite.compute(grp).callAsync(task).get(timeout, SECONDS); } else return task.call(); } catch (IgniteClientDisconnectedException | ComputeTaskTimeoutException e) { throw new SQLException("Failed to establish connection.", SqlStateCode.CONNECTION_FAILURE, e); } catch (IgniteException ignored) { return false; } }
UUID nodeId = snapshot.keySet().iterator().next(); return prj.node(nodeId);
/** * @throws Exception If failed. */ @Test public void testAgeClusterGroupSerialization() throws Exception { Marshaller marshaller = ignite.configuration().getMarshaller(); ClusterGroup grp = ignite.cluster().forYoungest(); ClusterNode node = grp.node(); byte[] arr = marshaller.marshal(grp); ClusterGroup obj = marshaller.unmarshal(arr, null); assertEquals(node.id(), obj.node().id()); try (Ignite ignore = startGrid()) { obj = marshaller.unmarshal(arr, null); assertEquals(grp.node().id(), obj.node().id()); assertFalse(node.id().equals(obj.node().id())); } }
/** * @throws Exception If failed. */ @Test public void testYoungest() throws Exception { ClusterGroup youngest = ignite.cluster().forYoungest(); ClusterNode node = null; long maxOrder = Long.MIN_VALUE; for (ClusterNode n : ignite.cluster().nodes()) { if (n.order() > maxOrder) { node = n; maxOrder = n.order(); } } assertEquals(youngest.node(), ignite.cluster().forNode(node).node()); ClusterGroup emptyGrp = ignite.cluster().forAttribute("nonExistent", "val"); assertEquals(0, emptyGrp.forYoungest().nodes().size()); }
/** * @throws Exception If failed. */ @Test public void testRandom() throws Exception { assertTrue(ignite.cluster().nodes().contains(ignite.cluster().forRandom().node())); }
/** * @throws Exception If failed. */ @Test public void testOldest() throws Exception { ClusterGroup oldest = ignite.cluster().forOldest(); ClusterNode node = null; long minOrder = Long.MAX_VALUE; for (ClusterNode n : ignite.cluster().nodes()) { if (n.order() < minOrder) { node = n; minOrder = n.order(); } } assertEquals(oldest.node(), ignite.cluster().forNode(node).node()); ClusterGroup emptyGrp = ignite.cluster().forAttribute("nonExistent", "val"); assertEquals(0, emptyGrp.forOldest().nodes().size()); }
/** * @throws Exception If failed. */ @Test public void testNewNodes() throws Exception { ClusterGroup youngest = ignite.cluster().forYoungest(); ClusterGroup oldest = ignite.cluster().forOldest(); ClusterNode old = oldest.node(); ClusterNode last = youngest.node(); assertNotNull(last); try (Ignite g = startGrid(NODES_CNT)) { ClusterNode n = g.cluster().localNode(); ClusterNode latest = youngest.node(); assertNotNull(latest); assertEquals(latest.id(), n.id()); assertEquals(oldest.node(), old); } }
/** * @param expOldestIgnite Expected oldest ignite. * @throws InterruptedException If failed. */ private void remoteListenForOldest(Ignite expOldestIgnite) throws InterruptedException { ClusterGroup grp = ignite1.cluster().forOldest(); assertEquals(1, grp.nodes().size()); assertEquals(expOldestIgnite.cluster().localNode().id(), grp.node().id()); ignite1.message(grp).remoteListen(null, new P2<UUID, Object>() { @Override public boolean apply(UUID nodeId, Object msg) { System.out.println("Received new message [msg=" + msg + ", senderNodeId=" + nodeId + ']'); MSG_CNT.incrementAndGet(); return true; } }); ignite1.message().send(null, MSG_1); Thread.sleep(3000); assertEquals(1, MSG_CNT.get()); } }
/** * Compares checksums between primary and backup partitions of specified caches. * Works properly only on idle cluster - there may be false positive conflict reports if data in cluster is being * concurrently updated. * * @param ig Ignite instance. * @param caches Cache names (if null, all user caches will be verified). * @return Conflicts result. * @throws IgniteException If none caches or node found. */ protected IdleVerifyResultV2 idleVerify(Ignite ig, String... caches) { IgniteEx ig0 = (IgniteEx)ig; Set<String> cacheNames = new HashSet<>(); if (F.isEmpty(caches)) cacheNames.addAll(ig0.cacheNames()); else Collections.addAll(cacheNames, caches); if (cacheNames.isEmpty()) throw new IgniteException("None cache for checking."); ClusterNode node = !ig0.localNode().isClient() ? ig0.localNode() : ig0.cluster().forServers().forRandom().node(); if (node == null) throw new IgniteException("None server node for verification."); VisorIdleVerifyTaskArg taskArg = new VisorIdleVerifyTaskArg(cacheNames); return ig.compute().execute( VisorIdleVerifyTaskV2.class.getName(), new VisorTaskArgument<>(node.id(), taskArg, false) ); }
/** {@inheritDoc} */ @Override public boolean isValid(int timeout) throws SQLException { ensureNotClosed(); if (timeout < 0) throw new SQLException("Invalid timeout: " + timeout); try { JdbcConnectionValidationTask task = new JdbcConnectionValidationTask(cacheName, nodeId == null ? ignite : null); if (nodeId != null) { ClusterGroup grp = ignite.cluster().forServers().forNodeId(nodeId); if (grp.nodes().isEmpty()) throw new SQLException("Failed to establish connection with node (is it a server node?): " + nodeId); assert grp.nodes().size() == 1; if (grp.node().isDaemon()) throw new SQLException("Failed to establish connection with node (is it a server node?): " + nodeId); return ignite.compute(grp).callAsync(task).get(timeout, SECONDS); } else return task.call(); } catch (IgniteClientDisconnectedException | ComputeTaskTimeoutException e) { throw new SQLException("Failed to establish connection.", SqlStateCode.CONNECTION_FAILURE, e); } catch (IgniteException ignored) { return false; } }
assertEquals(grid(gridMaxOrder(clusterSize, true)).localNode().id(), evenYoungest.node().id()); assertEquals(grid(1).localNode().id(), evenOldest.node().id()); assertEquals(grid(gridMaxOrder(clusterSize, false)).localNode().id(), oddYoungest.node().id()); assertEquals(grid(2).localNode().id(), oddOldest.node().id()); assertEquals(grid(gridMaxOrder(clusterSize, true)).localNode().id(), evenYoungest.node().id()); assertEquals(grid(1).localNode().id(), evenOldest.node().id()); assertEquals(grid(gridMaxOrder(clusterSize, false)).localNode().id(), oddYoungest.node().id()); assertEquals(grid(2).localNode().id(), oddOldest.node().id());
UUID nodeId = snapshot.keySet().iterator().next(); return prj.node(nodeId);
/** * @throws Exception If failed. */ @Test public void testConsistentId() throws Exception { Object id0 = grid(0).localNode().consistentId(); Serializable id1 = grid(0).configuration().getConsistentId(); assertEquals(id0, id1); assertEquals(grid(0).name(), id0); assertEquals(id0, grid(1).cluster().forRemotes().node().consistentId()); for (int i = 0; i < 4; ++i) { stopAllGrids(); startGrids(2); assertEquals(id0, grid(0).localNode().consistentId()); } } }
@Override public boolean apply(ClusterNode n) { return cctx.discovery().cacheAffinityNode(n, cctx.name()) && (prj == null || prj.node(n.id()) != null) && (part == null || owners.contains(n)); } });
public boolean isMaster() { return ig.cluster().forOldest().node().equals(ig.cluster().localNode()); }
ClusterNode ownerNode = ignite.cluster().forNodeId(UUID.fromString(ownerId)).node(); if (ownerNode == null) { queue.remove(ownerId);
ClusterNode ownerNode = ignite.cluster().forNodeId(UUID.fromString(ownerId)).node(); if (ownerNode == null) { queue.remove(ownerId);