Search in sources :

Example 1 with NoOpStorageFactory

use of io.pravega.segmentstore.storage.noop.NoOpStorageFactory in project pravega by pravega.

the class StorageLoader method load.

public StorageFactory load(ConfigSetup setup, String storageImplementation, StorageLayoutType storageLayoutType, ScheduledExecutorService executor) {
    ServiceLoader<StorageFactoryCreator> loader = ServiceLoader.load(StorageFactoryCreator.class);
    StorageExtraConfig noOpConfig = setup.getConfig(StorageExtraConfig::builder);
    for (StorageFactoryCreator factoryCreator : loader) {
        val factories = factoryCreator.getStorageFactories();
        for (val factoryInfo : factories) {
            log.info("Loading {}, trying {}", storageImplementation, factoryInfo);
            if (factoryInfo.getName().equals(storageImplementation) && factoryInfo.getStorageLayoutType() == storageLayoutType) {
                StorageFactory factory = factoryCreator.createFactory(factoryInfo, setup, executor);
                if (!noOpConfig.isStorageNoOpMode()) {
                    return factory;
                } else {
                    // The specified storage implementation is in No-Op mode.
                    log.warn("{} IS IN NO-OP MODE: DATA LOSS WILL HAPPEN! MAKE SURE IT IS BY FULL INTENTION FOR TESTING PURPOSE!", storageImplementation);
                    return new NoOpStorageFactory(noOpConfig, executor, factory, null);
                }
            }
        }
    }
    return null;
}
Also used : lombok.val(lombok.val) StorageFactory(io.pravega.segmentstore.storage.StorageFactory) NoOpStorageFactory(io.pravega.segmentstore.storage.noop.NoOpStorageFactory) NoOpStorageFactory(io.pravega.segmentstore.storage.noop.NoOpStorageFactory) StorageFactoryCreator(io.pravega.segmentstore.storage.StorageFactoryCreator) StorageExtraConfig(io.pravega.segmentstore.storage.noop.StorageExtraConfig)

Example 2 with NoOpStorageFactory

use of io.pravega.segmentstore.storage.noop.NoOpStorageFactory in project pravega by pravega.

the class StorageLoaderTest method testNoOpWithInMemoryStorage.

