Search in sources :

Example 1 with DiscoverySpiCustomMessage

use of org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage in project ignite by apache.

the class BinaryMetadataUpdatesFlowTest method startListening.

/**
     * @param idx Index.
     * @param deafClient Deaf client.
     * @param observedIds Observed ids.
     */
private void startListening(int idx, boolean deafClient, Set<Integer> observedIds) throws Exception {
    clientMode = true;
    ContinuousQuery qry = new ContinuousQuery();
    qry.setLocalListener(new CQListener(observedIds));
    if (deafClient) {
        applyDiscoveryHook = true;
        discoveryHook = new DiscoveryHook() {

            @Override
            public void handleDiscoveryMessage(DiscoverySpiCustomMessage msg) {
                DiscoveryCustomMessage customMsg = msg == null ? null : (DiscoveryCustomMessage) IgniteUtils.field(msg, "delegate");
                if (customMsg instanceof MetadataUpdateProposedMessage) {
                    if (((MetadataUpdateProposedMessage) customMsg).typeId() == BINARY_TYPE_ID)
                        GridTestUtils.setFieldValue(customMsg, "typeId", 1);
                } else if (customMsg instanceof MetadataUpdateAcceptedMessage) {
                    if (((MetadataUpdateAcceptedMessage) customMsg).typeId() == BINARY_TYPE_ID)
                        GridTestUtils.setFieldValue(customMsg, "typeId", 1);
                }
            }
        };
        IgniteEx client = startGrid(idx);
        client.cache(DEFAULT_CACHE_NAME).withKeepBinary().query(qry);
    } else {
        applyDiscoveryHook = false;
        IgniteEx client = startGrid(idx);
        client.cache(DEFAULT_CACHE_NAME).withKeepBinary().query(qry);
    }
}
Also used : DiscoverySpiCustomMessage(org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) IgniteEx(org.apache.ignite.internal.IgniteEx) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) DiscoveryHook(org.apache.ignite.testframework.GridTestUtils.DiscoveryHook)

Example 2 with DiscoverySpiCustomMessage

use of org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage in project ignite by apache.

the class GridBinaryCacheEntryMemorySizeSelfTest method createMarshaller.

/** {@inheritDoc} */
@Override
protected Marshaller createMarshaller() throws IgniteCheckedException {
    BinaryMarshaller marsh = new BinaryMarshaller();
    IgniteConfiguration iCfg = new IgniteConfiguration();
    iCfg.setDiscoverySpi(new TcpDiscoverySpi() {

        @Override
        public void sendCustomEvent(DiscoverySpiCustomMessage msg) throws IgniteException {
        // No-op.
        }
    });
    iCfg.setClientMode(false);
    GridTestKernalContext kernCtx = new GridTestKernalContext(log, iCfg);
    kernCtx.add(new GridDiscoveryManager(kernCtx));
    MarshallerContextTestImpl marshCtx = new MarshallerContextTestImpl(null);
    marshCtx.onMarshallerProcessorStarted(kernCtx, null);
    marsh.setContext(marshCtx);
    BinaryContext pCtx = new BinaryContext(BinaryNoopMetadataHandler.instance(), iCfg, new NullLogger());
    IgniteUtils.invoke(BinaryMarshaller.class, marsh, "setBinaryContext", pCtx, iCfg);
    return marsh;
}
Also used : DiscoverySpiCustomMessage(org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage) GridDiscoveryManager(org.apache.ignite.internal.managers.discovery.GridDiscoveryManager) NullLogger(org.apache.ignite.logger.NullLogger) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) IgniteException(org.apache.ignite.IgniteException) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) BinaryContext(org.apache.ignite.internal.binary.BinaryContext) MarshallerContextTestImpl(org.apache.ignite.marshaller.MarshallerContextTestImpl) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 3 with DiscoverySpiCustomMessage

use of org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage in project ignite by apache.

the class GridAbstractTest method newContext.

/**
     * @return Test kernal context.
     */
