airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chath...@apache.org
Subject svn commit: r1437639 - in /airavata/trunk/tools/registry-tool: README pom.xml src/main/java/org/apache/airavata/registry/tool/DBMigrator.java
Date Wed, 23 Jan 2013 19:20:54 GMT
Author: chathuri
Date: Wed Jan 23 19:20:53 2013
New Revision: 1437639

URL: http://svn.apache.org/viewvc?rev=1437639&view=rev
Log:
enabling to read parameters from command line

Added:
    airavata/trunk/tools/registry-tool/README
Modified:
    airavata/trunk/tools/registry-tool/pom.xml
    airavata/trunk/tools/registry-tool/src/main/java/org/apache/airavata/registry/tool/DBMigrator.java

Added: airavata/trunk/tools/registry-tool/README
URL: http://svn.apache.org/viewvc/airavata/trunk/tools/registry-tool/README?rev=1437639&view=auto
==============================================================================
--- airavata/trunk/tools/registry-tool/README (added)
+++ airavata/trunk/tools/registry-tool/README Wed Jan 23 19:20:53 2013
@@ -0,0 +1,9 @@
+0.5 => 0.6
+==============
+
+1. Build registry-tools
+2. Copy registry-tool-0.6-SNAPSHOT.jar and commons-cli-1.1.jar (you will find this in your
maven repository) to <AIRAVATA_HOME>/lib
+3. Copy db-migrate.sh file to <AIRAVATA_HOME>/bin
+4. Make sure 0.5 airavata database is up and running
+5. Run db-migrate.sh script file
+        ./db-migrate.sh -url jdbc:mysql://localhost:3306/persistent_data -user airavata -pwd
airavata
\ No newline at end of file

Modified: airavata/trunk/tools/registry-tool/pom.xml
URL: http://svn.apache.org/viewvc/airavata/trunk/tools/registry-tool/pom.xml?rev=1437639&r1=1437638&r2=1437639&view=diff
==============================================================================
--- airavata/trunk/tools/registry-tool/pom.xml (original)
+++ airavata/trunk/tools/registry-tool/pom.xml Wed Jan 23 19:20:53 2013
@@ -58,5 +58,10 @@
             <artifactId>jcl-over-slf4j</artifactId>
             <version>1.6.1</version>
         </dependency>
+        <dependency>
+            <groupId>commons-cli</groupId>
+            <artifactId>commons-cli</artifactId>
+            <version>1.1</version>
+        </dependency>
     </dependencies>
 </project>

Modified: airavata/trunk/tools/registry-tool/src/main/java/org/apache/airavata/registry/tool/DBMigrator.java
URL: http://svn.apache.org/viewvc/airavata/trunk/tools/registry-tool/src/main/java/org/apache/airavata/registry/tool/DBMigrator.java?rev=1437639&r1=1437638&r2=1437639&view=diff
==============================================================================
--- airavata/trunk/tools/registry-tool/src/main/java/org/apache/airavata/registry/tool/DBMigrator.java
(original)
+++ airavata/trunk/tools/registry-tool/src/main/java/org/apache/airavata/registry/tool/DBMigrator.java
Wed Jan 23 19:20:53 2013
@@ -21,6 +21,7 @@
 
 package org.apache.airavata.registry.tool;
 
+import org.apache.commons.cli.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -42,22 +43,32 @@ public class DBMigrator {
     private static final String INSERT_QUERY = "INSERT INTO CONFIGURATION (config_key, config_val,
expire_date, category_id) VALUES('" +
             REGISTRY_VERSION + "', '" + getIncrementedVersion(currentAiravataVersion) + "',
'" + getCurrentDate() +
             "','SYSTEM')";
-
+    private static String jdbcURL;
+    private static String jdbcUser;
+    private static String jdbcPwd;
 
     public static void main(String[] args) {
-         updateDB("jdbc:mysql://localhost:3306/persistent_data",
-                 "airavata",
-                 null);
+        parseArguments(args);
+        updateDB(jdbcURL, jdbcUser, jdbcPwd);
     }
 
     //we assume given database is up and running
     public static void updateDB (String jdbcUrl, String jdbcUser, String jdbcPwd){
         InputStream sqlStream = null;
         Scanner in = new Scanner(System.in);
+        if (jdbcUrl == null || jdbcUrl.equals("")){
+            System.out.println("Enter JDBC URL : ");
+            jdbcUrl = in.next();
+        }
+        if (jdbcUser == null || jdbcUser.equals("")){
+            System.out.println("Enter JDBC Username : ");
+            jdbcUser = in.next();
+        }
         if (jdbcPwd == null || jdbcPwd.equals("")){
             System.out.println("Enter JDBC password : ");
             jdbcPwd = in.next();
         }
+
         String dbType = getDBType(jdbcUrl);
         String jdbcDriver = null;
 
@@ -78,15 +89,15 @@ public class DBMigrator {
                 updateConfigTable(connection);
             }
         } catch (ClassNotFoundException e) {
-            e.printStackTrace();
+           logger.error("Unable to find SQL scripts..." , e);
         } catch (InstantiationException e) {
-            e.printStackTrace();
+            logger.error("Error while updating the database..." , e);
         } catch (IllegalAccessException e) {
-            e.printStackTrace();
+            logger.error("Error while updating the database..." , e);
         } catch (SQLException e) {
-            e.printStackTrace();
+            logger.error("Error while updating the database..." , e);
         } catch (Exception e) {
-            e.printStackTrace();
+            logger.error("Error while updating the database..." , e);
         }
     }
 
@@ -273,4 +284,26 @@ public class DBMigrator {
             }
         }
     }
+
+    public static void parseArguments(String[] args){
+        try{
+            Options options = new Options();
+            options.addOption("url", true , "JDBC URL");
+            options.addOption("user", true, "JDBC Username");
+            options.addOption("pwd", true, "JDBC Password");
+            CommandLineParser parser = new PosixParser();
+            CommandLine cmd = parser.parse( options, args);
+            jdbcURL = cmd.getOptionValue("url");
+            if (jdbcURL == null){
+                logger.info("You should enter JDBC URL and JDBC Credentials as parameters...");
+            }
+            jdbcUser = cmd.getOptionValue("user");
+            if (jdbcUser ==  null){
+                logger.info("You should enter JDBC URL and JDBC Credentials as parameters...");
+            }
+            jdbcPwd = cmd.getOptionValue("pwd");
+        } catch (ParseException e) {
+            logger.error("Error while reading command line parameters" , e);
+        }
+    }
 }



Mime
View raw message