adding registry server module
Project: http://git-wip-us.apache.org/repos/asf/airavata/repo Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/2d9fd253 Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/2d9fd253 Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/2d9fd253 Branch: refs/heads/develop Commit: 2d9fd253b6e348a4cfb83e64b235f6adabfe4fa6 Parents: f88859b Author: scnakandala <[email protected]> Authored: Mon Aug 8 14:14:09 2016 -0400 Committer: scnakandala <[email protected]> Committed: Mon Aug 8 14:14:09 2016 -0400 ---------------------------------------------------------------------- .../airavata/api/server/AiravataAPIServer.java | 3 + .../api/server/util/ReplicaCatalogInitUtil.java | 160 + .../main/resources/airavata-server.properties | 9 + modules/registry/pom.xml | 1 + modules/registry/registry-server/pom.xml | 28 + .../registry-api-service/pom.xml | 46 + .../registry/api/service/RegistryAPIServer.java | 163 + .../service/handler/RegistryServerHandler.java | 1677 + .../api/service/util/AppCatalogInitUtil.java | 168 + .../api/service/util/ConnectionPool.java | 383 + .../registry/api/service/util/Constants.java | 29 + .../api/service/util/DatabaseCreator.java | 353 + .../service/util/ExperimentCatalogInitUtil.java | 203 + .../registry/api/service/util/JdbcStorage.java | 176 + .../service/util/ReplicaCatalogInitUtil.java | 160 + .../service/util/WorkflowCatalogInitUtil.java | 160 + .../registry-server/registry-api-stubs/pom.xml | 26 + .../airavata/registry/api/RegistryService.java | 136899 ++++++++++++++++ .../api/exception/RegistryServiceException.java | 407 + .../registry/api/registry_apiConstants.java | 57 + .../component-cpis/generate-cpi-stubs.sh | 10 +- .../component-cpis/registry-api.thrift | 2072 + .../component-cpis/registry_api_errors.thrift | 32 + 23 files changed, 143221 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/airavata/blob/2d9fd253/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/AiravataAPIServer.java ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/AiravataAPIServer.java b/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/AiravataAPIServer.java index 01649ab..5290e83 100644 --- a/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/AiravataAPIServer.java +++ b/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/AiravataAPIServer.java @@ -72,6 +72,9 @@ public class AiravataAPIServer implements IServer{ WorkflowCatalogInitUtil.initializeDB(); // creating credential store db CredentialStoreInitUtil.initializeDB(); + // creating replica catalog db + ReplicaCatalogInitUtil.initializeDB(); + 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")); http://git-wip-us.apache.org/repos/asf/airavata/blob/2d9fd253/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/util/ReplicaCatalogInitUtil.java ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/util/ReplicaCatalogInitUtil.java b/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/util/ReplicaCatalogInitUtil.java new file mode 100644 index 0000000..4093d7f --- /dev/null +++ b/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/util/ReplicaCatalogInitUtil.java @@ -0,0 +1,160 @@ +/* +* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +* +*/ + +package org.apache.airavata.api.server.util; + +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.utils.ServerSettings; +import org.apache.derby.drda.NetworkServerControl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.net.InetAddress; +import java.net.URI; +import java.sql.Connection; +import java.sql.SQLException; + +public class ReplicaCatalogInitUtil { + private static final Logger logger = LoggerFactory.getLogger(ReplicaCatalogInitUtil.class); + public static final String REPLICA_CATALOG = "REPLICA_CATALOG"; + public static final String REPLICA_CATALOG_JDBC_DRIVER = "replicacatalog.jdbc.driver"; + public static final String REPLICA_CATALOG_JDBC_URL = "replicacatalog.jdbc.url"; + public static final String REPLICA_CATALOG_JDBC_USER = "replicacatalog.jdbc.user"; + public static final String REPLICA_CATALOG_JDBC_PASSWORD = "replicacatalog.jdbc.password"; + public static final String START_DERBY_ENABLE = "start.derby.server.mode"; + public static final String DERBY_SERVER_MODE_SYS_PROPERTY = "derby.drda.startNetworkServer"; + private static NetworkServerControl server; + private static JdbcStorage db; + private static String jdbcURl; + private static String jdbcDriver; + private static String jdbcUser; + private static String jdbcPassword; + + + public static void initializeDB() { +// System.setProperty("appcatalog.initialize.state", "0"); + try{ + jdbcDriver = ServerSettings.getSetting(REPLICA_CATALOG_JDBC_DRIVER); + jdbcURl = ServerSettings.getSetting(REPLICA_CATALOG_JDBC_URL); + jdbcUser = ServerSettings.getSetting(REPLICA_CATALOG_JDBC_USER); + jdbcPassword = ServerSettings.getSetting(REPLICA_CATALOG_JDBC_PASSWORD); + jdbcURl = jdbcURl + "?" + "user=" + jdbcUser + "&" + "password=" + jdbcPassword; + } catch (ApplicationSettingsException e) { + logger.error("Unable to read airavata server properties", e.getMessage()); + } + + 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(REPLICA_CATALOG, conn)) { + DatabaseCreator.createRegistryDatabase("database_scripts/replicacatalog", conn); + logger.info("New Database created for Replica Catalog !!! "); + } else { + logger.info("Database already created for Replica 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); + } + } +// System.setProperty("appcatalog.initialize.state", "1"); + } + + public static String getDBType(String jdbcUrl){ + try{ + String cleanURI = jdbcUrl.substring(5); + URI uri = URI.create(cleanURI); + return uri.getScheme(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + return null; + } + } + + public static boolean isDerbyStartEnabled(){ + try { + String s = ServerSettings.getSetting(START_DERBY_ENABLE); + if("true".equals(s)){ + return true; + } + } catch (ApplicationSettingsException e) { + logger.error("Unable to read airavata server properties", e.getMessage(), e); + return false; + } + return false; + } + + public static void startDerbyInServerMode() { + try { + System.setProperty(DERBY_SERVER_MODE_SYS_PROPERTY, "true"); + server = new NetworkServerControl(InetAddress.getByName("0.0.0.0"), + getPort(jdbcURl), + jdbcUser, jdbcPassword); + java.io.PrintWriter consoleWriter = new java.io.PrintWriter(System.out, true); + server.start(consoleWriter); + } catch (IOException e) { + logger.error("Unable to start Apache derby in the server mode! Check whether " + + "specified port is available"); + } catch (Exception e) { + logger.error("Unable to start Apache derby in the server mode! Check whether " + + "specified port is available"); + } + } + + public static void stopDerbyInServerMode() { + System.setProperty(DERBY_SERVER_MODE_SYS_PROPERTY, "false"); + if (server!=null){ + try { + server.shutdown(); + } catch (Exception e) { + logger.error("Error when stopping the derby server : "+e.getLocalizedMessage()); + } + } + } + + public static int getPort(String jdbcURL){ + try{ + String cleanURI = jdbcURL.substring(5); + URI uri = URI.create(cleanURI); + return uri.getPort(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + return -1; + } + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/2d9fd253/modules/configuration/server/src/main/resources/airavata-server.properties ---------------------------------------------------------------------- diff --git a/modules/configuration/server/src/main/resources/airavata-server.properties b/modules/configuration/server/src/main/resources/airavata-server.properties index 526c312..a2cb584 100644 --- a/modules/configuration/server/src/main/resources/airavata-server.properties +++ b/modules/configuration/server/src/main/resources/airavata-server.properties @@ -134,6 +134,15 @@ start.submitter=true embedded.mode=true enable.validation=true +########################################################################### +# Registry Server Configurations +########################################################################### +regserver=org.apache.airavata.registry.api.service.RegistryAPIServer +regserver.server.name=regserver-node0 +regserver.server.host=localhost +regserver.server.port=8960 +regserver.server.min.threads=50 + ########################################################################### # GFac Server Configurations http://git-wip-us.apache.org/repos/asf/airavata/blob/2d9fd253/modules/registry/pom.xml ---------------------------------------------------------------------- diff --git a/modules/registry/pom.xml b/modules/registry/pom.xml index d5623a0..f9fe9f5 100644 --- a/modules/registry/pom.xml +++ b/modules/registry/pom.xml @@ -33,6 +33,7 @@ <module>registry-cpi</module> <module>registry-core</module> <module>registry-tools</module> + <module>registry-server</module> </modules> </profile> </profiles> http://git-wip-us.apache.org/repos/asf/airavata/blob/2d9fd253/modules/registry/registry-server/pom.xml ---------------------------------------------------------------------- diff --git a/modules/registry/registry-server/pom.xml b/modules/registry/registry-server/pom.xml new file mode 100644 index 0000000..f2e138b --- /dev/null +++ b/modules/registry/registry-server/pom.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <artifactId>registry</artifactId> + <groupId>org.apache.airavata</groupId> + <version>0.17-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + <modelVersion>4.0.0</modelVersion> + + <artifactId>registry-server</artifactId> + <packaging>pom</packaging> + <modules> + <module>registry-api-service</module> + <module>registry-api-stubs</module> + </modules> + <dependencies> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>${org.slf4j.version}</version> + </dependency> + </dependencies> + + +</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/2d9fd253/modules/registry/registry-server/registry-api-service/pom.xml ---------------------------------------------------------------------- diff --git a/modules/registry/registry-server/registry-api-service/pom.xml b/modules/registry/registry-server/registry-api-service/pom.xml new file mode 100644 index 0000000..7cd8b29 --- /dev/null +++ b/modules/registry/registry-server/registry-api-service/pom.xml @@ -0,0 +1,46 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <artifactId>registry-server</artifactId> + <groupId>org.apache.airavata</groupId> + <version>0.17-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + + <artifactId>registry-api-service</artifactId> + + <dependencies> + <dependency> + <groupId>org.apache.airavata</groupId> + <artifactId>airavata-commons</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.airavata</groupId> + <artifactId>airavata-data-models</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.airavata</groupId> + <artifactId>registry-api-stubs</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.airavata</groupId> + <artifactId>airavata-registry-cpi</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.airavata</groupId> + <artifactId>airavata-registry-core</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.thrift</groupId> + <artifactId>libthrift</artifactId> + <version>${thrift.version}</version> + </dependency> + </dependencies> +</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/2d9fd253/modules/registry/registry-server/registry-api-service/src/main/java/org/apache/airavata/registry/api/service/RegistryAPIServer.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-server/registry-api-service/src/main/java/org/apache/airavata/registry/api/service/RegistryAPIServer.java b/modules/registry/registry-server/registry-api-service/src/main/java/org/apache/airavata/registry/api/service/RegistryAPIServer.java new file mode 100644 index 0000000..7213f80 --- /dev/null +++ b/modules/registry/registry-server/registry-api-service/src/main/java/org/apache/airavata/registry/api/service/RegistryAPIServer.java @@ -0,0 +1,163 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * +*/ +package org.apache.airavata.registry.api.service; + +import org.apache.airavata.common.utils.IServer; +import org.apache.airavata.common.utils.ServerSettings; +import org.apache.airavata.registry.api.RegistryService; +import org.apache.airavata.registry.api.service.handler.RegistryServerHandler; +import org.apache.airavata.registry.api.service.util.*; +import org.apache.thrift.server.TServer; +import org.apache.thrift.server.TThreadPoolServer; +import org.apache.thrift.transport.TServerSocket; +import org.apache.thrift.transport.TServerTransport; +import org.apache.thrift.transport.TTransportException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.net.InetSocketAddress; + +public class RegistryAPIServer implements IServer { + private final static Logger logger = LoggerFactory.getLogger(RegistryAPIServer.class); + + private static final String SERVER_NAME = "Registry API Server"; + private static final String SERVER_VERSION = "1.0"; + + private ServerStatus status; + + private TServer server; + + public RegistryAPIServer() { + setStatus(ServerStatus.STOPPED); + } + + public void StartRegistryServer(RegistryService.Processor<RegistryServerHandler> orchestratorServerHandlerProcessor) + throws Exception { + // creating experiment catalog db + ExperimentCatalogInitUtil.initializeDB(); + // creating app catalog db + AppCatalogInitUtil.initializeDB(); + // creating workflow catalog db + WorkflowCatalogInitUtil.initializeDB(); + // creating replica catalog 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); + } + + 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(); + } catch (TTransportException e) { + logger.error(e.getMessage()); + setStatus(ServerStatus.FAILED); + logger.error("Failed to start Registry server on port " + serverPort + " ..."); + } + } + + public static void main(String[] args) { + try { + new RegistryAPIServer().start(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + } + } + + @Override + public void start() throws Exception { + setStatus(ServerStatus.STARTING); + RegistryService.Processor<RegistryServerHandler> orchestratorService = + new RegistryService.Processor<RegistryServerHandler>(new RegistryServerHandler()); + StartRegistryServer(orchestratorService); + } + + @Override + public void stop() throws Exception { + if (server!=null && server.isServing()){ + setStatus(ServerStatus.STOPING); + server.stop(); + } + + } + + @Override + public void restart() throws Exception { + stop(); + start(); + } + + @Override + public void configure() throws Exception { + // TODO Auto-generated method stub + + } + + @Override + public ServerStatus getStatus() throws Exception { + return status; + } + + private void setStatus(ServerStatus stat){ + status=stat; + status.updateTime(); + } + + @Override + public String getName() { + return SERVER_NAME; + } + + @Override + public String getVersion() { + return SERVER_VERSION; + } + +} \ No newline at end of file
