Search in sources :

Example 41 with TcpDiscoveryVmIpFinder

use of org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder in project ignite by apache.

the class GridTcpSpiForwardingSelfTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@SuppressWarnings({ "IfMayBeConditional", "deprecation" })
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder();
    if (ipFinderUseLocPorts)
        ipFinder.setAddresses(Arrays.asList("127.0.0.1:" + locPort1, "127.0.0.1:" + locPort2));
    else
        ipFinder.setAddresses(Arrays.asList("127.0.0.1:" + extPort1, "127.0.0.1:" + extPort2));
    TcpDiscoverySpi spi = new TcpDiscoverySpi();
    final int locPort;
    final int commLocPort;
    if (getTestIgniteInstanceName(0).equals(igniteInstanceName)) {
        locPort = locPort1;
        commLocPort = commLocPort1;
    } else if (getTestIgniteInstanceName(1).equals(igniteInstanceName)) {
        locPort = locPort2;
        commLocPort = commLocPort2;
    } else
        throw new IllegalArgumentException("Unknown Ignite instance name");
    spi.setIpFinder(ipFinder);
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    spi.setLocalPort(locPort);
    spi.setLocalPortRange(1);
    cfg.setDiscoverySpi(spi);
    cfg.setLocalHost("127.0.0.1");
    cfg.setConnectorConfiguration(null);
    TcpCommunicationSpi commSpi = new TcpCommunicationSpi() {

        @Override
        protected GridCommunicationClient createTcpClient(ClusterNode node, int connIdx) throws IgniteCheckedException {
            Map<String, Object> attrs = new HashMap<>(node.attributes());
            attrs.remove(createSpiAttributeName(ATTR_PORT));
            ((TcpDiscoveryNode) node).setAttributes(attrs);
            return super.createTcpClient(node, connIdx);
        }
    };
    commSpi.setLocalAddress("127.0.0.1");
    commSpi.setLocalPort(commLocPort);
    commSpi.setLocalPortRange(1);
    commSpi.setSharedMemoryPort(-1);
    commSpi.setConnectionsPerNode(1);
    cfg.setCommunicationSpi(commSpi);
    assert rslvr != null;
    cfg.setAddressResolver(rslvr);
    return cfg;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) TcpDiscoveryVmIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder) HashMap(java.util.HashMap) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi) TcpDiscoveryNode(org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 42 with TcpDiscoveryVmIpFinder

use of org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder in project ignite by apache.

the class CacheTopologyCommandHandlerTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration() throws Exception {
    // Discovery config.
    TcpDiscoverySpi disco = new TcpDiscoverySpi().setIpFinder(new TcpDiscoveryVmIpFinder(true)).setJoinTimeout(5000);
    // Cache config.
    CacheConfiguration ccfg = new CacheConfiguration("cache*").setCacheMode(CacheMode.LOCAL).setAtomicityMode(CacheAtomicityMode.ATOMIC);
    ConnectorConfiguration clnCfg = new ConnectorConfiguration().setHost("127.0.0.1");
    return super.getConfiguration().setLocalHost("127.0.0.1").setConnectorConfiguration(clnCfg).setDiscoverySpi(disco).setCacheConfiguration(ccfg);
}
Also used : TcpDiscoveryVmIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder) ConnectorConfiguration(org.apache.ignite.configuration.ConnectorConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 43 with TcpDiscoveryVmIpFinder

use of org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder in project ignite by apache.

the class GridCacheTcpClientDiscoveryMultiThreadedTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    // Filling configuration for client nodes
    if (client) {
        TcpDiscoveryVmIpFinder clientFinder = new TcpDiscoveryVmIpFinder();
        Collection<String> addrs = new ArrayList<>(ipFinder.getRegisteredAddresses().size());
        for (InetSocketAddress sockAddr : ipFinder.getRegisteredAddresses()) addrs.add(sockAddr.getHostString() + ":" + sockAddr.getPort());
        clientFinder.setAddresses(addrs);
        cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(clientFinder));
        cfg.setClientMode(true);
    }
    cfg.setLocalHost("127.0.0.1");
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) TcpDiscoveryVmIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 44 with TcpDiscoveryVmIpFinder

use of org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder in project ignite by apache.

the class TcpClientDiscoverySpiSelfTest method reconnectAfterSuspend.

/**
 * @param changeTop If {@code true} topology is changed after client disconnects
 * @throws Exception if failed.
 */
