/** * Reads the client connector configuration. * * @param in Reader. * @return Config. */ private static ClientConnectorConfiguration readClientConnectorConfiguration(BinaryRawReader in) { return new ClientConnectorConfiguration() .setHost(in.readString()) .setPort(in.readInt()) .setPortRange(in.readInt()) .setSocketSendBufferSize(in.readInt()) .setSocketReceiveBufferSize(in.readInt()) .setTcpNoDelay(in.readBoolean()) .setMaxOpenCursorsPerConnection(in.readInt()) .setThreadPoolSize(in.readInt()) .setIdleTimeout(in.readLong()) .setThinClientEnabled(in.readBoolean()) .setOdbcEnabled(in.readBoolean()) .setJdbcEnabled(in.readBoolean()); }
/** {@inheritDoc} */ @SuppressWarnings("deprecation") @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); cfg.setMarshaller(new BinaryMarshaller()); cfg.setClientConnectorConfiguration( new ClientConnectorConfiguration() .setSslEnabled(true) .setUseIgniteSslContextFactory(setSslCtxFactoryToIgnite) .setSslClientAuth(true) .setSslContextFactory(setSslCtxFactoryToCli ? sslCtxFactory : null)); cfg.setSslContextFactory(setSslCtxFactoryToIgnite ? sslCtxFactory : null); return cfg; }
/** * Creates SQL connector configuration by copying all properties from given configuration. * * @param cfg Configuration to copy. */ public ClientConnectorConfiguration(ClientConnectorConfiguration cfg) { assert cfg != null; host = cfg.getHost(); maxOpenCursorsPerConn = cfg.getMaxOpenCursorsPerConnection(); port = cfg.getPort(); portRange = cfg.getPortRange(); sockRcvBufSize = cfg.getSocketReceiveBufferSize(); sockSndBufSize = cfg.getSocketSendBufferSize(); tcpNoDelay = cfg.isTcpNoDelay(); threadPoolSize = cfg.getThreadPoolSize(); idleTimeout = cfg.getIdleTimeout(); sslEnabled = cfg.isSslEnabled(); sslClientAuth = cfg.isSslClientAuth(); useIgniteSslCtxFactory = cfg.isUseIgniteSslContextFactory(); sslCtxFactory = cfg.getSslContextFactory(); }
/** * Validate client connector configuration. * * @param cfg Configuration. * @throws IgniteCheckedException If failed. */ private void validateConfiguration(ClientConnectorConfiguration cfg) throws IgniteCheckedException { assertParameter(cfg.getPort() > 1024, "port > 1024"); assertParameter(cfg.getPort() <= 65535, "port <= 65535"); assertParameter(cfg.getPortRange() >= 0, "portRange > 0"); assertParameter(cfg.getSocketSendBufferSize() >= 0, "socketSendBufferSize > 0"); assertParameter(cfg.getSocketReceiveBufferSize() >= 0, "socketReceiveBufferSize > 0"); assertParameter(cfg.getMaxOpenCursorsPerConnection() >= 0, "maxOpenCursorsPerConnection() >= 0"); assertParameter(cfg.getThreadPoolSize() > 0, "threadPoolSize > 0"); }
cliConnCfg = new ClientConnectorConfiguration(); 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()); 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());
/** * Writes the client connector configuration. * * @param w Writer. */ private static void writeClientConnectorConfiguration(BinaryRawWriter w, ClientConnectorConfiguration cfg) { assert w != null; if (cfg != null) { w.writeBoolean(true); w.writeString(cfg.getHost()); w.writeInt(cfg.getPort()); w.writeInt(cfg.getPortRange()); w.writeInt(cfg.getSocketSendBufferSize()); w.writeInt(cfg.getSocketReceiveBufferSize()); w.writeBoolean(cfg.isTcpNoDelay()); w.writeInt(cfg.getMaxOpenCursorsPerConnection()); w.writeInt(cfg.getThreadPoolSize()); w.writeLong(cfg.getIdleTimeout()); w.writeBoolean(cfg.isThinClientEnabled()); w.writeBoolean(cfg.isOdbcEnabled()); w.writeBoolean(cfg.isJdbcEnabled()); } else { w.writeBoolean(false); } }
/** * Test port. * * @throws Exception If failed. */ @Test public void testPort() throws Exception { check(new ClientConnectorConfiguration().setPort(-1), false); check(new ClientConnectorConfiguration().setPort(0), false); check(new ClientConnectorConfiguration().setPort(512), false); check(new ClientConnectorConfiguration().setPort(65536), false); check(new ClientConnectorConfiguration().setPort(ClientConnectorConfiguration.DFLT_PORT), true); checkJdbc(null, ClientConnectorConfiguration.DFLT_PORT); check(new ClientConnectorConfiguration().setPort(ClientConnectorConfiguration.DFLT_PORT + 200), true); checkJdbc(null, ClientConnectorConfiguration.DFLT_PORT + 200); }
/** */ private static IgniteConfiguration getConfiguration(NodeConfiguration nodeCfg) { IgniteConfiguration igniteCfg = Config.getServerConfiguration(); ((TcpDiscoverySpi)igniteCfg.getDiscoverySpi()).getIpFinder().registerAddresses( Collections.singletonList(new InetSocketAddress(HOST, nodeCfg.getDiscoveryPort())) ); igniteCfg.setClientConnectorConfiguration(new ClientConnectorConfiguration() .setHost(HOST) .setPort(nodeCfg.getClientPort()) ); return igniteCfg; }
/** * Checks if JDBC connection enabled and others are disabled, JDBC still works. * * @throws Exception If failed. */ @Test 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); }
String host = cliConnCfg.getHost(); "client-connector", cfg.getIgniteInstanceName(), cliConnCfg.getThreadPoolSize(), cliConnCfg.getThreadPoolSize(), 0, new LinkedBlockingQueue<Runnable>()); int portTo = cliConnCfg.getPort() + cliConnCfg.getPortRange(); long idleTimeout = cliConnCfg.getIdleTimeout(); for (int port = cliConnCfg.getPort(); port <= portTo && port <= 65535; port++) { try { GridNioServer<byte[]> srv0 = GridNioServer.<byte[]>builder() .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) "host=" + host + ", portFrom=" + cliConnCfg.getPort() + ", portTo=" + portTo + ", lastErr=" + lastErr + ']');
/** * Test thread pool size. * * @throws Exception If failed. */ @Test public void testThreadPoolSize() throws Exception { check(new ClientConnectorConfiguration().setThreadPoolSize(0), false); check(new ClientConnectorConfiguration().setThreadPoolSize(-1), false); check(new ClientConnectorConfiguration().setThreadPoolSize(4), true); checkJdbc(null, ClientConnectorConfiguration.DFLT_PORT); }
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); cfg.setClientConnectorConfiguration(new ClientConnectorConfiguration() .setSslEnabled(true) .setUseIgniteSslContextFactory(true)); cfg.setSslContextFactory(createSslFactory()); CacheConfiguration ccfg = new CacheConfiguration(TEST_CACHE_NAME); cfg.setCacheConfiguration(ccfg); return cfg; }
/** * Test socket buffers. * * @throws Exception If failed. */ @Test public void testSocketBuffers() throws Exception { check(new ClientConnectorConfiguration().setSocketSendBufferSize(-4 * 1024), false); check(new ClientConnectorConfiguration().setSocketReceiveBufferSize(-4 * 1024), false); check(new ClientConnectorConfiguration().setSocketSendBufferSize(4 * 1024), true); checkJdbc(null, ClientConnectorConfiguration.DFLT_PORT); check(new ClientConnectorConfiguration().setSocketReceiveBufferSize(4 * 1024), true); checkJdbc(null, ClientConnectorConfiguration.DFLT_PORT + 1); }
/** * Checks if JDBC connection disabled for daemon node. * * @throws Exception If failed. */ @Test 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"); }
/** * Test host. * * @throws Exception If failed. */ @Test public void testHost() throws Exception { check(new ClientConnectorConfiguration().setHost("126.0.0.1"), false); check(new ClientConnectorConfiguration().setHost("127.0.0.1"), true); checkJdbc("127.0.0.1", ClientConnectorConfiguration.DFLT_PORT); check(new ClientConnectorConfiguration().setHost("0.0.0.0"), true); checkJdbc("0.0.0.0", ClientConnectorConfiguration.DFLT_PORT + 1); }
sslCfg.setTrustStorePassword("123456".toCharArray()); srvCfg.setClientConnectorConfiguration(new ClientConnectorConfiguration() .setSslEnabled(true) .setSslClientAuth(true) );
/** * Test max open cursors per connection. * * @throws Exception If failed. */ @Test public void testMaxOpenCusrorsPerConnection() throws Exception { check(new ClientConnectorConfiguration().setMaxOpenCursorsPerConnection(-1), false); check(new ClientConnectorConfiguration().setMaxOpenCursorsPerConnection(0), true); checkJdbc(null, ClientConnectorConfiguration.DFLT_PORT); check(new ClientConnectorConfiguration().setMaxOpenCursorsPerConnection(100), true); checkJdbc(null, ClientConnectorConfiguration.DFLT_PORT + 1); }
/** * Test port. * * @throws Exception If failed. */ @Test public void testPortRange() throws Exception { check(new ClientConnectorConfiguration().setPortRange(-1), false); check(new ClientConnectorConfiguration().setPortRange(0), true); checkJdbc(null, ClientConnectorConfiguration.DFLT_PORT); check(new ClientConnectorConfiguration().setPortRange(10), true); checkJdbc(null, ClientConnectorConfiguration.DFLT_PORT + 1); }
/** * @return Client connection string as defined by * {@link ClientConfiguration#setAddresses(String...)}. */ public Collection<String> clientAddresses() { return srvs.stream() .map(s -> { ClientConnectorConfiguration cfg = s.configuration().getClientConnectorConfiguration(); return cfg == null ? null : String.format("%s:%s", cfg.getHost(), cfg.getPort()); }) .collect(Collectors.toCollection(ArrayList::new)); }
/** * Test host. * * @throws Exception If failed. */ @Test public void testDefault() throws Exception { check(new ClientConnectorConfiguration(), true); checkJdbc(null, ClientConnectorConfiguration.DFLT_PORT); }