You are viewing a plain text version of this content. The canonical link for it is here.
Posted to kalumet-commits@incubator.apache.org by jb...@apache.org on 2011/12/08 18:38:39 UTC

svn commit: r1212027 - in /incubator/kalumet/trunk: agent/src/main/java/org/apache/kalumet/agent/updater/ common/src/main/java/org/apache/kalumet/ utils/src/main/java/org/apache/kalumet/utils/

Author: jbonofre
Date: Thu Dec  8 18:38:39 2011
New Revision: 1212027

URL: http://svn.apache.org/viewvc?rev=1212027&view=rev
Log:
Remove output when executing SQL scripts

Modified:
    incubator/kalumet/trunk/agent/src/main/java/org/apache/kalumet/agent/updater/SoftwareUpdater.java
    incubator/kalumet/trunk/agent/src/main/java/org/apache/kalumet/agent/updater/SqlScriptUpdater.java
    incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/FileManipulator.java
    incubator/kalumet/trunk/utils/src/main/java/org/apache/kalumet/utils/FileUtils.java

Modified: incubator/kalumet/trunk/agent/src/main/java/org/apache/kalumet/agent/updater/SoftwareUpdater.java
URL: http://svn.apache.org/viewvc/incubator/kalumet/trunk/agent/src/main/java/org/apache/kalumet/agent/updater/SoftwareUpdater.java?rev=1212027&r1=1212026&r2=1212027&view=diff
==============================================================================
--- incubator/kalumet/trunk/agent/src/main/java/org/apache/kalumet/agent/updater/SoftwareUpdater.java (original)
+++ incubator/kalumet/trunk/agent/src/main/java/org/apache/kalumet/agent/updater/SoftwareUpdater.java Thu Dec  8 18:38:39 2011
@@ -908,7 +908,7 @@ public class SoftwareUpdater {
                             String output = SqlScriptUtils.executeUsingCommand(singleSqlScriptRuntime, command);
                             updateLog.addUpdateMessage(new UpdateMessage("info", "SQL script " + name + " executed: " + output));
                             EventUtils.post(environment, "UPDATE", "SQL script " + name + " executed: " + output);
-                            LOGGER.info("SQL script {} executed: {}", name, output);
+                            LOGGER.info("SQL script {} executed succesfully", name);
                         } else {
                             // execute SQL script using JDBC
                             String user = null;
@@ -990,7 +990,7 @@ public class SoftwareUpdater {
                         String output = SqlScriptUtils.executeUsingCommand(sqlScriptRuntime, command);
                         updateLog.addUpdateMessage(new UpdateMessage("info", "SQL script " + sqlScript.getName() + " executed: " + output));
                         EventUtils.post(environment, "UPDATE", "SQL script " + sqlScript.getName() + " executed: " + output);
-                        LOGGER.info("SQL script " + sqlScript.getName() + " executed: " + output);
+                        LOGGER.info("SQL script {} executed successfully", sqlScript.getName());
                     } else {
                         // execute SQL script using JDBC
                         LOGGER.info("Executing SQL script using JDBC");
@@ -1035,7 +1035,7 @@ public class SoftwareUpdater {
                     updateLog.setUpdated(true);
                     updateLog.addUpdateMessage(new UpdateMessage("info", "SQL script " + sqlScript.getName() + " executed"));
                     EventUtils.post(environment, "UPDATE", "SQL script " + sqlScript.getName() + " executed");
-                    LOGGER.info("SQL script " + sqlScript.getName() + " executed");
+                    LOGGER.info("SQL script {} executed sucessfully", sqlScript.getName());
                 }
             } catch (Exception e) {
                 // SQL script execution failed, delete SQL script from the cache

Modified: incubator/kalumet/trunk/agent/src/main/java/org/apache/kalumet/agent/updater/SqlScriptUpdater.java
URL: http://svn.apache.org/viewvc/incubator/kalumet/trunk/agent/src/main/java/org/apache/kalumet/agent/updater/SqlScriptUpdater.java?rev=1212027&r1=1212026&r2=1212027&view=diff
==============================================================================
--- incubator/kalumet/trunk/agent/src/main/java/org/apache/kalumet/agent/updater/SqlScriptUpdater.java (original)
+++ incubator/kalumet/trunk/agent/src/main/java/org/apache/kalumet/agent/updater/SqlScriptUpdater.java Thu Dec  8 18:38:39 2011
@@ -129,8 +129,8 @@ public class SqlScriptUpdater {
                             String command = VariableUtils.replace(database.getSqlCommand(), environment.getVariables());
                             String output = SqlScriptUtils.executeUsingCommand(singleSqlScriptRuntime, command);
                             updateLog.addUpdateMessage(new UpdateMessage("info", "SQL script " + name + " executed: " + output));
-                            EventUtils.post(environment, "UPDATE", "SQL script " + name + " executed: " + output);
-                            LOGGER.info("SQL script " + name + " executed: " + output);
+                            EventUtils.post(environment, "UPDATE", "SQL script " + name + " executed:" + output);
+                            LOGGER.info("SQL script " + name + " executed successfully");
                         } else {
                             // execute SQL script using JDBC
                             String user = null;
@@ -253,66 +253,6 @@ public class SqlScriptUpdater {
             Mapping mapping = (Mapping) mappingIterator.next();
             FileManipulator.searchAndReplace(mapping.getKey(), VariableUtils.replace(mapping.getValue(), environment.getVariables()), sqlScriptCache);
         }
-
-        // compare the SQL script with the target one
-        try {
-            if (sqlScript.isForce() || (!fileManipulator.contentEquals(sqlScriptCache, sqlScriptRuntime))) {
-                // the SQL script needs to be updated and executed
-                // copy the SQL script to the target
-                fileManipulator.copy(sqlScriptCache, sqlScriptRuntime);
-                if (database.getSqlCommand() != null && database.getSqlCommand().trim().length() > 0) {
-                    // execute SQL script using system command
-                    String command = VariableUtils.replace(database.getSqlCommand(), environment.getVariables());
-                    String output = SqlScriptUtils.executeUsingCommand(applicationCacheDir + "/sql/" + sqlScript.getName(), command);
-                    updateLog.addUpdateMessage(new UpdateMessage("info", "SQL script " + sqlScript.getName() + " executed: " + output));
-                    EventUtils.post(environment, "UPDATE", "SQL script " + sqlScript.getName() + " executed: " + output);
-                    LOGGER.info("SQL script {} executed: {}", sqlScript.getName(), output);
-                } else {
-                    // execute SQL script using JDBC
-                    String user = null;
-                    String password = null;
-                    String driver = null;
-                    String url = null;
-                    if (database.getConnectionPool() != null && database.getConnectionPool().trim().length() > 0) {
-                        // the database is linked to a connection pool
-                        // looking for the connection pool (from the cache)
-                        String connectionPoolName = VariableUtils.replace(database.getConnectionPool(), environment.getVariables());
-                        JDBCConnectionPool connectionPool = server.getJDBCConnectionPool(connectionPoolName);
-                        if (connectionPool == null) {
-                            LOGGER.error("JDBC connection pool {} is not found in J2EE application server {}", database.getConnectionPool(), server.getName());
-                            throw new UpdateException("JDBC connection pool " + database.getConnectionPool() + " is not found in J2EE application server " + server.getName());
-                        }
-                        user = VariableUtils.replace(connectionPool.getUser(), environment.getVariables());
-                        password = VariableUtils.replace(connectionPool.getPassword(), environment.getVariables());
-                        driver = VariableUtils.replace(connectionPool.getDriver(), environment.getVariables());
-                        url = VariableUtils.replace(connectionPool.getUrl(), environment.getVariables());
-                    } else {
-                        // use the database connection data
-                        user = VariableUtils.replace(database.getUser(), environment.getVariables());
-                        password = VariableUtils.replace(database.getPassword(), environment.getVariables());
-                        driver = VariableUtils.replace(database.getDriver(), environment.getVariables());
-                        url = VariableUtils.replace(database.getJdbcurl(), environment.getVariables());
-                    }
-                    // execute SQL script using JDBC
-                    SqlScriptUtils.executeUsingJdbc(sqlScriptRuntime, driver, user, password, url);
-                }
-                // add message
-                updateLog.setStatus("Update performed");
-                updateLog.setUpdated(true);
-                updateLog.addUpdateMessage(new UpdateMessage("info", "SQL script " + sqlScript.getName() + " executed"));
-                EventUtils.post(environment, "UPDATE", "SQL script " + sqlScript.getName() + " executed");
-                LOGGER.info("SQL script {} executed", sqlScript.getName());
-            }
-        } catch (Exception e) {
-            // SQL script execution failed, delete the SQL script from the cache
-            try {
-                fileManipulator.delete(sqlScriptRuntime);
-            } catch (FileManipulatorException fileManipulatorException) {
-                LOGGER.warn("Can't delete {}/sql/{}", new Object[]{applicationCacheDir, sqlScript.getName()}, fileManipulatorException);
-            }
-            LOGGER.error("SQL script {} execution failed", sqlScript.getName(), e);
-            throw new UpdateException("SQL script " + sqlScript.getName() + " execution failed", e);
-        }
     }
 
     /**

Modified: incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/FileManipulator.java
URL: http://svn.apache.org/viewvc/incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/FileManipulator.java?rev=1212027&r1=1212026&r2=1212027&view=diff
==============================================================================
--- incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/FileManipulator.java (original)
+++ incubator/kalumet/trunk/common/src/main/java/org/apache/kalumet/FileManipulator.java Thu Dec  8 18:38:39 2011
@@ -23,6 +23,7 @@ import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.SystemUtils;
 import org.apache.commons.vfs.*;
+import org.apache.commons.vfs.impl.StandardFileSystemManager;
 import org.apache.kalumet.model.J2EEApplication;
 import org.apache.kalumet.model.Environment;
 import org.apache.kalumet.model.Software;
@@ -74,7 +75,7 @@ public class FileManipulator {
             this.fileSystemManager = VFS.getManager();
             // this.fileSystemManager = new StandardFileSystemManager();
             // fileSystemManager.setCacheStrategy(CacheStrategy.ON_CALL);
-            // fileSystemManager.setReplicator(new KalumetFileReplicator());
+            ((StandardFileSystemManager) this.fileSystemManager).setReplicator(new KalumetFileReplicator());
             // fileSystemManager.init();
         } catch (Exception e) {
             throw new FileManipulatorException(e);
@@ -150,6 +151,7 @@ public class FileManipulator {
             LOGGER.error("No file matching {} found on {}", pattern, baseName);
             throw new FileManipulatorException("No file matching " + pattern + " found on " + baseName);
         }
+        baseUrl.close();
         return fileObjects[0];
     }
 

Modified: incubator/kalumet/trunk/utils/src/main/java/org/apache/kalumet/utils/FileUtils.java
URL: http://svn.apache.org/viewvc/incubator/kalumet/trunk/utils/src/main/java/org/apache/kalumet/utils/FileUtils.java?rev=1212027&r1=1212026&r2=1212027&view=diff
==============================================================================
--- incubator/kalumet/trunk/utils/src/main/java/org/apache/kalumet/utils/FileUtils.java (original)
+++ incubator/kalumet/trunk/utils/src/main/java/org/apache/kalumet/utils/FileUtils.java Thu Dec  8 18:38:39 2011
@@ -44,16 +44,25 @@ public class FileUtils {
      */
     public static String view(String path) {
         String content = null;
+        InputStream stream = null;
         try  {
             // get a file manipulator instance
             FileManipulator fileManipulator = FileManipulator.getInstance();
             // get the file content
-            InputStream stream = fileManipulator.read(path);
+            stream = fileManipulator.read(path);
             // populate the content string
             content = IOUtils.toString(stream);
         }
         catch (Exception e) {
             LOGGER.warn("Can't view {}", path, e);
+        } finally {
+            if (stream != null) {
+                try {
+                    stream.close();
+                } catch (Exception e) {
+                    // nothing to do
+                }
+            }
         }
         return content;
     }