You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oozie.apache.org by tu...@apache.org on 2012/03/08 23:10:48 UTC

svn commit: r1298613 - in /incubator/oozie/trunk: docs/src/site/twiki/AG_Install.twiki docs/src/site/twiki/AG_OozieUpgrade.twiki release-log.txt tools/src/main/java/org/apache/oozie/tools/OozieDBCLI.java

Author: tucu
Date: Thu Mar  8 22:10:48 2012
New Revision: 1298613

URL: http://svn.apache.org/viewvc?rev=1298613&view=rev
Log:
OOZIE-750 enhance ooziedb tool not to require manual upgrade steps and not to require the -sqlfile option (tucu)

Modified:
    incubator/oozie/trunk/docs/src/site/twiki/AG_Install.twiki
    incubator/oozie/trunk/docs/src/site/twiki/AG_OozieUpgrade.twiki
    incubator/oozie/trunk/release-log.txt
    incubator/oozie/trunk/tools/src/main/java/org/apache/oozie/tools/OozieDBCLI.java

Modified: incubator/oozie/trunk/docs/src/site/twiki/AG_Install.twiki
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/docs/src/site/twiki/AG_Install.twiki?rev=1298613&r1=1298612&r2=1298613&view=diff
==============================================================================
--- incubator/oozie/trunk/docs/src/site/twiki/AG_Install.twiki (original)
+++ incubator/oozie/trunk/docs/src/site/twiki/AG_Install.twiki Thu Mar  8 22:10:48 2012
@@ -153,10 +153,16 @@ DONE
 
 Oozie DB has been created for Oozie version '3.2.0'
 
+The SQL commands have been written to: oozie.sql
+
 $
 </verbatim>
 
-If the '-run' option is not specified, only the SQL file with the command that would be executed will be created.
+NOTE: If using MySQL or Oracle, copy the corresponding JDBC driver JAR file to the =libext/= directory before running
+the =ooziedb.sh= command line tool.
+
+NOTE: If instead using the '-run' option, the '-sqlfile <FILE>' option is used, then all the
+database changes will be written to the specified file and the database won't be modified.
 
 If using HSQL there is no need to use the =ooziedb= command line tool as HSQL is an im-memory database. Use the
 following configuration properties in the oozie-site.xml:

Modified: incubator/oozie/trunk/docs/src/site/twiki/AG_OozieUpgrade.twiki
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/docs/src/site/twiki/AG_OozieUpgrade.twiki?rev=1298613&r1=1298612&r2=1298613&view=diff
==============================================================================
--- incubator/oozie/trunk/docs/src/site/twiki/AG_OozieUpgrade.twiki (original)
+++ incubator/oozie/trunk/docs/src/site/twiki/AG_OozieUpgrade.twiki Thu Mar  8 22:10:48 2012
@@ -18,7 +18,7 @@ Copy the oozie-site.xml from your curren
 
 Expand the new Oozie tarball in a new location.
 
-Edit the new oozie-site.xml setting all custom properties values from the old oozie-site.xml
+Edit the new =oozie-site.xml= setting all custom properties values from the old =oozie-site.xml=
 
 IMPORTANT: From Oozie 2.x to Oozie 3.x the names of the database configuration properties have
 changed. Their prefix has changed from =oozie.service.StoreService.*= to =oozie.service.JPAService.*=.
@@ -37,7 +37,7 @@ Once =oozie-site.xml= has been configure
 command line tool to upgrade the database:
 
 <verbatim>
-$ bin/ooziedb.sh upgrade -sqlfile oozie.sql -run
+$ bin/ooziedb.sh upgrade -run
 
 Validate DB Connection.
 DONE
@@ -56,19 +56,24 @@ Upgrade COORD_JOBS new columns default v
 DONE
 Upgrade COORD_JOBS & COORD_ACTIONS status values.
 DONE
-
-IMPORTANT: the following manual changes may have to be done in the Oozie DB
-
-  The 'execution_path' column in the 'WF_ACTIONS' table should be modified to be a VARCHAR2(1024)
-
+Table 'WF_ACTIONS' column 'execution_path', length changed to 1024
+DONE
 
 Oozie DB has been upgraded to Oozie version '3.2.0'
 
+The SQL commands have been written to: /tmp/ooziedb-5737263881793872034.sql
+
 $
 </verbatim>
 
 The new version of the Oozie server is ready to be started.
 
+NOTE: If using MySQL or Oracle, copy the corresponding JDBC driver JAR file to the =libext/= directory before running
+the =ooziedb.sh= command line tool.
+
+NOTE: If instead using the '-run' option, the '-sqlfile <FILE>' option is used, then all the
+database changes will be written to the specified file and the database won't be modified.
+
 ---+ Oozie Client Upgrade
 
 While older Oozie clients work with newer Oozie server, to have access to all the

