Search in sources :

Example 31 with StorageException

use of com.microsoft.azure.storage.StorageException in project jackrabbit-oak by apache.

the class AzureBlobStoreBackend method deleteMetadataRecord.

@Override
public boolean deleteMetadataRecord(String name) {
    long start = System.currentTimeMillis();
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        CloudBlockBlob blob = getAzureContainer().getBlockBlobReference(addMetaKeyPrefix(name));
        boolean result = blob.deleteIfExists();
        LOG.debug("Metadata record {}. metadataName={} duration={}", result ? "deleted" : "delete requested, but it does not exist (perhaps already deleted)", name, (System.currentTimeMillis() - start));
        return result;
    } catch (StorageException e) {
        LOG.info("Error deleting metadata record. metadataName={}", name, e);
    } catch (DataStoreException | URISyntaxException e) {
        LOG.debug("Error deleting metadata record. metadataName={}", name, e);
    } finally {
        if (contextClassLoader != null) {
            Thread.currentThread().setContextClassLoader(contextClassLoader);
        }
    }
    return false;
}
Also used : DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) URISyntaxException(java.net.URISyntaxException) CloudBlockBlob(com.microsoft.azure.storage.blob.CloudBlockBlob) StorageException(com.microsoft.azure.storage.StorageException)

Example 32 with StorageException

use of com.microsoft.azure.storage.StorageException 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);
        }
    }
}
Also used : DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) URISyntaxException(java.net.URISyntaxException) CloudBlockBlob(com.microsoft.azure.storage.blob.CloudBlockBlob) StorageException(com.microsoft.azure.storage.StorageException)

Example 33 with StorageException

use of com.microsoft.azure.storage.StorageException 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);
        }
    }
}
Also used : CloudBlob(com.microsoft.azure.storage.blob.CloudBlob) DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) ListBlobItem(com.microsoft.azure.storage.blob.ListBlobItem) CloudBlobDirectory(com.microsoft.azure.storage.blob.CloudBlobDirectory) URISyntaxException(java.net.URISyntaxException) StorageException(com.microsoft.azure.storage.StorageException)

Example 34 with StorageException

use of com.microsoft.azure.storage.StorageException 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);
        }
    }
}
Also used : DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) URISyntaxException(java.net.URISyntaxException) CloudBlockBlob(com.microsoft.azure.storage.blob.CloudBlockBlob) StorageException(com.microsoft.azure.storage.StorageException)

Example 35 with StorageException

use of com.microsoft.azure.storage.StorageException 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;
}
Also used : DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) ListBlobItem(com.microsoft.azure.storage.blob.ListBlobItem) CloudBlobDirectory(com.microsoft.azure.storage.blob.CloudBlobDirectory) URISyntaxException(java.net.URISyntaxException) CloudBlob(com.microsoft.azure.storage.blob.CloudBlob) AbstractDataRecord(org.apache.jackrabbit.oak.spi.blob.AbstractDataRecord) DataRecord(org.apache.jackrabbit.core.data.DataRecord) StorageException(com.microsoft.azure.storage.StorageException)

Aggregations

StorageException (com.microsoft.azure.storage.StorageException)55 URISyntaxException (java.net.URISyntaxException)34 IOException (java.io.IOException)31 Path (org.apache.hadoop.fs.Path)13 FileNotFoundException (java.io.FileNotFoundException)10 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)10 CloudBlockBlob (com.microsoft.azure.storage.blob.CloudBlockBlob)8 InputStream (java.io.InputStream)7 JsonParseException (com.fasterxml.jackson.core.JsonParseException)5 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)5 CloudStorageAccount (com.microsoft.azure.storage.CloudStorageAccount)5 CloudBlob (com.microsoft.azure.storage.blob.CloudBlob)5 EOFException (java.io.EOFException)5 InvalidKeyException (java.security.InvalidKeyException)5 FileAlreadyExistsException (org.apache.hadoop.fs.FileAlreadyExistsException)5 AccessCondition (com.microsoft.azure.storage.AccessCondition)4 BlobRequestOptions (com.microsoft.azure.storage.blob.BlobRequestOptions)4 CloudBlobClient (com.microsoft.azure.storage.blob.CloudBlobClient)4 CloudBlobContainer (com.microsoft.azure.storage.blob.CloudBlobContainer)4 CloudBlobDirectory (com.microsoft.azure.storage.blob.CloudBlobDirectory)4