Search in sources :

Example 6 with ClientConnectorConfiguration

use of org.apache.ignite.configuration.ClientConnectorConfiguration 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()) {
        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 = new IgniteThreadPoolExecutor("client-connector", cfg.getIgniteInstanceName(), cliConnCfg.getThreadPoolSize(), cliConnCfg.getThreadPoolSize(), 0, new LinkedBlockingQueue<Runnable>());
            Exception lastErr = null;
            int portTo = cliConnCfg.getPort() + cliConnCfg.getPortRange();
            if (// Handle int overflow.
            portTo <= 0)
                portTo = Integer.MAX_VALUE;
            GridNioFilter[] filters = makeFilters(cliConnCfg);
            int maxOpenCursors = cliConnCfg.getMaxOpenCursorsPerConnection();
            long idleTimeout = cliConnCfg.getIdleTimeout();
            for (int port = cliConnCfg.getPort(); port <= portTo && port <= 65535; port++) {
                try {
                    GridNioServer<byte[]> srv0 = GridNioServer.<byte[]>builder().address(hostAddr).port(port).listener(new ClientListenerNioListener(ctx, busyLock, cliConnCfg)).logger(log).selectorCount(DFLT_SELECTOR_CNT).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(false).idleTimeout(idleTimeout > 0 ? idleTimeout : Long.MAX_VALUE).build();
                    srv0.start();
                    srv = srv0;
                    ctx.ports().registerPort(port, IgnitePortProtocol.TCP, getClass());
                    if (log.isInfoEnabled())
                        log.info("Client connector processor has started on TCP port " + port);
                    lastErr = null;
                    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 + ']');
        } catch (Exception e) {
            throw new IgniteCheckedException("Failed to start client connector processor.", e);
        }
    }
}
Also used : GridNioFilter(org.apache.ignite.internal.util.nio.GridNioFilter) IgniteThreadPoolExecutor(org.apache.ignite.thread.IgniteThreadPoolExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) ClientConnectorConfiguration(org.apache.ignite.configuration.ClientConnectorConfiguration) InetAddress(java.net.InetAddress)

Example 7 with ClientConnectorConfiguration

use of org.apache.ignite.configuration.ClientConnectorConfiguration in project ignite by apache.

the class ClientListenerProcessor method prepareConfiguration.

/**
 * Prepare connector configuration.
 *
 * @param cfg Ignite configuration.
 * @return Connector configuration.
 * @throws IgniteCheckedException If failed.
 */
@SuppressWarnings("deprecation")
@Nullable
private ClientConnectorConfiguration prepareConfiguration(IgniteConfiguration cfg) throws IgniteCheckedException {
    OdbcConfiguration odbcCfg = cfg.getOdbcConfiguration();
    SqlConnectorConfiguration sqlConnCfg = cfg.getSqlConnectorConfiguration();
    ClientConnectorConfiguration cliConnCfg = cfg.getClientConnectorConfiguration();
    if (cliConnCfg == null && sqlConnCfg == null && odbcCfg == null)
        return null;
    if (isNotDefault(cliConnCfg)) {
        // User set configuration explicitly. User it, but print a warning about ignored SQL/ODBC configs.
        if (odbcCfg != null) {
            U.warn(log, "Deprecated " + OdbcConfiguration.class.getSimpleName() + " will be ignored because " + ClientConnectorConfiguration.class.getSimpleName() + " is set.");
        }
        if (sqlConnCfg != null) {
            U.warn(log, "Deprecated " + SqlConnectorConfiguration.class.getSimpleName() + " will be ignored " + "because " + ClientConnectorConfiguration.class.getSimpleName() + " is set.");
        }
    } else {
        cliConnCfg = new ClientConnectorConfiguration();
        if (sqlConnCfg != null) {
            // Migrate from SQL configuration.
            cliConnCfg.setHost(sqlConnCfg.getHost());
            cliConnCfg.setMaxOpenCursorsPerConnection(sqlConnCfg.getMaxOpenCursorsPerConnection());
            cliConnCfg.setPort(sqlConnCfg.getPort());
            cliConnCfg.setPortRange(sqlConnCfg.getPortRange());
            cliConnCfg.setSocketSendBufferSize(sqlConnCfg.getSocketSendBufferSize());
            cliConnCfg.setSocketReceiveBufferSize(sqlConnCfg.getSocketReceiveBufferSize());
            cliConnCfg.setTcpNoDelay(sqlConnCfg.isTcpNoDelay());
            cliConnCfg.setThreadPoolSize(sqlConnCfg.getThreadPoolSize());
            U.warn(log, "Automatically converted deprecated " + SqlConnectorConfiguration.class.getSimpleName() + " to " + ClientConnectorConfiguration.class.getSimpleName() + ".");
            if (odbcCfg != null) {
                U.warn(log, "Deprecated " + OdbcConfiguration.class.getSimpleName() + " will be ignored because " + SqlConnectorConfiguration.class.getSimpleName() + " is set.");
            }
        } else if (odbcCfg != null) {
            // Migrate from ODBC configuration.
            HostAndPortRange hostAndPort = parseOdbcEndpoint(odbcCfg);
            cliConnCfg.setHost(hostAndPort.host());
            cliConnCfg.setPort(hostAndPort.portFrom());
            cliConnCfg.setPortRange(hostAndPort.portTo() - hostAndPort.portFrom());
            cliConnCfg.setThreadPoolSize(odbcCfg.getThreadPoolSize());
            cliConnCfg.setSocketSendBufferSize(odbcCfg.getSocketSendBufferSize());
            cliConnCfg.setSocketReceiveBufferSize(odbcCfg.getSocketReceiveBufferSize());
            cliConnCfg.setMaxOpenCursorsPerConnection(odbcCfg.getMaxOpenCursors());
            U.warn(log, "Automatically converted deprecated " + OdbcConfiguration.class.getSimpleName() + " to " + ClientConnectorConfiguration.class.getSimpleName() + ".");
        }
    }
    return cliConnCfg;
}
Also used : ClientConnectorConfiguration(org.apache.ignite.configuration.ClientConnectorConfiguration) HostAndPortRange(org.apache.ignite.internal.util.HostAndPortRange) OdbcConfiguration(org.apache.ignite.configuration.OdbcConfiguration) SqlConnectorConfiguration(org.apache.ignite.configuration.SqlConnectorConfiguration) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with ClientConnectorConfiguration

