use of org.apache.jackrabbit.core.data.DataStoreException in project jackrabbit-oak by apache.
the class AzureBlobStoreBackend method getRecord.
@Override
public DataRecord getRecord(DataIdentifier identifier) throws DataStoreException {
if (null == identifier) {
throw new NullPointerException("identifier");
}
String key = getKeyName(identifier);
long start = System.currentTimeMillis();
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
CloudBlockBlob blob = getAzureContainer().getBlockBlobReference(key);
if (blob.exists()) {
blob.downloadAttributes();
AzureBlobStoreDataRecord record = new AzureBlobStoreDataRecord(this, connectionString, containerName, new DataIdentifier(getIdentifierName(blob.getName())), blob.getProperties().getLastModified().getTime(), blob.getProperties().getLength());
LOG.debug("Data record read for blob. identifier={} duration={} record={}", key, (System.currentTimeMillis() - start), record);
return record;
} else {
LOG.debug("Blob not found. identifier={} duration={}", key, (System.currentTimeMillis() - start));
throw new DataStoreException(String.format("Cannot find blob. identifier=%s", key));
}
} catch (StorageException e) {
LOG.info("Error getting data record for blob. identifier={}", key, e);
throw new DataStoreException(String.format("Cannot retrieve blob. identifier=%s", key), e);
} catch (URISyntaxException e) {
LOG.debug("Error getting data record for blob. identifier={}", key, e);
throw new DataStoreException(String.format("Cannot retrieve blob. identifier=%s", key), e);
} finally {
if (contextClassLoader != null) {
Thread.currentThread().setContextClassLoader(contextClassLoader);
}
}
}
use of org.apache.jackrabbit.core.data.DataStoreException in project jackrabbit-oak by apache.
the class AzureBlobStoreBackend method deleteAllMetadataRecords.
@Override
public void deleteAllMetadataRecords(String prefix) {
if (null == prefix) {
throw new NullPointerException("prefix");
}
long start = System.currentTimeMillis();
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
CloudBlobDirectory metaDir = getAzureContainer().getDirectoryReference(META_DIR_NAME);
int total = 0;
for (ListBlobItem item : metaDir.listBlobs(prefix)) {
if (item instanceof CloudBlob) {
if (((CloudBlob) item).deleteIfExists()) {
total++;
}
}
}
LOG.debug("Metadata records deleted. recordsDeleted={} metadataFolder={} duration={}", total, prefix, (System.currentTimeMillis() - start));
} catch (StorageException e) {
LOG.info("Error deleting all metadata records. metadataFolder={}", prefix, e);
} catch (DataStoreException | URISyntaxException e) {
LOG.debug("Error deleting all metadata records. metadataFolder={}", prefix, e);
} finally {
if (null != contextClassLoader) {
Thread.currentThread().setContextClassLoader(contextClassLoader);
}
}
}
use of org.apache.jackrabbit.core.data.DataStoreException in project jackrabbit-oak by apache.
the class AzureBlobStoreBackend method read.
@Override
public InputStream read(DataIdentifier identifier) throws DataStoreException {
if (null == identifier)
throw new NullPointerException("identifier");
String key = getKeyName(identifier);
long start = System.currentTimeMillis();
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
CloudBlockBlob blob = getAzureContainer().getBlockBlobReference(key);
if (!blob.exists()) {
throw new DataStoreException(String.format("Trying to read missing blob. identifier=%s", key));
}
InputStream is = blob.openInputStream();
LOG.debug("Got input stream for blob. identifier={} duration={}", key, (System.currentTimeMillis() - start));
return is;
} catch (StorageException e) {
LOG.info("Error reading blob. identifier=%s", key);
throw new DataStoreException(String.format("Cannot read blob. identifier=%s", key), e);
} catch (URISyntaxException e) {
LOG.debug("Error reading blob. identifier=%s", key);
throw new DataStoreException(String.format("Cannot read blob. identifier=%s", key), e);
} finally {
if (contextClassLoader != null) {
Thread.currentThread().setContextClassLoader(contextClassLoader);
}
}
}
use of org.apache.jackrabbit.core.data.DataStoreException in project jackrabbit-oak by apache.
the class AzureBlobStoreBackend method getAllMetadataRecords.
@Override
public List<DataRecord> getAllMetadataRecords(String prefix) {
if (null == prefix) {
throw new NullPointerException("prefix");
}
long start = System.currentTimeMillis();
final List<DataRecord> records = Lists.newArrayList();
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
CloudBlobDirectory metaDir = getAzureContainer().getDirectoryReference(META_DIR_NAME);
for (ListBlobItem item : metaDir.listBlobs(prefix)) {
if (item instanceof CloudBlob) {
CloudBlob blob = (CloudBlob) item;
records.add(new AzureBlobStoreDataRecord(this, connectionString, containerName, new DataIdentifier(stripMetaKeyPrefix(blob.getName())), blob.getProperties().getLastModified().getTime(), blob.getProperties().getLength(), true));
}
}
LOG.debug("Metadata records read. recordsRead={} metadataFolder={} duration={}", records.size(), prefix, (System.currentTimeMillis() - start));
} catch (StorageException e) {
LOG.info("Error reading all metadata records. metadataFolder={}", prefix, e);
} catch (DataStoreException | URISyntaxException e) {
LOG.debug("Error reading all metadata records. metadataFolder={}", prefix, e);
} finally {
if (null != contextClassLoader) {
Thread.currentThread().setContextClassLoader(contextClassLoader);
}
}
return records;
}
use of org.apache.jackrabbit.core.data.DataStoreException in project jackrabbit-oak by apache.
the class AzureBlobStoreBackend method exists.
@Override
public boolean exists(DataIdentifier identifier) throws DataStoreException {
long start = System.currentTimeMillis();
String key = getKeyName(identifier);
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
boolean exists = getAzureContainer().getBlockBlobReference(key).exists();
LOG.debug("Blob exists={} identifier={} duration={}", exists, key, (System.currentTimeMillis() - start));
return exists;
} catch (Exception e) {
throw new DataStoreException(e);
} finally {
if (null != contextClassLoader) {
Thread.currentThread().setContextClassLoader(contextClassLoader);
}
}
}
Aggregations