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);
}
}
}
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;
}
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);
}
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);
}
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");
}
Aggregations