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)");
}
}
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);
}
}
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);
}
}
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();
}
}
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);
}
}
Aggregations