Search in sources :

Example 1 with ClusterTagUpdatedEvent

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

the class IgniteClusterIdTagTest method testTagChangedEventMultinodeWithRemoteFilter.

/**
 * Verifies that event about cluster tag update is fired on remote nodes as well.
 *
 * @throws Exception If failed.
 */
@Test
public void testTagChangedEventMultinodeWithRemoteFilter() throws Exception {
    IgniteEx ig0 = startGrid(0);
    IgniteEx ig1 = startGrid(1);
    UUID clusterId = ig0.cluster().id();
    String generatedTag = ig0.cluster().tag();
    AtomicReference<UUID> eventNodeId = new AtomicReference<>(null);
    AtomicReference<UUID> clusterIdFromEvent = new AtomicReference<>(null);
    AtomicReference<String> oldTagFromEvent = new AtomicReference<>(null);
    AtomicReference<String> newTagFromEvent = new AtomicReference<>(null);
    AtomicBoolean evtFired = new AtomicBoolean(false);
    ig0.events(ig0.cluster().forRemotes()).remoteListen((IgniteBiPredicate<UUID, Event>) (uuid, event) -> {
        eventNodeId.set(uuid);
        evtFired.set(true);
        ClusterTagUpdatedEvent tagUpdatedEvt = (ClusterTagUpdatedEvent) event;
        clusterIdFromEvent.set(tagUpdatedEvt.clusterId());
        oldTagFromEvent.set(tagUpdatedEvt.previousTag());
        newTagFromEvent.set(tagUpdatedEvt.newTag());
        return true;
    }, (IgnitePredicate<Event>) event -> event.type() == EventType.EVT_CLUSTER_TAG_UPDATED);
    ig0.cluster().tag(CUSTOM_TAG_0);
    assertTrue(GridTestUtils.waitForCondition(evtFired::get, 10_000));
    assertEquals(ig1.localNode().id(), eventNodeId.get());
    assertEquals(clusterId, clusterIdFromEvent.get());
    assertEquals(generatedTag, oldTagFromEvent.get());
    assertEquals(CUSTOM_TAG_0, newTagFromEvent.get());
}
Also used : IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) EventType(org.apache.ignite.events.EventType) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Event(org.apache.ignite.events.Event) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteEx(org.apache.ignite.internal.IgniteEx) Test(org.junit.Test) UUID(java.util.UUID) Ignite(org.apache.ignite.Ignite) AtomicReference(java.util.concurrent.atomic.AtomicReference) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) IgniteCluster(org.apache.ignite.IgniteCluster) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) ClusterTagUpdatedEvent(org.apache.ignite.events.ClusterTagUpdatedEvent) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClusterTagUpdatedEvent(org.apache.ignite.events.ClusterTagUpdatedEvent) IgniteEx(org.apache.ignite.internal.IgniteEx) Event(org.apache.ignite.events.Event) ClusterTagUpdatedEvent(org.apache.ignite.events.ClusterTagUpdatedEvent) AtomicReference(java.util.concurrent.atomic.AtomicReference) UUID(java.util.UUID) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 2 with ClusterTagUpdatedEvent

use of org.apache.ignite.events.ClusterTagUpdatedEvent in project gridgain by gridgain.

the class IgniteClusterIdTagTest method testTagChangedEventMultinodeWithRemoteFilter.

/**
 * Verifies that event about cluster tag update is fired on remote nodes as well.
 *
 * @throws Exception If failed.
 */
