Search in sources :

Example 6 with EStartup

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

the class TracDataService method doStartup.

@Override
protected void doStartup(Duration startupTimeout) {
    PlatformConfig platformConfig;
    DataServiceConfig dataSvcConfig;
    try {
        if (MemoryUtil.UNSAFE == null)
            throw new NullPointerException("MemoryUtil.UNSAFE == null");
    } catch (RuntimeException e) {
        log.error("Failed to set up native memory access for Apache Arrow", e);
        throw new EStartup("Failed to set up native memory access for Apache Arrow", e);
    }
    try {
        pluginManager.initRegularPlugins();
    } catch (Exception e) {
        var errorMessage = "There was a problem loading the plugins: " + e.getMessage();
        log.error(errorMessage, e);
        throw new EStartup(errorMessage, e);
    }
    try {
        log.info("Loading TRAC platform config...");
        platformConfig = configManager.loadRootConfigObject(PlatformConfig.class);
        dataSvcConfig = platformConfig.getServices().getData();
        // TODO: Config validation
        log.info("Config looks ok");
    } catch (Exception e) {
        var errorMessage = "There was a problem loading the platform config: " + e.getMessage();
        log.error(errorMessage, e);
        throw new EStartup(errorMessage, e);
    }
    try {
        var channelType = NioServerSocketChannel.class;
        var clientChannelType = NioSocketChannel.class;
        var workerThreads = Runtime.getRuntime().availableProcessors() * 2;
        workerGroup = new NioEventLoopGroup(workerThreads, new DefaultThreadFactory("data-svc"));
        bossGroup = new NioEventLoopGroup(1, new DefaultThreadFactory("data-boss"));
        var execRegister = new ExecutionRegister(workerGroup);
        // TODO: Review setup of Arrow allocator, inc. interaction with Netty / Protobuf allocators
        var arrowAllocatorConfig = RootAllocator.configBuilder().allocationManagerFactory(NettyAllocationManager.FACTORY).build();
        var arrowAllocator = new RootAllocator(arrowAllocatorConfig);
        var formats = new CodecManager(pluginManager);
        var storage = new StorageManager(pluginManager);
        storage.initStorage(dataSvcConfig.getStorageMap(), formats);
        // Check default storage and format are available
        checkDefaultStorageAndFormat(storage, formats, dataSvcConfig);
        var metaClient = prepareMetadataClient(platformConfig, clientChannelType);
        var dataSvc = new DataService(dataSvcConfig, arrowAllocator, storage, formats, metaClient);
        var fileSvc = new FileService(dataSvcConfig, storage, metaClient);
        var publicApi = new TracDataApi(dataSvc, fileSvc);
        // Create the main server
        this.server = NettyServerBuilder.forPort(dataSvcConfig.getPort()).addService(publicApi).channelType(channelType).bossEventLoopGroup(bossGroup).workerEventLoopGroup(workerGroup).directExecutor().intercept(execRegister.registerExecContext()).build();
        // Good to go, let's start!
        server.start();
        log.info("Data service is listening on port {}", server.getPort());
    } catch (IOException e) {
        throw new EStartup(e.getMessage(), e);
    }
}
Also used : NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) FileService(com.accenture.trac.svc.data.service.FileService) StorageManager(com.accenture.trac.common.storage.StorageManager) IStorageManager(com.accenture.trac.common.storage.IStorageManager) IOException(java.io.IOException) EStartup(com.accenture.trac.common.exception.EStartup) IOException(java.io.IOException) DataService(com.accenture.trac.svc.data.service.DataService) TracDataApi(com.accenture.trac.svc.data.api.TracDataApi) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) DataServiceConfig(com.accenture.trac.config.DataServiceConfig) PlatformConfig(com.accenture.trac.config.PlatformConfig) RootAllocator(org.apache.arrow.memory.RootAllocator) ExecutionRegister(com.accenture.trac.common.concurrent.ExecutionRegister) ICodecManager(com.accenture.trac.common.codec.ICodecManager) CodecManager(com.accenture.trac.common.codec.CodecManager) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 7 with EStartup

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

