mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
add support to run scripts on usage DB
This commit is contained in:
parent
9a560173eb
commit
5401ee84ba
@ -161,6 +161,15 @@ public class Transaction {
|
||||
}
|
||||
}
|
||||
|
||||
public static Connection getStandaloneUsageConnection() {
|
||||
try {
|
||||
return s_usageDS.getConnection();
|
||||
} catch (SQLException e) {
|
||||
s_logger.warn("Unexpected exception: ", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected static boolean checkAnnotation(int stack, Transaction txn) {
|
||||
final StackTraceElement[] stacks = Thread.currentThread().getStackTrace();
|
||||
StackElement se = txn.peekInStack(CURRENT_TXN);
|
||||
|
||||
@ -58,4 +58,34 @@ public class DbTestUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static void executeUsageScript(String file, boolean autoCommit, boolean stopOnError) {
|
||||
File cleanScript = PropertiesUtil.findConfigFile(file);
|
||||
if (cleanScript == null) {
|
||||
throw new RuntimeException("Unable to clean the database because I can't find " + file);
|
||||
}
|
||||
|
||||
Connection conn = Transaction.getStandaloneUsageConnection();
|
||||
|
||||
ScriptRunner runner = new ScriptRunner(conn, autoCommit, stopOnError);
|
||||
FileReader reader;
|
||||
try {
|
||||
reader = new FileReader(cleanScript);
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeException("Unable to read " + file, e);
|
||||
}
|
||||
try {
|
||||
runner.runScript(reader);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Unable to read " + file, e);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException("Unable to execute " + file, e);
|
||||
}
|
||||
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException("Unable to close DB connection", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user