Search in sources :

Example 1 with GridSslContextFactory

use of org.apache.ignite.internal.client.ssl.GridSslContextFactory in project ignite by apache.

the class GridTcpRestProtocol method start.

/**
 * {@inheritDoc}
 */
@Override
public void start(final GridRestProtocolHandler hnd) throws IgniteCheckedException {
    assert hnd != null;
    ConnectorConfiguration cfg = ctx.config().getConnectorConfiguration();
    assert cfg != null;
    lsnr = new GridTcpRestNioListener(log, this, hnd, ctx);
    GridNioParser parser = new GridTcpRestParser(false, ctx.marshallerContext().jdkMarshaller());
    try {
        host = resolveRestTcpHost(ctx.config());
        SSLContext sslCtx = null;
        if (cfg.isSslEnabled()) {
            Factory<SSLContext> igniteFactory = ctx.config().getSslContextFactory();
            Factory<SSLContext> factory = cfg.getSslFactory();
            // This factory deprecated and will be removed.
            GridSslContextFactory depFactory = cfg.getSslContextFactory();
            if (factory == null && depFactory == null && igniteFactory == null)
                // Thrown SSL exception instead of IgniteCheckedException for writing correct warning message into log.
                throw new SSLException("SSL is enabled, but SSL context factory is not specified.");
            if (factory != null)
                sslCtx = factory.create();
            else if (depFactory != null)
                sslCtx = depFactory.createSslContext();
            else
                sslCtx = igniteFactory.create();
        }
        int startPort = cfg.getPort();
        int portRange = cfg.getPortRange();
        int lastPort = portRange == 0 ? startPort : startPort + portRange - 1;
        for (int port0 = startPort; port0 <= lastPort; port0++) {
            if (startTcpServer(host, port0, lsnr, parser, sslCtx, cfg)) {
                port = port0;
                if (log.isInfoEnabled())
                    log.info(startInfo());
                return;
            }
        }
        U.warn(log, "Failed to start TCP binary REST server (possibly all ports in range are in use) " + "[firstPort=" + cfg.getPort() + ", lastPort=" + lastPort + ", host=" + host + ']');
    } catch (SSLException e) {
        U.warn(log, "Failed to start " + name() + " protocol on port " + port + ". Check if SSL context factory " + "is properly configured: " + e.getMessage());
    } catch (IOException e) {
        U.warn(log, "Failed to start " + name() + " protocol on port " + port + ". " + "Check restTcpHost configuration property: " + e.getMessage());
    }
}
Also used : GridSslContextFactory(org.apache.ignite.internal.client.ssl.GridSslContextFactory) GridNioParser(org.apache.ignite.internal.util.nio.GridNioParser) ConnectorConfiguration(org.apache.ignite.configuration.ConnectorConfiguration) SSLContext(javax.net.ssl.SSLContext) IOException(java.io.IOException) SSLException(javax.net.ssl.SSLException)

Example 2 with GridSslContextFactory

use of org.apache.ignite.internal.client.ssl.GridSslContextFactory in project ignite by apache.

the class GridTcpRouterImpl method start.

/**
 * Starts router.
 *
 * @throws IgniteException If failed.
 */
