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

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

Introduction

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

Prototype

public SaslClientBootstrap(TransportConf conf, String appId, SecretKeyHolder secretKeyHolder) 

Source Link

Usage

From source file:org.apache.carbondata.spark.dictionary.client.SecureDictionaryClient.java

License:Apache License

/**
 * start dictionary client/*  w ww  . j  ava 2  s.  co  m*/
 *
 * @param address
 * @param port
 */
@Override
public void startClient(String secretKey, String address, int port, boolean encryptSecureServer) {
    LOGGER.info("Starting client on " + address + " " + port);
    long start = System.currentTimeMillis();

    SecurityManager securityMgr;
    SparkConf conf = new SparkConf().setAppName("Carbon Dictionary Client");

    conf.set("spark.authenticate", "true");

    if (null != secretKey) {
        conf.set("spark.authenticate.secret", secretKey);
    }

    if (encryptSecureServer) {
        conf.set("spark.authenticate.enableSaslEncryption", "true");
    }

    TransportConf transportConf = SparkTransportConf.fromSparkConf(conf, "Carbon Dictionary Client", 0);
    if (null != secretKey) {
        securityMgr = new SecurityManager(conf,
                scala.Option.apply(secretKey.getBytes(Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET))));
    } else {
        securityMgr = new SecurityManager(conf, null);
    }

    TransportContext context = new TransportContext(transportConf, dictionaryClientHandler);
    clientFactory = context.createClientFactory(Lists.<TransportClientBootstrap>newArrayList(
            new SaslClientBootstrap(transportConf, "Carbon Dictionary Client", securityMgr)));

    try {
        client = clientFactory.createClient(address, port);
    } catch (Exception e) {
        LOGGER.error("Dictionary Client Failed to bind to port:", e);
    }
    LOGGER.info("Dictionary client Started, Total time spent : " + (System.currentTimeMillis() - start));
}