Search in sources :

Example 1 with EStartup

use of com.accenture.trac.common.exception.EStartup in project tracdap by finos.

the class StartupSequence method initStartupLogging.

private void initStartupLogging() {
    try (var logConfig = Startup.class.getResourceAsStream(STARTUP_LOG_CONFIG)) {
        if (logConfig == null)
            throw new EStartup("Failed to load logging config for bootstrap");
        var configSource = new ConfigurationSource(logConfig);
        Configurator.initialize(Startup.class.getClassLoader(), configSource);
    } catch (IOException e) {
        throw new EStartup("Failed to load logging config for startup sequence (this is a bug)");
    }
}
Also used : ConfigurationSource(org.apache.logging.log4j.core.config.ConfigurationSource) IOException(java.io.IOException) EStartup(com.accenture.trac.common.exception.EStartup) EStartup(com.accenture.trac.common.exception.EStartup)

Example 2 with EStartup

use of com.accenture.trac.common.exception.EStartup in project tracdap by finos.

the class JdbcSetup method createDatasource.

public static DataSource createDatasource(Properties props, String configBase) {
    try {
        var hikariProps = createHikariProperties(props, configBase);
        var config = new HikariConfig(hikariProps);
        var source = new HikariDataSource(config);
        var log = LoggerFactory.getLogger(JdbcSetup.class);
        log.info("Database connection pool has " + source.getMaximumPoolSize() + " connections");
        return source;
    } catch (RuntimeException e) {
        // Particularly in the case of missing JDBC drivers!
        if (e.getCause() instanceof SQLException)
            if (!e.getMessage().contains(e.getCause().getMessage())) {
                var messageTemplate = "Could not connect to database: %s (%s)";
                var message = String.format(messageTemplate, e.getMessage(), e.getCause().getMessage());
                throw new EStartup(message, e);
            }
        var messageTemplate = "Could not connect to database: %s";
        var message = String.format(messageTemplate, e.getMessage());
        throw new EStartup(message, e);
    }
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) SQLException(java.sql.SQLException) HikariConfig(com.zaxxer.hikari.HikariConfig) EStartup(com.accenture.trac.common.exception.EStartup)

Example 3 with EStartup

use of com.accenture.trac.common.exception.EStartup in project tracdap by finos.

the class StorageManager method initStorage.

public void initStorage(Map<String, StorageConfig> storageConfigMap, ICodecManager formats) {
    log.info("Configuring storage...");
    for (var store : storageConfigMap.entrySet()) {
        var storageKey = store.getKey();
        var config = store.getValue();
        var backend = new StorageBackend();
        for (var instanceConfig : config.getInstancesList()) {
            var protocol = instanceConfig.getStorageType();
            var rawProps = instanceConfig.getStoragePropsMap();
            var props = new Properties();
            props.put(PROP_STORAGE_KEY, storageKey);
            props.putAll(rawProps);
            log.info("Attach storage: [{}] (protocol: {})", storageKey, protocol);
            if (plugins.isServiceAvailable(IFileStorage.class, protocol)) {
                var fileInstance = plugins.createService(IFileStorage.class, protocol, props);
                backend.fileInstances.add(fileInstance);
            }
            if (plugins.isServiceAvailable(IDataStorage.class, protocol)) {
                var dataInstance = plugins.createService(IDataStorage.class, protocol, props);
                backend.dataInstances.add(dataInstance);
            } else if (!backend.fileInstances.isEmpty()) {
                log.info("Using flat data storage (datasets will be saved as files)");
                for (var fileInstance : backend.fileInstances) {
                    var dataInstance = new FlatDataStorage(fileInstance, formats);
                    backend.dataInstances.add(dataInstance);
                }
            }
            if (backend.fileInstances.isEmpty() && backend.dataInstances.isEmpty()) {
                var message = String.format("No plugin found to support storage protocol [%s]", protocol);
                var error = new EStartup(message);
                log.error(message, error);
                throw error;
            }
        }
        storage.put(storageKey, backend);
    }
}
Also used : EStartup(com.accenture.trac.common.exception.EStartup) FlatDataStorage(com.accenture.trac.common.storage.flat.FlatDataStorage)

