use of org.apache.thrift.transport.TServerSocket in project zeppelin by apache.
the class ClusterMockTest method startCluster.
public static void startCluster() throws IOException, InterruptedException {
LOGGER.info("startCluster >>>");
zconf = ZeppelinConfiguration.create();
// Set the cluster IP and port
zServerHost = RemoteInterpreterUtils.findAvailableHostAddress();
zServerPort = RemoteInterpreterUtils.findRandomAvailablePortOnAllLocalInterfaces();
zconf.setClusterAddress(zServerHost + ":" + zServerPort);
// mock cluster manager server
clusterServer = ClusterManagerServer.getInstance(zconf);
clusterServer.start();
// mock cluster manager client
clusterClient = ClusterManagerClient.getInstance(zconf);
clusterClient.start(metaKey);
// Waiting for cluster startup
int wait = 0;
while (wait++ < 100) {
if (clusterServer.isClusterLeader() && clusterServer.raftInitialized() && clusterClient.raftInitialized()) {
LOGGER.info("wait {}(ms) found cluster leader", wait * 3000);
break;
}
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
assertEquals(true, clusterServer.isClusterLeader());
try {
tSocket = new TServerSocket(0);
} catch (TTransportException e) {
throw new IOException("Fail to create TServerSocket", e);
}
LOGGER.info("startCluster <<<");
}
use of org.apache.thrift.transport.TServerSocket in project jstorm by alibaba.
the class AMServer method simple.
public void simple(JstormAM.Processor processor) {
try {
TServerTransport serverTransport = new TServerSocket(port);
TServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor));
LOG.info("Starting the simple server...");
server.serve();
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.apache.thrift.transport.TServerSocket in project dubbo by alibaba.
the class AbstractTest method init.
protected void init() throws Exception {
serverTransport = new TServerSocket(PORT);
TBinaryProtocol.Factory bFactory = new TBinaryProtocol.Factory();
server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).inputProtocolFactory(bFactory).outputProtocolFactory(bFactory).inputTransportFactory(getTransportFactory()).outputTransportFactory(getTransportFactory()).processor(getProcessor()));
Thread startTread = new Thread() {
@Override
public void run() {
server.serve();
}
};
startTread.setName("thrift-server");
startTread.start();
while (!server.isServing()) {
Thread.sleep(100);
}
protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getExtension(ThriftProtocol.NAME);
invoker = protocol.refer(getInterface(), getUrl());
}
use of org.apache.thrift.transport.TServerSocket in project hive by apache.
the class HiveAuthUtils method getServerSSLSocket.
public static TServerSocket getServerSSLSocket(String hiveHost, int portNum, String keyStorePath, String keyStorePassWord, String keyStoreType, String keyStoreAlgorithm, List<String> sslVersionBlacklist, String includeCipherSuites) throws TTransportException, UnknownHostException {
TSSLTransportFactory.TSSLTransportParameters params = null;
if (!includeCipherSuites.trim().isEmpty()) {
Set<String> includeCS = Sets.newHashSet(Splitter.on(":").trimResults().omitEmptyStrings().split(includeCipherSuites.trim()));
int eSize = includeCS.size();
if (eSize > 0) {
params = new TSSLTransportFactory.TSSLTransportParameters("TLS", includeCS.toArray(new String[eSize]));
}
}
if (params == null) {
params = new TSSLTransportFactory.TSSLTransportParameters();
}
String kStoreType = keyStoreType.isEmpty() ? KeyStore.getDefaultType() : keyStoreType;
String kStoreAlgorithm = keyStoreAlgorithm.isEmpty() ? KeyManagerFactory.getDefaultAlgorithm() : keyStoreAlgorithm;
params.setKeyStore(keyStorePath, keyStorePassWord, kStoreAlgorithm, kStoreType);
InetSocketAddress serverAddress;
if (hiveHost == null || hiveHost.isEmpty()) {
// Wildcard bind
serverAddress = new InetSocketAddress(portNum);
} else {
serverAddress = new InetSocketAddress(hiveHost, portNum);
}
TServerSocket thriftServerSocket = TSSLTransportFactory.getServerSocket(portNum, 0, serverAddress.getAddress(), params);
if (thriftServerSocket.getServerSocket() instanceof SSLServerSocket) {
List<String> sslVersionBlacklistLocal = new ArrayList<String>();
for (String sslVersion : sslVersionBlacklist) {
sslVersionBlacklistLocal.add(sslVersion.trim().toLowerCase());
}
SSLServerSocket sslServerSocket = (SSLServerSocket) thriftServerSocket.getServerSocket();
List<String> enabledProtocols = new ArrayList<String>();
for (String protocol : sslServerSocket.getEnabledProtocols()) {
if (sslVersionBlacklistLocal.contains(protocol.toLowerCase())) {
LOG.debug("Disabling SSL Protocol: " + protocol);
} else {
enabledProtocols.add(protocol);
}
}
sslServerSocket.setEnabledProtocols(enabledProtocols.toArray(new String[0]));
LOG.info("SSL Server Socket Enabled Protocols: " + Arrays.toString(sslServerSocket.getEnabledProtocols()));
}
return thriftServerSocket;
}
use of org.apache.thrift.transport.TServerSocket in project hive by apache.
the class TestHiveMetastore method start.
/**
* Starts a TestHiveMetastore with a provided connection pool size and HiveConf.
* @param conf The hive configuration to use
* @param poolSize The number of threads in the executor pool
*/
public void start(HiveConf conf, int poolSize) {
try {
hiveLocalDir = createTempDirectory("hive", asFileAttribute(fromString("rwxrwxrwx"))).toFile();
hiveWarehouseDir = new File(hiveLocalDir, "managed");
hiveExternalWarehouseDir = new File(hiveLocalDir, "external");
File derbyLogFile = new File(hiveLocalDir, "derby.log");
System.setProperty("derby.stream.error.file", derbyLogFile.getAbsolutePath());
// create and initialize HMS backend DB for ACID and non-ACID tables as well
MetastoreConf.setVar(conf, MetastoreConf.ConfVars.CONNECT_URL_KEY, "jdbc:derby:" + getDerbyPath() + ";create=true");
TestTxnDbUtil.prepDb(conf);
TServerSocket socket = new TServerSocket(0);
int port = socket.getServerSocket().getLocalPort();
initConf(conf, port);
this.hiveConf = conf;
this.server = newThriftServer(socket, poolSize, hiveConf);
this.executorService = Executors.newSingleThreadExecutor();
this.executorService.submit(() -> server.serve());
// in Hive3, setting this as a system prop ensures that it will be picked up whenever a new HiveConf is created
System.setProperty(HiveConf.ConfVars.METASTOREURIS.varname, hiveConf.getVar(HiveConf.ConfVars.METASTOREURIS));
this.clientPool = new HiveClientPool(1, hiveConf);
} catch (Exception e) {
throw new RuntimeException("Cannot start TestHiveMetastore", e);
}
}
Aggregations