Search in sources :

Example 31 with OnmsUpgradeException

use of org.opennms.upgrade.api.OnmsUpgradeException in project opennms by OpenNMS.

the class Upgrade method executeUpgrade.

/**
 * Execute upgrade.
 *
 * @param upg the upgrade implementation class
 */
protected void executeUpgrade(OnmsUpgrade upg) {
    Date start = new Date();
    try {
        if (wasExecuted(upg)) {
            log("  Task %s has been executed at %s\n", upg.getId(), getUpgradeStatus().getLastExecutionTime(upg));
            return;
        }
        log("- Running pre-execution phase\n");
        upg.preExecute();
    } catch (OnmsUpgradeException e) {
        log("  Ignoring: %s\n", e.getMessage());
        return;
    }
    try {
        log("- Running execution phase\n");
        upg.execute();
        log("- Saving the execution state\n");
        markAsExecuted(upg);
    } catch (OnmsUpgradeException executeException) {
        log("  Warning: can't perform the upgrade operation because: %s\n", executeException.getMessage());
        try {
            log("- Executing rollback phase\n");
            upg.rollback();
        } catch (OnmsUpgradeException rollbackException) {
            log("  Warning: can't rollback the upgrade because: %s\n", rollbackException.getMessage());
            rollbackException.printStackTrace();
        }
    }
    try {
        log("- Running post-execution phase\n");
        upg.postExecute();
    } catch (OnmsUpgradeException e) {
        log("  Warning: can't run the post-execute phase because: %s\n", e.getMessage());
    }
    log("\nFinished in %s\n\n", FuzzyDateFormatter.calculateDifference(start, new Date()));
}
Also used : Date(java.util.Date) OnmsUpgradeException(org.opennms.upgrade.api.OnmsUpgradeException)

Aggregations

OnmsUpgradeException (org.opennms.upgrade.api.OnmsUpgradeException)31 IOException (java.io.IOException)23 File (java.io.File)14 FileWriter (java.io.FileWriter)8 StringWriter (java.io.StringWriter)6 ArrayList (java.util.ArrayList)5 Matcher (java.util.regex.Matcher)5 Map (java.util.Map)3 Pattern (java.util.regex.Pattern)3 LineIterator (org.apache.commons.io.LineIterator)3 DefaultDataCollectionConfigDao (org.opennms.netmgt.config.DefaultDataCollectionConfigDao)3 Service (org.opennms.netmgt.config.service.Service)3 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 Writer (java.io.Writer)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2