Search in sources :

Example 26 with DiscoveryEvent

use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.

the class TcpDiscoverySelfTest method testNoRingMessageWorkerAbnormalFailureOnSegmentation.

/**
     * @throws Exception If failed
     */
public void testNoRingMessageWorkerAbnormalFailureOnSegmentation() throws Exception {
    try {
        TestMessageWorkerFailureSpi1 spi1 = new TestMessageWorkerFailureSpi1(TestMessageWorkerFailureSpi1.SEGMENTATION_MODE);
        nodeSpi.set(spi1);
        Ignite ignite1 = startGrid("testNoRingMessageWorkerAbnormalFailureNormalNode");
        nodeSpi.set(new TcpDiscoverySpi());
        final Ignite ignite2 = startGrid("testNoRingMessageWorkerAbnormalFailureSegmentedNode");
        final AtomicBoolean disconnected = new AtomicBoolean();
        final AtomicBoolean segmented = new AtomicBoolean();
        final CountDownLatch disLatch = new CountDownLatch(1);
        final CountDownLatch segLatch = new CountDownLatch(1);
        final UUID failedNodeId = ignite2.cluster().localNode().id();
        ignite1.events().localListen(new IgnitePredicate<Event>() {

            @Override
            public boolean apply(Event evt) {
                if (evt.type() == EventType.EVT_NODE_FAILED && failedNodeId.equals(((DiscoveryEvent) evt).eventNode().id()))
                    disconnected.set(true);
                disLatch.countDown();
                return false;
            }
        }, EventType.EVT_NODE_FAILED);
        ignite2.events().localListen(new IgnitePredicate<Event>() {

            @Override
            public boolean apply(Event evt) {
                if (!failedNodeId.equals(((DiscoveryEvent) evt).eventNode().id()))
                    return true;
                if (evt.type() == EventType.EVT_NODE_SEGMENTED) {
                    segmented.set(true);
                    segLatch.countDown();
                }
                return true;
            }
        }, EventType.EVT_NODE_SEGMENTED);
        spi1.stop = true;
        disLatch.await(15, TimeUnit.SECONDS);
        assertTrue(disconnected.get());
        spi1.stop = false;
        segLatch.await(15, TimeUnit.SECONDS);
        assertTrue(segmented.get());
        Thread.sleep(10_000);
        String result = strLog.toString();
        assert result.contains("Local node SEGMENTED") && !result.contains("TcpDiscoverSpi's message worker thread failed abnormally") : result;
    } finally {
        stopAllGrids();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) UUID(java.util.UUID)

Example 27 with DiscoveryEvent

use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.

the class TcpDiscoverySelfTest method testMetricsSending.

/**
     * @throws Exception If any error occurs.
     */
public void testMetricsSending() throws Exception {
    final AtomicBoolean stopping = new AtomicBoolean();
    try {
        final CountDownLatch latch1 = new CountDownLatch(1);
        final Ignite g1 = startGrid(1);
        IgnitePredicate<Event> lsnr1 = new IgnitePredicate<Event>() {

            @Override
            public boolean apply(Event evt) {
                info(evt.message());
                latch1.countDown();
                return true;
            }
        };
        g1.events().localListen(lsnr1, EVT_NODE_METRICS_UPDATED);
        assert latch1.await(10, SECONDS);
        g1.events().stopLocalListen(lsnr1);
        final CountDownLatch latch1_1 = new CountDownLatch(1);
        final CountDownLatch latch1_2 = new CountDownLatch(1);
        final CountDownLatch latch2_1 = new CountDownLatch(1);
        final CountDownLatch latch2_2 = new CountDownLatch(1);
        final Ignite g2 = startGrid(2);
        g2.events().localListen(new IgnitePredicate<Event>() {

            @Override
            public boolean apply(Event evt) {
                if (stopping.get())
                    return true;
                info(evt.message());
                UUID id = ((DiscoveryEvent) evt).eventNode().id();
                if (id.equals(g1.cluster().localNode().id()))
                    latch2_1.countDown();
                else if (id.equals(g2.cluster().localNode().id()))
                    latch2_2.countDown();
                else
                    assert false : "Event fired for unknown node.";
                return true;
            }
        }, EVT_NODE_METRICS_UPDATED);
        g1.events().localListen(new IgnitePredicate<Event>() {

            @Override
            public boolean apply(Event evt) {
                if (stopping.get())
                    return true;
                info(evt.message());
                UUID id = ((DiscoveryEvent) evt).eventNode().id();
                if (id.equals(g1.cluster().localNode().id()))
                    latch1_1.countDown();
                else if (id.equals(g2.cluster().localNode().id()))
                    latch1_2.countDown();
                else
                    assert false : "Event fired for unknown node.";
                return true;
            }
        }, EVT_NODE_METRICS_UPDATED);
        assert latch1_1.await(10, SECONDS);
        assert latch1_2.await(10, SECONDS);
        assert latch2_1.await(10, SECONDS);
        assert latch2_2.await(10, SECONDS);
    } finally {
        stopping.set(true);
        stopAllGrids();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) UUID(java.util.UUID)

Example 28 with DiscoveryEvent

use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.

the class TcpDiscoveryMultiThreadedTest method getConfiguration.

/** {@inheritDoc} */
@SuppressWarnings({ "IfMayBeConditional" })
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    UUID id = nodeId.get();
    if (id != null) {
        cfg.setNodeId(id);
        nodeId.set(null);
    }
    if (client())
        cfg.setClientMode(true);
    cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(ipFinder).setJoinTimeout(60_000).setNetworkTimeout(10_000));
    int[] evts = { EVT_NODE_FAILED, EVT_NODE_LEFT };
    Map<IgnitePredicate<? extends Event>, int[]> lsnrs = new HashMap<>();
    lsnrs.put(new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event evt) {
            DiscoveryEvent discoveryEvt = (DiscoveryEvent) evt;
            failedNodes.add(discoveryEvt.eventNode().id());
            return true;
        }
    }, evts);
    cfg.setLocalEventListeners(lsnrs);
    cfg.setCacheConfiguration();
    cfg.setIncludeEventTypes(EVT_TASK_FAILED, EVT_TASK_FINISHED, EVT_JOB_MAPPED);
    cfg.setIncludeProperties();
    ((TcpCommunicationSpi) cfg.getCommunicationSpi()).setSharedMemoryPort(-1);
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) HashMap(java.util.HashMap) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Event(org.apache.ignite.events.Event) CacheEntryEvent(javax.cache.event.CacheEntryEvent) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) UUID(java.util.UUID) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi)

