Search in sources :

Example 1 with ClientConnectionView

use of org.apache.ignite.spi.systemview.view.ClientConnectionView in project ignite by apache.

the class SystemViewSelfTest method testClientsConnections.

/**
 */
@Test
public void testClientsConnections() throws Exception {
    try (IgniteEx g0 = startGrid(0)) {
        String host = g0.configuration().getClientConnectorConfiguration().getHost();
        if (host == null)
            host = g0.configuration().getLocalHost();
        int port = g0.configuration().getClientConnectorConfiguration().getPort();
        SystemView<ClientConnectionView> conns = g0.context().systemView().view(CLI_CONN_VIEW);
        try (IgniteClient cli = Ignition.startClient(new ClientConfiguration().setAddresses(host + ":" + port))) {
            assertEquals(1, conns.size());
            ClientConnectionView cliConn = conns.iterator().next();
            assertEquals("THIN", cliConn.type());
            assertEquals(cliConn.localAddress().getHostName(), cliConn.remoteAddress().getHostName());
            assertEquals(g0.configuration().getClientConnectorConfiguration().getPort(), cliConn.localAddress().getPort());
            assertEquals(cliConn.version(), ProtocolVersion.LATEST_VER.toString());
            try (Connection conn = new IgniteJdbcThinDriver().connect("jdbc:ignite:thin://" + host, new Properties())) {
                assertEquals(2, conns.size());
                assertEquals(1, F.size(jdbcConnectionsIterator(conns)));
                ClientConnectionView jdbcConn = jdbcConnectionsIterator(conns).next();
                assertEquals("JDBC", jdbcConn.type());
                assertEquals(jdbcConn.localAddress().getHostName(), jdbcConn.remoteAddress().getHostName());
                assertEquals(g0.configuration().getClientConnectorConfiguration().getPort(), jdbcConn.localAddress().getPort());
                assertEquals(jdbcConn.version(), JdbcConnectionContext.CURRENT_VER.asString());
            }
        }
        boolean res = GridTestUtils.waitForCondition(() -> conns.size() == 0, 5_000);
        assertTrue(res);
    }
}
Also used : ClientConnectionView(org.apache.ignite.spi.systemview.view.ClientConnectionView) IgniteJdbcThinDriver(org.apache.ignite.IgniteJdbcThinDriver) IgniteClient(org.apache.ignite.client.IgniteClient) IgniteEx(org.apache.ignite.internal.IgniteEx) Connection(java.sql.Connection) Properties(java.util.Properties) IgniteSystemProperties(org.apache.ignite.IgniteSystemProperties) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) Test(org.junit.Test) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)

Example 2 with ClientConnectionView

use of org.apache.ignite.spi.systemview.view.ClientConnectionView in project ignite by apache.

the class ClientListenerProcessor method start.

/**
 * {@inheritDoc}
 */
