Search in sources :

Example 16 with EStartup

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

the class TracDataService method checkDefaultStorageAndFormat.

private void checkDefaultStorageAndFormat(IStorageManager storage, ICodecManager formats, DataServiceConfig config) {
    try {
        storage.getFileStorage(config.getDefaultStorageKey());
        storage.getDataStorage(config.getDefaultStorageKey());
        formats.getCodec(config.getDefaultStorageFormat());
    } catch (EStorageConfig e) {
        var msg = String.format("Storage not configured for default storage key: [%s]", config.getDefaultStorageKey());
        log.error(msg);
        throw new EStartup(msg, e);
    } catch (EPluginNotAvailable e) {
        var msg = String.format("Codec not available for default storage format: [%s]", config.getDefaultStorageFormat());
        log.error(msg);
        throw new EStartup(msg, e);
    }
}
Also used : EPluginNotAvailable(com.accenture.trac.common.exception.EPluginNotAvailable) EStorageConfig(com.accenture.trac.common.exception.EStorageConfig) EStartup(com.accenture.trac.common.exception.EStartup)

Example 17 with EStartup

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

the class TracOrchestratorService method doStartup.

@Override
protected void doStartup(Duration startupTimeout) {
    PlatformConfig platformConfig;
    OrchServiceConfig orchestratorConfig;
    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);
        orchestratorConfig = platformConfig.getServices().getOrch();
        // 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;
        bossGroup = new NioEventLoopGroup(1, new DefaultThreadFactory("orch-boss"));
        nettyGroup = new NioEventLoopGroup(2, new DefaultThreadFactory("orch-netty"));
        serviceGroup = new NioEventLoopGroup(CONCURRENT_REQUESTS, new DefaultThreadFactory("orch-svc"));
        prepareMetadataClientChannel(platformConfig, clientChannelType);
        var metaClient = TrustedMetadataApiGrpc.newFutureStub(clientChannel);
        var jobLifecycle = new JobLifecycle(platformConfig, metaClient);
        jobCache = new LocalJobCache();
        // jobCache = InterfaceLogging.wrap(jobCache, IJobCache.class);
        var executors = new ExecutionManager(pluginManager);
        executors.initExecutor(orchestratorConfig.getExecutor());
        jobExecCtrl = executors.getExecutor();
        jobMonitor = new JobManagementService(jobLifecycle, jobCache, jobExecCtrl, serviceGroup);
        jobMonitor.start();
        var orchestrator = new JobApiService(jobLifecycle, jobCache);
        var orchestratorApi = new TracOrchestratorApi(orchestrator);
        this.server = NettyServerBuilder.forPort(orchestratorConfig.getPort()).addService(orchestratorApi).channelType(channelType).bossEventLoopGroup(bossGroup).workerEventLoopGroup(nettyGroup).executor(serviceGroup).build();
        this.server.start();
        log.info("Orchestrator is listening on port {}", server.getPort());
    } catch (IOException e) {
        throw new EStartup(e.getMessage(), e);
    }
}
Also used : JobLifecycle(com.accenture.trac.svc.orch.service.JobLifecycle) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) LocalJobCache(com.accenture.trac.svc.orch.cache.local.LocalJobCache) ExecutionManager(com.accenture.trac.common.exec.ExecutionManager) TracOrchestratorApi(com.accenture.trac.svc.orch.api.TracOrchestratorApi) IOException(java.io.IOException) EStartup(com.accenture.trac.common.exception.EStartup) IOException(java.io.IOException) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) PlatformConfig(com.accenture.trac.config.PlatformConfig) JobManagementService(com.accenture.trac.svc.orch.service.JobManagementService) OrchServiceConfig(com.accenture.trac.config.OrchServiceConfig) JobApiService(com.accenture.trac.svc.orch.service.JobApiService) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 18 with EStartup

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

the class GcpConfigLoader method loadTextFile.

@Override
public String loadTextFile(URI uri) {
    var ERROR_MSG_TEMPLATE = "Failed to load config file from GCP: %2$s [%1$s]";
    String path = uri.getPath();
    if (path.startsWith("/")) {
        path = path.substring(1);
    }
    StorageOptions options = StorageOptions.newBuilder().build();
    Storage storage = options.getService();
    Blob blob = storage.get(uri.getHost(), path);
    if (blob == null) {
        var message = String.format("Cannot load config from GCP: [%s]. File does not exist.", uri);
        throw new EStartup(message);
    }
    ReadChannel readChannel = blob.reader();
    BufferedReader br = new BufferedReader(Channels.newReader(readChannel, StandardCharsets.UTF_8));
    String output;
    try {
        output = br.lines().collect(Collectors.joining());
        return output;
    } catch (IllegalArgumentException | UncheckedIOException e) {
        var message = String.format(ERROR_MSG_TEMPLATE, path, e.getMessage());
        throw new EStartup(message, e);
    }
}
Also used : Blob(com.google.cloud.storage.Blob) Storage(com.google.cloud.storage.Storage) StorageOptions(com.google.cloud.storage.StorageOptions) BufferedReader(java.io.BufferedReader) UncheckedIOException(java.io.UncheckedIOException) EStartup(com.accenture.trac.common.exception.EStartup) ReadChannel(com.google.cloud.ReadChannel)

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