use of org.apache.ignite.spi.discovery.DiscoveryNotification in project ignite by apache.
the class IsolatedDiscoverySpi method spiStart.
/**
* {@inheritDoc}
*/
@Override
public void spiStart(@Nullable String igniteInstanceName) throws IgniteSpiException {
if (nodeAuth != null) {
try {
SecurityCredentials locSecCred = (SecurityCredentials) locNode.attributes().get(ATTR_SECURITY_CREDENTIALS);
Map<String, Object> attrs = withSecurityContext(authenticateLocalNode(locNode, locSecCred, nodeAuth), locNode.attributes(), marsh);
attrs.remove(ATTR_SECURITY_CREDENTIALS);
locNode.setAttributes(attrs);
} catch (IgniteCheckedException e) {
throw new IgniteSpiException("Failed to authenticate local node (will shutdown local node).", e);
}
}
exec.execute(() -> {
lsnr.onLocalNodeInitialized(locNode);
lsnr.onDiscovery(new DiscoveryNotification(EVT_NODE_JOINED, 1, locNode, singleton(locNode)));
});
}
use of org.apache.ignite.spi.discovery.DiscoveryNotification in project ignite by apache.
the class IsolatedDiscoverySpi method sendCustomEvent.
/**
* {@inheritDoc}
*/
@Override
public void sendCustomEvent(DiscoverySpiCustomMessage msg) throws IgniteException {
exec.execute(() -> {
IgniteFuture<?> fut = lsnr.onDiscovery(new DiscoveryNotification(EVT_DISCOVERY_CUSTOM_EVT, 1, locNode, singleton(locNode), null, msg, null));
// Acknowledge message must be send after initial message processed.
fut.listen((f) -> {
DiscoverySpiCustomMessage ack = msg.ackMessage();
if (ack != null) {
exec.execute(() -> lsnr.onDiscovery(new DiscoveryNotification(EVT_DISCOVERY_CUSTOM_EVT, 1, locNode, singleton(locNode), null, ack, null)));
}
});
});
}
use of org.apache.ignite.spi.discovery.DiscoveryNotification in project ignite by apache.
the class ServerImpl method spiStop0.
/**
* Stops SPI finally or stops SPI for restart.
*
* @param disconnect {@code True} if SPI is being disconnected.
* @throws IgniteSpiException If failed.
*/
private void spiStop0(boolean disconnect) throws IgniteSpiException {
if (log.isDebugEnabled()) {
if (disconnect)
log.debug("Disconnecting SPI.");
else
log.debug("Preparing to start local node stop procedure.");
}
if (disconnect) {
synchronized (mux) {
spiState = DISCONNECTING;
}
}
if (msgWorker != null && msgWorker.runner() != null && msgWorker.runner().isAlive() && !disconnect) {
// Send node left message only if it is final stop.
TcpDiscoveryNodeLeftMessage nodeLeftMsg = new TcpDiscoveryNodeLeftMessage(locNode.id());
Span rootSpan = tracing.create(TraceableMessagesTable.traceName(nodeLeftMsg.getClass())).addTag(SpanTags.tag(SpanTags.EVENT_NODE, SpanTags.ID), () -> locNode.id().toString()).addTag(SpanTags.tag(SpanTags.EVENT_NODE, SpanTags.CONSISTENT_ID), () -> locNode.consistentId().toString()).addLog(() -> "Created");
nodeLeftMsg.spanContainer().serializedSpanBytes(tracing.serialize(rootSpan));
msgWorker.addMessage(nodeLeftMsg);
rootSpan.addLog(() -> "Sent").end();
synchronized (mux) {
long timeout = spi.netTimeout;
long thresholdNanos = System.nanoTime() + U.millisToNanos(timeout);
while (spiState != LEFT && timeout > 0) {
try {
mux.wait(timeout);
timeout = U.nanosToMillis(thresholdNanos - System.nanoTime());
} catch (InterruptedException ignored) {
Thread.currentThread().interrupt();
break;
}
}
if (spiState == LEFT) {
if (log.isDebugEnabled())
log.debug("Verification for local node leave has been received from coordinator" + " (continuing stop procedure).");
} else if (log.isInfoEnabled()) {
log.info("No verification for local node leave has been received from coordinator" + " (will stop node anyway).");
}
}
}
if (tcpSrvr != null)
tcpSrvr.stop();
tcpSrvr = null;
Collection<SocketReader> tmp;
synchronized (mux) {
tmp = U.arrayList(readers);
}
U.interrupt(tmp);
U.joinThreads(tmp, log);
U.interrupt(ipFinderCleaner);
U.join(ipFinderCleaner, log);
U.cancel(msgWorker);
U.join(msgWorker, log);
for (ClientMessageWorker clientWorker : clientMsgWorkers.values()) {
if (clientWorker != null) {
U.interrupt(clientWorker.runner());
U.join(clientWorker.runner(), log);
}
}
clientMsgWorkers.clear();
IgniteUtils.shutdownNow(ServerImpl.class, utilityPool, log);
U.interrupt(statsPrinter);
U.join(statsPrinter, log);
Collection<TcpDiscoveryNode> nodes = null;
if (!disconnect)
spi.printStopInfo();
else {
spi.getSpiContext().deregisterPorts();
nodes = ring.visibleNodes();
}
long topVer = ring.topologyVersion();
ring.clear();
if (nodes != null) {
// This is restart/disconnection and we need to fire FAIL event for each remote node.
DiscoverySpiListener lsnr = spi.lsnr;
if (lsnr != null) {
Collection<ClusterNode> processed = new HashSet<>(nodes.size());
for (TcpDiscoveryNode n : nodes) {
if (n.isLocal())
continue;
assert n.visible();
processed.add(n);
List<ClusterNode> top = U.arrayList(nodes, F.notIn(processed));
topVer++;
Map<Long, Collection<ClusterNode>> hist = updateTopologyHistory(topVer, Collections.unmodifiableList(top));
lsnr.onDiscovery(new DiscoveryNotification(EVT_NODE_FAILED, topVer, n, top, hist, null, null)).get();
}
}
}
printStatistics();
spi.stats.clear();
synchronized (mux) {
// Clear stored data.
leavingNodes.clear();
failedNodes.clear();
spiState = DISCONNECTED;
}
}
use of org.apache.ignite.spi.discovery.DiscoveryNotification in project ignite by apache.
the class ServerImpl method notifyDiscovery.
/**
* Notify external listener on discovery event.
*
* @param type Discovery event type. See {@link org.apache.ignite.events.DiscoveryEvent} for more details.
* @param topVer Topology version.
* @param node Remote node this event is connected with.
*/
private boolean notifyDiscovery(int type, long topVer, TcpDiscoveryNode node, SpanContainer spanContainer) {
assert type > 0;
assert node != null;
DiscoverySpiListener lsnr = spi.lsnr;
TcpDiscoverySpiState spiState = spiStateCopy();
DebugLogger log = type == EVT_NODE_METRICS_UPDATED ? traceLog : debugLog;
if (lsnr != null && node.visible() && (spiState == CONNECTED || spiState == DISCONNECTING)) {
if (log.isDebugEnabled())
log.debug("Discovery notification [node=" + node + ", spiState=" + spiState + ", type=" + U.gridEventName(type) + ", topVer=" + topVer + ']');
Collection<ClusterNode> top = upcast(ring.visibleNodes());
Map<Long, Collection<ClusterNode>> hist = updateTopologyHistory(topVer, top);
lsnr.onDiscovery(new DiscoveryNotification(type, topVer, node, top, hist, null, spanContainer));
return true;
} else {
if (log.isDebugEnabled())
log.debug("Skipped discovery notification [node=" + node + ", spiState=" + spiState + ", type=" + U.gridEventName(type) + ", topVer=" + topVer + ']');
}
return false;
}
Aggregations