@Test
public void testNoOpWithInMemoryStorage() throws Exception {
    @Cleanup("shutdownNow") ScheduledExecutorService executor = ExecutorServiceHelpers.newScheduledThreadPool(1, "test");
    ServiceBuilderConfig.Builder configBuilder = ServiceBuilderConfig.builder().include(StorageExtraConfig.builder().with(StorageExtraConfig.STORAGE_NO_OP_MODE, true)).include(ServiceConfig.builder().with(ServiceConfig.CONTAINER_COUNT, 1).with(ServiceConfig.STORAGE_IMPLEMENTATION, ServiceConfig.StorageType.INMEMORY.name()));
    ServiceBuilder builder = ServiceBuilder.newInMemoryBuilder(configBuilder.build()).withStorageFactory(setup -> {
        StorageLoader loader = new StorageLoader();
        expectedFactory = loader.load(setup, "INMEMORY", StorageLayoutType.ROLLING_STORAGE, executor);
        return expectedFactory;
    });
    builder.initialize();
    assertTrue(expectedFactory instanceof NoOpStorageFactory);
    builder.close();
    configBuilder.include(StorageExtraConfig.builder().with(StorageExtraConfig.STORAGE_NO_OP_MODE, false));
    builder = ServiceBuilder.newInMemoryBuilder(configBuilder.build()).withStorageFactory(setup -> {
        StorageLoader loader = new StorageLoader();
        expectedFactory = loader.load(setup, "INMEMORY", StorageLayoutType.ROLLING_STORAGE, executor);
        return expectedFactory;
    });
    builder.initialize();
    assertTrue(expectedFactory instanceof InMemoryStorageFactory);
    builder.close();
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ServiceConfig(io.pravega.segmentstore.server.store.ServiceConfig) StorageFactory(io.pravega.segmentstore.storage.StorageFactory) Cleanup(lombok.Cleanup) ChunkedSegmentStorageConfig(io.pravega.segmentstore.storage.chunklayer.ChunkedSegmentStorageConfig) ServiceBuilderConfig(io.pravega.segmentstore.server.store.ServiceBuilderConfig) ServiceBuilder(io.pravega.segmentstore.server.store.ServiceBuilder) HDFSSimpleStorageFactory(io.pravega.storage.hdfs.HDFSSimpleStorageFactory) FileSystemStorageFactory(io.pravega.storage.filesystem.FileSystemStorageFactory) InMemoryStorageFactory(io.pravega.segmentstore.storage.mocks.InMemoryStorageFactory) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) FileSystemStorageConfig(io.pravega.storage.filesystem.FileSystemStorageConfig) FileSystemSimpleStorageFactory(io.pravega.storage.filesystem.FileSystemSimpleStorageFactory) ExtendedS3SimpleStorageFactory(io.pravega.storage.extendeds3.ExtendedS3SimpleStorageFactory) ConfigSetup(io.pravega.segmentstore.storage.ConfigSetup) lombok.val(lombok.val) ExtendedS3StorageFactory(io.pravega.storage.extendeds3.ExtendedS3StorageFactory) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) NoOpStorageFactory(io.pravega.segmentstore.storage.noop.NoOpStorageFactory) HDFSStorageFactory(io.pravega.storage.hdfs.HDFSStorageFactory) StorageLayoutType(io.pravega.segmentstore.storage.StorageLayoutType) StorageExtraConfig(io.pravega.segmentstore.storage.noop.StorageExtraConfig) ExecutorServiceHelpers(io.pravega.common.concurrent.ExecutorServiceHelpers) ExtendedS3StorageConfig(io.pravega.storage.extendeds3.ExtendedS3StorageConfig) HDFSStorageConfig(io.pravega.storage.hdfs.HDFSStorageConfig) Mockito.mock(org.mockito.Mockito.mock) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ServiceBuilderConfig(io.pravega.segmentstore.server.store.ServiceBuilderConfig) NoOpStorageFactory(io.pravega.segmentstore.storage.noop.NoOpStorageFactory) InMemoryStorageFactory(io.pravega.segmentstore.storage.mocks.InMemoryStorageFactory) Cleanup(lombok.Cleanup) ServiceBuilder(io.pravega.segmentstore.server.store.ServiceBuilder) Test(org.junit.Test)

Aggregations

StorageFactory (io.pravega.segmentstore.storage.StorageFactory)2 NoOpStorageFactory (io.pravega.segmentstore.storage.noop.NoOpStorageFactory)2 StorageExtraConfig (io.pravega.segmentstore.storage.noop.StorageExtraConfig)2 lombok.val (lombok.val)2 ExecutorServiceHelpers (io.pravega.common.concurrent.ExecutorServiceHelpers)1 ServiceBuilder (io.pravega.segmentstore.server.store.ServiceBuilder)1 ServiceBuilderConfig (io.pravega.segmentstore.server.store.ServiceBuilderConfig)1 ServiceConfig (io.pravega.segmentstore.server.store.ServiceConfig)1 ConfigSetup (io.pravega.segmentstore.storage.ConfigSetup)1 StorageFactoryCreator (io.pravega.segmentstore.storage.StorageFactoryCreator)1 StorageLayoutType (io.pravega.segmentstore.storage.StorageLayoutType)1 ChunkedSegmentStorageConfig (io.pravega.segmentstore.storage.chunklayer.ChunkedSegmentStorageConfig)1 InMemoryStorageFactory (io.pravega.segmentstore.storage.mocks.InMemoryStorageFactory)1 ExtendedS3SimpleStorageFactory (io.pravega.storage.extendeds3.ExtendedS3SimpleStorageFactory)1 ExtendedS3StorageConfig (io.pravega.storage.extendeds3.ExtendedS3StorageConfig)1 ExtendedS3StorageFactory (io.pravega.storage.extendeds3.ExtendedS3StorageFactory)1 FileSystemSimpleStorageFactory (io.pravega.storage.filesystem.FileSystemSimpleStorageFactory)1 FileSystemStorageConfig (io.pravega.storage.filesystem.FileSystemStorageConfig)1 FileSystemStorageFactory (io.pravega.storage.filesystem.FileSystemStorageFactory)1 HDFSSimpleStorageFactory (io.pravega.storage.hdfs.HDFSSimpleStorageFactory)1