/** {@inheritDoc} */ @Override public Set<String> attributeValues(String attrName) { Set<String> values = new TreeSet<>(); for (ClusterNode node : cluster.nodes()) { Object val = node.attribute(attrName); if (val != null) values.add(val.toString()); } return values; }
/** * @throws Exception If failed. */ @Test public void testEmptyGroup() throws Exception { ClusterGroup emptyGrp = ignite.cluster().forAttribute("nonExistent", "val"); assertEquals(0, emptyGrp.forOldest().nodes().size()); assertEquals(0, emptyGrp.forYoungest().nodes().size()); assertEquals(0, emptyGrp.forAttribute("nonExistent2", "val").nodes().size()); assertEquals(0, emptyGrp.forCacheNodes("cacheName").nodes().size()); assertEquals(0, emptyGrp.forClientNodes("cacheName").nodes().size()); assertEquals(0, emptyGrp.forClients().nodes().size()); assertEquals(0, emptyGrp.forDaemons().nodes().size()); assertEquals(0, emptyGrp.forDataNodes("cacheName").nodes().size()); assertEquals(0, emptyGrp.forRandom().nodes().size()); assertEquals(0, emptyGrp.forRemotes().nodes().size()); assertEquals(0, emptyGrp.forServers().nodes().size()); assertEquals(0, emptyGrp.forHost(ignite.cluster().localNode()).nodes().size()); assertEquals(0, emptyGrp.forHost("127.0.0.1").nodes().size()); }
/** {@inheritDoc} */ @Override public int getTotalServerNodes() { return cluster.forServers().nodes().size(); }
/** {@inheritDoc} */ @Override public int getTotalClientNodes() { return cluster.forClients().nodes().size(); }
/** * Get list with the specified node types. * * @param srv {@code True} to include server nodes. * @param client {@code True} to include client nodes. * @return List with the specified node types. */ private List<ClusterNode> nodesList(boolean srv, boolean client) { List<ClusterNode> nodes = new ArrayList<>(); if (srv) nodes.addAll(cluster.forServers().nodes()); if (client) nodes.addAll(cluster.forClients().nodes()); return nodes; }
/** {@inheritDoc} */ @Override public void runIoTest( long warmup, long duration, int threads, long maxLatency, int rangesCnt, int payLoadSize, boolean procFromNioThread ) { ctx.io().runIoTest(warmup, duration, threads, maxLatency, rangesCnt, payLoadSize, procFromNioThread, new ArrayList(ctx.cluster().get().forServers().forRemotes().nodes())); }
/** {@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; } }
@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 int getActiveBaselineNodes() { Collection<BaselineNode> baselineNodes = cluster.ignite().cluster().currentBaselineTopology(); if (baselineNodes != null && !baselineNodes.isEmpty()) { Set<Object> bltIds = new HashSet<>(baselineNodes.size()); for (BaselineNode baselineNode : baselineNodes) bltIds.add(baselineNode.consistentId()); int count = 0; for (ClusterNode node : cluster.forServers().nodes()) if (bltIds.contains(node.consistentId())) count++; return count; } return 0; }
/** * @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 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()); }
/** {@inheritDoc} */ @Override public IgniteInternalFuture<Long> sizeLongAsync(final int part, final CachePeekMode[] peekModes) { assert peekModes != null; final PeekModes modes = parsePeekModes(peekModes, true); IgniteClusterEx cluster = ctx.grid().cluster(); final GridCacheAffinityManager aff = ctx.affinity(); final AffinityTopologyVersion topVer = aff.affinityTopologyVersion(); ClusterGroup grp = cluster.forDataNodes(name()); Collection<ClusterNode> nodes = new ArrayList<>(grp.forPredicate(new IgnitePredicate<ClusterNode>() { /** {@inheritDoc} */ @Override public boolean apply(ClusterNode clusterNode) { return ((modes.primary && aff.primaryByPartition(clusterNode, part, topVer)) || (modes.backup && aff.backupByPartition(clusterNode, part, topVer))); } }).nodes()); if (nodes.isEmpty()) return new GridFinishedFuture<>(0L); ctx.kernalContext().task().setThreadContext(TC_SUBGRID, nodes); return ctx.kernalContext().task().execute( new PartitionSizeLongTask(ctx.name(), ctx.affinity().affinityTopologyVersion(), peekModes, part), null); }
ClusterGroup evenYoungest = remotes.forPredicate(evenP).forYoungest(); ClusterGroup evenOldest = remotes.forPredicate(evenP).forOldest(); ClusterGroup oddYoungest = remotes.forPredicate(oddP).forYoungest(); ClusterGroup oddOldest = remotes.forPredicate(oddP).forOldest(); 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());
/** * @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()); } }
/** * @param cacheName Cache name. */ private int mapped(String cacheName) { int mapped = 0; ClusterGroup srvs = ignite.cluster().forServers(); Collection<ClusterNode> nodes = srvs.forDataNodes(cacheName).nodes(); for (ClusterNode node : nodes) mapped += ignite.affinity(cacheName).primaryPartitions(node).length; return mapped; }
/** * Test for projection on not existing node IDs. */ @Test public void testInvalidProjection() { Collection<UUID> ids = new HashSet<>(); ids.add(UUID.randomUUID()); ids.add(UUID.randomUUID()); ClusterGroup invalidPrj = prj.forNodeIds(ids); assertEquals(0, invalidPrj.nodes().size()); }
/** * 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) ); }
/** * Constructor. * * @param platformCtx Context. * @param grp Cluster group. */ public PlatformCompute(PlatformContext platformCtx, ClusterGroup grp, String platformAttr) { super(platformCtx); assert grp != null; assert platformAttr != null; compute = (IgniteComputeImpl)grp.ignite().compute(grp); ClusterGroup platformGrp = grp.forAttribute(platformAttr, platformCtx.platform()); computeForPlatform = (IgniteComputeImpl)grp.ignite().compute(platformGrp); }