Search in sources :

Example 51 with ClusterGroup

use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.

the class ClusterGroupExample method main.

/**
     * Executes example.
     *
     * @param args Command line arguments, none required.
     * @throws IgniteException If example execution failed.
     */
public static void main(String[] args) throws IgniteException {
    try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
        if (!ExamplesUtils.checkMinTopologySize(ignite.cluster(), 2))
            return;
        System.out.println();
        System.out.println("Compute example started.");
        IgniteCluster cluster = ignite.cluster();
        // Say hello to all nodes in the cluster, including local node.
        sayHello(ignite, cluster);
        // Say hello to all remote nodes.
        sayHello(ignite, cluster.forRemotes());
        // Pick random node out of remote nodes.
        ClusterGroup randomNode = cluster.forRemotes().forRandom();
        // Say hello to a random node.
        sayHello(ignite, randomNode);
        // Say hello to all nodes residing on the same host with random node.
        sayHello(ignite, cluster.forHost(randomNode.node()));
        // Say hello to all nodes that have current CPU load less than 50%.
        sayHello(ignite, cluster.forPredicate(new IgnitePredicate<ClusterNode>() {

            @Override
            public boolean apply(ClusterNode n) {
                return n.metrics().getCurrentCpuLoad() < 0.5;
            }
        }));
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteCluster(org.apache.ignite.IgniteCluster) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignite(org.apache.ignite.Ignite)

Example 52 with ClusterGroup

use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.

the class ClusterGroupExample method main.

/**
     * Executes example.
     *
     * @param args Command line arguments, none required.
     * @throws IgniteException If example execution failed.
     */
public static void main(String[] args) throws IgniteException {
    try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
        if (!ExamplesUtils.checkMinTopologySize(ignite.cluster(), 2))
            return;
        System.out.println();
        System.out.println("Compute example started.");
        IgniteCluster cluster = ignite.cluster();
        // Say hello to all nodes in the cluster, including local node.
        sayHello(ignite, cluster);
        // Say hello to all remote nodes.
        sayHello(ignite, cluster.forRemotes());
        // Pick random node out of remote nodes.
        ClusterGroup randomNode = cluster.forRemotes().forRandom();
        // Say hello to a random node.
        sayHello(ignite, randomNode);
        // Say hello to all nodes residing on the same host with random node.
        sayHello(ignite, cluster.forHost(randomNode.node()));
        // Say hello to all nodes that have current CPU load less than 50%.
        sayHello(ignite, cluster.forPredicate(n -> n.metrics().getCurrentCpuLoad() < 0.5));
    }
}
Also used : ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignition(org.apache.ignite.Ignition) IgniteCluster(org.apache.ignite.IgniteCluster) ExamplesUtils(org.apache.ignite.examples.ExamplesUtils) IgniteException(org.apache.ignite.IgniteException) Ignite(org.apache.ignite.Ignite) ExampleNodeStartup(org.apache.ignite.examples.ExampleNodeStartup) IgniteCluster(org.apache.ignite.IgniteCluster) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignite(org.apache.ignite.Ignite)

Example 53 with ClusterGroup

use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.

the class MessagingExample method main.

/**
     * Executes example.
     *
     * @param args Command line arguments, none required.
     * @throws IgniteException If example execution failed.
     */
public static void main(String[] args) throws Exception {
    try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
        if (!ExamplesUtils.checkMinTopologySize(ignite.cluster(), 2))
            return;
        System.out.println();
        System.out.println(">>> Messaging example started.");
        // Group for remote nodes.
        ClusterGroup rmtGrp = ignite.cluster().forRemotes();
        // Listen for messages from remote nodes to make sure that they received all the messages.
        int msgCnt = rmtGrp.nodes().size() * MESSAGES_NUM;
        CountDownLatch orderedLatch = new CountDownLatch(msgCnt);
        CountDownLatch unorderedLatch = new CountDownLatch(msgCnt);
        localListen(ignite.message(ignite.cluster().forLocal()), orderedLatch, unorderedLatch);
        // Register listeners on all cluster nodes.
        startListening(ignite, ignite.message(rmtGrp));
        // Send unordered messages to all remote nodes.
        for (int i = 0; i < MESSAGES_NUM; i++) ignite.message(rmtGrp).send(TOPIC.UNORDERED, Integer.toString(i));
        System.out.println(">>> Finished sending unordered messages.");
        // Send ordered messages to all remote nodes.
        for (int i = 0; i < MESSAGES_NUM; i++) ignite.message(rmtGrp).sendOrdered(TOPIC.ORDERED, Integer.toString(i), 0);
        System.out.println(">>> Finished sending ordered messages.");
        System.out.println(">>> Check output on all nodes for message printouts.");
        System.out.println(">>> Will wait for messages acknowledgements from all remote nodes.");
        orderedLatch.await();
        unorderedLatch.await();
        System.out.println(">>> Messaging example finished.");
    }
}
Also used : ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 54 with ClusterGroup

use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.

the class IgfsMetaManager method clientCompute.

/**
 * Get compute facade for client tasks.
 *
 * @return Compute facade.
 */
private IgniteCompute clientCompute() {
    assert client;
    IgniteCompute cliCompute0 = cliCompute;
    if (cliCompute0 == null) {
        IgniteEx ignite = igfsCtx.kernalContext().grid();
        ClusterGroup cluster = ignite.cluster().forIgfsMetadataDataNodes(cfg.getName(), metaCacheName);
        cliCompute0 = ignite.compute(cluster);
        cliCompute = cliCompute0;
    }
    assert cliCompute0 != null;
    return cliCompute0;
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) IgniteCompute(org.apache.ignite.IgniteCompute)

Example 55 with ClusterGroup

use of org.apache.ignite.cluster.ClusterGroup in project camel by apache.

the class IgniteEventsEndpoint method createIgniteEvents.

private IgniteEvents createIgniteEvents() {
    Ignite ignite = ignite();
    IgniteEvents events;
    if (clusterGroupExpression == null) {
        LOG.info("Ignite Events endpoint for event types {} using no Cluster Group.", this.events);
        events = ignite.events();
    } else {
        ClusterGroup group = clusterGroupExpression.getClusterGroup(ignite);
        LOG.info("Ignite Events endpoint for event types {} using Cluster Group: {}.", this.events, group);
        events = ignite.events(group);
    }
    return events;
}
Also used : IgniteEvents(org.apache.ignite.IgniteEvents) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignite(org.apache.ignite.Ignite)

Aggregations

ClusterGroup (org.apache.ignite.cluster.ClusterGroup)99 Ignite (org.apache.ignite.Ignite)51 Test (org.junit.Test)49 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)36 UUID (java.util.UUID)26 CountDownLatch (java.util.concurrent.CountDownLatch)18 ClusterNode (org.apache.ignite.cluster.ClusterNode)16 GridCommonTest (org.apache.ignite.testframework.junits.common.GridCommonTest)14 IgniteException (org.apache.ignite.IgniteException)12 ArrayList (java.util.ArrayList)9 IgniteCompute (org.apache.ignite.IgniteCompute)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 IgniteCluster (org.apache.ignite.IgniteCluster)6 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)6 GridConcurrentHashSet (org.apache.ignite.internal.util.GridConcurrentHashSet)5 IgniteFuture (org.apache.ignite.lang.IgniteFuture)5 Map (java.util.Map)4 IgniteEx (org.apache.ignite.internal.IgniteEx)4 IgniteClusterEx (org.apache.ignite.internal.cluster.IgniteClusterEx)4 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)4