use of org.apache.ignite.configuration.ClientConnectorConfiguration in project ignite by apache.

the class ClientConnectorConfigurationValidationSelfTest method testJdbcConnectionEnabled.

/**
 * Checks if JDBC connection enabled and others are disabled, JDBC still works.
 *
 * @throws Exception If failed.
 */
public void testJdbcConnectionEnabled() throws Exception {
    IgniteConfiguration cfg = baseConfiguration();
    cfg.setClientConnectorConfiguration(new ClientConnectorConfiguration().setJdbcEnabled(true).setOdbcEnabled(false).setThinClientEnabled(false));
    Ignition.start(cfg);
    checkJdbc(null, ClientConnectorConfiguration.DFLT_PORT);
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) ClientConnectorConfiguration(org.apache.ignite.configuration.ClientConnectorConfiguration)

Example 9 with ClientConnectorConfiguration

use of org.apache.ignite.configuration.ClientConnectorConfiguration in project ignite by apache.

the class ClientConnectorConfigurationValidationSelfTest method testIgnoreOdbcWhenClientSet.

/**
 * Test SQL connector conversion.
 *
 * @throws Exception If failed.
 */
public void testIgnoreOdbcWhenClientSet() throws Exception {
    int cliPort = ClientConnectorConfiguration.DFLT_PORT - 1;
    int odbcPort = ClientConnectorConfiguration.DFLT_PORT - 2;
    IgniteConfiguration cfg = baseConfiguration();
    cfg.setClientConnectorConfiguration(new ClientConnectorConfiguration().setPort(cliPort));
    cfg.setOdbcConfiguration(new OdbcConfiguration().setEndpointAddress("127.0.0.1:" + odbcPort));
    Ignition.start(cfg);
    checkJdbc(null, cliPort);
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) ClientConnectorConfiguration(org.apache.ignite.configuration.ClientConnectorConfiguration) OdbcConfiguration(org.apache.ignite.configuration.OdbcConfiguration)

Example 10 with ClientConnectorConfiguration

use of org.apache.ignite.configuration.ClientConnectorConfiguration in project ignite by apache.

the class ClientConnectorConfigurationValidationSelfTest method testJdbcConnectionDisabledForDaemon.

/**
 *  Checks if JDBC connection disabled for daemon node.
 *
 * @throws Exception If failed.
 */
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public void testJdbcConnectionDisabledForDaemon() throws Exception {
    final IgniteConfiguration cfg = baseConfiguration().setDaemon(true);
    cfg.setClientConnectorConfiguration(new ClientConnectorConfiguration().setJdbcEnabled(true).setThinClientEnabled(true));
    Ignition.start(cfg);
    GridTestUtils.assertThrows(log, new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            checkJdbc(null, ClientConnectorConfiguration.DFLT_PORT);
            return null;
        }
    }, SQLException.class, "Failed to connect");
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) ClientConnectorConfiguration(org.apache.ignite.configuration.ClientConnectorConfiguration) IgniteException(org.apache.ignite.IgniteException) SQLException(java.sql.SQLException)

Aggregations

ClientConnectorConfiguration (org.apache.ignite.configuration.ClientConnectorConfiguration)13 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)11 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)4 OdbcConfiguration (org.apache.ignite.configuration.OdbcConfiguration)3 SqlConnectorConfiguration (org.apache.ignite.configuration.SqlConnectorConfiguration)3 SQLException (java.sql.SQLException)2 IgniteException (org.apache.ignite.IgniteException)2 BinaryMarshaller (org.apache.ignite.internal.binary.BinaryMarshaller)2 InetAddress (java.net.InetAddress)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 HostAndPortRange (org.apache.ignite.internal.util.HostAndPortRange)1 GridNioFilter (org.apache.ignite.internal.util.nio.GridNioFilter)1 TcpCommunicationSpi (org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi)1 IgniteThreadPoolExecutor (org.apache.ignite.thread.IgniteThreadPoolExecutor)1 Nullable (org.jetbrains.annotations.Nullable)1