Example 4 with EStartup

use of com.accenture.trac.common.exception.EStartup in project tracdap by finos.

the class ConfigParser method parseConfig.

public static <TConfig extends Message, B extends Message.Builder> TConfig parseConfig(ByteBuf configData, ConfigFormat configFormat, Class<TConfig> configClass) {
    try {
        var newBuilder = configClass.getMethod("newBuilder");
        var builder = (TConfig.Builder) newBuilder.invoke(null);
        var blankConfig = (TConfig) builder.build();
        switch(configFormat) {
            case PROTO:
                return parseProtoConfig(configData, blankConfig);
            case JSON:
                return parseJsonConfig(configData, blankConfig);
            case YAML:
                return parseYamlConfig(configData, blankConfig);
            default:
                throw new EStartup(String.format("Unknown config format [%s]", configFormat));
        }
    } catch (InvalidProtocolBufferException e) {
        throw new EStartup("Invalid config: " + e.getMessage(), e);
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
        // Error invoking reflective method for builder
        throw new EUnexpected();
    } finally {
        configData.release();
    }
}
Also used : InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) EUnexpected(com.accenture.trac.common.exception.EUnexpected) EStartup(com.accenture.trac.common.exception.EStartup) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 5 with EStartup

use of com.accenture.trac.common.exception.EStartup in project tracdap by finos.

the class ConfigParser method parseYamlConfig_.

static <TConfig> TConfig parseYamlConfig_(String configData, Class<TConfig> elementClass) throws EStartup {
    try {
        var loaderOptions = new LoaderOptions();
        loaderOptions.setEnumCaseSensitive(false);
        var constructor = new Constructor(elementClass, loaderOptions);
        var yaml = new Yaml(constructor);
        return yaml.loadAs(configData, elementClass);
    } catch (MarkedYAMLException e) {
        // TODO: Errors
        log.error("YAML Error", e);
        throw new EStartup("YAML error", e);
    } catch (YAMLException e) {
        throw new EStartup("There was an unexpected problem parsing YAML config: " + e.getMessage(), e);
    }
}
Also used : Constructor(org.yaml.snakeyaml.constructor.Constructor) MarkedYAMLException(org.yaml.snakeyaml.error.MarkedYAMLException) YAMLException(org.yaml.snakeyaml.error.YAMLException) MarkedYAMLException(org.yaml.snakeyaml.error.MarkedYAMLException) EStartup(com.accenture.trac.common.exception.EStartup)

Aggregations

EStartup (com.accenture.trac.common.exception.EStartup)18 IOException (java.io.IOException)7 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)3 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)3 DefaultThreadFactory (io.netty.util.concurrent.DefaultThreadFactory)3 PlatformConfig (com.accenture.trac.config.PlatformConfig)2 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)2 CodecManager (com.accenture.trac.common.codec.CodecManager)1 ICodecManager (com.accenture.trac.common.codec.ICodecManager)1 ExecutionRegister (com.accenture.trac.common.concurrent.ExecutionRegister)1 ConfigManager (com.accenture.trac.common.config.ConfigManager)1 EPluginNotAvailable (com.accenture.trac.common.exception.EPluginNotAvailable)1 EStorageConfig (com.accenture.trac.common.exception.EStorageConfig)1 ETrac (com.accenture.trac.common.exception.ETrac)1 ETracInternal (com.accenture.trac.common.exception.ETracInternal)1 EUnexpected (com.accenture.trac.common.exception.EUnexpected)1 ExecutionManager (com.accenture.trac.common.exec.ExecutionManager)1 IStorageManager (com.accenture.trac.common.storage.IStorageManager)1 StorageManager (com.accenture.trac.common.storage.StorageManager)1 FlatDataStorage (com.accenture.trac.common.storage.flat.FlatDataStorage)1