Search in sources :

Example 11 with TServerSocket

use of org.apache.thrift.transport.TServerSocket in project airavata by apache.

the class AiravataAPIServer method startAiravataServer.

public void startAiravataServer(Airavata.Processor<Airavata.Iface> airavataAPIServer) throws AiravataSystemException {
    try {
        final String serverHost = ServerSettings.getSetting(Constants.API_SERVER_HOST, null);
        if (!ServerSettings.isTLSEnabled()) {
            final int serverPort = Integer.parseInt(ServerSettings.getSetting(Constants.API_SERVER_PORT, "8930"));
            TServerTransport serverTransport;
            if (ServerSettings.isAPIServerTLSEnabled()) {
                logger.info("Starting API Server with TLS Security..");
                String keystore = ServerSettings.getApiServerKeystore();
                String keystorePWD = ServerSettings.getApiServerKeystorePasswd();
                TSSLTransportFactory.TSSLTransportParameters tlsParams = new TSSLTransportFactory.TSSLTransportParameters();
                tlsParams.setKeyStore(keystore, keystorePWD);
                serverTransport = TSSLTransportFactory.getServerSocket(serverPort, 10000, InetAddress.getByName(serverHost), tlsParams);
            } else {
                if (serverHost == null) {
                    serverTransport = new TServerSocket(serverPort);
                } else {
                    InetSocketAddress inetSocketAddress = new InetSocketAddress(serverHost, serverPort);
                    serverTransport = new TServerSocket(inetSocketAddress);
                }
            }
            TThreadPoolServer.Args options = new TThreadPoolServer.Args(serverTransport);
            options.minWorkerThreads = Integer.parseInt(ServerSettings.getSetting(Constants.API_SERVER_MIN_THREADS, "50"));
            server = new TThreadPoolServer(options.processor(airavataAPIServer));
            new Thread() {

                public void run() {
                    server.serve();
                    setStatus(ServerStatus.STOPPED);
                    logger.info("Airavata API Server Stopped.");
                }
            }.start();
            new Thread() {

                public void run() {
                    while (!server.isServing()) {
                        try {
                            Thread.sleep(500);
                        } catch (InterruptedException e) {
                            break;
                        }
                    }
                    if (server.isServing()) {
                        setStatus(ServerStatus.STARTED);
                        logger.info("Starting Airavata API Server on Port " + serverPort);
                        logger.info("Listening to Airavata Clients ....");
                    }
                }
            }.start();
            logger.info("Started API Server ....");
        } else {
            /**
             ********start thrift server over TLS*****************
             */
            TSSLTransportFactory.TSSLTransportParameters TLSParams = new TSSLTransportFactory.TSSLTransportParameters();
            TLSParams.setKeyStore(ServerSettings.getKeyStorePath(), ServerSettings.getKeyStorePassword());
            TServerSocket TLSServerTransport = TSSLTransportFactory.getServerSocket(ServerSettings.getTLSServerPort(), ServerSettings.getTLSClientTimeout(), InetAddress.getByName(serverHost), TLSParams);
            TThreadPoolServer.Args settings = new TThreadPoolServer.Args(TLSServerTransport);
            settings.minWorkerThreads = Integer.parseInt(ServerSettings.getSetting(Constants.API_SERVER_MIN_THREADS, "50"));
            TLSServer = new TThreadPoolServer(settings.processor(airavataAPIServer));
            new Thread() {

                public void run() {
                    TLSServer.serve();
                    setStatus(ServerStatus.STOPPED);
                    logger.info("Airavata API Server over TLS Stopped.");
                }
            }.start();
            new Thread() {

                public void run() {
                    while (!TLSServer.isServing()) {
                        try {
                            Thread.sleep(500);
                        } catch (InterruptedException e) {
                            break;
                        }
                    }
                    if (TLSServer.isServing()) {
                        setStatus(ServerStatus.STARTED);
                    }
                }
            }.start();
            logger.info("API server started over TLS on Port: " + ServerSettings.getTLSServerPort() + " ...");
        }
        /*perform any security related initialization at the server startup, according to the underlying security
             manager implementation being used.*/
        AiravataSecurityManager securityManager = SecurityManagerFactory.getSecurityManager();
        securityManager.initializeSecurityInfra();
    } catch (TTransportException e) {
        logger.error(e.getMessage(), e);
        setStatus(ServerStatus.FAILED);
        logger.error("Failed to start API server ...");
        throw new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR);
    } catch (ApplicationSettingsException e) {
        logger.error(e.getMessage(), e);
        throw new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR);
    } catch (UnknownHostException e) {
        logger.error(e.getMessage(), e);
        throw new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR);
    } catch (AiravataSecurityException e) {
        logger.error(e.getMessage(), e);
        throw new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR);
    }
}
Also used : ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) UnknownHostException(java.net.UnknownHostException) InetSocketAddress(java.net.InetSocketAddress) AiravataSecurityManager(org.apache.airavata.service.security.AiravataSecurityManager) TTransportException(org.apache.thrift.transport.TTransportException) TSSLTransportFactory(org.apache.thrift.transport.TSSLTransportFactory) TServerTransport(org.apache.thrift.transport.TServerTransport) TServerSocket(org.apache.thrift.transport.TServerSocket) AiravataSystemException(org.apache.airavata.model.error.AiravataSystemException) TThreadPoolServer(org.apache.thrift.server.TThreadPoolServer) AiravataSecurityException(org.apache.airavata.security.AiravataSecurityException)

