Example usage for org.apache.spark.network.sasl SaslServerBootstrap SaslServerBootstrap

List of usage examples for org.apache.spark.network.sasl SaslServerBootstrap SaslServerBootstrap

Introduction

In this page you can find the example usage for org.apache.spark.network.sasl SaslServerBootstrap SaslServerBootstrap.

Prototype

public SaslServerBootstrap(TransportConf conf, SecretKeyHolder secretKeyHolder) 

Source Link

Usage

From source file:org.apache.carbondata.spark.dictionary.server.SecureDictionaryServer.java

License:Apache License

/**
 * Binds dictionary server to an available port.
 *
 *//*ww w.j a v a 2s  . c  o  m*/
@Override
public void bindToPort() {
    long start = System.currentTimeMillis();
    // Configure the server.
    int i = 0;
    while (i < 10) {
        int newPort = port + i;
        try {
            SecurityManager securityManager;
            SparkConf conf = this.conf.clone();
            conf.setAppName("Carbon Dictionary Server");

            // As spark.network.sasl.serverAlwaysEncrypt is not exposed parameter
            // set it explicitly so that Dictionary Server and Client communication
            // occurs encrypted. The below parameter can be removed once spark Documents it.
            // conf.set("spark.network.sasl.serverAlwaysEncrypt", "true");
            conf.set("spark.authenticate.enableSaslEncryption", "true");

            if (conf.get("spark.authenticate.enableSaslEncryption", "false").equalsIgnoreCase("true")) {
                setEncryptSecureServer(true);
            } else {
                setEncryptSecureServer(false);
            }

            TransportConf transportConf = SparkTransportConf.fromSparkConf(conf, "Carbon Dictionary Server", 0);
            securityManager = new SecurityManager(conf, Some.<byte[]>empty());
            secretKey = securityManager.getSecretKey();
            TransportContext context = new TransportContext(transportConf, secureDictionaryServerHandler);
            TransportServerBootstrap bootstrap = new SaslServerBootstrap(transportConf, securityManager);
            String host = findLocalIpAddress(LOGGER);
            //iteratively listening to newports
            context.createServer(host, newPort, Lists.<TransportServerBootstrap>newArrayList(bootstrap));
            LOGGER.info("Dictionary Server started, Time spent " + (System.currentTimeMillis() - start)
                    + " Listening on port " + newPort);
            this.port = newPort;
            this.host = host;
            break;
        } catch (Exception e) {
            LOGGER.error("Dictionary Server Failed to bind to port: " + newPort, e);
            if (i == 9) {
                throw new RuntimeException("Dictionary Server Could not bind to any port");
            }
        }
        i++;
    }
}