Search in sources :

Example 91 with TTransport

use of org.apache.thrift.transport.TTransport in project hive by apache.

the class HiveMetaStore method startMetaStore.

/**
 * Start Metastore based on a passed {@link HadoopThriftAuthBridge}
 *
 * @param port
 * @param bridge
 * @param conf
 *          configuration overrides
 * @throws Throwable
 */
public static void startMetaStore(int port, HadoopThriftAuthBridge bridge, Configuration conf, Lock startLock, Condition startCondition, AtomicBoolean startedServing) throws Throwable {
    try {
        isMetaStoreRemote = true;
        // Server will create new threads up to max as necessary. After an idle
        // period, it will destroy threads to keep the number of threads in the
        // pool to min.
        long maxMessageSize = MetastoreConf.getLongVar(conf, ConfVars.SERVER_MAX_MESSAGE_SIZE);
        int minWorkerThreads = MetastoreConf.getIntVar(conf, ConfVars.SERVER_MIN_THREADS);
        int maxWorkerThreads = MetastoreConf.getIntVar(conf, ConfVars.SERVER_MAX_THREADS);
        boolean tcpKeepAlive = MetastoreConf.getBoolVar(conf, ConfVars.TCP_KEEP_ALIVE);
        boolean useFramedTransport = MetastoreConf.getBoolVar(conf, ConfVars.USE_THRIFT_FRAMED_TRANSPORT);
        boolean useCompactProtocol = MetastoreConf.getBoolVar(conf, ConfVars.USE_THRIFT_COMPACT_PROTOCOL);
        boolean useSSL = MetastoreConf.getBoolVar(conf, ConfVars.USE_SSL);
        useSasl = MetastoreConf.getBoolVar(conf, ConfVars.USE_THRIFT_SASL);
        if (useSasl) {
            // we are in secure mode. Login using keytab
            String kerberosName = SecurityUtil.getServerPrincipal(MetastoreConf.getVar(conf, ConfVars.KERBEROS_PRINCIPAL), "0.0.0.0");
            String keyTabFile = MetastoreConf.getVar(conf, ConfVars.KERBEROS_KEYTAB_FILE);
            UserGroupInformation.loginUserFromKeytab(kerberosName, keyTabFile);
        }
        TProcessor processor;
        TTransportFactory transFactory;
        final TProtocolFactory protocolFactory;
        final TProtocolFactory inputProtoFactory;
        if (useCompactProtocol) {
            protocolFactory = new TCompactProtocol.Factory();
            inputProtoFactory = new TCompactProtocol.Factory(maxMessageSize, maxMessageSize);
        } else {
            protocolFactory = new TBinaryProtocol.Factory();
            inputProtoFactory = new TBinaryProtocol.Factory(true, true, maxMessageSize, maxMessageSize);
        }
        HMSHandler baseHandler = new HiveMetaStore.HMSHandler("new db based metaserver", conf, false);
        IHMSHandler handler = newRetryingHMSHandler(baseHandler, conf);
        // Initialize materializations invalidation cache
        MaterializationsInvalidationCache.get().init(conf, handler);
        TServerSocket serverSocket;
        if (useSasl) {
            // we are in secure mode.
            if (useFramedTransport) {
                throw new HiveMetaException("Framed transport is not supported with SASL enabled.");
            }
            saslServer = bridge.createServer(MetastoreConf.getVar(conf, ConfVars.KERBEROS_KEYTAB_FILE), MetastoreConf.getVar(conf, ConfVars.KERBEROS_PRINCIPAL), MetastoreConf.getVar(conf, ConfVars.CLIENT_KERBEROS_PRINCIPAL));
            // Start delegation token manager
            delegationTokenManager = new MetastoreDelegationTokenManager();
            delegationTokenManager.startDelegationTokenSecretManager(conf, baseHandler, HadoopThriftAuthBridge.Server.ServerMode.METASTORE);
            saslServer.setSecretManager(delegationTokenManager.getSecretManager());
            transFactory = saslServer.createTransportFactory(MetaStoreUtils.getMetaStoreSaslProperties(conf, useSSL));
            processor = saslServer.wrapProcessor(new ThriftHiveMetastore.Processor<>(handler));
            LOG.info("Starting DB backed MetaStore Server in Secure Mode");
        } else {
            // we are in unsecure mode.
            if (MetastoreConf.getBoolVar(conf, ConfVars.EXECUTE_SET_UGI)) {
                transFactory = useFramedTransport ? new ChainedTTransportFactory(new TFramedTransport.Factory(), new TUGIContainingTransport.Factory()) : new TUGIContainingTransport.Factory();
                processor = new TUGIBasedProcessor<>(handler);
                LOG.info("Starting DB backed MetaStore Server with SetUGI enabled");
            } else {
                transFactory = useFramedTransport ? new TFramedTransport.Factory() : new TTransportFactory();
                processor = new TSetIpAddressProcessor<>(handler);
                LOG.info("Starting DB backed MetaStore Server");
            }
        }
        if (!useSSL) {
            serverSocket = SecurityUtils.getServerSocket(null, port);
        } else {
            String keyStorePath = MetastoreConf.getVar(conf, ConfVars.SSL_KEYSTORE_PATH).trim();
            if (keyStorePath.isEmpty()) {
                throw new IllegalArgumentException(ConfVars.SSL_KEYSTORE_PATH.toString() + " Not configured for SSL connection");
            }
            String keyStorePassword = MetastoreConf.getPassword(conf, MetastoreConf.ConfVars.SSL_KEYSTORE_PASSWORD);
            // enable SSL support for HMS
            List<String> sslVersionBlacklist = new ArrayList<>();
            for (String sslVersion : MetastoreConf.getVar(conf, ConfVars.SSL_PROTOCOL_BLACKLIST).split(",")) {
                sslVersionBlacklist.add(sslVersion);
            }
            serverSocket = SecurityUtils.getServerSSLSocket(null, port, keyStorePath, keyStorePassword, sslVersionBlacklist);
        }
        if (tcpKeepAlive) {
            serverSocket = new TServerSocketKeepAlive(serverSocket);
        }
        // Metrics will have already been initialized if we're using them since HMSHandler
        // initializes them.
        openConnections = Metrics.getOrCreateGauge(MetricsConstants.OPEN_CONNECTIONS);
        TThreadPoolServer.Args args = new TThreadPoolServer.Args(serverSocket).processor(processor).transportFactory(transFactory).protocolFactory(protocolFactory).inputProtocolFactory(inputProtoFactory).minWorkerThreads(minWorkerThreads).maxWorkerThreads(maxWorkerThreads);
        TServer tServer = new TThreadPoolServer(args);
        TServerEventHandler tServerEventHandler = new TServerEventHandler() {

            @Override
            public void preServe() {
            }

            @Override
            public ServerContext createContext(TProtocol tProtocol, TProtocol tProtocol1) {
                openConnections.incrementAndGet();
                return null;
            }

            @Override
            public void deleteContext(ServerContext serverContext, TProtocol tProtocol, TProtocol tProtocol1) {
                openConnections.decrementAndGet();
                // If the IMetaStoreClient#close was called, HMSHandler#shutdown would have already
                // cleaned up thread local RawStore. Otherwise, do it now.
                cleanupRawStore();
            }

            @Override
            public void processContext(ServerContext serverContext, TTransport tTransport, TTransport tTransport1) {
            }
        };
        tServer.setServerEventHandler(tServerEventHandler);
        HMSHandler.LOG.info("Started the new metaserver on port [" + port + "]...");
        HMSHandler.LOG.info("Options.minWorkerThreads = " + minWorkerThreads);
        HMSHandler.LOG.info("Options.maxWorkerThreads = " + maxWorkerThreads);
        HMSHandler.LOG.info("TCP keepalive = " + tcpKeepAlive);
        HMSHandler.LOG.info("Enable SSL = " + useSSL);
        if (startLock != null) {
            signalOtherThreadsToStart(tServer, startLock, startCondition, startedServing);
        }
        tServer.serve();
    } catch (Throwable x) {
        x.printStackTrace();
        HMSHandler.LOG.error(StringUtils.stringifyException(x));
        throw x;
    }
}
Also used : TProtocolFactory(org.apache.thrift.protocol.TProtocolFactory) TProcessor(org.apache.thrift.TProcessor) TServerEventHandler(org.apache.thrift.server.TServerEventHandler) TServer(org.apache.thrift.server.TServer) ArrayList(java.util.ArrayList) TProtocolFactory(org.apache.thrift.protocol.TProtocolFactory) LoggerFactory(org.slf4j.LoggerFactory) TTransportFactory(org.apache.thrift.transport.TTransportFactory) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol) TServerSocket(org.apache.thrift.transport.TServerSocket) TProcessor(org.apache.thrift.TProcessor) TProtocol(org.apache.thrift.protocol.TProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) TUGIContainingTransport(org.apache.hadoop.hive.metastore.security.TUGIContainingTransport) TTransportFactory(org.apache.thrift.transport.TTransportFactory) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) ServerContext(org.apache.thrift.server.ServerContext) TTransport(org.apache.thrift.transport.TTransport) TThreadPoolServer(org.apache.thrift.server.TThreadPoolServer) MetastoreDelegationTokenManager(org.apache.hadoop.hive.metastore.security.MetastoreDelegationTokenManager)