Example 29 with DiscoveryEvent

use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.

the class TcpDiscoveryNodeAttributesUpdateOnReconnectTest method testReconnect.

/**
     * @throws Exception If failed.
     */
public void testReconnect() throws Exception {
    Ignite srv = startGrid("server");
    IgniteEvents evts = srv.events();
    evts.enableLocal(EventType.EVTS_DISCOVERY_ALL);
    evts.localListen(new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event evt) {
            ClusterNode node = ((DiscoveryEvent) evt).eventNode();
            rejoinAttr = node.attribute("test");
            return true;
        }
    }, EventType.EVT_NODE_JOINED);
    Ignite client = startGrid("client");
    reconnectClientNode(log, client, srv, null);
    assertEquals("2", rejoinAttr);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteEvents(org.apache.ignite.IgniteEvents) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Event(org.apache.ignite.events.Event) Ignite(org.apache.ignite.Ignite)

Example 30 with DiscoveryEvent

use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.

the class TcpDiscoverySelfTest method testNodeAdded.

/**
     * @throws Exception If any error occurs.
     */
public void testNodeAdded() throws Exception {
    try {
        final Ignite g1 = startGrid(1);
        final CountDownLatch cnt = new CountDownLatch(2);
        g1.events().localListen(new IgnitePredicate<Event>() {

            @Override
            public boolean apply(Event evt) {
                info("Node joined: " + evt.message());
                DiscoveryEvent discoEvt = (DiscoveryEvent) evt;
                TcpDiscoveryNode node = ((TcpDiscoveryNode) discoMap.get(g1.name()).getNode(discoEvt.eventNode().id()));
                assert node != null && node.visible();
                cnt.countDown();
                return true;
            }
        }, EventType.EVT_NODE_JOINED);
        startGrid(2);
        startGrid(3);
        info("Nodes were started");
        assert cnt.await(1, SECONDS);
    } finally {
        stopAllGrids();
    }
}
Also used : Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) TcpDiscoveryNode(org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode)

Aggregations

DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)68 Event (org.apache.ignite.events.Event)49 UUID (java.util.UUID)36 ClusterNode (org.apache.ignite.cluster.ClusterNode)27 GridLocalEventListener (org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener)22 Ignite (org.apache.ignite.Ignite)20 CountDownLatch (java.util.concurrent.CountDownLatch)19 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)14 ArrayList (java.util.ArrayList)11 Collection (java.util.Collection)10 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)10 List (java.util.List)9 GridMessageListener (org.apache.ignite.internal.managers.communication.GridMessageListener)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 JobEvent (org.apache.ignite.events.JobEvent)8 GridAffinityFunctionContextImpl (org.apache.ignite.internal.processors.affinity.GridAffinityFunctionContextImpl)7 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 IgniteException (org.apache.ignite.IgniteException)5 HashMap (java.util.HashMap)4