Search in sources :

Example 6 with TcpDiscoveryMulticastIpFinder

use of org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder in project ignite by apache.

the class TcpClientDiscoverySpiMulticastTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    cfg.setLocalHost("127.0.0.1");
    TcpDiscoverySpi spi = new TcpDiscoverySpi();
    TcpDiscoveryMulticastIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder();
    ipFinder.setAddressRequestAttempts(5);
    spi.setIpFinder(ipFinder);
    Boolean clientFlag = client.get();
    client.set(null);
    if (clientFlag != null && clientFlag) {
        cfg.setClientMode(true);
        spi.setForceServerMode(forceSrv);
    } else {
        Integer port = discoPort.get();
        discoPort.set(null);
        if (port != null)
            spi.setLocalPort(port);
    }
    cfg.setDiscoverySpi(spi);
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) TcpDiscoveryMulticastIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder)

Example 7 with TcpDiscoveryMulticastIpFinder

use of org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder in project ignite by apache.

the class TcpDiscoveryConcurrentStartTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    TcpDiscoveryMulticastIpFinder finder = new TcpDiscoveryMulticastIpFinder();
    finder.setMulticastGroup(GridTestUtils.getNextMulticastGroup(getClass()));
    finder.setMulticastPort(GridTestUtils.getNextMulticastPort(getClass()));
    cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(finder));
    cfg.setCacheConfiguration();
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) TcpDiscoveryMulticastIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder)

Example 8 with TcpDiscoveryMulticastIpFinder

use of org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder in project ignite by apache.

the class ClientImpl method joinTopology.

/**
     * @param recon {@code True} if reconnects.
     * @param timeout Timeout.
     * @return Opened socket or {@code null} if timeout.
     * @throws InterruptedException If interrupted.
     * @throws IgniteSpiException If failed.
     * @see TcpDiscoverySpi#joinTimeout
     */
@SuppressWarnings("BusyWait")
@Nullable
private T2<SocketStream, Boolean> joinTopology(boolean recon, long timeout) throws IgniteSpiException, InterruptedException {
    Collection<InetSocketAddress> addrs = null;
    long startTime = U.currentTimeMillis();
    while (true) {
        if (Thread.currentThread().isInterrupted())
            throw new InterruptedException();
        while (addrs == null || addrs.isEmpty()) {
            addrs = spi.resolvedAddresses();
            if (!F.isEmpty(addrs)) {
                if (log.isDebugEnabled())
                    log.debug("Resolved addresses from IP finder: " + addrs);
            } else {
                if (timeout > 0 && (U.currentTimeMillis() - startTime) > timeout)
                    return null;
                LT.warn(log, "IP finder returned empty addresses list. " + "Please check IP finder configuration" + (spi.ipFinder instanceof TcpDiscoveryMulticastIpFinder ? " and make sure multicast works on your network. " : ". ") + "Will retry every 2 secs.", true);
                Thread.sleep(2000);
            }
        }
        Collection<InetSocketAddress> addrs0 = new ArrayList<>(addrs);
        Iterator<InetSocketAddress> it = addrs.iterator();
        boolean wait = false;
        while (it.hasNext()) {
            if (Thread.currentThread().isInterrupted())
                throw new InterruptedException();
            InetSocketAddress addr = it.next();
            T3<SocketStream, Integer, Boolean> sockAndRes = sendJoinRequest(recon, addr);
            if (sockAndRes == null) {
                it.remove();
                continue;
            }
            assert sockAndRes.get1() != null && sockAndRes.get2() != null : sockAndRes;
            Socket sock = sockAndRes.get1().socket();
            if (log.isDebugEnabled())
                log.debug("Received response to join request [addr=" + addr + ", res=" + sockAndRes.get2() + ']');
            switch(sockAndRes.get2()) {
                case RES_OK:
                    return new T2<>(sockAndRes.get1(), sockAndRes.get3());
                case RES_CONTINUE_JOIN:
                case RES_WAIT:
                    wait = true;
                    U.closeQuiet(sock);
                    break;
                default:
                    if (log.isDebugEnabled())
                        log.debug("Received unexpected response to join request: " + sockAndRes.get2());
                    U.closeQuiet(sock);
            }
        }
        if (wait) {
            if (timeout > 0 && (U.currentTimeMillis() - startTime) > timeout)
                return null;
            if (log.isDebugEnabled())
                log.debug("Will wait before retry join.");
            Thread.sleep(2000);
        } else if (addrs.isEmpty()) {
            if (timeout > 0 && (U.currentTimeMillis() - startTime) > timeout)
                return null;
            LT.warn(log, "Failed to connect to any address from IP finder (will retry to join topology " + "every 2 secs): " + toOrderedList(addrs0), true);
            Thread.sleep(2000);
        }
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) TcpDiscoveryMulticastIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder) Socket(java.net.Socket) T2(org.apache.ignite.internal.util.typedef.T2) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with TcpDiscoveryMulticastIpFinder