@Override
public void start() throws IgniteCheckedException {
    IgniteConfiguration cfg = ctx.config();
    // Daemon node should not open client port
    if (cfg.isDaemon()) {
        if (log.isDebugEnabled())
            log.debug("Client connection configuration ignored for daemon node.");
        return;
    }
    ClientConnectorConfiguration cliConnCfg = prepareConfiguration(cfg);
    if (cliConnCfg != null) {
        try {
            validateConfiguration(cliConnCfg);
            // Resolve host.
            String host = cliConnCfg.getHost();
            if (host == null)
                host = cfg.getLocalHost();
            InetAddress hostAddr;
            try {
                hostAddr = U.resolveLocalHost(host);
            } catch (Exception e) {
                throw new IgniteCheckedException("Failed to resolve client connector host: " + host, e);
            }
            execSvc = ctx.pools().getThinClientExecutorService();
            Exception lastErr = null;
            int portTo = cliConnCfg.getPort() + cliConnCfg.getPortRange();
            if (// Handle int overflow.
            portTo <= 0)
                portTo = Integer.MAX_VALUE;
            GridNioFilter[] filters = makeFilters(cliConnCfg);
            long idleTimeout = cliConnCfg.getIdleTimeout();
            int selectorCnt = cliConnCfg.getSelectorCount();
            ctx.metric().registry(CLIENT_CONNECTOR_METRICS);
            for (int port = cliConnCfg.getPort(); port <= portTo && port <= 65535; port++) {
                try {
                    srv = GridNioServer.<ClientMessage>builder().address(hostAddr).port(port).listener(new ClientListenerNioListener(ctx, busyLock, cliConnCfg)).logger(log).selectorCount(selectorCnt).igniteInstanceName(ctx.igniteInstanceName()).serverName("client-listener").tcpNoDelay(cliConnCfg.isTcpNoDelay()).directBuffer(DFLT_TCP_DIRECT_BUF).byteOrder(ByteOrder.nativeOrder()).socketSendBufferSize(cliConnCfg.getSocketSendBufferSize()).socketReceiveBufferSize(cliConnCfg.getSocketReceiveBufferSize()).filters(filters).directMode(true).idleTimeout(idleTimeout > 0 ? idleTimeout : Long.MAX_VALUE).metricRegistry(ctx.metric().registry(CLIENT_CONNECTOR_METRICS)).build();
                    ctx.ports().registerPort(port, IgnitePortProtocol.TCP, getClass());
                    if (log.isInfoEnabled())
                        log.info("Client connector processor has started on TCP port " + port);
                    lastErr = null;
                    ctx.addNodeAttribute(CLIENT_LISTENER_PORT, port);
                    break;
                } catch (Exception e) {
                    lastErr = e;
                }
            }
            assert (srv != null && lastErr == null) || (srv == null && lastErr != null);
            if (lastErr != null)
                throw new IgniteCheckedException("Failed to bind to any [host:port] from the range [" + "host=" + host + ", portFrom=" + cliConnCfg.getPort() + ", portTo=" + portTo + ", lastErr=" + lastErr + ']', lastErr);
            if (!U.IGNITE_MBEANS_DISABLED)
                registerMBean();
            ctx.systemView().registerView(CLI_CONN_VIEW, CLI_CONN_VIEW_DESC, new ClientConnectionViewWalker(), srv.sessions(), ClientConnectionView::new);
            distrThinCfg = new DistributedThinClientConfiguration(ctx);
        } catch (Exception e) {
            throw new IgniteCheckedException("Failed to start client connector processor.", e);
        }
    }
}
Also used : GridNioFilter(org.apache.ignite.internal.util.nio.GridNioFilter) ClientConnectionView(org.apache.ignite.spi.systemview.view.ClientConnectionView) DistributedThinClientConfiguration(org.apache.ignite.internal.processors.configuration.distributed.DistributedThinClientConfiguration) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) JMException(javax.management.JMException) ClientConnectionViewWalker(org.apache.ignite.internal.managers.systemview.walker.ClientConnectionViewWalker) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) ClientConnectorConfiguration(org.apache.ignite.configuration.ClientConnectorConfiguration) InetAddress(java.net.InetAddress)

Aggregations

ClientConnectionView (org.apache.ignite.spi.systemview.view.ClientConnectionView)2 InetAddress (java.net.InetAddress)1 Connection (java.sql.Connection)1 Properties (java.util.Properties)1 JMException (javax.management.JMException)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 IgniteJdbcThinDriver (org.apache.ignite.IgniteJdbcThinDriver)1 IgniteSystemProperties (org.apache.ignite.IgniteSystemProperties)1 IgniteClient (org.apache.ignite.client.IgniteClient)1 ClientConfiguration (org.apache.ignite.configuration.ClientConfiguration)1 ClientConnectorConfiguration (org.apache.ignite.configuration.ClientConnectorConfiguration)1 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 ClientConnectionViewWalker (org.apache.ignite.internal.managers.systemview.walker.ClientConnectionViewWalker)1 DistributedThinClientConfiguration (org.apache.ignite.internal.processors.configuration.distributed.DistributedThinClientConfiguration)1 GridNioFilter (org.apache.ignite.internal.util.nio.GridNioFilter)1 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)1 Test (org.junit.Test)1