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());
}
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());
}
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);
});
}
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());
}
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());
}
Aggregations