Search in sources :

Example 11 with DataStore

use of org.apache.jackrabbit.core.data.DataStore in project jackrabbit-oak by apache.

the class DataStoreCheckTest method setup.

@Before
public void setup() throws Exception {
    if (S3DataStoreUtils.isS3Configured()) {
        Properties props = S3DataStoreUtils.getS3Config();
        props.setProperty("cacheSize", "0");
        container = props.getProperty(S3Constants.S3_BUCKET);
        DataStore ds = S3DataStoreUtils.getS3DataStore(S3DataStoreUtils.getFixtures().get(0), props, temporaryFolder.newFolder().getAbsolutePath());
        setupDataStore = new DataStoreBlobStore(ds);
        cfgFilePath = createTempConfig(temporaryFolder.newFile(), props);
        dsOption = "s3ds";
    } else if (AzureDataStoreUtils.isAzureConfigured()) {
        Properties props = AzureDataStoreUtils.getAzureConfig();
        props.setProperty("cacheSize", "0");
        container = props.getProperty(AzureConstants.AZURE_BLOB_CONTAINER_NAME);
        DataStore ds = AzureDataStoreUtils.getAzureDataStore(props, temporaryFolder.newFolder().getAbsolutePath());
        setupDataStore = new DataStoreBlobStore(ds);
        cfgFilePath = createTempConfig(temporaryFolder.newFile(), props);
        dsOption = "azureblobds";
    } else {
        OakFileDataStore delegate = new OakFileDataStore();
        dsPath = temporaryFolder.newFolder().getAbsolutePath();
        delegate.setPath(dsPath);
        delegate.init(null);
        setupDataStore = new DataStoreBlobStore(delegate);
        File cfgFile = temporaryFolder.newFile();
        Properties props = new Properties();
        props.put("path", dsPath);
        props.put("minRecordLength", new Long(4096));
        cfgFilePath = createTempConfig(cfgFile, props);
        dsOption = "fds";
    }
    File storeFile = temporaryFolder.newFolder();
    storePath = storeFile.getAbsolutePath();
    FileStore fileStore = FileStoreBuilder.fileStoreBuilder(storeFile).withBlobStore(setupDataStore).withMaxFileSize(256).withSegmentCacheSize(64).build();
    NodeStore store = SegmentNodeStoreBuilders.builder(fileStore).build();
    /* Create nodes with blobs stored in DS*/
    NodeBuilder a = store.getRoot().builder();
    int numBlobs = 10;
    blobsAdded = Sets.newHashSet();
    for (int i = 0; i < numBlobs; i++) {
        SegmentBlob b = (SegmentBlob) store.createBlob(randomStream(i, 18342));
        Iterator<String> idIter = setupDataStore.resolveChunks(b.getBlobId());
        while (idIter.hasNext()) {
            String chunk = idIter.next();
            blobsAdded.add(chunk);
        }
        a.child("c" + i).setProperty("x", b);
    }
    store.merge(a, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    log.info("Created blobs : {}", blobsAdded);
    fileStore.close();
}
Also used : OakFileDataStore(org.apache.jackrabbit.oak.plugins.blob.datastore.OakFileDataStore) SegmentBlob(org.apache.jackrabbit.oak.segment.SegmentBlob) Properties(java.util.Properties) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) DataStore(org.apache.jackrabbit.core.data.DataStore) OakFileDataStore(org.apache.jackrabbit.oak.plugins.blob.datastore.OakFileDataStore) File(java.io.File) DataStoreBlobStore(org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore) Before(org.junit.Before)

Example 12 with DataStore

use of org.apache.jackrabbit.core.data.DataStore in project jackrabbit-oak by apache.

the class BlobStoreFixture method getDataStore.