Example 12 with TServerSocket

use of org.apache.thrift.transport.TServerSocket in project airavata by apache.

the class SharingRegistryServer method start.

@Override
public void start() throws Exception {
    try {
        setStatus(IServer.ServerStatus.STARTING);
        final int serverPort = Integer.parseInt(ServerSettings.getSetting(SHARING_REG_SERVER_PORT));
        final String serverHost = ServerSettings.getSetting(SHARING_REG_SERVER_HOST);
        SharingRegistryService.Processor processor = new SharingRegistryService.Processor(new SharingRegistryServerHandler());
        TServerTransport serverTransport;
        if (serverHost == null) {
            serverTransport = new TServerSocket(serverPort);
        } else {
            InetSocketAddress inetSocketAddress = new InetSocketAddress(serverHost, serverPort);
            serverTransport = new TServerSocket(inetSocketAddress);
        }
        TThreadPoolServer.Args options = new TThreadPoolServer.Args(serverTransport);
        options.minWorkerThreads = 30;
        server = new TThreadPoolServer(options.processor(processor));
        new Thread() {

            public void run() {
                server.serve();
                setStatus(IServer.ServerStatus.STOPPED);
                logger.info("Sharing Registry Server Stopped.");
            }
        }.start();
        new Thread() {

            public void run() {
                while (!server.isServing()) {
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                        break;
                    }
                }
                if (server.isServing()) {
                    try {
                        logger.info("Register sharing service with DB Event publishers");
                        SharingServiceDBEventMessagingFactory.registerSharingServiceWithPublishers(Constants.PUBLISHERS);
                        logger.info("Start sharing service DB Event subscriber");
                        SharingServiceDBEventMessagingFactory.getDBEventSubscriber();
                    } catch (AiravataException | SharingRegistryException e) {
                        logger.error("Error starting sharing service. Error setting up DB event services.");
                        server.stop();
                    }
                    setStatus(IServer.ServerStatus.STARTED);
                    logger.info("Starting Sharing Registry Server on Port " + serverPort);
                    logger.info("Listening to Sharing Registry server clients ....");
                }
            }
        }.start();
    } catch (TTransportException e) {
        setStatus(IServer.ServerStatus.FAILED);
        throw new Exception("Error while starting the Sharing Registry service", e);
    }
}
Also used : SharingRegistryService(org.apache.airavata.sharing.registry.service.cpi.SharingRegistryService) InetSocketAddress(java.net.InetSocketAddress) TTransportException(org.apache.thrift.transport.TTransportException) TServerTransport(org.apache.thrift.transport.TServerTransport) SharingRegistryException(org.apache.airavata.sharing.registry.models.SharingRegistryException) TTransportException(org.apache.thrift.transport.TTransportException) AiravataException(org.apache.airavata.common.exception.AiravataException) TServerSocket(org.apache.thrift.transport.TServerSocket) TThreadPoolServer(org.apache.thrift.server.TThreadPoolServer)

Example 13 with TServerSocket

use of org.apache.thrift.transport.TServerSocket in project airavata by apache.

the class CredentialStoreServer method start.

@Override
public void start() throws Exception {
    try {
        setStatus(ServerStatus.STARTING);
        final int serverPort = Integer.parseInt(ServerSettings.getCredentialStoreServerPort());
        final String serverHost = ServerSettings.getCredentialStoreServerHost();
        CredentialStoreService.Processor processor = new CredentialStoreService.Processor(new CredentialStoreServerHandler());
        TServerTransport serverTransport;
        if (serverHost == null) {
            serverTransport = new TServerSocket(serverPort);
        } else {
            InetSocketAddress inetSocketAddress = new InetSocketAddress(serverHost, serverPort);
            serverTransport = new TServerSocket(inetSocketAddress);
        }
        TThreadPoolServer.Args options = new TThreadPoolServer.Args(serverTransport);
        options.minWorkerThreads = 30;
        server = new TThreadPoolServer(options.processor(processor));
        new Thread() {

            public void run() {
                server.serve();
                setStatus(ServerStatus.STOPPED);
                logger.info("Credential store Server Stopped.");
            }
        }.start();
        new Thread() {

            public void run() {
                while (!server.isServing()) {
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                        break;
                    }
                }
                if (server.isServing()) {
                    setStatus(ServerStatus.STARTED);
                    logger.info("Starting Credential store Server on Port " + serverPort);
                    logger.info("Listening to Credential store clients ....");
                }
            }
        }.start();
    } catch (TTransportException e) {
        setStatus(ServerStatus.FAILED);
        throw new Exception("Error while starting the credential store service", e);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) TTransportException(org.apache.thrift.transport.TTransportException) TServerTransport(org.apache.thrift.transport.TServerTransport) TTransportException(org.apache.thrift.transport.TTransportException) TServerSocket(org.apache.thrift.transport.TServerSocket) TThreadPoolServer(org.apache.thrift.server.TThreadPoolServer) CredentialStoreService(org.apache.airavata.credential.store.cpi.CredentialStoreService)