use of org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder in project ignite by apache.

the class TcpIpDiscovery method multicastAndStaticDemo.

@Test
void multicastAndStaticDemo() {
    // tag::multicastAndStatic[]
    TcpDiscoverySpi spi = new TcpDiscoverySpi();
    TcpDiscoveryMulticastIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder();
    // Set Multicast group.
    ipFinder.setMulticastGroup("228.10.10.157");
    // Set initial IP addresses.
    // Note that you can optionally specify a port or a port range.
    ipFinder.setAddresses(Arrays.asList("1.2.3.4", "1.2.3.5:47500..47509"));
    spi.setIpFinder(ipFinder);
    IgniteConfiguration cfg = new IgniteConfiguration();
    // Override default discovery SPI.
    cfg.setDiscoverySpi(spi);
    // Start a node.
    Ignite ignite = Ignition.start(cfg);
    // end::multicastAndStatic[]
    ignite.close();
}
Also used : TcpDiscoveryMulticastIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Ignite(org.apache.ignite.Ignite) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi) Test(org.junit.jupiter.api.Test)

Example 10 with TcpDiscoveryMulticastIpFinder

use of org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder in project ignite by apache.

the class TcpIpDiscovery method multicastIpFinderDemo.

@Test
void multicastIpFinderDemo() {
    // tag::multicast[]
    TcpDiscoverySpi spi = new TcpDiscoverySpi();
    TcpDiscoveryMulticastIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder();
    ipFinder.setMulticastGroup("228.10.10.157");
    spi.setIpFinder(ipFinder);
    IgniteConfiguration cfg = new IgniteConfiguration();
    // Override default discovery SPI.
    cfg.setDiscoverySpi(spi);
    // Start the node.
    Ignite ignite = Ignition.start(cfg);
    // end::multicast[]
    ignite.close();
}
Also used : TcpDiscoveryMulticastIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Ignite(org.apache.ignite.Ignite) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi) Test(org.junit.jupiter.api.Test)

Aggregations

TcpDiscoveryMulticastIpFinder (org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder)13 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)5 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)5 InetSocketAddress (java.net.InetSocketAddress)4 Socket (java.net.Socket)3 ArrayList (java.util.ArrayList)3 Ignite (org.apache.ignite.Ignite)3 T2 (org.apache.ignite.internal.util.typedef.T2)3 TcpDiscoveryVmIpFinder (org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder)3 Nullable (org.jetbrains.annotations.Nullable)3 TcpCommunicationSpi (org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi)2 TcpDiscoveryIpFinder (org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder)2 Test (org.junit.jupiter.api.Test)2 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 SSLContext (javax.net.ssl.SSLContext)1 IgniteException (org.apache.ignite.IgniteException)1 IgniteInterruptedException (org.apache.ignite.IgniteInterruptedException)1 IgniteKernal (org.apache.ignite.internal.IgniteKernal)1 GridPortRecord (org.apache.ignite.internal.processors.port.GridPortRecord)1