Search in sources :

Example 1 with FlatDataStorage

use of com.accenture.trac.common.storage.flat.FlatDataStorage 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)

Aggregations

EStartup (com.accenture.trac.common.exception.EStartup)1 FlatDataStorage (com.accenture.trac.common.storage.flat.FlatDataStorage)1