Search in sources :

Example 1 with SharingRegistryException

use of org.apache.airavata.sharing.registry.models.SharingRegistryException in project airavata by apache.

the class JPAUtils method initializeDB.

public static void initializeDB() throws SharingRegistryException {
    jdbcDriver = readServerProperties(SHARING_REG_JDBC_DRIVER);
    jdbcURl = readServerProperties(SHARING_REG_JDBC_URL);
    jdbcUser = readServerProperties(SHARING_REG_JDBC_USER);
    jdbcPassword = readServerProperties(SHARING_REG_JDBC_PWD);
    jdbcURl = jdbcURl + "?" + "user=" + jdbcUser + "&" + "password=" + jdbcPassword;
    if (getDBType(jdbcURl).equals("derby") && isDerbyStartEnabled()) {
        startDerbyInServerMode();
    }
    db = new JdbcStorage(10, 50, jdbcURl, jdbcDriver, true);
    Connection conn = null;
    try {
        conn = db.connect();
        if (!DatabaseCreator.isDatabaseStructureCreated(CONFIGURATION, conn)) {
            DatabaseCreator.createRegistryDatabase("database_scripts/sharing-registry", conn);
            logger.info("New Database created for Sharing Catalog !!! ");
        } else {
            logger.info("Database already created for Sharing Catalog !!!");
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new RuntimeException("Database failure", e);
    } finally {
        db.closeConnection(conn);
        try {
            if (conn != null) {
                if (!conn.getAutoCommit()) {
                    conn.commit();
                }
                conn.close();
            }
        } catch (SQLException e) {
            logger.error("Error while closing database connection...", e.getMessage(), e);
        }
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) SharingRegistryException(org.apache.airavata.sharing.registry.models.SharingRegistryException) IOException(java.io.IOException) SQLException(java.sql.SQLException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 2 with SharingRegistryException

use of org.apache.airavata.sharing.registry.models.SharingRegistryException 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 3 with SharingRegistryException

use of org.apache.airavata.sharing.registry.models.SharingRegistryException in project airavata by apache.

the class SharingRegistryServiceClientFactory method createSharingRegistryClient.

public static SharingRegistryService.Client createSharingRegistryClient(String serverHost, int serverPort) throws SharingRegistryException {
    try {
        TSocket e = new TSocket(serverHost, serverPort);
        e.open();
        TBinaryProtocol protocol = new TBinaryProtocol(e);
        return new SharingRegistryService.Client(protocol);
    } catch (TTransportException var4) {
        logger.error("failed to create sharing registry client", var4);
        throw new SharingRegistryException();
    }
}
Also used : TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TTransportException(org.apache.thrift.transport.TTransportException) TSocket(org.apache.thrift.transport.TSocket) SharingRegistryException(org.apache.airavata.sharing.registry.models.SharingRegistryException)

Aggregations

SharingRegistryException (org.apache.airavata.sharing.registry.models.SharingRegistryException)3 TTransportException (org.apache.thrift.transport.TTransportException)2 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 AiravataException (org.apache.airavata.common.exception.AiravataException)1 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)1 SharingRegistryService (org.apache.airavata.sharing.registry.service.cpi.SharingRegistryService)1 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)1 TThreadPoolServer (org.apache.thrift.server.TThreadPoolServer)1 TServerSocket (org.apache.thrift.transport.TServerSocket)1 TServerTransport (org.apache.thrift.transport.TServerTransport)1 TSocket (org.apache.thrift.transport.TSocket)1