Search in sources :

Example 1 with SSLFactory

use of org.apache.tez.http.SSLFactory in project tez by apache.

the class AsyncHttpConnection method initClient.

private void initClient(HttpConnectionParams httpConnParams) throws IOException {
    if (httpAsyncClient != null) {
        return;
    }
    if (httpAsyncClient == null) {
        synchronized (AsyncHttpConnection.class) {
            if (httpAsyncClient == null) {
                LOG.info("Initializing AsyncClient (TezBodyDeferringAsyncHandler)");
                AsyncHttpClientConfig.Builder builder = new AsyncHttpClientConfig.Builder();
                if (httpConnParams.isSslShuffle()) {
                    // Configure SSL
                    SSLFactory sslFactory = httpConnParams.getSslFactory();
                    Preconditions.checkArgument(sslFactory != null, "SSLFactory can not be null");
                    sslFactory.configure(builder);
                }
                /**
                 * TODO : following settings need fine tuning.
                 * Change following config to accept common thread pool later.
                 * Change max connections based on the total inputs (ordered & unordered). Need to tune
                 * setMaxConnections & addRequestFilter.
                 */
                builder.setAllowPoolingConnection(httpConnParams.isKeepAlive()).setAllowSslConnectionPool(httpConnParams.isKeepAlive()).setCompressionEnabled(false).setMaximumConnectionsPerHost(1).setConnectionTimeoutInMs(httpConnParams.getConnectionTimeout()).setRequestTimeoutInMs(httpConnParams.getReadTimeout()).setUseRawUrl(true).build();
                httpAsyncClient = new AsyncHttpClient(builder.build());
            }
        }
    }
}
Also used : SSLFactory(org.apache.tez.http.SSLFactory) RequestBuilder(com.ning.http.client.RequestBuilder) AsyncHttpClientConfig(com.ning.http.client.AsyncHttpClientConfig) AsyncHttpClient(com.ning.http.client.AsyncHttpClient)

Example 2 with SSLFactory

use of org.apache.tez.http.SSLFactory in project tez by apache.

the class TezRuntimeUtils method getHttpConnectionParams.

public static HttpConnectionParams getHttpConnectionParams(Configuration conf) {
    int connectionTimeout = conf.getInt(TezRuntimeConfiguration.TEZ_RUNTIME_SHUFFLE_CONNECT_TIMEOUT, TezRuntimeConfiguration.TEZ_RUNTIME_SHUFFLE_STALLED_COPY_TIMEOUT_DEFAULT);
    int readTimeout = conf.getInt(TezRuntimeConfiguration.TEZ_RUNTIME_SHUFFLE_READ_TIMEOUT, TezRuntimeConfiguration.TEZ_RUNTIME_SHUFFLE_READ_TIMEOUT_DEFAULT);
    int bufferSize = conf.getInt(TezRuntimeConfiguration.TEZ_RUNTIME_SHUFFLE_BUFFER_SIZE, TezRuntimeConfiguration.TEZ_RUNTIME_SHUFFLE_BUFFER_SIZE_DEFAULT);
    boolean keepAlive = conf.getBoolean(TezRuntimeConfiguration.TEZ_RUNTIME_SHUFFLE_KEEP_ALIVE_ENABLED, TezRuntimeConfiguration.TEZ_RUNTIME_SHUFFLE_KEEP_ALIVE_ENABLED_DEFAULT);
    int keepAliveMaxConnections = conf.getInt(TezRuntimeConfiguration.TEZ_RUNTIME_SHUFFLE_KEEP_ALIVE_MAX_CONNECTIONS, TezRuntimeConfiguration.TEZ_RUNTIME_SHUFFLE_KEEP_ALIVE_MAX_CONNECTIONS_DEFAULT);
    if (keepAlive) {
        System.setProperty("sun.net.http.errorstream.enableBuffering", "true");
        System.setProperty("http.maxConnections", String.valueOf(keepAliveMaxConnections));
    }
    boolean sslShuffle = conf.getBoolean(TezRuntimeConfiguration.TEZ_RUNTIME_SHUFFLE_ENABLE_SSL, TezRuntimeConfiguration.TEZ_RUNTIME_SHUFFLE_ENABLE_SSL_DEFAULT);
    if (sslShuffle) {
        if (sslFactory == null) {
            synchronized (HttpConnectionParams.class) {
                // Create sslFactory if it is null or if it was destroyed earlier
                if (sslFactory == null || sslFactory.getKeystoresFactory().getTrustManagers() == null) {
                    sslFactory = new SSLFactory(org.apache.hadoop.security.ssl.SSLFactory.Mode.CLIENT, conf);
                    try {
                        sslFactory.init();
                    } catch (Exception ex) {
                        sslFactory.destroy();
                        sslFactory = null;
                        throw new RuntimeException(ex);
                    }
                }
            }
        }
    }
    HttpConnectionParams httpConnParams = new HttpConnectionParams(keepAlive, keepAliveMaxConnections, connectionTimeout, readTimeout, bufferSize, sslShuffle, sslFactory);
    return httpConnParams;
}
Also used : HttpConnectionParams(org.apache.tez.http.HttpConnectionParams) SSLFactory(org.apache.tez.http.SSLFactory) TezUncheckedException(org.apache.tez.dag.api.TezUncheckedException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

SSLFactory (org.apache.tez.http.SSLFactory)2 AsyncHttpClient (com.ning.http.client.AsyncHttpClient)1 AsyncHttpClientConfig (com.ning.http.client.AsyncHttpClientConfig)1 RequestBuilder (com.ning.http.client.RequestBuilder)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 TezUncheckedException (org.apache.tez.dag.api.TezUncheckedException)1 HttpConnectionParams (org.apache.tez.http.HttpConnectionParams)1