private void reconnectAfterSuspend(boolean changeTop) throws Exception {
    reconnectCnt = 2;
    startServerNodes(2);
    Ignite srv0 = grid("server-0");
    TcpDiscoveryNode srv0Node = (TcpDiscoveryNode) srv0.cluster().localNode();
    TcpDiscoveryNode srv1Node = (TcpDiscoveryNode) grid("server-1").cluster().localNode();
    clientIpFinder = new TcpDiscoveryVmIpFinder();
    clientIpFinder.setAddresses(Collections.singleton("localhost:" + srv0Node.discoveryPort()));
    startClientNodes(1);
    Ignite client = grid("client-0");
    TcpDiscoveryNode clientNode = (TcpDiscoveryNode) client.cluster().localNode();
    TestTcpDiscoverySpi clientSpi = (TestTcpDiscoverySpi) client.configuration().getDiscoverySpi();
    UUID clientNodeId = clientNode.id();
    checkNodes(2, 1);
    clientIpFinder.setAddresses(Collections.singleton("localhost:" + srv1Node.discoveryPort()));
    srvFailedLatch = new CountDownLatch(1);
    attachListeners(2, 1);
    log.info("Pausing router");
    TestTcpDiscoverySpi srvSpi = (TestTcpDiscoverySpi) srv0.configuration().getDiscoverySpi();
    int joinedNodesNum = 3;
    final CountDownLatch srvJoinedLatch = new CountDownLatch(joinedNodesNum);
    if (changeTop) {
        client.events().localListen(new IgnitePredicate<Event>() {

            @Override
            public boolean apply(Event e) {
                srvJoinedLatch.countDown();
                return true;
            }
        }, EVT_NODE_JOINED);
    }
    srvSpi.pauseAll(true);
    if (changeTop)
        startServerNodes(joinedNodesNum);
    try {
        await(srvFailedLatch, 60_000);
        if (changeTop)
            await(srvJoinedLatch, 5000);
        assertEquals("connected", clientSpi.getSpiState());
        assertEquals(clientNodeId, clientNode.id());
        assertEquals(srv1Node.id(), clientNode.clientRouterNodeId());
    } finally {
        srvSpi.resumeAll();
    }
}
Also used : TcpDiscoveryVmIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder) Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) CountDownLatch(java.util.concurrent.CountDownLatch) TcpDiscoveryNode(org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode)

Example 45 with TcpDiscoveryVmIpFinder

use of org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder in project ignite by apache.

the class TcpClientDiscoverySpiSelfTest method missedAddFinishedMessage.

/**
 * @param singleSrv If {@code true} starts one server node two otherwise.
 * @throws Exception If failed.
 */
private void missedAddFinishedMessage(boolean singleSrv) throws Exception {
    int srvs = singleSrv ? 1 : 2;
    startServerNodes(srvs);
    afterWrite = new CIX2<TcpDiscoveryAbstractMessage, Socket>() {

        private boolean first = true;

        @Override
        public void applyx(TcpDiscoveryAbstractMessage msg, Socket sock) throws IgniteCheckedException {
            if (first && (msg instanceof TcpDiscoveryJoinRequestMessage)) {
                first = false;
                log.info("Close socket after message write [msg=" + msg + "]");
                try {
                    sock.close();
                } catch (IOException e) {
                    throw new IgniteCheckedException(e);
                }
                log.info("Delay after message write [msg=" + msg + "]");
                // Wait when server process join request.
                U.sleep(5000);
            }
        }
    };
    Ignite srv = singleSrv ? G.ignite("server-0") : G.ignite("server-1");
    TcpDiscoveryNode srvNode = (TcpDiscoveryNode) srv.cluster().localNode();
    assertEquals(singleSrv ? 1 : 2, srvNode.order());
    clientIpFinder = new TcpDiscoveryVmIpFinder();
    clientIpFinder.setAddresses(Collections.singleton("localhost:" + srvNode.discoveryPort()));
    startClientNodes(1);
    TcpDiscoveryNode clientNode = (TcpDiscoveryNode) G.ignite("client-0").cluster().localNode();
    assertEquals(srvNode.id(), clientNode.clientRouterNodeId());
    checkNodes(srvs, 1);
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) TcpDiscoveryAbstractMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage) TcpDiscoveryVmIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder) Ignite(org.apache.ignite.Ignite) IOException(java.io.IOException) Socket(java.net.Socket) TcpDiscoveryNode(org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode) TcpDiscoveryJoinRequestMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryJoinRequestMessage)

Aggregations

TcpDiscoveryVmIpFinder (org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder)97 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)81 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)80 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)38 FileSystemConfiguration (org.apache.ignite.configuration.FileSystemConfiguration)16 Ignite (org.apache.ignite.Ignite)14 IgfsGroupDataBlocksKeyMapper (org.apache.ignite.igfs.IgfsGroupDataBlocksKeyMapper)12 ConnectorConfiguration (org.apache.ignite.configuration.ConnectorConfiguration)8 BinaryMarshaller (org.apache.ignite.internal.binary.BinaryMarshaller)6 TcpDiscoveryNode (org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode)6 ArrayList (java.util.ArrayList)5 IgfsIpcEndpointConfiguration (org.apache.ignite.igfs.IgfsIpcEndpointConfiguration)5 HashMap (java.util.HashMap)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 IgniteException (org.apache.ignite.IgniteException)4 TcpDiscoveryIpFinder (org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder)4 InetSocketAddress (java.net.InetSocketAddress)3 UUID (java.util.UUID)3 TcpCommunicationSpi (org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi)3 File (java.io.File)2