use of com.microsoft.azure.storage.blob.CloudBlobDirectory in project tdi-studio-se by Talend.
the class AzureFileSystem method deleteFolder.
public void deleteFolder(String folder, CloudBlobContainer container) throws StorageException, URISyntaxException {
for (ListBlobItem blobItem : container.listBlobs(folder)) {
if (blobItem instanceof CloudBlob) {
CloudBlob blob = (CloudBlob) blobItem;
blob.delete();
} else {
if (blobItem instanceof CloudBlobDirectory)
deleteFolder(((CloudBlobDirectory) blobItem).getPrefix(), container);
}
}
}
use of com.microsoft.azure.storage.blob.CloudBlobDirectory 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 com.microsoft.azure.storage.blob.CloudBlobDirectory 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 com.microsoft.azure.storage.blob.CloudBlobDirectory in project jackrabbit-oak by apache.
the class AzureArchiveManager method renameTo.
@Override
public boolean renameTo(String from, String to) {
try {
CloudBlobDirectory targetDirectory = getDirectory(to);
getBlobs(from).forEach(cloudBlob -> {
try {
renameBlob(cloudBlob, targetDirectory);
} catch (IOException e) {
log.error("Can't rename segment {}", cloudBlob.getUri().getPath(), e);
}
});
return true;
} catch (IOException e) {
log.error("Can't rename archive {} to {}", from, to, e);
return false;
}
}
use of com.microsoft.azure.storage.blob.CloudBlobDirectory in project jackrabbit-oak by apache.
the class AzureBlobStoreBackend method getMetadataRecord.
@Override
public DataRecord getMetadataRecord(String name) {
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
long start = System.currentTimeMillis();
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
CloudBlobDirectory metaDir = getAzureContainer().getDirectoryReference(META_DIR_NAME);
CloudBlockBlob blob = metaDir.getBlockBlobReference(name);
if (!blob.exists()) {
LOG.warn("Trying to read missing metadata. metadataName={}", name);
return null;
}
blob.downloadAttributes();
long lastModified = blob.getProperties().getLastModified().getTime();
long length = blob.getProperties().getLength();
AzureBlobStoreDataRecord record = new AzureBlobStoreDataRecord(this, connectionString, containerName, new DataIdentifier(name), lastModified, length, true);
LOG.debug("Metadata record read. metadataName={} duration={} record={}", name, (System.currentTimeMillis() - start), record);
return record;
} catch (StorageException e) {
LOG.info("Error reading metadata record. metadataName={}", name, e);
throw new RuntimeException(e);
} catch (Exception e) {
LOG.debug("Error reading metadata record. metadataName={}", name, e);
throw new RuntimeException(e);
} finally {
if (null != contextClassLoader) {
Thread.currentThread().setContextClassLoader(contextClassLoader);
}
}
}
Aggregations