Skip to content
Snippets Groups Projects
Commit e612f133 authored by Daniel Hornung's avatar Daniel Hornung
Browse files

MAINT DOC: Reordered methods in CaosDBServer.

Also a bit of documentation.
parent 98e14752
Branches
Tags
No related merge requests found
# TODO: Add documentation.
- purpose: scripting:administration/diagnostics.py
roles:
- administration
......
......@@ -115,17 +115,17 @@ CERTIFICATES_KEY_STORE_PASSWORD=
SESSION_TIMEOUT_MS=600000
# Time after which one-time tokens expire.
# This is only a default value. The actual timeout of each token can be
# configured otherwise.
# This is only a default value. The actual timeout of tokens can be
# configured otherwise, for example in authtoken.yml.
# 7days
ONE_TIME_TOKEN_EXPIRES_MS=604800000
# Path to config file for one time tokens.
# Path to config file for one time tokens, for example authtoken.yml.
AUTHTOKEN_CONFIG=
# Timeout after which a consumed one-time token expires regardless of the
# maximum of attempts that are allowed for that token. This is only a default
# value. The actual timeout of each token can be configured otherwise.
# value. The actual timeout of tokens can be configured otherwise.
# 30 s
ONE_TIME_TOKEN_ATTEMPTS_TIMEOUT_MS=30000
......
......@@ -128,6 +128,60 @@ public class CaosDBServer extends Application {
return getServerProperties().getProperty(key);
}
/**
* This main method starts up a web application that will listen on a port defined in the config
* file.
*
* @param args One option temporarily (for testing) available: silent: If present: disable
* System.out-stream (stream to a NullPrintStream). This makes the response of the database
* amazingly faster.
* @throws IOException
* @throws FileNotFoundException
* @throws SecurityException
* @throws Exception If problems occur.
*/
public static void main(final String[] args)
throws SecurityException, FileNotFoundException, IOException {
try {
init(args);
initScheduler();
initServerProperties();
initTimeZone();
initOneTimeTokens();
initShiro();
initBackend();
initWebServer();
initShutDownHook();
} catch (Exception e1) {
logger.error("Could not start the server.", e1);
System.exit(1);
}
}
private static void init(final String[] args) {
// Important change:
// Make silent the default option
START_GUI = false;
for (final String s : args) {
if (s.equals("silent")) {
START_GUI = false;
} else if (s.equals("gui")) {
START_GUI = true;
} else if (s.equals("nobackend")) {
START_BACKEND = false;
} else if (s.equals("insecure")) {
INSECURE = true;
}
}
INSECURE = INSECURE && isDebugMode(); // only allow insecure in debug mode
START_BACKEND = START_BACKEND || !isDebugMode(); // always start backend if not in debug mode
}
private static void initScheduler() throws SchedulerException {
SCHEDULER = StdSchedulerFactory.getDefaultScheduler();
SCHEDULER.start();
}
public static void initServerProperties() throws IOException {
SERVER_PROPERTIES = ServerProperties.initServerProperties();
}
......@@ -211,23 +265,15 @@ public class CaosDBServer extends Application {
}
}
private static void init(final String[] args) {
// Important change:
// Make silent the default option
START_GUI = false;
for (final String s : args) {
if (s.equals("silent")) {
START_GUI = false;
} else if (s.equals("gui")) {
START_GUI = true;
} else if (s.equals("nobackend")) {
START_BACKEND = false;
} else if (s.equals("insecure")) {
INSECURE = true;
}
}
INSECURE = INSECURE && isDebugMode(); // only allow insecure in debug mode
START_BACKEND = START_BACKEND || !isDebugMode(); // always start backend if // not in debug mode
public static void initOneTimeTokens() throws Exception {
OneTimeAuthenticationToken.initConfig();
ConsumedInfoCleanupJob.scheduleDaily();
}
public static void initShiro() {
// init Shiro (user authentication/authorization and session management)
final Ini config = getShiroConfig();
initShiro(config);
}
public static Ini getShiroConfig() {
......@@ -255,12 +301,6 @@ public class CaosDBServer extends Application {
SecurityUtils.setSecurityManager(securityManager);
}
public static void initShiro() {
// init Shiro (user authentication/authorization and session management)
final Ini config = getShiroConfig();
initShiro(config);
}
public static void initBackend() throws Exception {
if (START_BACKEND) {
try (final Initialization init = Initialization.setUp()) {
......@@ -286,67 +326,6 @@ public class CaosDBServer extends Application {
}
}
public static void initGUI() throws InterruptedException {
if (START_GUI) {
final CaosDBTerminal caosDBTerminal = new CaosDBTerminal();
caosDBTerminal.setName("CaosDBTerminal");
caosDBTerminal.start();
addPreShutdownHook(
new Runnable() {
@Override
public void run() {
caosDBTerminal.shutDown();
SystemErrPanel.close();
}
});
// wait until the terminal is initialized.
Thread.sleep(1000);
// add Benchmark
StatsPanel.addStat("TransactionBenchmark", TransactionBenchmark.getRootInstance());
} else {
logger.info("NO GUI");
System.setOut(new NullPrintStream());
}
}
public static void initOneTimeTokens() throws Exception {
OneTimeAuthenticationToken.initConfig();
ConsumedInfoCleanupJob.scheduleDaily();
}
/**
* This main method starts up a web application that will listen on a port defined in the config
* file.
*
* @param args One option temporarily (for testing) available: silent: If present: disable
* System.out-stream (stream to a NullPrintStream). This makes the response of the database
* amazingly faster.
* @throws IOException
* @throws FileNotFoundException
* @throws SecurityException
* @throws Exception If problems occur.
*/
public static void main(final String[] args)
throws SecurityException, FileNotFoundException, IOException {
try {
init(args);
initScheduler();
initServerProperties();
initTimeZone();
initOneTimeTokens();
initShiro();
initBackend();
initWebServer();
initShutDownHook();
} catch (Exception e1) {
logger.error("Could not start the server.", e1);
System.exit(1);
}
}
private static void initWebServer() throws Exception {
final int port_https =
Integer.parseInt(getServerProperty(ServerProperties.KEY_SERVER_PORT_HTTPS));
......@@ -372,9 +351,30 @@ public class CaosDBServer extends Application {
}
}
private static void initScheduler() throws SchedulerException {
SCHEDULER = StdSchedulerFactory.getDefaultScheduler();
SCHEDULER.start();
public static void initGUI() throws InterruptedException {
if (START_GUI) {
final CaosDBTerminal caosDBTerminal = new CaosDBTerminal();
caosDBTerminal.setName("CaosDBTerminal");
caosDBTerminal.start();
addPreShutdownHook(
new Runnable() {
@Override
public void run() {
caosDBTerminal.shutDown();
SystemErrPanel.close();
}
});
// wait until the terminal is initialized.
Thread.sleep(1000);
// add Benchmark
StatsPanel.addStat("TransactionBenchmark", TransactionBenchmark.getRootInstance());
} else {
logger.info("NO GUI");
System.setOut(new NullPrintStream());
}
}
private static void initDatatypes(final Access access) throws Exception {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment