Tabnine Logo
ClusterGroup
Code IndexAdd Tabnine to your IDE (free)

How to use
ClusterGroup
in
org.apache.ignite.cluster

Best Java code snippets using org.apache.ignite.cluster.ClusterGroup (Showing top 20 results out of 315)

origin: apache/ignite

/** {@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;
}
origin: apache/ignite

  UUID nodeId = snapshot.keySet().iterator().next();
  return prj.node(nodeId);
Collection<ClusterNode> nodes = prj.nodes();
if (prj.predicate() == F.<ClusterNode>alwaysTrue()) {
  int idx = ThreadLocalRandom.current().nextInt(snapshot.size());
origin: apache/ignite

/**
 * @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());
}
origin: apache/ignite

/** {@inheritDoc} */
@Override public int getTotalServerNodes() {
  return cluster.forServers().nodes().size();
}
origin: apache/ignite

/** {@inheritDoc} */
@Override public int getTotalClientNodes() {
  return cluster.forClients().nodes().size();
}
origin: apache/ignite

/**
 * 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;
}
origin: apache/ignite

/** {@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()));
}
origin: apache/ignite

/** {@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;
  }
}
origin: apache/ignite

  @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));
  }
});
origin: apache/ignite

/** {@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;
}
origin: apache/ignite

/**
 * @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());
}
origin: apache/ignite

/**
 * @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());
}
origin: apache/ignite

/** {@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);
}
origin: apache/ignite

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());
origin: apache/ignite

  /**
   * @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());
  }
}
origin: apache/ignite

/**
 * @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;
}
origin: apache/ignite

  @Override public IgniteFuture<?> applyx(ClusterGroup prj) {
    Affinity<Object> aff = prj.ignite().affinity(DEFAULT_CACHE_NAME);
    ClusterNode node = F.first(prj.nodes());
    return compute(prj).affinityRunAsync(DEFAULT_CACHE_NAME, keyForNode(aff, node), new TestRunnable());
  }
});
origin: apache/ignite

/**
 * 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());
}
origin: apache/ignite

/**
 * 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)
  );
}
origin: apache/ignite

/**
 * 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);
}
org.apache.ignite.clusterClusterGroup

Javadoc

Defines a cluster group which contains all or a subset of cluster nodes. The IgniteCluster interface itself also extends ClusterGroup which makes an instance of IgniteCluster into a cluster group containing all cluster nodes. Clustering Cluster group allows to group cluster nodes into various subgroups to perform distributed operations on them. All 'forXXX(...)' methods will create a child cluster group from the existing cluster group. If you create a new cluster group from the current one, then the resulting cluster group will include a subset of nodes from the current one. The following code shows how to create and nest cluster groups:
 
Ignite ignite = Ignition.ignite(); 
IgniteCluster cluster = ignite.cluster(); 
// Cluster group over remote nodes. 
ClusterGroup remoteNodes = cluster.forRemotes(); 
// Cluster group over random remote node. 
ClusterGroup randomNode = remoteNodes.forRandom(); 
// Cluster group over all nodes with cache named "myCache" enabled. 
ClusterGroup cacheNodes = cluster.forCacheNodes("myCache"); 
// Cluster group over all nodes that have the user attribute "group" set to the value "worker". 
ClusterGroup workerNodes = cluster.forAttribute("group", "worker"); 

Most used methods

  • nodes
    Gets the read-only collection of nodes in this cluster group.
  • node
    Gets a node for given ID from this cluster group.
  • forPredicate
    Creates a new cluster group which includes all nodes that pass the given predicate filter.
  • forAttribute
    Creates a new cluster group for nodes containing given name and value specified in user attributes.
  • forClients
    Creates a cluster group of nodes started in client mode.
  • forDataNodes
    Creates a cluster group for all data nodes that have the cache with the specified name running.
  • forNodeIds
    Creates a cluster group over nodes with specified node IDs.
  • forRandom
    Creates a cluster group with one random node from the current cluster group.
  • forRemotes
    Gets cluster group consisting from the nodes in this cluster group excluding the local node.
  • forServers
    Creates a cluster group of nodes started in server mode.
  • hostNames
    Gets the read-only collection of hostnames in this cluster group.
  • ignite
    Gets instance of grid.
  • hostNames,
  • ignite,
  • metrics,
  • predicate,
  • forCacheNodes,
  • forClientNodes,
  • forDaemons,
  • forHost,
  • forNodeId,
  • forOldest

Popular in Java

  • Reactive rest calls using spring rest template
  • requestLocationUpdates (LocationManager)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • onRequestPermissionsResult (Fragment)
  • Proxy (java.net)
    This class represents proxy server settings. A created instance of Proxy stores a type and an addres
  • KeyStore (java.security)
    KeyStore is responsible for maintaining cryptographic keys and their owners. The type of the syste
  • MessageDigest (java.security)
    Uses a one-way hash function to turn an arbitrary number of bytes into a fixed-length byte sequence.
  • Arrays (java.util)
    This class contains various methods for manipulating arrays (such as sorting and searching). This cl
  • ZipFile (java.util.zip)
    This class provides random read access to a zip file. You pay more to read the zip file's central di
  • ServletException (javax.servlet)
    Defines a general exception a servlet can throw when it encounters difficulty.
  • 21 Best IntelliJ Plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now