Example 92 with TTransport

use of org.apache.thrift.transport.TTransport in project hive by apache.

the class TSetIpAddressProcessor method setIpAddress.

protected void setIpAddress(final TProtocol in) {
    TTransport transport = in.getTransport();
    if (!(transport instanceof TSocket)) {
        return;
    }
    setIpAddress(((TSocket) transport).getSocket());
}
Also used : TTransport(org.apache.thrift.transport.TTransport) TSocket(org.apache.thrift.transport.TSocket)

Example 93 with TTransport

use of org.apache.thrift.transport.TTransport in project vcell by virtualcell.

the class BioformatsImageDatasetReader method readImageDatasetFromMultiFiles.

@Override
public ImageDataset readImageDatasetFromMultiFiles(File[] files, ClientTaskStatusSupport status, boolean isTimeSeries, double timeInterval) throws Exception {
    try (TTransport transport = new TSocket("localhost", port)) {
        transport.open();
        TProtocol protocol = new TBinaryProtocol(transport);
        ImageDatasetService.Client client = new ImageDatasetService.Client(protocol);
        ArrayList<String> fileList = new ArrayList<String>();
        for (File f : files) {
            fileList.add(f.getAbsolutePath());
        }
        org.vcell.imagedataset.ImageDataset t_imageDataset = client.readImageDatasetFromMultiFiles(fileList, isTimeSeries, timeInterval);
        ImageDataset imageDataset = getImageDataset(t_imageDataset);
        return imageDataset;
    }
}
Also used : ImageDataset(cbit.vcell.VirtualMicroscopy.ImageDataset) ArrayList(java.util.ArrayList) ImageDatasetService(org.vcell.imagedataset.ImageDatasetService) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TTransport(org.apache.thrift.transport.TTransport) File(java.io.File) TSocket(org.apache.thrift.transport.TSocket)