@Test
public void testTagChangedEventMultinodeWithRemoteFilter() throws Exception {
    IgniteEx ig0 = startGrid(0);
    IgniteEx ig1 = startGrid(1);
    UUID clusterId = ig0.cluster().id();
    String generatedTag = ig0.cluster().tag();
    AtomicReference<UUID> eventNodeId = new AtomicReference<>(null);
    AtomicReference<UUID> clusterIdFromEvent = new AtomicReference<>(null);
    AtomicReference<String> oldTagFromEvent = new AtomicReference<>(null);
    AtomicReference<String> newTagFromEvent = new AtomicReference<>(null);
    AtomicBoolean evtFired = new AtomicBoolean(false);
    ig0.events(ig0.cluster().forRemotes()).remoteListen((IgniteBiPredicate<UUID, Event>) (uuid, event) -> {
        eventNodeId.set(uuid);
        evtFired.set(true);
        ClusterTagUpdatedEvent tagUpdatedEvt = (ClusterTagUpdatedEvent) event;
        clusterIdFromEvent.set(tagUpdatedEvt.clusterId());
        oldTagFromEvent.set(tagUpdatedEvt.previousTag());
        newTagFromEvent.set(tagUpdatedEvt.newTag());
        return true;
    }, (IgnitePredicate<Event>) event -> event.type() == EventType.EVT_CLUSTER_TAG_UPDATED);
    ig0.cluster().tag(CUSTOM_TAG_0);
    assertTrue(GridTestUtils.waitForCondition(evtFired::get, 10_000));
    assertEquals(ig1.localNode().id(), eventNodeId.get());
    assertEquals(clusterId, clusterIdFromEvent.get());
    assertEquals(generatedTag, oldTagFromEvent.get());
    assertEquals(CUSTOM_TAG_0, newTagFromEvent.get());
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgnitionEx(org.apache.ignite.internal.IgnitionEx) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) ClusterState(org.apache.ignite.cluster.ClusterState) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteEx(org.apache.ignite.internal.IgniteEx) AtomicReference(java.util.concurrent.atomic.AtomicReference) ClusterIdUpdatedEvent(org.apache.ignite.events.ClusterIdUpdatedEvent) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) IgniteClusterMXBeanImpl(org.apache.ignite.internal.processors.cluster.IgniteClusterMXBeanImpl) ClusterTagUpdatedEvent(org.apache.ignite.events.ClusterTagUpdatedEvent) IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) EventType(org.apache.ignite.events.EventType) Event(org.apache.ignite.events.Event) Test(org.junit.Test) UUID(java.util.UUID) Ignite(org.apache.ignite.Ignite) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteClusterMXBean(org.apache.ignite.mxbean.IgniteClusterMXBean) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) IGNITE_CLUSTER_ID_AND_TAG_FEATURE(org.apache.ignite.internal.SupportFeaturesUtils.IGNITE_CLUSTER_ID_AND_TAG_FEATURE) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClusterTagUpdatedEvent(org.apache.ignite.events.ClusterTagUpdatedEvent) IgniteEx(org.apache.ignite.internal.IgniteEx) ClusterIdUpdatedEvent(org.apache.ignite.events.ClusterIdUpdatedEvent) ClusterTagUpdatedEvent(org.apache.ignite.events.ClusterTagUpdatedEvent) Event(org.apache.ignite.events.Event) AtomicReference(java.util.concurrent.atomic.AtomicReference) UUID(java.util.UUID) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 3 with ClusterTagUpdatedEvent

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

the class ClusterProcessor method onReadyForRead.

/**
 * {@inheritDoc}
 */
@Override
public void onReadyForRead(ReadableDistributedMetaStorage metastorage) {
    ClusterIdAndTag idAndTag = readKey(metastorage, CLUSTER_ID_TAG_KEY, "Reading cluster ID and tag " + "from metastorage failed, default values will be generated");
    if (log.isInfoEnabled())
        log.info("Cluster ID and tag has been read from metastorage: " + idAndTag);
    if (idAndTag != null) {
        locClusterId = idAndTag.id();
        locClusterTag = idAndTag.tag();
    }
    metastorage.listen((k) -> k.equals(CLUSTER_ID_TAG_KEY), (String k, ClusterIdAndTag oldVal, ClusterIdAndTag newVal) -> {
        if (log.isInfoEnabled())
            log.info("Cluster tag will be set to new value: " + newVal != null ? newVal.tag() : "null" + ", previous value was: " + oldVal != null ? oldVal.tag() : "null");
        if (oldVal != null && newVal != null) {
            if (ctx.event().isRecordable(EVT_CLUSTER_TAG_UPDATED)) {
                String msg = "Tag of cluster with id " + oldVal.id() + " has been updated to new value: " + newVal.tag() + ", previous value was " + oldVal.tag();
                ctx.closure().runLocalSafe((GridPlainRunnable) () -> ctx.event().record(new ClusterTagUpdatedEvent(ctx.discovery().localNode(), msg, oldVal.id(), oldVal.tag(), newVal.tag())));
            }
        }
        cluster.setTag(newVal != null ? newVal.tag() : null);
    });
}
Also used : ClusterTagUpdatedEvent(org.apache.ignite.events.ClusterTagUpdatedEvent)

Example 4 with ClusterTagUpdatedEvent

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

the class IgniteClusterIdTagTest method testTagChangedEvent.

/**
 * Verifies that event is fired when tag change request sent by user is completed.
 *
 * @throws Exception If failed.
 */
