Search in sources :

Example 6 with DiscoveryNotification

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)));
    });
}
Also used : SecurityCredentials(org.apache.ignite.plugin.security.SecurityCredentials) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) DiscoveryNotification(org.apache.ignite.spi.discovery.DiscoveryNotification) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException)

Example 7 with DiscoveryNotification

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)));
            }
        });
    });
}
Also used : DiscoverySpiCustomMessage(org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage) DiscoveryNotification(org.apache.ignite.spi.discovery.DiscoveryNotification)

Example 8 with DiscoveryNotification

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;
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) DiscoverySpiListener(org.apache.ignite.spi.discovery.DiscoverySpiListener) Span(org.apache.ignite.internal.processors.tracing.Span) Collection(java.util.Collection) DiscoveryNotification(org.apache.ignite.spi.discovery.DiscoveryNotification) TcpDiscoveryNodeLeftMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryNodeLeftMessage) TcpDiscoveryNode(org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode) GridBoundedLinkedHashSet(org.apache.ignite.internal.util.GridBoundedLinkedHashSet) HashSet(java.util.HashSet) GridConcurrentHashSet(org.apache.ignite.internal.util.GridConcurrentHashSet)

Example 9 with DiscoveryNotification

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;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) TcpDiscoverySpiState(org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoverySpiState) Collection(java.util.Collection) DiscoveryNotification(org.apache.ignite.spi.discovery.DiscoveryNotification) DiscoverySpiListener(org.apache.ignite.spi.discovery.DiscoverySpiListener)

Aggregations

DiscoveryNotification (org.apache.ignite.spi.discovery.DiscoveryNotification)9 ClusterNode (org.apache.ignite.cluster.ClusterNode)7 DiscoverySpiListener (org.apache.ignite.spi.discovery.DiscoverySpiListener)4 Collection (java.util.Collection)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 IgniteException (org.apache.ignite.IgniteException)2 SecurityCredentials (org.apache.ignite.plugin.security.SecurityCredentials)2 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)2 DiscoveryDataBag (org.apache.ignite.spi.discovery.DiscoveryDataBag)2 DiscoverySpiCustomMessage (org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage)2 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 UUID (java.util.UUID)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)1 IgniteInterruptedException (org.apache.ignite.IgniteInterruptedException)1 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)1