protected GridTestKernalContext newContext() throws IgniteCheckedException {
    IgniteConfiguration cfg = new IgniteConfiguration();
    cfg.setClientMode(false);
    cfg.setDiscoverySpi(new TcpDiscoverySpi() {

        @Override
        public void sendCustomEvent(DiscoverySpiCustomMessage msg) throws IgniteException {
        //No-op
        }
    });
    GridTestKernalContext ctx = new GridTestKernalContext(log(), cfg);
    return ctx;
}
Also used : DiscoverySpiCustomMessage(org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteException(org.apache.ignite.IgniteException) TestTcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TestTcpDiscoverySpi) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 4 with DiscoverySpiCustomMessage

use of org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage in project ignite by apache.

the class BinaryMarshallerSelfTest method binaryMarshaller.

/**
     * @return Binary marshaller.
     */
protected BinaryMarshaller binaryMarshaller(BinaryNameMapper nameMapper, BinaryIdMapper mapper, BinarySerializer serializer, Collection<BinaryTypeConfiguration> cfgs, Collection<String> excludedClasses) throws IgniteCheckedException {
    IgniteConfiguration iCfg = new IgniteConfiguration();
    BinaryConfiguration bCfg = new BinaryConfiguration();
    bCfg.setNameMapper(nameMapper);
    bCfg.setIdMapper(mapper);
    bCfg.setSerializer(serializer);
    bCfg.setCompactFooter(compactFooter());
    bCfg.setTypeConfigurations(cfgs);
    iCfg.setBinaryConfiguration(bCfg);
    iCfg.setClientMode(false);
    iCfg.setDiscoverySpi(new TcpDiscoverySpi() {

        @Override
        public void sendCustomEvent(DiscoverySpiCustomMessage msg) throws IgniteException {
        //No-op.
        }
    });
    BinaryContext ctx = new BinaryContext(BinaryCachingMetadataHandler.create(), iCfg, new NullLogger());
    BinaryMarshaller marsh = new BinaryMarshaller();
    MarshallerContextTestImpl marshCtx = new MarshallerContextTestImpl(null, excludedClasses);
    GridTestKernalContext kernCtx = new GridTestKernalContext(log, iCfg);
    kernCtx.add(new GridDiscoveryManager(kernCtx));
    marshCtx.onMarshallerProcessorStarted(kernCtx, null);
    marsh.setContext(marshCtx);
    IgniteUtils.invoke(BinaryMarshaller.class, marsh, "setBinaryContext", ctx, iCfg);
    return marsh;
}
Also used : DiscoverySpiCustomMessage(org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage) GridDiscoveryManager(org.apache.ignite.internal.managers.discovery.GridDiscoveryManager) NullLogger(org.apache.ignite.logger.NullLogger) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) IgniteException(org.apache.ignite.IgniteException) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) MarshallerContextTestImpl(org.apache.ignite.marshaller.MarshallerContextTestImpl) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 5 with DiscoverySpiCustomMessage

use of org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage in project ignite by apache.

the class GridDiscoveryManager method start.