@Test
public void testTagChangedEvent() throws Exception {
    IgniteEx ig = startGrid(0);
    UUID clusterId = ig.cluster().id();
    String generatedTag = ig.cluster().tag();
    AtomicReference<UUID> clusterIdFromEvent = new AtomicReference<>(null);
    AtomicReference<String> oldTagFromEvent = new AtomicReference<>(null);
    AtomicReference<String> newTagFromEvent = new AtomicReference<>(null);
    AtomicBoolean evtFired = new AtomicBoolean(false);
    ig.events().localListen((evt) -> {
        evtFired.set(true);
        ClusterTagUpdatedEvent tagUpdatedEvt = (ClusterTagUpdatedEvent) evt;
        clusterIdFromEvent.set(tagUpdatedEvt.clusterId());
        oldTagFromEvent.set(tagUpdatedEvt.previousTag());
        newTagFromEvent.set(tagUpdatedEvt.newTag());
        return true;
    }, EventType.EVT_CLUSTER_TAG_UPDATED);
    ig.cluster().tag(CUSTOM_TAG_0);
    assertTrue(GridTestUtils.waitForCondition(evtFired::get, 10_000));
    assertEquals(clusterId, clusterIdFromEvent.get());
    assertEquals(generatedTag, oldTagFromEvent.get());
    assertEquals(CUSTOM_TAG_0, newTagFromEvent.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClusterTagUpdatedEvent(org.apache.ignite.events.ClusterTagUpdatedEvent) IgniteEx(org.apache.ignite.internal.IgniteEx) AtomicReference(java.util.concurrent.atomic.AtomicReference) UUID(java.util.UUID) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 5 with ClusterTagUpdatedEvent

use of org.apache.ignite.events.ClusterTagUpdatedEvent in project gridgain by gridgain.

the class IgniteClusterIdTagTest method testTagChangedEvent.

/**
 * Verifies that event is fired when tag change request sent by user is completed.
 *
 * @throws Exception If failed.
 */
@Test
public void testTagChangedEvent() throws Exception {
    IgniteEx ig = startGrid(0);
    UUID clusterId = ig.cluster().id();
    String generatedTag = ig.cluster().tag();
    AtomicReference<UUID> clusterIdFromEvent = new AtomicReference<>(null);
    AtomicReference<String> oldTagFromEvent = new AtomicReference<>(null);
    AtomicReference<String> newTagFromEvent = new AtomicReference<>(null);
    AtomicBoolean evtFired = new AtomicBoolean(false);
    ig.events().localListen((evt) -> {
        evtFired.set(true);
        ClusterTagUpdatedEvent tagUpdatedEvt = (ClusterTagUpdatedEvent) evt;
        clusterIdFromEvent.set(tagUpdatedEvt.clusterId());
        oldTagFromEvent.set(tagUpdatedEvt.previousTag());
        newTagFromEvent.set(tagUpdatedEvt.newTag());
        return true;
    }, EventType.EVT_CLUSTER_TAG_UPDATED);
    ig.cluster().tag(CUSTOM_TAG_0);
    assertTrue(GridTestUtils.waitForCondition(evtFired::get, 10_000));
    assertEquals(clusterId, clusterIdFromEvent.get());
    assertEquals(generatedTag, oldTagFromEvent.get());
    assertEquals(CUSTOM_TAG_0, newTagFromEvent.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClusterTagUpdatedEvent(org.apache.ignite.events.ClusterTagUpdatedEvent) IgniteEx(org.apache.ignite.internal.IgniteEx) AtomicReference(java.util.concurrent.atomic.AtomicReference) UUID(java.util.UUID) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

ClusterTagUpdatedEvent (org.apache.ignite.events.ClusterTagUpdatedEvent)5 UUID (java.util.UUID)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 IgniteEx (org.apache.ignite.internal.IgniteEx)4 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)4 Test (org.junit.Test)4 Ignite (org.apache.ignite.Ignite)2 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)2 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)2 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)2 Event (org.apache.ignite.events.Event)2 EventType (org.apache.ignite.events.EventType)2 IgniteBiPredicate (org.apache.ignite.lang.IgniteBiPredicate)2 IgnitePredicate (org.apache.ignite.lang.IgnitePredicate)2 GridTestUtils (org.apache.ignite.testframework.GridTestUtils)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteCluster (org.apache.ignite.IgniteCluster)1 ClusterState (org.apache.ignite.cluster.ClusterState)1 ClusterIdUpdatedEvent (org.apache.ignite.events.ClusterIdUpdatedEvent)1