use of horse.wtf.nzyme.configuration.CLIArguments in project nzyme by lennartkoopmann.
the class Main method main.
public static void main(String[] argv) {
final CLIArguments cliArguments = new CLIArguments();
// Parse CLI arguments.
JCommander.newBuilder().addObject(cliArguments).build().parse(argv);
// Override log level if requested.
if (cliArguments.isDebugMode()) {
Logging.setRootLoggerLevel(Level.DEBUG);
}
if (cliArguments.isTraceMode()) {
Logging.setRootLoggerLevel(Level.TRACE);
}
// Parse configuration.
BaseConfiguration baseConfiguration = null;
try {
baseConfiguration = new BaseConfigurationLoader(new File(cliArguments.getConfigFilePath())).get();
} catch (InvalidConfigurationException | ConfigException e) {
LOG.error("Invalid baseconfiguration. Please refer to the example configuration file or documentation.", e);
System.exit(FAILURE);
} catch (IncompleteConfigurationException e) {
LOG.error("Incomplete base configuration. Please refer to the example configuration file or documentation.", e);
System.exit(FAILURE);
} catch (FileNotFoundException e) {
LOG.error("Could not read configuration file.", e);
System.exit(FAILURE);
}
switch(baseConfiguration.mode()) {
case LEADER:
LeaderConfiguration leaderConfiguration = null;
try {
leaderConfiguration = new LeaderConfigurationLoader(new File(cliArguments.getConfigFilePath()), false).get();
} catch (InvalidConfigurationException | ConfigException e) {
LOG.error("Invalid configuration. Please refer to the example configuration file or documentation.", e);
System.exit(FAILURE);
} catch (IncompleteConfigurationException e) {
LOG.error("Incomplete configuration. Please refer to the example configuration file or documentation.", e);
System.exit(FAILURE);
} catch (FileNotFoundException e) {
LOG.error("Could not read configuration file.", e);
System.exit(FAILURE);
}
// Database.
Database database = new Database(leaderConfiguration);
try {
database.initializeAndMigrate();
} catch (LiquibaseException e) {
LOG.fatal("Error during database initialization and migration.", e);
System.exit(FAILURE);
}
NzymeLeader nzyme = new NzymeLeaderImpl(baseConfiguration, leaderConfiguration, database);
try {
nzyme.initialize();
} catch (Exception e) {
LOG.fatal("Could not initialize nzyme.", e);
System.exit(FAILURE);
}
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
Thread.currentThread().setName("shutdown-hook");
nzyme.shutdown();
}));
break;
case TRACKER:
TrackerConfiguration trackerConfiguration = null;
try {
trackerConfiguration = new TrackerConfigurationLoader(new File(cliArguments.getConfigFilePath())).get();
} catch (InvalidConfigurationException | ConfigException e) {
LOG.error("Invalid configuration. Please refer to the example configuration file or documentation.", e);
System.exit(FAILURE);
} catch (IncompleteConfigurationException e) {
LOG.error("Incomplete configuration. Please refer to the example configuration file or documentation.", e);
System.exit(FAILURE);
} catch (FileNotFoundException e) {
LOG.error("Could not read configuration file.", e);
System.exit(FAILURE);
}
NzymeTracker tracker = new NzymeTrackerImpl(baseConfiguration, trackerConfiguration);
try {
tracker.initialize();
} catch (Exception e) {
LOG.fatal("Could not initialize nzyme.", e);
System.exit(FAILURE);
}
}
while (true) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
break;
/* nein */
}
}
}
Aggregations