public static BlobStoreFixture getDataStore(final File basedir, final int fdsCacheInMB, final StatisticsProvider statisticsProvider) {
    return new BlobStoreFixture("DS") {

        private DataStore dataStore;

        private BlobStore blobStore;

        private File storeDir;

        private Map<String, ?> config;

        @Override
        public BlobStore setUp() {
            String className = System.getProperty("dataStore");
            checkNotNull(className, "No system property named 'dataStore' defined");
            try {
                dataStore = Class.forName(className).asSubclass(DataStore.class).newInstance();
                config = getConfig();
                configure(dataStore, config);
                dataStore = configureIfCloudDataStore(className, dataStore, config, unique.toLowerCase(), statisticsProvider);
                storeDir = new File(basedir, unique);
                dataStore.init(storeDir.getAbsolutePath());
                blobStore = new DataStoreBlobStore(dataStore, true, fdsCacheInMB);
                configure(blobStore);
                return blobStore;
            } catch (Exception e) {
                throw new IllegalStateException("Cannot instantiate DataStore " + className, e);
            }
        }

        @Override
        public void tearDown() {
            if (blobStore instanceof DataStoreBlobStore) {
                try {
                    ((DataStoreBlobStore) blobStore).close();
                    cleanup(storeDir, config, unique.toLowerCase());
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }

        @Override
        public long size() {
            throw new UnsupportedOperationException("Implementation pending");
        }
    };
}
Also used : DataStoreUtils.configureIfCloudDataStore(org.apache.jackrabbit.oak.fixture.DataStoreUtils.configureIfCloudDataStore) DataStore(org.apache.jackrabbit.core.data.DataStore) FileDataStore(org.apache.jackrabbit.core.data.FileDataStore) File(java.io.File) Map(java.util.Map) BlobStore(org.apache.jackrabbit.oak.spi.blob.BlobStore) MemoryBlobStore(org.apache.jackrabbit.oak.spi.blob.MemoryBlobStore) DataStoreBlobStore(org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore) FileBlobStore(org.apache.jackrabbit.oak.spi.blob.FileBlobStore) IOException(java.io.IOException) DataStoreBlobStore(org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore)

Example 13 with DataStore

use of org.apache.jackrabbit.core.data.DataStore in project jackrabbit-oak by apache.

the class TestS3Ds method createDataStore.

protected DataStore createDataStore() throws RepositoryException {
    DataStore s3ds = null;
    try {
        s3ds = getS3DataStore(s3Class, props, dataStoreDir);
    } catch (Exception e) {
        e.printStackTrace();
    }
    sleep(1000);
    return s3ds;
}
Also used : S3DataStore(org.apache.jackrabbit.oak.blob.cloud.aws.s3.S3DataStore) DataStore(org.apache.jackrabbit.core.data.DataStore) S3DataStoreUtils.getS3DataStore(org.apache.jackrabbit.oak.blob.cloud.s3.S3DataStoreUtils.getS3DataStore) RepositoryException(javax.jcr.RepositoryException)

Example 14 with DataStore

use of org.apache.jackrabbit.core.data.DataStore in project jackrabbit-oak by apache.

the class S3DataStoreUtils method getS3DataStore.

public static DataStore getS3DataStore(String className, Properties props, String homeDir) throws Exception {
    DataStore ds = Class.forName(className).asSubclass(DataStore.class).newInstance();
    PropertiesUtil.populate(ds, Maps.fromProperties(props), false);
    // Set the props object
    if (S3.getName().equals(className)) {
        ((S3DataStore) ds).setProperties(props);
    } else if (JR2_S3.getName().equals(className)) {
        ((org.apache.jackrabbit.oak.blob.cloud.aws.s3.SharedS3DataStore) ds).setProperties(props);
    }
    ds.init(homeDir);
    return ds;
}
Also used : SharedS3DataStore(org.apache.jackrabbit.oak.blob.cloud.aws.s3.SharedS3DataStore) DataStore(org.apache.jackrabbit.core.data.DataStore) SharedS3DataStore(org.apache.jackrabbit.oak.blob.cloud.aws.s3.SharedS3DataStore)

Example 15 with DataStore

use of org.apache.jackrabbit.core.data.DataStore in project jackrabbit-oak by apache.

the class DataStoreServiceTest method configCachingFDS.

/**
     *
     * Test @CachingFDS is returned when cacheSize > 0
     */
@Test
public void configCachingFDS() throws Exception {
    System.setProperty(JR2_CACHING_PROP, "true");
    try {
        String nasPath = folder.getRoot().getAbsolutePath() + "/NASPath";
        String cachePath = folder.getRoot().getAbsolutePath() + "/cachePath";
        long cacheSize = 100L;
        Map<String, Object> config = new HashMap<String, Object>();
        config.put("repository.home", folder.getRoot().getAbsolutePath());
        config.put(FileDataStoreService.CACHE_SIZE, cacheSize);
        config.put(FileDataStoreService.PATH, nasPath);
        config.put(FileDataStoreService.CACHE_PATH, cachePath);
        FileDataStoreService fdsSvc = new FileDataStoreService();
        DataStore ds = fdsSvc.createDataStore(context.componentContext(), config);
        PropertiesUtil.populate(ds, config, false);
        ds.init(folder.getRoot().getAbsolutePath());
        assertTrue("not instance of CachingFDS", ds instanceof CachingFDS);
        CachingFDS cds = (CachingFDS) ds;
        assertEquals("cachesize not equal", cacheSize, cds.getCacheSize());
        assertEquals("cachepath not equal", cachePath, cds.getPath());
        Backend backend = cds.getBackend();
        Properties props = (Properties) getField(backend);
        assertEquals("path not equal", nasPath, props.getProperty(FSBackend.FS_BACKEND_PATH));
    } finally {
        System.clearProperty(JR2_CACHING_PROP);
    }
}
Also used : SharedBackend(org.apache.jackrabbit.oak.spi.blob.SharedBackend) Backend(org.apache.jackrabbit.core.data.Backend) FSBackend(org.apache.jackrabbit.core.data.FSBackend) HashMap(java.util.HashMap) DataStore(org.apache.jackrabbit.core.data.DataStore) FileDataStore(org.apache.jackrabbit.core.data.FileDataStore) CachingFDS(org.apache.jackrabbit.core.data.CachingFDS) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

DataStore (org.apache.jackrabbit.core.data.DataStore)22 FileDataStore (org.apache.jackrabbit.core.data.FileDataStore)9 Test (org.junit.Test)8 File (java.io.File)7 Properties (java.util.Properties)6 DataStoreBlobStore (org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore)5 IOException (java.io.IOException)4 RepositoryException (javax.jcr.RepositoryException)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 HashMap (java.util.HashMap)3 Random (java.util.Random)3 DataRecord (org.apache.jackrabbit.core.data.DataRecord)3 SharedS3DataStore (org.apache.jackrabbit.oak.blob.cloud.aws.s3.SharedS3DataStore)3 AbstractBlobStoreTest (org.apache.jackrabbit.oak.spi.blob.AbstractBlobStoreTest)3 BlobStore (org.apache.jackrabbit.oak.spi.blob.BlobStore)3 Closer (com.google.common.io.Closer)2 OptionParser (joptsimple.OptionParser)2 OptionSet (joptsimple.OptionSet)2 ClusterNode (org.apache.jackrabbit.core.cluster.ClusterNode)2 DataIdentifier (org.apache.jackrabbit.core.data.DataIdentifier)2