Example 94 with TTransport

use of org.apache.thrift.transport.TTransport in project vcell by virtualcell.

the class BioformatsImageDatasetReader method getImageSizeInfoForceZ.

@Override
public ImageSizeInfo getImageSizeInfoForceZ(String fileName, int forceZSize) throws Exception {
    try (TTransport transport = new TSocket("localhost", port)) {
        transport.open();
        TProtocol protocol = new TBinaryProtocol(transport);
        ImageDatasetService.Client client = new ImageDatasetService.Client(protocol);
        org.vcell.imagedataset.ImageSizeInfo t_imageSizeInfo = client.getImageSizeInfoForceZ(fileName, forceZSize);
        org.vcell.imagedataset.ISize t_size = t_imageSizeInfo.getISize();
        double[] timePoints = new double[t_imageSizeInfo.getTimePoints().size()];
        for (int i = 0; i < t_imageSizeInfo.getTimePointsSize(); i++) {
            timePoints[i] = t_imageSizeInfo.getTimePoints().get(i);
        }
        ImageSizeInfo imageSizeInfo = new ImageSizeInfo(t_imageSizeInfo.imagePath, new ISize(t_size.getX(), t_size.getY(), t_size.getZ()), t_imageSizeInfo.numChannels, timePoints, t_imageSizeInfo.selectedTimeIndex);
        return imageSizeInfo;
    }
}
Also used : ISize(org.vcell.util.ISize) ImageSizeInfo(cbit.image.ImageSizeInfo) ImageDatasetService(org.vcell.imagedataset.ImageDatasetService) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TTransport(org.apache.thrift.transport.TTransport) TSocket(org.apache.thrift.transport.TSocket)

Example 95 with TTransport

use of org.apache.thrift.transport.TTransport in project tech by ffyyhh995511.

the class RedisDistributedLock method serverTimeMillis.

/**
 * 获取服务器时间
 * @return
 */
private long serverTimeMillis() {
    long time = 0;
    TTransport transport = null;
    try {
        // 设置传输通道,对于非阻塞服务,需要使用TFramedTransport,它将数据分块发送
        transport = new TFramedTransport(new TSocket("192.168.11.173", 7911));
        transport.open();
        // 使用高密度二进制协议
        TProtocol protocol = new TCompactProtocol(transport);
        // 创建Client
        ServerTime.Client client = new ServerTime.Client(protocol);
        time = client.getTime();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (transport != null) {
            // 关闭资源
            transport.close();
        }
    }
    return time;
}
Also used : TProtocol(org.apache.thrift.protocol.TProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) TTransport(org.apache.thrift.transport.TTransport) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol) ServerTime(org.tech.commons.model.ServerTime) IOException(java.io.IOException) TSocket(org.apache.thrift.transport.TSocket)

Aggregations

TTransport (org.apache.thrift.transport.TTransport)99 TSocket (org.apache.thrift.transport.TSocket)43 TProtocol (org.apache.thrift.protocol.TProtocol)42 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)36 TFramedTransport (org.apache.thrift.transport.TFramedTransport)28 TTransportException (org.apache.thrift.transport.TTransportException)20 Test (org.junit.Test)20 TException (org.apache.thrift.TException)18 IOException (java.io.IOException)12 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)10 ArrayList (java.util.ArrayList)9 TIOStreamTransport (org.apache.thrift.transport.TIOStreamTransport)8 HashMap (java.util.HashMap)6 Socket (java.net.Socket)5 TCLIService (org.apache.hive.service.rpc.thrift.TCLIService)5 THttpClient (org.apache.thrift.transport.THttpClient)4 TSaslClientTransport (org.apache.thrift.transport.TSaslClientTransport)4 ChannelBuffer (com.alibaba.dubbo.remoting.buffer.ChannelBuffer)3 Request (com.alibaba.dubbo.remoting.exchange.Request)3 Demo (com.alibaba.dubbo.rpc.gen.thrift.Demo)3