Search in sources :

Example 1 with ETracInternal

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

the class VersionInfo method readVersionInfo.

private static String readVersionInfo(Class<?> component, String propKey) throws IOException {
    var versionInfoStream = component.getClassLoader().getResourceAsStream(VERSION_INFO_PROPS);
    if (versionInfoStream == null)
        throw new ETracInternal("Component version info not available");
    var versionInfo = new Properties();
    versionInfo.load(versionInfoStream);
    var unpackedVersion = versionInfo.getProperty(propKey);
    if (unpackedVersion != null && !unpackedVersion.isBlank())
        return unpackedVersion;
    throw new ETracInternal("Component version info not available");
}
Also used : ETracInternal(com.accenture.trac.common.exception.ETracInternal) Properties(java.util.Properties)

Example 2 with ETracInternal

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

the class GrpcServerResponseStream method onSubscribe.

@Override
public void onSubscribe(Flow.Subscription subscription) {
    if (this.subscription != null)
        throw new ETracInternal("Multiple subscriptions on gRPC observer wrapper");
    this.subscription = subscription;
    subscription.request(1);
}
Also used : ETracInternal(com.accenture.trac.common.exception.ETracInternal)

Example 3 with ETracInternal

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

the class ServiceHelpers method startService.

public static <TSvc extends CommonServiceBase> TSvc startService(Class<TSvc> serviceClass, Path workingDir, URL configPath, String keystoreKey) {
    try {
        var startup = Startup.useConfigFile(TracMetadataService.class, workingDir, configPath.toString(), keystoreKey);
        startup.runStartupSequence();
        var plugins = startup.getPlugins();
        var config = startup.getConfig();
        var constructor = serviceClass.getConstructor(PluginManager.class, ConfigManager.class);
        var service = constructor.newInstance(plugins, config);
        service.start();
        return service;
    } catch (NoSuchMethodException e) {
        var err = String.format("Service class [%s] does not provide the standard service constructor", serviceClass.getSimpleName());
        throw new ETracInternal(err);
    } catch (InvocationTargetException | IllegalAccessException | InstantiationException e) {
        var err = String.format("Service class [%s] cannot be constructed: %s", serviceClass.getSimpleName(), e.getMessage());
        throw new ETracInternal(err, e);
    }
}
Also used : ETracInternal(com.accenture.trac.common.exception.ETracInternal) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 4 with ETracInternal

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

the class JdbcSetup method destroyDatasource.

public static void destroyDatasource(DataSource source) {
    if (!(source instanceof HikariDataSource))
        throw new ETracInternal("Datasource being destroyed was not created by JdbcSetup");
    var hikariSource = (HikariDataSource) source;
    hikariSource.close();
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) ETracInternal(com.accenture.trac.common.exception.ETracInternal)

Example 5 with ETracInternal

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

the class LocalConfigLoader method loadTextFile.

@Override
public String loadTextFile(URI uri) {
    var ERROR_MSG_TEMPLATE = "Failed to load config file: %2$s [%1$s]";
    Path path = null;
    try {
        path = Paths.get(uri);
        return Files.readString(path, StandardCharsets.UTF_8);
    } catch (IllegalArgumentException e) {
        // This should not happen
        // ConfigManager should only pass file URLs to this loader
        // Treat this as an internal error
        var message = String.format("URL is not a file path: [%s]", uri);
        throw new ETracInternal(message, e);
    } catch (NoSuchFileException e) {
        var message = String.format(ERROR_MSG_TEMPLATE, path, "File does not exist");
        throw new EStartup(message, e);
    } catch (AccessDeniedException e) {
        var message = String.format(ERROR_MSG_TEMPLATE, path, "Access denied");
        throw new EStartup(message, e);
    } catch (IOException e) {
        var message = String.format(ERROR_MSG_TEMPLATE, path, e.getMessage());
        throw new EStartup(message, e);
    }
}
Also used : ETracInternal(com.accenture.trac.common.exception.ETracInternal) IOException(java.io.IOException) EStartup(com.accenture.trac.common.exception.EStartup)

Aggregations

ETracInternal (com.accenture.trac.common.exception.ETracInternal)5 EStartup (com.accenture.trac.common.exception.EStartup)1 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Properties (java.util.Properties)1