/** {@inheritDoc} */
@Override
public void start(boolean activeOnStart) throws IgniteCheckedException {
    long totSysMemory = -1;
    try {
        totSysMemory = U.<Long>property(os, "totalPhysicalMemorySize");
    } catch (RuntimeException ignored) {
    // No-op.
    }
    ctx.addNodeAttribute(IgniteNodeAttributes.ATTR_PHY_RAM, totSysMemory);
    DiscoverySpi spi = getSpi();
    discoOrdered = discoOrdered();
    histSupported = historySupported();
    isLocDaemon = ctx.isDaemon();
    hasRslvrs = !ctx.config().isClientMode() && !F.isEmpty(ctx.config().getSegmentationResolvers());
    segChkFreq = ctx.config().getSegmentCheckFrequency();
    if (hasRslvrs) {
        if (segChkFreq < 0)
            throw new IgniteCheckedException("Segment check frequency cannot be negative: " + segChkFreq);
        if (segChkFreq > 0 && segChkFreq < 2000)
            U.warn(log, "Configuration parameter 'segmentCheckFrequency' is too low " + "(at least 2000 ms recommended): " + segChkFreq);
        int segResAttemp = ctx.config().getSegmentationResolveAttempts();
        if (segResAttemp < 1)
            throw new IgniteCheckedException("Segment resolve attempts cannot be negative or zero: " + segResAttemp);
        checkSegmentOnStart();
    }
    metricsUpdateTask = ctx.timeout().schedule(new MetricsUpdater(), METRICS_UPDATE_FREQ, METRICS_UPDATE_FREQ);
    spi.setMetricsProvider(createMetricsProvider());
    if (ctx.security().enabled()) {
        if (isSecurityCompatibilityMode())
            ctx.addNodeAttribute(ATTR_SECURITY_COMPATIBILITY_MODE, true);
        spi.setAuthenticator(new DiscoverySpiNodeAuthenticator() {

            @Override
            public SecurityContext authenticateNode(ClusterNode node, SecurityCredentials cred) {
                try {
                    return ctx.security().authenticateNode(node, cred);
                } catch (IgniteCheckedException e) {
                    throw U.convertException(e);
                }
            }

            @Override
            public boolean isGlobalNodeAuthentication() {
                return ctx.security().isGlobalNodeAuthentication();
            }
        });
    }
    spi.setListener(new DiscoverySpiListener() {

        private long gridStartTime;

        /** {@inheritDoc} */
        @Override
        public void onLocalNodeInitialized(ClusterNode locNode) {
            for (IgniteInClosure<ClusterNode> lsnr : localNodeInitLsnrs) lsnr.apply(locNode);
        }

        @Override
        public void onDiscovery(final int type, final long topVer, final ClusterNode node, final Collection<ClusterNode> topSnapshot, final Map<Long, Collection<ClusterNode>> snapshots, @Nullable DiscoverySpiCustomMessage spiCustomMsg) {
            DiscoveryCustomMessage customMsg = spiCustomMsg == null ? null : ((CustomMessageWrapper) spiCustomMsg).delegate();
            if (skipMessage(type, customMsg))
                return;
            final ClusterNode locNode = localNode();
            if (snapshots != null)
                topHist = snapshots;
            boolean verChanged;
            if (type == EVT_NODE_METRICS_UPDATED)
                verChanged = false;
            else {
                if (type != EVT_NODE_SEGMENTED && type != EVT_CLIENT_NODE_DISCONNECTED && type != EVT_CLIENT_NODE_RECONNECTED && type != DiscoveryCustomEvent.EVT_DISCOVERY_CUSTOM_EVT) {
                    minorTopVer = 0;
                    verChanged = true;
                } else
                    verChanged = false;
            }
            if (type == EVT_NODE_FAILED || type == EVT_NODE_LEFT) {
                for (DiscoCache c : discoCacheHist.values()) c.updateAlives(node);
                updateClientNodes(node.id());
            }
            final AffinityTopologyVersion nextTopVer;
            if (type == DiscoveryCustomEvent.EVT_DISCOVERY_CUSTOM_EVT) {
                assert customMsg != null;
                boolean incMinorTopVer = ctx.cache().onCustomEvent(customMsg, new AffinityTopologyVersion(topVer, minorTopVer));
                if (incMinorTopVer) {
                    minorTopVer++;
                    verChanged = true;
                }
                nextTopVer = new AffinityTopologyVersion(topVer, minorTopVer);
                if (verChanged)
                    ctx.cache().onDiscoveryEvent(type, node, nextTopVer);
            } else {
                nextTopVer = new AffinityTopologyVersion(topVer, minorTopVer);
                ctx.cache().onDiscoveryEvent(type, node, nextTopVer);
            }
            if (type == DiscoveryCustomEvent.EVT_DISCOVERY_CUSTOM_EVT) {
                for (Class cls = customMsg.getClass(); cls != null; cls = cls.getSuperclass()) {
                    List<CustomEventListener<DiscoveryCustomMessage>> list = customEvtLsnrs.get(cls);
                    if (list != null) {
                        for (CustomEventListener<DiscoveryCustomMessage> lsnr : list) {
                            try {
                                lsnr.onCustomEvent(nextTopVer, node, customMsg);
                            } catch (Exception e) {
                                U.error(log, "Failed to notify direct custom event listener: " + customMsg, e);
                            }
                        }
                    }
                }
            }
            final DiscoCache discoCache;
            // event notifications, since SPI notifies manager about all events from this listener.
            if (verChanged) {
                discoCache = createDiscoCache(locNode, topSnapshot);
                discoCacheHist.put(nextTopVer, discoCache);
                boolean set = updateTopologyVersionIfGreater(nextTopVer, discoCache);
                assert set || topVer == 0 : "Topology version has not been updated [this.topVer=" + topSnap + ", topVer=" + topVer + ", node=" + node + ", evt=" + U.gridEventName(type) + ']';
            } else
                // Current version.
                discoCache = discoCache();
            // If this is a local join event, just save it and do not notify listeners.
            if (type == EVT_NODE_JOINED && node.id().equals(locNode.id())) {
                if (gridStartTime == 0)
                    gridStartTime = getSpi().getGridStartTime();
                updateTopologyVersionIfGreater(new AffinityTopologyVersion(locNode.order()), discoCache);
                startLatch.countDown();
                DiscoveryEvent discoEvt = new DiscoveryEvent();
                discoEvt.node(ctx.discovery().localNode());
                discoEvt.eventNode(node);
                discoEvt.type(EVT_NODE_JOINED);
                discoEvt.topologySnapshot(topVer, new ArrayList<>(F.view(topSnapshot, FILTER_DAEMON)));
                locJoin.onDone(new T2<>(discoEvt, discoCache));
                return;
            } else if (type == EVT_CLIENT_NODE_DISCONNECTED) {
                assert locNode.isClient() : locNode;
                assert node.isClient() : node;
                ((IgniteKernal) ctx.grid()).onDisconnected();
                locJoin = new GridFutureAdapter<>();
                registeredCaches.clear();
                for (AffinityTopologyVersion histVer : discoCacheHist.keySet()) {
                    Object rmvd = discoCacheHist.remove(histVer);
                    assert rmvd != null : histVer;
                }
                topHist.clear();
                topSnap.set(new Snapshot(AffinityTopologyVersion.ZERO, createDiscoCache(locNode, Collections.<ClusterNode>emptySet())));
            } else if (type == EVT_CLIENT_NODE_RECONNECTED) {
                assert locNode.isClient() : locNode;
                assert node.isClient() : node;
                boolean clusterRestarted = gridStartTime != getSpi().getGridStartTime();
                gridStartTime = getSpi().getGridStartTime();
                ((IgniteKernal) ctx.grid()).onReconnected(clusterRestarted);
                ctx.cluster().clientReconnectFuture().listen(new CI1<IgniteFuture<?>>() {

                    @Override
                    public void apply(IgniteFuture<?> fut) {
                        try {
                            fut.get();
                            discoWrk.addEvent(type, nextTopVer, node, discoCache, topSnapshot, null);
                        } catch (IgniteException ignore) {
                        // No-op.
                        }
                    }
                });
                return;
            }
            if (type == EVT_CLIENT_NODE_DISCONNECTED || type == EVT_NODE_SEGMENTED || !ctx.clientDisconnected())
                discoWrk.addEvent(type, nextTopVer, node, discoCache, topSnapshot, customMsg);
        }
    });
    spi.setDataExchange(new DiscoverySpiDataExchange() {

        @Override
        public DiscoveryDataBag collect(DiscoveryDataBag dataBag) {
            assert dataBag != null;
            assert dataBag.joiningNodeId() != null;
            if (ctx.localNodeId().equals(dataBag.joiningNodeId())) {
                for (GridComponent c : ctx.components()) c.collectJoiningNodeData(dataBag);
            } else {
                for (GridComponent c : ctx.components()) c.collectGridNodeData(dataBag);
            }
            return dataBag;
        }

        @Override
        public void onExchange(DiscoveryDataBag dataBag) {
            if (ctx.localNodeId().equals(dataBag.joiningNodeId())) {
                //NodeAdded msg reached joining node after round-trip over the ring
                for (GridComponent c : ctx.components()) {
                    if (c.discoveryDataType() != null)
                        c.onGridDataReceived(dataBag.gridDiscoveryData(c.discoveryDataType().ordinal()));
                }
            } else {
                //discovery data from newly joined node has to be applied to the current old node
                for (GridComponent c : ctx.components()) {
                    if (c.discoveryDataType() != null) {
                        JoiningNodeDiscoveryData data = dataBag.newJoinerDiscoveryData(c.discoveryDataType().ordinal());
                        if (data != null)
                            c.onJoiningNodeDataReceived(data);
                    }
                }
            }
        }
    });
    startSpi();
    registeredDiscoSpi = true;
    try {
        U.await(startLatch);
    } catch (IgniteInterruptedException e) {
        throw new IgniteCheckedException("Failed to start discovery manager (thread has been interrupted).", e);
    }
    // Start segment check worker only if frequency is greater than 0.
    if (hasRslvrs && segChkFreq > 0) {
        segChkWrk = new SegmentCheckWorker();
        segChkThread = new IgniteThread(segChkWrk);
        segChkThread.start();
    }
    locNode = spi.getLocalNode();
    checkAttributes(discoCache().remoteNodes());
    ctx.service().initCompatibilityMode(discoCache().remoteNodes());
    // Start discovery worker.
    new IgniteThread(discoWrk).start();
    if (log.isDebugEnabled())
        log.debug(startInfo());
}
Also used : GridComponent(org.apache.ignite.internal.GridComponent) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) IgniteFuture(org.apache.ignite.lang.IgniteFuture) CI1(org.apache.ignite.internal.util.typedef.CI1) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) JoiningNodeDiscoveryData(org.apache.ignite.spi.discovery.DiscoveryDataBag.JoiningNodeDiscoveryData) DiscoveryDataBag(org.apache.ignite.spi.discovery.DiscoveryDataBag) IgniteException(org.apache.ignite.IgniteException) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) List(java.util.List) T2(org.apache.ignite.internal.util.typedef.T2) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteKernal(org.apache.ignite.internal.IgniteKernal) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) DiscoverySpiNodeAuthenticator(org.apache.ignite.spi.discovery.DiscoverySpiNodeAuthenticator) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) DiscoverySpiListener(org.apache.ignite.spi.discovery.DiscoverySpiListener) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) IgniteException(org.apache.ignite.IgniteException) SecurityCredentials(org.apache.ignite.plugin.security.SecurityCredentials) DiscoverySpiCustomMessage(org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage) ClusterMetricsSnapshot(org.apache.ignite.internal.ClusterMetricsSnapshot) DiscoverySpiDataExchange(org.apache.ignite.spi.discovery.DiscoverySpiDataExchange) DiscoverySpi(org.apache.ignite.spi.discovery.DiscoverySpi) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi) SecurityContext(org.apache.ignite.internal.processors.security.SecurityContext) AtomicLong(java.util.concurrent.atomic.AtomicLong) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) Collection(java.util.Collection) IgniteThread(org.apache.ignite.thread.IgniteThread)

Aggregations

DiscoverySpiCustomMessage (org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage)7 IgniteException (org.apache.ignite.IgniteException)4 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)4 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)3 DiscoveryCustomMessage (org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage)3 DiscoveryHook (org.apache.ignite.testframework.GridTestUtils.DiscoveryHook)3 IgniteEx (org.apache.ignite.internal.IgniteEx)2 GridDiscoveryManager (org.apache.ignite.internal.managers.discovery.GridDiscoveryManager)2 NullLogger (org.apache.ignite.logger.NullLogger)2 MarshallerContextTestImpl (org.apache.ignite.marshaller.MarshallerContextTestImpl)2 GridTestKernalContext (org.apache.ignite.testframework.junits.GridTestKernalContext)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 UUID (java.util.UUID)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 AssertionFailedError (junit.framework.AssertionFailedError)1 Ignite (org.apache.ignite.Ignite)1