Search in sources :

Example 1 with TrackerConfigurationLoader

use of horse.wtf.nzyme.configuration.tracker.TrackerConfigurationLoader 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 */
        }
    }
}
Also used : BaseConfigurationLoader(horse.wtf.nzyme.configuration.base.BaseConfigurationLoader) CLIArguments(horse.wtf.nzyme.configuration.CLIArguments) FileNotFoundException(java.io.FileNotFoundException) ConfigException(com.typesafe.config.ConfigException) TrackerConfigurationLoader(horse.wtf.nzyme.configuration.tracker.TrackerConfigurationLoader) IncompleteConfigurationException(horse.wtf.nzyme.configuration.IncompleteConfigurationException) IncompleteConfigurationException(horse.wtf.nzyme.configuration.IncompleteConfigurationException) FileNotFoundException(java.io.FileNotFoundException) InvalidConfigurationException(horse.wtf.nzyme.configuration.InvalidConfigurationException) ConfigException(com.typesafe.config.ConfigException) LiquibaseException(liquibase.exception.LiquibaseException) TrackerConfiguration(horse.wtf.nzyme.configuration.tracker.TrackerConfiguration) InvalidConfigurationException(horse.wtf.nzyme.configuration.InvalidConfigurationException) LeaderConfiguration(horse.wtf.nzyme.configuration.leader.LeaderConfiguration) BaseConfiguration(horse.wtf.nzyme.configuration.base.BaseConfiguration) Database(horse.wtf.nzyme.database.Database) LiquibaseException(liquibase.exception.LiquibaseException) File(java.io.File) LeaderConfigurationLoader(horse.wtf.nzyme.configuration.leader.LeaderConfigurationLoader)

Aggregations

ConfigException (com.typesafe.config.ConfigException)1 CLIArguments (horse.wtf.nzyme.configuration.CLIArguments)1 IncompleteConfigurationException (horse.wtf.nzyme.configuration.IncompleteConfigurationException)1 InvalidConfigurationException (horse.wtf.nzyme.configuration.InvalidConfigurationException)1 BaseConfiguration (horse.wtf.nzyme.configuration.base.BaseConfiguration)1 BaseConfigurationLoader (horse.wtf.nzyme.configuration.base.BaseConfigurationLoader)1 LeaderConfiguration (horse.wtf.nzyme.configuration.leader.LeaderConfiguration)1 LeaderConfigurationLoader (horse.wtf.nzyme.configuration.leader.LeaderConfigurationLoader)1 TrackerConfiguration (horse.wtf.nzyme.configuration.tracker.TrackerConfiguration)1 TrackerConfigurationLoader (horse.wtf.nzyme.configuration.tracker.TrackerConfigurationLoader)1 Database (horse.wtf.nzyme.database.Database)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 LiquibaseException (liquibase.exception.LiquibaseException)1