the class JdbcIntegration method beforeAll.

@Override
public void beforeAll(ExtensionContext context) {
    // Method for getting standard args from environment instead of command line
    // It may be useful to have this in StandardArgsProcessor
    var env = System.getenv();
    var workingDir = Paths.get(".").toAbsolutePath().normalize();
    var configFile = env.get(TRAC_CONFIG_FILE);
    var keystoreKey = env.get(TRAC_KEYSTORE_KEY);
    if (configFile == null || configFile.isBlank())
        throw new EStartup("Missing environment variable for integration testing: " + TRAC_CONFIG_FILE);
    var configManager = Startup.quickConfig(workingDir, configFile, keystoreKey);
    var platformConfig = configManager.loadRootConfigObject(PlatformConfig.class);
    var metaConfig = platformConfig.getServices().getMeta();
    var dalProps = new Properties();
    dalProps.putAll(metaConfig.getDalPropsMap());
    dialect = JdbcSetup.getSqlDialect(dalProps, "");
    source = JdbcSetup.createDatasource(dalProps, "");
}
Also used : EStartup(com.accenture.trac.common.exception.EStartup) Properties(java.util.Properties)

Example 8 with EStartup

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

the class AwsConfigLoader method loadTextFile.

@Override
public String loadTextFile(URI uri) {
    var ERROR_MSG_TEMPLATE = "Failed to load config file from S3: %2$s [%1$s]";
    final AmazonS3 s3 = AmazonS3ClientBuilder.standard().build();
    String path = uri.getPath();
    if (path.startsWith("/")) {
        path = path.substring(1);
    }
    String output;
    try {
        S3Object o = s3.getObject(uri.getHost(), path);
        try (S3ObjectInputStream s3is = o.getObjectContent()) {
            try (ByteArrayOutputStream fos = new ByteArrayOutputStream()) {
                byte[] read_buf = new byte[1024];
                int read_len;
                while ((read_len = s3is.read(read_buf)) > 0) {
                    fos.write(read_buf, 0, read_len);
                }
                output = fos.toString();
            }
        }
        return output;
    } catch (AmazonS3Exception | IOException e) {
        var message = String.format(ERROR_MSG_TEMPLATE, path, e.getMessage());
        throw new EStartup(message, e);
    }
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) S3ObjectInputStream(com.amazonaws.services.s3.model.S3ObjectInputStream) S3Object(com.amazonaws.services.s3.model.S3Object) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AmazonS3Exception(com.amazonaws.services.s3.model.AmazonS3Exception) IOException(java.io.IOException) EStartup(com.accenture.trac.common.exception.EStartup)

Example 9 with EStartup

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

the class JdbcSetup method getSqlDialect.

public static JdbcDialect getSqlDialect(Properties props, String configBase) {
    var dialectPropKey = configBase + DIALECT_PROPERTY;
    var dialect = props.getProperty(dialectPropKey, null);
    if (dialect == null || dialect.isBlank())
        throw new EStartup("Missing required config property: " + dialectPropKey);
    try {
        return Enum.valueOf(JdbcDialect.class, dialect);
    } catch (IllegalArgumentException e) {
        throw new EStartup(String.format("Unsupported SQL dialect: [%s]", dialect));
    }
}
Also used : EStartup(com.accenture.trac.common.exception.EStartup)

Example 10 with EStartup

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

the class TestConfigLoader method loadTextFile.

@Override
public String loadTextFile(URI uri) {
    // Ignore leading slash on path component
    var relativePath = uri.getPath().substring(1);
    var absolutePath = tempDir.resolve(relativePath);
    try {
        return Files.readString(absolutePath);
    } catch (IOException e) {
        throw new EStartup("Config file could not be read: " + e.getMessage(), e);
    }
}
Also used : IOException(java.io.IOException) 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