airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scnakand...@apache.org
Subject [09/50] [abbrv] airavata git commit: Fix: hardcoded db-script name, Add: utility method to get filename given a directory path for db-script
Date Wed, 05 Apr 2017 19:10:33 GMT
Fix: hardcoded db-script name, Add: utility method to get filename given a directory path for
db-script


Project: http://git-wip-us.apache.org/repos/asf/airavata/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/c48a8ff4
Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/c48a8ff4
Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/c48a8ff4

Branch: refs/heads/develop
Commit: c48a8ff490f80a3279f4df0577ee32c70ea05441
Parents: be2c940
Author: Gourav Shenoy <shenoy.200@gmail.com>
Authored: Mon Apr 3 14:12:17 2017 -0400
Committer: Gourav Shenoy <shenoy.200@gmail.com>
Committed: Mon Apr 3 14:12:17 2017 -0400

----------------------------------------------------------------------
 .../registry/api/service/RegistryAPIServer.java |  7 ++++
 .../api/service/util/DatabaseCreator.java       | 36 +++++++++++++++++---
 2 files changed, 38 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/c48a8ff4/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
index 69cd7cd..991ace2 100644
--- 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
@@ -53,12 +53,19 @@ public class RegistryAPIServer implements IServer {
     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"));

http://git-wip-us.apache.org/repos/asf/airavata/blob/c48a8ff4/modules/registry/registry-server/registry-api-service/src/main/java/org/apache/airavata/registry/api/service/util/DatabaseCreator.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-server/registry-api-service/src/main/java/org/apache/airavata/registry/api/service/util/DatabaseCreator.java
b/modules/registry/registry-server/registry-api-service/src/main/java/org/apache/airavata/registry/api/service/util/DatabaseCreator.java
index 6d13904..2484ac7 100644
--- a/modules/registry/registry-server/registry-api-service/src/main/java/org/apache/airavata/registry/api/service/util/DatabaseCreator.java
+++ b/modules/registry/registry-server/registry-api-service/src/main/java/org/apache/airavata/registry/api/service/util/DatabaseCreator.java
@@ -29,6 +29,8 @@ import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.sql.*;
 import java.util.StringTokenizer;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
  * This class creates the database tables required for airavata with default configuration
this
@@ -264,11 +266,9 @@ public class DatabaseCreator {
             if(is == null) {
                 logger.info("Script file not found at " + dbscriptName + ". Uses default
database script file");
                 DatabaseType databaseType = DatabaseCreator.getDatabaseType(conn);
-                if(databaseType.equals(DatabaseType.derby)){
-                    is = DatabaseCreator.class.getClassLoader().getResourceAsStream("expcatalog-derby.sql");
-                }else if(databaseType.equals(DatabaseType.mysql)){
-                    is = DatabaseCreator.class.getClassLoader().getResourceAsStream("expcatalog-mysql.sql");
-                }
+                is = DatabaseCreator.class.getClassLoader().getResourceAsStream(
+                        getDBScriptFileName(databaseType, dbscriptName)
+                );
             }
             reader = new BufferedReader(new InputStreamReader(is));
             String line;
@@ -350,4 +350,30 @@ public class DatabaseCreator {
         }
         return true;
     }
+
+    /**
+     * Method will accept a filepath containing a database script (eg: /user/database_scripts/expcatalog.sql)
+     *  and return only the filename of the database script (eg: expcatalog.sql).
+     * @param databaseType
+     * @param scriptFilePath
+     * @return
+     */
+    private static String getDBScriptFileName(DatabaseType databaseType, String scriptFilePath)
{
+        // pattern: {dir_name}/{scriptfile_name}-{dbtype}.sql".
+        // Eg: database_scripts/expcatalog-derby.sql
+        final String scriptFilePattern = "(\\w*)(-" + databaseType.toString() + ".sql)";
+        final Pattern pattern = Pattern.compile(scriptFilePattern);
+        final Matcher matcher = pattern.matcher(scriptFilePath);
+        String dbScriptFileName = null;
+        // find a match
+        if (matcher.find()) {
+            dbScriptFileName = matcher.group();
+        }
+        return dbScriptFileName;
+    }
+
+//    public static void main(String[] args) throws Exception {
+//        System.out.println(DatabaseCreator.getDBScriptFileName(DatabaseType.derby, "db/db/expcatalog-derby.sql"));
+//        System.out.println(DatabaseCreator.getDBScriptFileName(DatabaseType.mysql, "/expcatalog-mysql.sql"));
+//    }
 }


Mime
View raw message