@Override
public void start() throws IgniteException {
    try {
        client = createClient(cfg);
    } catch (GridClientException e) {
        throw new IgniteException("Failed to initialise embedded client.", e);
    }
    GridNioServerListener<GridClientMessage> lsnr = new GridTcpRouterNioListenerOsImpl(log, client);
    parser = new GridTcpRouterNioParser();
    final InetAddress hostAddr;
    try {
        hostAddr = InetAddress.getByName(cfg.getHost());
    } catch (UnknownHostException e) {
        throw new IgniteException("Failed to resolve grid address for configured host: " + cfg.getHost(), e);
    }
    SSLContext sslCtx;
    try {
        GridSslContextFactory sslCtxFactory = cfg.getSslContextFactory();
        sslCtx = sslCtxFactory == null ? null : sslCtxFactory.createSslContext();
    } catch (SSLException e) {
        throw new IgniteException("Failed to create SSL context.", e);
    }
    for (int port = cfg.getPort(), last = port + cfg.getPortRange(); port <= last; port++) {
        if (startTcpServer(hostAddr, port, lsnr, parser, cfg.isNoDelay(), sslCtx, cfg.isSslClientAuth(), cfg.isSslClientAuth())) {
            if (log.isInfoEnabled())
                log.info("TCP router successfully started for endpoint: " + hostAddr.getHostAddress() + ":" + port);
            bindPort = port;
            bindHost = hostAddr.getHostName();
            break;
        } else
            U.warn(log, "TCP REST router failed to start on endpoint: " + hostAddr.getHostAddress() + ":" + port + ". Will try next port within allowed port range.");
    }
    if (bindPort == 0)
        throw new IgniteException("Failed to bind TCP router server (possibly all ports in range " + "are in use) [firstPort=" + cfg.getPort() + ", lastPort=" + (cfg.getPort() + cfg.getPortRange()) + ", addr=" + hostAddr + ']');
    registerMBean();
}
Also used : GridClientException(org.apache.ignite.internal.client.GridClientException) GridSslContextFactory(org.apache.ignite.internal.client.ssl.GridSslContextFactory) UnknownHostException(java.net.UnknownHostException) IgniteException(org.apache.ignite.IgniteException) SSLContext(javax.net.ssl.SSLContext) InetAddress(java.net.InetAddress) SSLException(javax.net.ssl.SSLException) GridClientMessage(org.apache.ignite.internal.processors.rest.client.message.GridClientMessage)

Example 3 with GridSslContextFactory

use of org.apache.ignite.internal.client.ssl.GridSslContextFactory in project ignite by apache.

the class ClientAbstractMultiNodeSelfTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration c = super.getConfiguration(igniteInstanceName);
    c.setLocalHost(HOST);
    assert c.getConnectorConfiguration() == null;
    if (restEnabled) {
        ConnectorConfiguration clientCfg = new ConnectorConfiguration();
        clientCfg.setPort(REST_TCP_PORT_BASE);
        GridSslContextFactory sslCtxFactory = sslContextFactory();
        if (sslCtxFactory != null) {
            clientCfg.setSslEnabled(true);
            clientCfg.setSslContextFactory(sslCtxFactory);
        }
        c.setConnectorConfiguration(clientCfg);
    }
    TestCommunicationSpi spi = new TestCommunicationSpi();
    spi.setLocalPort(GridTestUtils.getNextCommPort(getClass()));
    c.setCommunicationSpi(spi);
    c.setCacheConfiguration(cacheConfiguration(DEFAULT_CACHE_NAME), cacheConfiguration(PARTITIONED_CACHE_NAME), cacheConfiguration(REPLICATED_CACHE_NAME), cacheConfiguration(REPLICATED_ASYNC_CACHE_NAME));
    c.setPublicThreadPoolSize(40);
    c.setSystemThreadPoolSize(40);
    return c;
}
Also used : GridSslContextFactory(org.apache.ignite.internal.client.ssl.GridSslContextFactory) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) ConnectorConfiguration(org.apache.ignite.configuration.ConnectorConfiguration)

Aggregations

GridSslContextFactory (org.apache.ignite.internal.client.ssl.GridSslContextFactory)3 SSLContext (javax.net.ssl.SSLContext)2 SSLException (javax.net.ssl.SSLException)2 ConnectorConfiguration (org.apache.ignite.configuration.ConnectorConfiguration)2 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 IgniteException (org.apache.ignite.IgniteException)1 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)1 GridClientException (org.apache.ignite.internal.client.GridClientException)1 GridClientMessage (org.apache.ignite.internal.processors.rest.client.message.GridClientMessage)1 GridNioParser (org.apache.ignite.internal.util.nio.GridNioParser)1