Modified: incubator/oozie/trunk/release-log.txt
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/release-log.txt?rev=1298613&r1=1298612&r2=1298613&view=diff
==============================================================================
--- incubator/oozie/trunk/release-log.txt (original)
+++ incubator/oozie/trunk/release-log.txt Thu Mar  8 22:10:48 2012
@@ -1,5 +1,6 @@
 -- Oozie 3.2.0 release
 
+OOZIE-750 enhance ooziedb tool not to require manual upgrade steps and not to require the -sqlfile option (tucu)
 OOZIE-684 CoordChangeXCommand already used is thrown while executing interrupt commands (Mohamed via Mohammad)
 OOZIE-723 Getting rid of the unused Commands classes (mohamed via tucu)
 OOZIE-719 Missing java docs for several methods on ActionXCommand.java (Mohamed via Mohammad)

Modified: incubator/oozie/trunk/tools/src/main/java/org/apache/oozie/tools/OozieDBCLI.java
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/tools/src/main/java/org/apache/oozie/tools/OozieDBCLI.java?rev=1298613&r1=1298612&r2=1298613&view=diff
==============================================================================
--- incubator/oozie/trunk/tools/src/main/java/org/apache/oozie/tools/OozieDBCLI.java (original)
+++ incubator/oozie/trunk/tools/src/main/java/org/apache/oozie/tools/OozieDBCLI.java Thu Mar  8 22:10:48 2012
@@ -27,6 +27,7 @@ import org.apache.oozie.cli.CLIParser;
 import org.apache.oozie.service.JPAService;
 import org.apache.oozie.service.Services;
 
+import java.io.File;
 import java.io.FileWriter;
 import java.io.PrintWriter;
 import java.sql.Connection;
