Search in sources :

Example 26 with TServerSocket

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 <<<");
}
Also used : TServerSocket(org.apache.thrift.transport.TServerSocket) TTransportException(org.apache.thrift.transport.TTransportException) IOException(java.io.IOException)

Example 27 with TServerSocket

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();
    }
}
Also used : TServerSocket(org.apache.thrift.transport.TServerSocket) TServer(org.apache.thrift.server.TServer) TThreadPoolServer(org.apache.thrift.server.TThreadPoolServer) TServerTransport(org.apache.thrift.transport.TServerTransport)

Example 28 with TServerSocket

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());
}
Also used : TServerSocket(org.apache.thrift.transport.TServerSocket) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TTransportFactory(org.apache.thrift.transport.TTransportFactory) TThreadPoolServer(org.apache.thrift.server.TThreadPoolServer)

Example 29 with TServerSocket

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;
}
Also used : TServerSocket(org.apache.thrift.transport.TServerSocket) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) TSSLTransportFactory(org.apache.thrift.transport.TSSLTransportFactory) SSLServerSocket(javax.net.ssl.SSLServerSocket)

Example 30 with TServerSocket

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);
    }
}
Also used : TServerSocket(org.apache.thrift.transport.TServerSocket) File(java.io.File) TException(org.apache.thrift.TException)

Aggregations

TServerSocket (org.apache.thrift.transport.TServerSocket)49 TThreadPoolServer (org.apache.thrift.server.TThreadPoolServer)30 TServerTransport (org.apache.thrift.transport.TServerTransport)20 TServer (org.apache.thrift.server.TServer)15 InetSocketAddress (java.net.InetSocketAddress)14 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)14 TTransportException (org.apache.thrift.transport.TTransportException)13 TTransportFactory (org.apache.thrift.transport.TTransportFactory)11 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)9 ArrayList (java.util.ArrayList)7 TProtocol (org.apache.thrift.protocol.TProtocol)7 TSimpleServer (org.apache.thrift.server.TSimpleServer)7 TTransport (org.apache.thrift.transport.TTransport)7 TProcessor (org.apache.thrift.TProcessor)6 TProtocolFactory (org.apache.thrift.protocol.TProtocolFactory)6 TServerEventHandler (org.apache.thrift.server.TServerEventHandler)6 IOException (java.io.IOException)5 ExecutorService (java.util.concurrent.ExecutorService)5 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)5 ServerContext (org.apache.thrift.server.ServerContext)5