Search in sources :

Example 21 with StartupException

use of org.olat.core.logging.StartupException in project OpenOLAT by OpenOLAT.

the class UpgradeManager method abort.

/**
 * On any RuntimeExceptions during init. Abort loading of application.
 * Modules should throw RuntimeExceptions if they can't live with a the
 * given state of configuration.
 * @param e
 */
protected void abort(Throwable e) {
    if (e instanceof StartupException) {
        StartupException se = (StartupException) e;
        logWarn("Message: " + se.getLogMsg(), se);
        Throwable cause = se.getCause();
        logWarn("Cause: " + (cause != null ? cause.getMessage() : "n/a"), se);
    }
    throw new RuntimeException("*** CRITICAL ERROR IN UPGRADE MANAGER. Loading aborted.", e);
}
Also used : StartupException(org.olat.core.logging.StartupException)

Example 22 with StartupException

use of org.olat.core.logging.StartupException in project OpenOLAT by OpenOLAT.

the class WebappHelper method setUserDataRoot.

/**
 * [spring]
 * @param userDataRoot
 */
public void setUserDataRoot(String userDataRoot) {
    if (!StringHelper.containsNonWhitespace(userDataRoot)) {
        userDataRoot = System.getProperty("java.io.tmpdir") + "/olatdata";
        log.info("using java.io.tmpdir as userdata. this is the default if userdata.dir is not set");
    }
    File fUserData = new File(userDataRoot);
    if (!fUserData.exists()) {
        if (!fUserData.mkdirs())
            throw new StartupException("Unable to create userdata dir '" + userDataRoot + "'. Please fix!");
    }
    // fxdiff: reset tmp-dir from within application to circumvent startup-params.
    // do not write to system default (/var/tmp) as this leads to permission problems with multiple instances on one host!
    log.info("Setting userdata root to: " + userDataRoot);
    WebappHelper.userDataRoot = userDataRoot;
}
Also used : StartupException(org.olat.core.logging.StartupException) File(java.io.File)

Example 23 with StartupException

use of org.olat.core.logging.StartupException in project openolat by klemens.

the class AbstractHierarchicalIndexer method addIndexer.

public void addIndexer(Indexer indexer) {
    try {
        childIndexers.add(indexer);
        logDebug("Adding indexer from configuraton. TypeName=" + indexer.getSupportedTypeName());
    } catch (ClassCastException cce) {
        throw new StartupException("Configured indexer is not of type Indexer", cce);
    }
}
Also used : StartupException(org.olat.core.logging.StartupException)

Example 24 with StartupException

use of org.olat.core.logging.StartupException in project openolat by klemens.

the class DatabaseUpgradeManager method loadAndExecuteSqlStatements.

/**
 * load file with alter statements and add to batch
 * @param statements
 * @param alterDbStatements
 */
private void loadAndExecuteSqlStatements(Statement statement, String alterDbStatements, Dialect dialect) {
    try {
        Resource setupDatabaseFile = new ClassPathResource("/database/" + dialect + "/" + alterDbStatements);
        if (!setupDatabaseFile.exists()) {
            throw new StartupException("The database upgrade file was not found on the classpath: " + "/database/" + dialect + "/" + alterDbStatements);
        }
        InputStream in = setupDatabaseFile.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String strLine;
        StringBuilder sb = new StringBuilder();
        // Read File Line By Line
        while ((strLine = br.readLine()) != null) {
            if (strLine.length() > 1 && (!strLine.startsWith("--") && !strLine.startsWith("#"))) {
                sb.append(strLine.trim()).append(' ');
            }
        }
        StringTokenizer tokenizer = new StringTokenizer(sb.toString(), ";");
        String sql = null;
        while (tokenizer.hasMoreTokens()) {
            try {
                String token = tokenizer.nextToken();
                if (!StringHelper.containsNonWhitespace(token)) {
                    continue;
                }
                sql = token + ";".toLowerCase();
                if (sql.startsWith("update") || sql.startsWith("delete") || sql.startsWith("alter") || sql.startsWith("insert")) {
                    statement.executeUpdate(sql);
                } else {
                    statement.execute(sql);
                }
                logInfo("Successfully upgraded database with the following sql: " + sql);
            } catch (SQLException e) {
                if (isErrorFatal(dialect, sql, e)) {
                    throw new StartupException("Fatal error trying to update database.", e);
                }
            } catch (Exception e) {
                // handle non sql errors
                logError("Could not upgrade your database!", e);
                throw new StartupException("Could not add alter db statements to batch.", e);
            }
        }
        in.close();
    } catch (FileNotFoundException e1) {
        logError("could not find deleteDatabase.sql file!", e1);
        abort(e1);
    } catch (IOException e) {
        logError("could not read deleteDatabase.sql file!", e);
        abort(e);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) SQLException(java.sql.SQLException) InputStream(java.io.InputStream) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) ClassPathResource(org.springframework.core.io.ClassPathResource) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SQLException(java.sql.SQLException) StartupException(org.olat.core.logging.StartupException) StringTokenizer(java.util.StringTokenizer) StartupException(org.olat.core.logging.StartupException) BufferedReader(java.io.BufferedReader)

Example 25 with StartupException

use of org.olat.core.logging.StartupException in project openolat by klemens.

the class FilePathHandler method init.

/**
 * @see org.olat.commons.servlets.pathhandlers.PathHandler#init(com.anthonyeden.lib.config.Configuration)
 */
public void init(String config) {
    String rootConf = config;
    if (rootConf == null)
        throw new StartupException("child 'root' missing in config for filepathhandler");
    File f = new File(rootConf);
    if (f.isAbsolute()) {
        setRoot(rootConf);
    } else {
        setRoot(WebappHelper.getContextRealPath("/" + rootConf));
    }
}
Also used : StartupException(org.olat.core.logging.StartupException) File(java.io.File)

Aggregations

StartupException (org.olat.core.logging.StartupException)26 File (java.io.File)10 IOException (java.io.IOException)6 SQLException (java.sql.SQLException)6 ClassPathResource (org.springframework.core.io.ClassPathResource)6 Resource (org.springframework.core.io.Resource)6 InputStream (java.io.InputStream)4 Statement (java.sql.Statement)4 XStream (com.thoughtworks.xstream.XStream)2 BufferedReader (java.io.BufferedReader)2 FileNotFoundException (java.io.FileNotFoundException)2 InputStreamReader (java.io.InputStreamReader)2 ResultSet (java.sql.ResultSet)2 Properties (java.util.Properties)2 StringTokenizer (java.util.StringTokenizer)2 FastHashMap (org.apache.commons.collections.FastHashMap)2 CoreSpringFactory (org.olat.core.CoreSpringFactory)2 AssertException (org.olat.core.logging.AssertException)2 AuthenticationProvider (org.olat.login.auth.AuthenticationProvider)2 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)2