com.microsoft.azure.storage.blob.CloudBlobDirectory Java Examples
The following examples show how to use
com.microsoft.azure.storage.blob.CloudBlobDirectory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AzureCloudBlobClientActions.java From cloudbreak with Apache License 2.0 | 7 votes |
private void deleteBlobsInDirectory(CloudBlobContainer cloudBlobContainer, String directoryName) throws URISyntaxException, StorageException { CloudBlobDirectory blobDirectory = cloudBlobContainer.getDirectoryReference(directoryName); for (ListBlobItem blobItem : blobDirectory.listBlobs()) { if (blobItem instanceof CloudBlobDirectory) { deleteBlobsInDirectory(cloudBlobContainer, ((CloudBlobDirectory) blobItem).getPrefix()); } else if (blobItem instanceof CloudPageBlob) { CloudPageBlob cloudPageBlob = cloudBlobContainer.getPageBlobReference(((CloudPageBlob) blobItem).getName()); cloudPageBlob.deleteIfExists(); } else if (blobItem instanceof CloudBlockBlob) { CloudBlockBlob cloudBlockBlob = cloudBlobContainer.getBlockBlobReference(((CloudBlockBlob) blobItem).getName()); cloudBlockBlob.deleteIfExists(); } } }
Example #2
Source File: AzureCloudBlobClientActions.java From cloudbreak with Apache License 2.0 | 7 votes |
private void listBlobsInDirectory(CloudBlobContainer cloudBlobContainer, String directoryName) throws URISyntaxException, StorageException { CloudBlobDirectory blobDirectory = cloudBlobContainer.getDirectoryReference(directoryName); for (ListBlobItem blobItem : blobDirectory.listBlobs()) { if (blobItem instanceof CloudBlobDirectory) { listBlobsInDirectory(cloudBlobContainer, ((CloudBlobDirectory) blobItem).getPrefix()); } else if (blobItem instanceof CloudPageBlob) { Log.log(LOGGER, format(" Azure Adls Gen 2 Cloud Page Blob is present with Name: [%s] and with bytes of content: [%d] at URI: [%s] ", ((CloudPageBlob) blobItem).getName(), ((CloudPageBlob) blobItem).getProperties().getLength(), blobItem.getUri().getPath())); } else if (blobItem instanceof CloudBlockBlob) { Log.log(LOGGER, format(" Azure Adls Gen 2 Cloud Block Blob is present with Name: [%s] and with bytes of content: [%d] at URI: [%s] ", ((CloudBlockBlob) blobItem).getName(), ((CloudBlockBlob) blobItem).getProperties().getLength(), blobItem.getUri().getPath())); } else { LOGGER.error("Azure Adls Gen 2 Cloud Storage Item that is present at URI: [{}] cannot be classify as CloudBlob, CloudPageBlob and " + "CloudBlockBlob. ", blobItem.getUri().getPath()); throw new TestFailException(String.format("Azure Adls Gen 2 Cloud Storage Item that is present at URI: [%s] cannot be classify as" + " CloudBlob, CloudPageBlob and CloudBlockBlob. ", blobItem.getUri().getPath())); } } }
Example #3
Source File: AzureCloudBlobClientActions.java From cloudbreak with Apache License 2.0 | 7 votes |
private void listBlobsInDirectoryWithValidation(CloudBlobContainer cloudBlobContainer, String directoryName, Boolean zeroContent) throws URISyntaxException, StorageException { CloudBlobDirectory blobDirectory = cloudBlobContainer.getDirectoryReference(directoryName); Set<String> blobsWithZeroLength = new HashSet<>(); for (ListBlobItem blobItem : blobDirectory.listBlobs()) { if (blobItem instanceof CloudBlobDirectory) { listBlobsInDirectoryWithValidation(cloudBlobContainer, ((CloudBlobDirectory) blobItem).getPrefix(), zeroContent); } else if (blobItem instanceof CloudPageBlob) { validateBlobItemLength(blobItem, zeroContent, blobsWithZeroLength); } else if (blobItem instanceof CloudBlockBlob) { validateBlobItemLength(blobItem, zeroContent, blobsWithZeroLength); } else { LOGGER.error("Azure Adls Gen 2 Cloud Storage Item that is present at URI: {} cannot be classify as CloudBlob, CloudPageBlob and " + "CloudBlockBlob. ", blobItem.getUri().getPath()); throw new TestFailException(String.format("Azure Adls Gen 2 Cloud Storage Item that is present at URI: %s cannot be classify as" + " CloudBlob, CloudPageBlob and CloudBlockBlob. ", blobItem.getUri().getPath())); } } }
Example #4
Source File: AzureCloudBlobClientActions.java From cloudbreak with Apache License 2.0 | 6 votes |
public SdxTestDto deleteAllFolders(TestContext testContext, SdxTestDto sdxTestDto, SdxClient sdxClient) { String containerName = getContainerName(sdxTestDto.getRequest().getCloudStorage().getBaseLocation()); CloudBlobContainer cloudBlobContainer = getCloudBlobContainer(containerName); try { for (ListBlobItem blob : cloudBlobContainer.listBlobs()) { String blobName = blob.getUri().getPath().split("/", 3)[2]; String blobUriPath = blob.getUri().getPath(); if (blob instanceof CloudBlob) { ((CloudBlob) blob).deleteIfExists(); } else { if (blobName.endsWith("/")) { blobName = blobName.replaceAll(".$", ""); } CloudBlobDirectory blobDirectory = cloudBlobContainer.getDirectoryReference(blobName); deleteBlobsInDirectory(cloudBlobContainer, blobDirectory.getPrefix()); } } } catch (StorageException | URISyntaxException e) { LOGGER.error("Azure Adls Gen 2 Blob couldn't process the call. So it has been returned with error!", e); throw new TestFailException(String.format("Azure Adls Gen 2 Blob couldn't process the call. So it has been returned the error: %s", e)); } return sdxTestDto; }
Example #5
Source File: AzureStorageRepository.java From hawkbit-extensions with Eclipse Public License 1.0 | 6 votes |
@Override public void deleteByTenant(final String tenant) { try { final CloudBlobContainer container = getContainer(); final CloudBlobDirectory tenantDirectory = container.getDirectoryReference(sanitizeTenant(tenant)); LOG.info("Deleting Azure Storage blob folder (tenant) from container {} for tenant {}", container.getName(), tenant); final ResultSegment<ListBlobItem> blobs = tenantDirectory.listBlobsSegmented(); ResultContinuation token = null; do { token = blobs.getContinuationToken(); blobs.getResults().stream().filter(CloudBlob.class::isInstance).map(CloudBlob.class::cast) .forEach(this::deleteBlob); } while (token != null); } catch (final URISyntaxException | StorageException e) { throw new ArtifactStoreException("Failed to delete tenant directory from Azure storage", e); } }
Example #6
Source File: AzureResource.java From arcusplatform with Apache License 2.0 | 6 votes |
@Override public boolean isDirectory() { try { CloudBlobContainer blobContainer = blobClient.getContainerReference(this.container); if (blobContainer.exists()) { CloudBlobDirectory blockBlobDir = blobContainer.getDirectoryReference(this.blob); // Blob Directories don't exists unless they have something underneath return blockBlobDir.listBlobs().iterator().hasNext(); } } catch (Exception e) { logger.debug("isDirectory failed to lookup URI - [{}]", getUri(), e); } return false; }
Example #7
Source File: AzureCloudBlobClientActions.java From cloudbreak with Apache License 2.0 | 6 votes |
public void deleteAllFolders() throws StorageException, URISyntaxException { String containerName = getContainerName(); CloudBlobContainer cloudBlobContainer = getCloudBlobContainer(containerName); try { for (ListBlobItem blob : cloudBlobContainer.listBlobs()) { String blobName = blob.getUri().getPath().split("/", 3)[2]; String blobUriPath = blob.getUri().getPath(); if (blob instanceof CloudBlob) { ((CloudBlob) blob).deleteIfExists(); } else { if (blobName.endsWith("/")) { blobName = blobName.replaceAll(".$", ""); } CloudBlobDirectory blobDirectory = cloudBlobContainer.getDirectoryReference(blobName); deleteBlobsInDirectory(cloudBlobContainer, blobDirectory.getPrefix()); } } } catch (StorageException | URISyntaxException e) { LOGGER.error("Azure Adls Gen 2 Blob couldn't process the call. So it has been returned with error!", e); throw e; } }
Example #8
Source File: AzureBackuper.java From cassandra-backup with Apache License 2.0 | 6 votes |
private void deleteStaleBlobs() throws Exception { final Date expiryDate = Date.from(ZonedDateTime.now().minusWeeks(1).toInstant()); final CloudBlobDirectory directoryReference = blobContainer.getDirectoryReference(request.storageLocation.clusterId + "/" + request.storageLocation.datacenterId); for (final ListBlobItem blob : directoryReference.listBlobs(null, true, EnumSet.noneOf(BlobListingDetails.class), null, null)) { if (!(blob instanceof CloudBlob)) { continue; } final BlobProperties properties = ((CloudBlob) blob).getProperties(); if (properties == null || properties.getLastModified() == null) { continue; } if (properties.getLastModified().before(expiryDate)) { ((CloudBlob) blob).delete(); } } }
Example #9
Source File: VideoStorageAzure.java From arcusplatform with Apache License 2.0 | 6 votes |
@Override public VideoStorageSession create(UUID recordingId, UUID cameraId, UUID accountId, UUID placeId, @Nullable UUID personId, long ttlInSeconds) throws Exception { long startTime = System.nanoTime(); try { CloudBlobContainer container = getRandomContainer(recordingId, cameraId, placeId); CloudBlobDirectory dir = container.getDirectoryReference(placeId.toString()); CloudAppendBlob blob = dir.getAppendBlobReference(recordingId.toString()); blob.getProperties().setCacheControl("no-cache"); blob.getProperties().setContentType("video/mp2t"); blob.setStreamWriteSizeInBytes(4*1024*1024); VideoStorageSession result = new AzureStorageSession(recordingId, cameraId, accountId, placeId, ttlInSeconds, personId, blob); VIDEO_STORAGE_AZURE_CREATE_SUCCESS.update(System.nanoTime() - startTime, TimeUnit.NANOSECONDS); return result; } catch (Exception ex) { VIDEO_STORAGE_AZURE_CREATE_FAIL.update(System.nanoTime() - startTime, TimeUnit.NANOSECONDS); throw ex; } }
Example #10
Source File: AzureStorageService.java From crate with Apache License 2.0 | 6 votes |
public Set<String> children(String account, String container, BlobPath path) throws URISyntaxException, StorageException { final var blobsBuilder = new HashSet<String>(); final Tuple<CloudBlobClient, Supplier<OperationContext>> client = client(); final CloudBlobContainer blobContainer = client.v1().getContainerReference(container); final String keyPath = path.buildAsString(); final EnumSet<BlobListingDetails> enumBlobListingDetails = EnumSet.of(BlobListingDetails.METADATA); for (ListBlobItem blobItem : blobContainer.listBlobs(keyPath, false, enumBlobListingDetails, null, client.v2().get())) { if (blobItem instanceof CloudBlobDirectory) { final URI uri = blobItem.getUri(); LOGGER.trace(() -> new ParameterizedMessage("blob url [{}]", uri)); // uri.getPath is of the form /container/keyPath.* and we want to strip off the /container/ // this requires 1 + container.length() + 1, with each 1 corresponding to one of the /. // Lastly, we add the length of keyPath to the offset to strip this container's path. final String uriPath = uri.getPath(); blobsBuilder.add(uriPath.substring(1 + container.length() + 1 + keyPath.length(), uriPath.length() - 1)); } } return Set.copyOf(blobsBuilder); }
Example #11
Source File: StorageInterfaceImpl.java From hadoop with Apache License 2.0 | 5 votes |
@Override public CloudBlobDirectoryWrapper getDirectoryReference(String relativePath) throws URISyntaxException, StorageException { CloudBlobDirectory dir = container.getDirectoryReference(relativePath); return new CloudBlobDirectoryWrapperImpl(dir); }
Example #12
Source File: AzureCloudBlobClientActions.java From cloudbreak with Apache License 2.0 | 5 votes |
public void listAllFolders(String baseLocation) { String containerName = getContainerName(baseLocation); CloudBlobContainer cloudBlobContainer = getCloudBlobContainer(containerName); Log.log(LOGGER, format(" Azure Blob Storage URI: %s", cloudBlobContainer.getStorageUri())); Log.log(LOGGER, format(" Azure Blob Container: %s", cloudBlobContainer.getName())); try { for (ListBlobItem blob : cloudBlobContainer.listBlobs()) { String blobName = blob.getUri().getPath().split("/", 3)[2]; String blobUriPath = blob.getUri().getPath(); if (blob instanceof CloudBlob) { if (((CloudBlob) blob).exists()) { Log.log(LOGGER, format(" Azure Adls Gen 2 Blob is present with Name: %s and with bytes of content: %d at URI: %s ", ((CloudBlob) blob).getName(), ((CloudBlob) blob).getProperties().getLength(), blobUriPath)); } } else { if (blobName.endsWith("/")) { blobName = blobName.replaceAll(".$", ""); } CloudBlobDirectory blobDirectory = cloudBlobContainer.getDirectoryReference(blobName); listBlobsInDirectory(cloudBlobContainer, blobDirectory.getPrefix()); } } } catch (StorageException | URISyntaxException e) { LOGGER.error("Azure Adls Gen 2 Blob couldn't process the call. So it has been returned with error!", e); throw new TestFailException(String.format("Azure Adls Gen 2 Blob couldn't process the call. So it has been returned the error: %s", e)); } }
Example #13
Source File: StorageInterfaceImpl.java From big-c with Apache License 2.0 | 5 votes |
@Override public ListBlobItem next() { ListBlobItem unwrapped = present.next(); if (unwrapped instanceof CloudBlobDirectory) { return new CloudBlobDirectoryWrapperImpl((CloudBlobDirectory) unwrapped); } else if (unwrapped instanceof CloudBlockBlob) { return new CloudBlockBlobWrapperImpl((CloudBlockBlob) unwrapped); } else if (unwrapped instanceof CloudPageBlob) { return new CloudPageBlobWrapperImpl((CloudPageBlob) unwrapped); } else { return unwrapped; } }
Example #14
Source File: StorageInterfaceImpl.java From hadoop with Apache License 2.0 | 5 votes |
@Override public ListBlobItem next() { ListBlobItem unwrapped = present.next(); if (unwrapped instanceof CloudBlobDirectory) { return new CloudBlobDirectoryWrapperImpl((CloudBlobDirectory) unwrapped); } else if (unwrapped instanceof CloudBlockBlob) { return new CloudBlockBlobWrapperImpl((CloudBlockBlob) unwrapped); } else if (unwrapped instanceof CloudPageBlob) { return new CloudPageBlobWrapperImpl((CloudPageBlob) unwrapped); } else { return unwrapped; } }
Example #15
Source File: StorageInterfaceImpl.java From big-c with Apache License 2.0 | 5 votes |
@Override public CloudBlobDirectoryWrapper getDirectoryReference(String relativePath) throws URISyntaxException, StorageException { CloudBlobDirectory dir = container.getDirectoryReference(relativePath); return new CloudBlobDirectoryWrapperImpl(dir); }
Example #16
Source File: LogBlobIterable.java From azure-storage-android with Apache License 2.0 | 5 votes |
protected LogBlobIterable(final CloudBlobDirectory logDirectory, final Date startTime, final Date endTime, final EnumSet<LoggingOperations> operations, final EnumSet<BlobListingDetails> details, final BlobRequestOptions options, final OperationContext opContext) { this.logDirectory = logDirectory; this.startTime = startTime; this.endTime = endTime; this.operations = operations; this.details = details; this.options = options; this.opContext = opContext; }
Example #17
Source File: LogBlobIterator.java From azure-storage-android with Apache License 2.0 | 5 votes |
public LogBlobIterator(final CloudBlobDirectory logDirectory, final Date startDate, final Date endDate, final EnumSet<LoggingOperations> operations, final EnumSet<BlobListingDetails> details, final BlobRequestOptions options, final OperationContext opContext) { TimeZone gmtTime = TimeZone.getTimeZone("GMT"); HOUR_FORMAT.setTimeZone(gmtTime); DAY_FORMAT.setTimeZone(gmtTime); MONTH_FORMAT.setTimeZone(gmtTime); YEAR_FORMAT.setTimeZone(gmtTime); this.logDirectory = logDirectory; this.operations = operations; this.details = details; this.opContext = opContext; if (options == null) { this.options = new BlobRequestOptions(); } else { this.options = options; } if (startDate != null) { this.startDate = new GregorianCalendar(); this.startDate.setTime(startDate); this.startDate.add(GregorianCalendar.MINUTE, (-this.startDate.get(GregorianCalendar.MINUTE))); this.startDate.setTimeZone(gmtTime); } if (endDate != null) { this.endDate = new GregorianCalendar(); this.endDate.setTime(endDate); this.endDate.setTimeZone(gmtTime); this.endPrefix = this.logDirectory.getPrefix() + HOUR_FORMAT.format(this.endDate.getTime()); } }
Example #18
Source File: StorageInterfaceImpl.java From big-c with Apache License 2.0 | 4 votes |
@Override public CloudBlobDirectory getParent() throws URISyntaxException, StorageException { return getBlob().getParent(); }
Example #19
Source File: AzureCloudBlobClientActions.java From cloudbreak with Apache License 2.0 | 4 votes |
public void listSelectedDirectory(String baseLocation, String selectedDirectory, Boolean zeroContent) { String containerName = getContainerName(baseLocation); CloudBlobContainer cloudBlobContainer = getCloudBlobContainer(containerName); Log.log(LOGGER, format(" Azure Blob Storage URI: %s", cloudBlobContainer.getStorageUri())); Log.log(LOGGER, format(" Azure Blob Container: %s", cloudBlobContainer.getName())); Log.log(LOGGER, format(" Azure Blob Directory: %s", selectedDirectory)); try { CloudBlobDirectory logsDirectory = cloudBlobContainer.getDirectoryReference("cluster-logs"); CloudBlobDirectory selectedLogsDirectory = logsDirectory.getDirectoryReference(selectedDirectory); Set<String> blobsWithZeroLength = new HashSet<>(); Iterable<ListBlobItem> blobListing = cloudBlobContainer.listBlobs("cluster-logs/" + selectedDirectory, true); List<ListBlobItem> listBlobItems = StreamSupport .stream(blobListing.spliterator(), false) .collect(Collectors.toList()); Log.log(LOGGER, format(" Azure Blob Directory: %s contains %d sub-objects.", selectedDirectory, listBlobItems.size())); for (ListBlobItem blob : selectedLogsDirectory.listBlobs()) { String blobName = blob.getUri().getPath().split("/", 3)[2]; String blobUriPath = blob.getUri().getPath(); if (blob instanceof CloudBlob) { if (((CloudBlob) blob).exists()) { validateBlobItemLength(blob, zeroContent, blobsWithZeroLength); } else { LOGGER.error("Azure Adls Gen 2 Blob is NOT present with Name: {} and with bytes of content: {} at URI: {}", ((CloudBlob) blob).getName(), ((CloudBlob) blob).getProperties().getLength(), blobUriPath); throw new TestFailException(String.format("Azure Adls Gen 2 Blob is NOT present with Name: %s", ((CloudBlob) blob).getName())); } } else { if (blobName.endsWith("/")) { blobName = blobName.replaceAll(".$", ""); } CloudBlobDirectory blobDirectory = cloudBlobContainer.getDirectoryReference(blobName); listBlobsInDirectoryWithValidation(cloudBlobContainer, blobDirectory.getPrefix(), zeroContent); } } } catch (StorageException | URISyntaxException e) { LOGGER.error("Azure Adls Gen 2 Blob couldn't process the call. So it has been returned with error!", e); throw new TestFailException(String.format("Azure Adls Gen 2 Blob couldn't process the call. So it has been returned the error: %s", e)); } }
Example #20
Source File: AzureStorageRepository.java From hawkbit-extensions with Eclipse Public License 1.0 | 4 votes |
private CloudBlockBlob getBlob(final String tenant, final String sha1Hash16) throws URISyntaxException, StorageException { final CloudBlobContainer container = getContainer(); final CloudBlobDirectory tenantDirectory = container.getDirectoryReference(sanitizeTenant(tenant)); return tenantDirectory.getBlockBlobReference(sha1Hash16); }
Example #21
Source File: MockStorageInterface.java From big-c with Apache License 2.0 | 4 votes |
@Override public CloudBlobDirectory getParent() throws URISyntaxException, StorageException { return null; }
Example #22
Source File: MockStorageInterface.java From big-c with Apache License 2.0 | 4 votes |
@Override public CloudBlobDirectory getParent() throws URISyntaxException, StorageException { return null; }
Example #23
Source File: StorageInterfaceImpl.java From big-c with Apache License 2.0 | 4 votes |
@Override public CloudBlobDirectory getParent() throws URISyntaxException, StorageException { return directory.getParent(); }
Example #24
Source File: StorageInterfaceImpl.java From big-c with Apache License 2.0 | 4 votes |
public CloudBlobDirectoryWrapperImpl(CloudBlobDirectory directory) { this.directory = directory; }
Example #25
Source File: MockStorageInterface.java From hadoop with Apache License 2.0 | 4 votes |
@Override public CloudBlobDirectory getParent() throws URISyntaxException, StorageException { return null; }
Example #26
Source File: MockStorageInterface.java From hadoop with Apache License 2.0 | 4 votes |
@Override public CloudBlobDirectory getParent() throws URISyntaxException, StorageException { return null; }
Example #27
Source File: StorageInterfaceImpl.java From hadoop with Apache License 2.0 | 4 votes |
@Override public CloudBlobDirectory getParent() throws URISyntaxException, StorageException { return getBlob().getParent(); }
Example #28
Source File: StorageInterfaceImpl.java From hadoop with Apache License 2.0 | 4 votes |
@Override public CloudBlobDirectory getParent() throws URISyntaxException, StorageException { return directory.getParent(); }
Example #29
Source File: StorageInterfaceImpl.java From hadoop with Apache License 2.0 | 4 votes |
public CloudBlobDirectoryWrapperImpl(CloudBlobDirectory directory) { this.directory = directory; }
Example #30
Source File: VideoStorageAzure.java From arcusplatform with Apache License 2.0 | 4 votes |
@Override public VideoStorageSession create(VideoRecording recording) throws Exception { long startTime = System.nanoTime(); try { if (recording == null || recording.storage == null) { VIDEO_STORAGE_AZURE_NO_LOCATION.inc(); throw new Exception("no storage location"); } CloudBlobContainer foundContainer = null; for (CloudBlobContainer container : containers) { URI uri = container.getUri(); String uriString = uri.toString(); if (recording.storage.startsWith(uriString)) { foundContainer = container; break; } } if (foundContainer == null) { VIDEO_STORAGE_AZURE_NO_CONTAINER.inc(); throw new Exception("no azure container for storage location"); } CloudBlobDirectory dir = foundContainer.getDirectoryReference(recording.placeId.toString()); CloudAppendBlob blob = dir.getAppendBlobReference(recording.recordingId.toString()); blob.getProperties().setCacheControl("no-cache"); blob.getProperties().setContentType("video/mp2t"); long expiration = recording.expiration; long ttlInSeconds = VideoV2Util.createActualTTL(recording.recordingId, expiration); VideoStorageSession result = new AzureStorageSession(recording.recordingId, recording.cameraId, recording.accountId, recording.placeId, ttlInSeconds, recording.personId, blob); VIDEO_STORAGE_AZURE_EXISTING_CREATE_SUCCESS.update(System.nanoTime() - startTime, TimeUnit.NANOSECONDS); return result; } catch (Exception ex) { VIDEO_STORAGE_AZURE_EXISTING_CREATE_FAIL.update(System.nanoTime() - startTime, TimeUnit.NANOSECONDS); throw ex; } }