use of org.apache.ignite.events.ClusterStateChangeEvent in project ignite by apache.
the class GridCachePartitionExchangeManager method onClusterStateChangeFinish.
/**
*/
private void onClusterStateChangeFinish(IgniteInternalFuture<AffinityTopologyVersion> fut, ExchangeActions exchActions, boolean baselineChanging) {
A.notNull(exchActions, "exchActions");
GridEventStorageManager evtMngr = cctx.kernalContext().event();
if (exchActions.activate() && evtMngr.isRecordable(EVT_CLUSTER_ACTIVATED) || exchActions.deactivate() && evtMngr.isRecordable(EVT_CLUSTER_DEACTIVATED) || exchActions.changedClusterState() && evtMngr.isRecordable(EVT_CLUSTER_STATE_CHANGED)) {
List<Event> evts = new ArrayList<>(2);
ClusterNode locNode = cctx.kernalContext().discovery().localNode();
Collection<BaselineNode> bltNodes = cctx.kernalContext().cluster().get().currentBaselineTopology();
boolean collectionUsed = false;
if (exchActions.activate() && evtMngr.isRecordable(EVT_CLUSTER_ACTIVATED)) {
assert !exchActions.deactivate() : exchActions;
collectionUsed = true;
evts.add(new ClusterActivationEvent(locNode, "Cluster activated.", EVT_CLUSTER_ACTIVATED, bltNodes));
}
if (exchActions.deactivate() && evtMngr.isRecordable(EVT_CLUSTER_DEACTIVATED)) {
assert !exchActions.activate() : exchActions;
collectionUsed = true;
evts.add(new ClusterActivationEvent(locNode, "Cluster deactivated.", EVT_CLUSTER_DEACTIVATED, bltNodes));
}
if (exchActions.changedClusterState() && evtMngr.isRecordable(EVT_CLUSTER_STATE_CHANGED)) {
StateChangeRequest req = exchActions.stateChangeRequest();
if (collectionUsed && bltNodes != null)
bltNodes = new ArrayList<>(bltNodes);
evts.add(new ClusterStateChangeEvent(req.prevState(), req.state(), bltNodes, locNode, "Cluster state changed."));
}
A.notEmpty(evts, "events " + exchActions);
cctx.kernalContext().pools().getSystemExecutorService().submit(() -> evts.forEach(e -> cctx.kernalContext().event().record(e)));
}
GridKernalContext ctx = cctx.kernalContext();
DiscoveryDataClusterState state = ctx.state().clusterState();
if (baselineChanging) {
ctx.pools().getStripedExecutorService().execute(new Runnable() {
@Override
public void run() {
if (ctx.event().isRecordable(EventType.EVT_BASELINE_CHANGED)) {
ctx.event().record(new BaselineChangedEvent(ctx.discovery().localNode(), "Baseline changed.", EventType.EVT_BASELINE_CHANGED, ctx.cluster().get().currentBaselineTopology()));
}
}
});
}
}
use of org.apache.ignite.events.ClusterStateChangeEvent in project ignite by apache.
the class ClusterStateChangeEventTest method changeStateAndCheckEvents.
/**
*/
private void changeStateAndCheckEvents(ClusterState state) throws IgniteCheckedException {
IgniteEx crd = grid(0);
ClusterState prevState = crd.cluster().state();
Collection<BaselineNode> blt = crd.cluster().currentBaselineTopology();
assertNotSame(prevState, state);
Map<Ignite, IgniteFuture<Event>> evtFuts = new HashMap<>();
for (Ignite node : G.allGrids()) {
Event event = max(node.events().localQuery(F.alwaysTrue(), EVT_CLUSTER_STATE_CHANGED), comparingLong(Event::localOrder));
log.info("Event with highest local id for node: " + node.name() + " is: " + event);
evtFuts.put(node, waitForLocalEvent(node.events(), e -> e.localOrder() > event.localOrder(), EVT_CLUSTER_STATE_CHANGED));
}
crd.cluster().state(state);
for (Ignite node : evtFuts.keySet()) {
assertEquals(node.name(), state, node.cluster().state());
Event e = evtFuts.get(node).get(1000L);
assertNotNull(node.name(), e);
assertTrue(node.name() + " " + e, e instanceof ClusterStateChangeEvent);
ClusterStateChangeEvent changeEvent = (ClusterStateChangeEvent) e;
assertEquals(prevState, changeEvent.previousState());
assertEquals(state, changeEvent.state());
if (blt == null)
assertNull(node.name(), changeEvent.baselineNodes());
else {
assertNotNull(changeEvent.baselineNodes());
Set<Object> bltIds = blt.stream().map(BaselineNode::consistentId).collect(toSet());
Set<Object> evtBltIds = changeEvent.baselineNodes().stream().map(BaselineNode::consistentId).collect(toSet());
assertEqualsCollections(bltIds, evtBltIds);
}
}
}
Aggregations