@@ -98,17 +99,30 @@ public class OozieDBCLI {
                 showVersion();
             }
             else {
-                if (!command.getCommandLine().hasOption(SQL_FILE_OPT)) {
-                    throw new Exception("'-sqlfile <FILE>' option must be specified");
+                if (!command.getCommandLine().hasOption(SQL_FILE_OPT) &&
+                    !command.getCommandLine().hasOption(RUN_OPT)) {
+                    throw new Exception("'-sqlfile <FILE>' or '-run' options must be specified");
                 }
+                CommandLine commandLine = command.getCommandLine();
+                String sqlFile = (commandLine.hasOption(SQL_FILE_OPT))
+                                 ? commandLine.getOptionValue(SQL_FILE_OPT)
+                                 : File.createTempFile("ooziedb-", ".sql").getAbsolutePath();
+                boolean run = commandLine.hasOption(RUN_OPT);
                 if (command.getName().equals(CREATE_CMD)) {
-                    createDB(command.getCommandLine());
+                    createDB(sqlFile, run);
                 }
                 if (command.getName().equals(UPGRADE_CMD)) {
-                    upgradeDB(command.getCommandLine());
+                    upgradeDB(sqlFile, run);
                 }
                 if (command.getName().equals(POST_UPGRADE_CMD)) {
-                    postUpgradeDB(command.getCommandLine());
+                    postUpgradeDB(sqlFile, run);
+                }
+                System.out.println();
+                System.out.println("The SQL commands have been written to: " + sqlFile);
+                if (!run) {
+                    System.out.println();
+                    System.out.println("WARN: The SQL commands have NOT been executed, you must use the '-run' option");
+                    System.out.println();
                 }
             }
             return 0;
@@ -149,12 +163,10 @@ public class OozieDBCLI {
         return jdbcConf;
     }
 
-    private void createDB(CommandLine commandLine) throws Exception {
+    private void createDB(String sqlFile, boolean run) throws Exception {
         validateConnection();
         validateDBSchema(false);
         verifyOozieSysTable(false);
-        String sqlFile = (commandLine.hasOption(SQL_FILE_OPT)) ? commandLine.getOptionValue(SQL_FILE_OPT) : null;
-        boolean run = commandLine.hasOption(RUN_OPT);
         createUpgradeDB(sqlFile, run, true);
         createOozieSysTable(sqlFile, run);
         System.out.println();
@@ -162,62 +174,46 @@ public class OozieDBCLI {
             System.out.println("Oozie DB has been created for Oozie version '" +
                                BuildInfo.getBuildInfo().getProperty(BuildInfo.BUILD_VERSION) + "'");
         }
-        else {
-            System.out.println("The SQL commands have NOT been executed, you must use the '-run' option");
-        }
         System.out.println();
     }
 
-    private void upgradeDB(CommandLine commandLine) throws Exception {
+    private void upgradeDB(String sqlFile, boolean run) throws Exception {
         // placeholder for later versions, to handle upgrades based on the OOZIE_SYS table.
-        upgradeDBTo32(commandLine);
+        upgradeDBTo32(sqlFile,  run);
     }
 
-    private void upgradeDBTo32(CommandLine commandLine) throws Exception {
+    private void upgradeDBTo32(String sqlFile, boolean run) throws Exception {
         validateConnection();
         validateDBSchema(true);
         verifyOozieSysTable(false);
         verifyDBState();
-        String sqlFile = (commandLine.hasOption(SQL_FILE_OPT)) ? commandLine.getOptionValue(SQL_FILE_OPT) : null;
-        boolean run = commandLine.hasOption(RUN_OPT);
         createUpgradeDB(sqlFile, run, false);
         createOozieSysTable(sqlFile, run);
         postUpgradeTasks(sqlFile, run, false);
-        manualStepsNotice();
+        ddlTweaks(sqlFile, run);
         if (run) {
             System.out.println();
             System.out.println("Oozie DB has been upgraded to Oozie version '" +
                                BuildInfo.getBuildInfo().getProperty(BuildInfo.BUILD_VERSION) + "'");
         }
-        else {
-            System.out.println();
-            System.out.println("The SQL commands have NOT been executed, you must use the '-run' option");
-        }
         System.out.println();
     }
 
-    private void postUpgradeDB(CommandLine commandLine) throws Exception {
-        postUpgradeDBTo32(commandLine);
+    private void postUpgradeDB(String sqlFile, boolean run) throws Exception {
+        postUpgradeDBTo32(sqlFile, run);
     }
 
-    private void postUpgradeDBTo32(CommandLine commandLine) throws Exception {
+    private void postUpgradeDBTo32(String sqlFile, boolean run) throws Exception {
         validateConnection();
         validateDBSchema(true);
         verifyOozieSysTable(true);
         verifyOozieDBVersion();
         verifyDBState();
-        String sqlFile = (commandLine.hasOption(SQL_FILE_OPT)) ? commandLine.getOptionValue(SQL_FILE_OPT) : null;
-        boolean run = commandLine.hasOption(RUN_OPT);
         postUpgradeTasks(sqlFile, run, true);
-        manualStepsNotice();
         if (run) {
             System.out.println();
             System.out.println("Post ugprade updates have been executed");
         }
-        else {
-            System.out.println();
-            System.out.println("Post ugprade updates have NOT been executed, you must use the '-run' option");
-        }
         System.out.println();
     }
 
@@ -243,10 +239,17 @@ public class OozieDBCLI {
         "select A.id from COORD_ACTIONS A, WF_JOBS B where A.external_id = B.id " +
         "and B.status = 'SUSPENDED' and A.status = 'RUNNING' )";
 
+    private String getDBVendor() throws Exception {
+        String url = getJdbcConf().get("url");
+        String vendor = url.substring("jdbc:".length());
+        vendor = vendor.substring(0, vendor.indexOf(":"));
+        return vendor;
+    }
+
     private void postUpgradeTasks(String sqlFile, boolean run, boolean force) throws Exception {
         PrintWriter writer = new PrintWriter(new FileWriter(sqlFile, true));
         writer.println();
-        boolean skipUpdates = getJdbcConf().get("url").contains("mysql");
+        boolean skipUpdates = getDBVendor().equals("mysql");
         Connection conn = (run) ? createConnection() : null;
         try {
             System.out.println("Post-upgrade COORD_JOBS new columns default values");
@@ -298,13 +301,44 @@ public class OozieDBCLI {
         }
     }
 
-    private void manualStepsNotice() {
-        System.out.println();
-        System.out.println("IMPORTANT: the following manual changes must be done in the Oozie DB");
-        System.out.println();
-        System.out.println(
-            "  The 'execution_path' column in the 'WF_ACTIONS' table has to be modified to be a VARCHAR2(1024)");
-        System.out.println();
+    private void ddlTweaks(String sqlFile, boolean run) throws Exception {
+        PrintWriter writer = new PrintWriter(new FileWriter(sqlFile, true));
+        writer.println();
+        String dbVendor = getDBVendor();
+        String ddlQuery = null;
+        if (dbVendor.equals("derby")) {
+            ddlQuery = "ALTER TABLE WF_ACTIONS ALTER COLUMN execution_path SET DATA TYPE VARCHAR(1024)";
+        }
+        else
+        if (dbVendor.equals("oracle")) {
+            ddlQuery = "ALTER TABLE WF_ACTIONS MODIFY (execution_path VARCHAR2(1024))";
+        }
+        else
+        if (dbVendor.equals("mysql")) {
+            ddlQuery = "ALTER TABLE WF_ACTIONS MODIFY execution_path VARCHAR(1024)";
+        }
+        else
+        if (dbVendor.equals("postgresql")) {
+            ddlQuery = "ALTER TABLE WF_ACTIONS ALTER COLUMN execution_path TYPE VARCHAR(1024)";
+        }
+        Connection conn = (run) ? createConnection() : null;
+        try {
+            System.out.println("Table 'WF_ACTIONS' column 'execution_path', length changed to 1024");
+            writer.println(ddlQuery + ";");
+            if (run) {
+                conn.setAutoCommit(true);
+                Statement st = conn.createStatement();
+                st.executeUpdate(ddlQuery);
+                st.close();
+            }
+            System.out.println("DONE");
+            writer.close();
+        }
+        finally {
+            if (run) {
+                conn.close();
+            }
+        }
     }
 
     private Connection createConnection() throws Exception {