Example 14 with TServerSocket

use of org.apache.thrift.transport.TServerSocket in project airavata by apache.

the class RegistryAPIServer method StartRegistryServer.

public void StartRegistryServer(RegistryService.Processor<RegistryServerHandler> orchestratorServerHandlerProcessor) throws Exception {
    // creating experiment catalog db
    logger.info("Initializing ExperimentCatalog DB");
    ExperimentCatalogInitUtil.initializeDB();
    // creating app catalog db
    logger.info("Initializing AppCatalog DB");
    AppCatalogInitUtil.initializeDB();
    // creating workflow catalog db
    logger.info("Initializing WorkflowCatalog DB");
    WorkflowCatalogInitUtil.initializeDB();
    // creating replica catalog db
    logger.info("Initializing ReplicaCatalog DB");
    ReplicaCatalogInitUtil.initializeDB();
    final int serverPort = Integer.parseInt(ServerSettings.getSetting(Constants.REGISTRY_SERVER_PORT, "8960"));
    try {
        final String serverHost = ServerSettings.getSetting(Constants.REGISTRY_SERVER_HOST, null);
        TServerTransport serverTransport;
        if (serverHost == null) {
            serverTransport = new TServerSocket(serverPort);
        } else {
            InetSocketAddress inetSocketAddress = new InetSocketAddress(serverHost, serverPort);
            serverTransport = new TServerSocket(inetSocketAddress);
        }
        // thrift server start
        TThreadPoolServer.Args options = new TThreadPoolServer.Args(serverTransport);
        options.minWorkerThreads = Integer.parseInt(ServerSettings.getSetting(Constants.REGISTRY_SERVER_MIN_THREADS, "30"));
        server = new TThreadPoolServer(options.processor(orchestratorServerHandlerProcessor));
        new Thread() {

            public void run() {
                server.serve();
                setStatus(ServerStatus.STARTING);
                logger.info("Starting Registry Server ... ");
            }
        }.start();
        new Thread() {

            public void run() {
                while (!server.isServing()) {
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                        break;
                    }
                }
                if (server.isServing()) {
                    setStatus(ServerStatus.STARTED);
                    logger.info("Started Registry Server on Port " + serverPort + " ...");
                    // start db event handlers
                    if (!startDatabaseEventHandlers()) {
                        logger.error("Stopping Registry Server as DB event handlers failed to start!");
                        server.stop();
                    }
                }
            }
        }.start();
    } catch (TTransportException e) {
        logger.error(e.getMessage());
        setStatus(ServerStatus.FAILED);
        logger.error("Failed to start Registry server on port " + serverPort + " ...");
    }
}
Also used : TServerSocket(org.apache.thrift.transport.TServerSocket) InetSocketAddress(java.net.InetSocketAddress) TTransportException(org.apache.thrift.transport.TTransportException) TThreadPoolServer(org.apache.thrift.server.TThreadPoolServer) TServerTransport(org.apache.thrift.transport.TServerTransport)

Example 15 with TServerSocket

use of org.apache.thrift.transport.TServerSocket in project airavata by apache.

the class GfacServer method StartGfacServer.

public void StartGfacServer(GfacService.Processor<GfacServerHandler> gfacServerHandlerProcessor) throws Exception {
    final int serverPort = Integer.parseInt(ServerSettings.getGFacServerPort());
    try {
        final String serverHost = ServerSettings.getGfacServerHost();
        InetSocketAddress inetSocketAddress = new InetSocketAddress(serverHost, serverPort);
        TServerTransport serverTransport = new TServerSocket(inetSocketAddress);
        server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(gfacServerHandlerProcessor));
        new Thread() {

            public void run() {
                server.serve();
                setStatus(ServerStatus.STARTING);
                logger.info("Starting Gfac Server ...");
            }
        }.start();
        new Thread() {

            public void run() {
                while (!server.isServing()) {
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                        break;
                    }
                }
                if (server.isServing()) {
                    setStatus(IServer.ServerStatus.STARTED);
                    logger.info("Started Gfac Server on Port " + serverPort + " ...");
                }
            }
        }.start();
    } catch (TTransportException e) {
        logger.error(e.getMessage());
        setStatus(IServer.ServerStatus.FAILED);
        logger.error("Failed to start Gfac server on port " + serverPort + " ...");
    }
}
Also used : TServerSocket(org.apache.thrift.transport.TServerSocket) InetSocketAddress(java.net.InetSocketAddress) TTransportException(org.apache.thrift.transport.TTransportException) TThreadPoolServer(org.apache.thrift.server.TThreadPoolServer) TServerTransport(org.apache.thrift.transport.TServerTransport)

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