Search in sources :

Example 6 with OdbcConfiguration

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

the class SqlListenerProcessor method start.

/** {@inheritDoc} */
@Override
public void start(boolean activeOnStart) throws IgniteCheckedException {
    IgniteConfiguration cfg = ctx.config();
    OdbcConfiguration odbcCfg = cfg.getOdbcConfiguration();
    if (odbcCfg != null) {
        try {
            HostAndPortRange hostPort;
            if (F.isEmpty(odbcCfg.getEndpointAddress())) {
                hostPort = new HostAndPortRange(OdbcConfiguration.DFLT_TCP_HOST, OdbcConfiguration.DFLT_TCP_PORT_FROM, OdbcConfiguration.DFLT_TCP_PORT_TO);
            } else {
                hostPort = HostAndPortRange.parse(odbcCfg.getEndpointAddress(), OdbcConfiguration.DFLT_TCP_PORT_FROM, OdbcConfiguration.DFLT_TCP_PORT_TO, "Failed to parse ODBC endpoint address");
            }
            assertParameter(odbcCfg.getThreadPoolSize() > 0, "threadPoolSize > 0");
            odbcExecSvc = new IgniteThreadPoolExecutor("odbc", cfg.getIgniteInstanceName(), odbcCfg.getThreadPoolSize(), odbcCfg.getThreadPoolSize(), 0, new LinkedBlockingQueue<Runnable>());
            InetAddress host;
            try {
                host = InetAddress.getByName(hostPort.host());
            } catch (Exception e) {
                throw new IgniteCheckedException("Failed to resolve ODBC host: " + hostPort.host(), e);
            }
            Exception lastErr = null;
            for (int port = hostPort.portFrom(); port <= hostPort.portTo(); port++) {
                try {
                    GridNioFilter[] filters = new GridNioFilter[] { new GridNioAsyncNotifyFilter(ctx.igniteInstanceName(), odbcExecSvc, log) {

                        @Override
                        public void onSessionOpened(GridNioSession ses) throws IgniteCheckedException {
                            proceedSessionOpened(ses);
                        }
                    }, new GridNioCodecFilter(new SqlListenerBufferedParser(), log, false) };
                    GridNioServer<byte[]> srv0 = GridNioServer.<byte[]>builder().address(host).port(port).listener(new SqlListenerNioListener(ctx, busyLock, odbcCfg.getMaxOpenCursors())).logger(log).selectorCount(DFLT_SELECTOR_CNT).igniteInstanceName(ctx.igniteInstanceName()).serverName("odbc").tcpNoDelay(DFLT_TCP_NODELAY).directBuffer(DFLT_TCP_DIRECT_BUF).byteOrder(ByteOrder.nativeOrder()).socketSendBufferSize(odbcCfg.getSocketSendBufferSize()).socketReceiveBufferSize(odbcCfg.getSocketReceiveBufferSize()).filters(filters).directMode(false).idleTimeout(Long.MAX_VALUE).build();
                    srv0.start();
                    srv = srv0;
                    ctx.ports().registerPort(port, IgnitePortProtocol.TCP, getClass());
                    log.info("ODBC 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 [" + "address=" + hostPort + ", lastErr=" + lastErr + ']');
        } catch (Exception e) {
            throw new IgniteCheckedException("Failed to start ODBC processor.", e);
        }
    }
}
Also used : GridNioFilter(org.apache.ignite.internal.util.nio.GridNioFilter) GridNioSession(org.apache.ignite.internal.util.nio.GridNioSession) HostAndPortRange(org.apache.ignite.internal.util.HostAndPortRange) IgniteThreadPoolExecutor(org.apache.ignite.thread.IgniteThreadPoolExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridNioAsyncNotifyFilter(org.apache.ignite.internal.util.nio.GridNioAsyncNotifyFilter) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridNioCodecFilter(org.apache.ignite.internal.util.nio.GridNioCodecFilter) OdbcConfiguration(org.apache.ignite.configuration.OdbcConfiguration) InetAddress(java.net.InetAddress)

Example 7 with OdbcConfiguration

use of org.apache.ignite.configuration.OdbcConfiguration 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 OdbcConfiguration

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

the class ClientConnectorConfigurationValidationSelfTest method testOdbcConnectorConversion.

/**
 * Test ODBC connector conversion.
 *
 * @throws Exception If failed.
 */
@Test
public void testOdbcConnectorConversion() throws Exception {
    int port = ClientConnectorConfiguration.DFLT_PORT - 1;
    IgniteConfiguration cfg = baseConfiguration();
    cfg.setOdbcConfiguration(new OdbcConfiguration().setEndpointAddress("127.0.0.1:" + port));
    Ignition.start(cfg);
    checkJdbc(null, port);
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) OdbcConfiguration(org.apache.ignite.configuration.OdbcConfiguration) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 9 with OdbcConfiguration

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

the class ClientConnectorConfigurationValidationSelfTest method testIgnoreOdbcWhenClientSet.

/**
 * Test SQL connector conversion.
 *
 * @throws Exception If failed.
 */
@Test
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) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

OdbcConfiguration (org.apache.ignite.configuration.OdbcConfiguration)9 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)6 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)5 Test (org.junit.Test)5 ClientConnectorConfiguration (org.apache.ignite.configuration.ClientConnectorConfiguration)3 SqlConnectorConfiguration (org.apache.ignite.configuration.SqlConnectorConfiguration)3 HostAndPortRange (org.apache.ignite.internal.util.HostAndPortRange)2 InetAddress (java.net.InetAddress)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 GridNioAsyncNotifyFilter (org.apache.ignite.internal.util.nio.GridNioAsyncNotifyFilter)1 GridNioCodecFilter (org.apache.ignite.internal.util.nio.GridNioCodecFilter)1 GridNioFilter (org.apache.ignite.internal.util.nio.GridNioFilter)1 GridNioSession (org.apache.ignite.internal.util.nio.GridNioSession)1 IgniteThreadPoolExecutor (org.apache.ignite.thread.IgniteThreadPoolExecutor)1 Nullable (org.jetbrains.annotations.Nullable)1