public static Stream<CloudBlob> getBlobs(CloudBlobDirectory directory) throws IOException { try { return StreamSupport.stream(directory.listBlobs(null, false, EnumSet.of(BlobListingDetails.METADATA), null, null).spliterator(), false) .filter(i -> i instanceof CloudBlob) .map(i -> (CloudBlob) i); } catch (StorageException | URISyntaxException e) { throw new IOException(e); } }
public static Stream<CloudBlob> getBlobs(CloudBlobDirectory directory) throws IOException { try { return StreamSupport.stream(directory.listBlobs(null, false, EnumSet.of(BlobListingDetails.METADATA), null, null).spliterator(), false) .filter(i -> i instanceof CloudBlob) .map(i -> (CloudBlob) i); } catch (StorageException | URISyntaxException e) { throw new IOException(e); } }
@Override public Iterable<ListBlobItem> listBlobs(String prefix, boolean useFlatBlobListing, EnumSet<BlobListingDetails> listingDetails, BlobRequestOptions options, OperationContext opContext) throws URISyntaxException, StorageException { return SASWrappingIterator.wrap(directory.listBlobs(prefix, useFlatBlobListing, listingDetails, options, opContext)); }
@Override public Iterable<ListBlobItem> listBlobs(String prefix, boolean useFlatBlobListing, EnumSet<BlobListingDetails> listingDetails, BlobRequestOptions options, OperationContext opContext) throws URISyntaxException, StorageException { return WrappingIterator.wrap(directory.listBlobs(prefix, useFlatBlobListing, listingDetails, options, opContext)); }
private List<CloudAppendBlob> getJournalBlobs() throws IOException { try { List<CloudAppendBlob> result = new ArrayList<>(); for (ListBlobItem b : directory.listBlobs(journalNamePrefix)) { if (b instanceof CloudAppendBlob) { result.add((CloudAppendBlob) b); } else { log.warn("Invalid blob type: {} {}", b.getUri(), b.getClass()); } } result.sort(Comparator.<CloudAppendBlob, String>comparing(AzureUtilities::getName).reversed()); return result; } catch (URISyntaxException | StorageException e) { throw new IOException(e); } }
private List<CloudAppendBlob> getJournalBlobs() throws IOException { try { List<CloudAppendBlob> result = new ArrayList<>(); for (ListBlobItem b : directory.listBlobs(journalNamePrefix)) { if (b instanceof CloudAppendBlob) { result.add((CloudAppendBlob) b); } else { log.warn("Invalid blob type: {} {}", b.getUri(), b.getClass()); } } result.sort(Comparator.<CloudAppendBlob, String>comparing(AzureUtilities::getName).reversed()); return result; } catch (URISyntaxException | StorageException e) { throw new IOException(e); } }
@Override public boolean segmentFilesExist() { try { for (ListBlobItem i : segmentstoreDirectory.listBlobs(null, false, EnumSet.noneOf(BlobListingDetails.class), null, null)) { if (i instanceof CloudBlobDirectory) { CloudBlobDirectory dir = (CloudBlobDirectory) i; String name = Paths.get(dir.getPrefix()).getFileName().toString(); if (name.endsWith(".tar")) { return true; } } } return false; } catch (StorageException | URISyntaxException e) { log.error("Can't check if the segment archives exists", e); return false; } }
@Override public List<String> listArchives() throws IOException { try { return StreamSupport.stream(cloudBlobDirectory .listBlobs(null, false, EnumSet.noneOf(BlobListingDetails.class), null, null) .spliterator(), false) .filter(i -> i instanceof CloudBlobDirectory) .map(i -> (CloudBlobDirectory) i) .filter(i -> getName(i).endsWith(".tar")) .map(CloudBlobDirectory::getPrefix) .map(Paths::get) .map(Path::getFileName) .map(Path::toString) .collect(Collectors.toList()); } catch (URISyntaxException | StorageException e) { throw new IOException(e); } }
@Override public List<String> listArchives() throws IOException { try { return StreamSupport.stream(cloudBlobDirectory .listBlobs(null, false, EnumSet.noneOf(BlobListingDetails.class), null, null) .spliterator(), false) .filter(i -> i instanceof CloudBlobDirectory) .map(i -> (CloudBlobDirectory) i) .filter(i -> getName(i).endsWith(".tar")) .map(CloudBlobDirectory::getPrefix) .map(Paths::get) .map(Path::getFileName) .map(Path::toString) .collect(Collectors.toList()); } catch (URISyntaxException | StorageException e) { throw new IOException(e); } }
@Override public boolean segmentFilesExist() { try { for (ListBlobItem i : segmentstoreDirectory.listBlobs(null, false, EnumSet.noneOf(BlobListingDetails.class), null, null)) { if (i instanceof CloudBlobDirectory) { CloudBlobDirectory dir = (CloudBlobDirectory) i; String name = Paths.get(dir.getPrefix()).getFileName().toString(); if (name.endsWith(".tar")) { return true; } } } return false; } catch (StorageException | URISyntaxException e) { log.error("Can't check if the segment archives exists", e); return false; } }
for (ListBlobItem item : metaDir.listBlobs(prefix)) { if (item instanceof CloudBlob) { if (((CloudBlob)item).deleteIfExists()) {
/** * Makes the next listBlob call if necessary and updates the currentIterator. * * @throws StorageException * @throws URISyntaxException */ private void updateIterator() throws StorageException, URISyntaxException { if (this.currentPrefixTime != null && this.currentPrefixTime.isEmpty()) { // If we've already called listBlobs() with an empty prefix, don't do so again. this.isExpired = true; return; } GregorianCalendar now = new GregorianCalendar(); now.add(GregorianCalendar.HOUR_OF_DAY, 1); now.setTimeZone(TimeZone.getTimeZone("GMT")); updatePrefix(); if ((this.startDate == null || this.startDate.compareTo(now) <= 0) && (this.endDate == null || ((this.logDirectory.getPrefix() + this.currentPrefixTime) .compareTo(this.endPrefix) <= 0))) { // Only make the next call if the prefix is still possible this.currentIterator = this.logDirectory.listBlobs(this.currentPrefixTime, true, this.details, this.options, this.opContext).iterator(); } else { // We are in the future. this.isExpired = true; } }
/** * Makes the next listBlob call if necessary and updates the currentIterator. * * @throws StorageException * @throws URISyntaxException */ private void updateIterator() throws StorageException, URISyntaxException { if (this.currentPrefixTime != null && this.currentPrefixTime.isEmpty()) { // If we've already called listBlobs() with an empty prefix, don't do so again. this.isExpired = true; return; } GregorianCalendar now = new GregorianCalendar(); now.add(GregorianCalendar.HOUR_OF_DAY, 1); now.setTimeZone(TimeZone.getTimeZone("GMT")); updatePrefix(); if ((this.startDate == null || this.startDate.compareTo(now) <= 0) && (this.endDate == null || ((this.logDirectory.getPrefix() + this.currentPrefixTime) .compareTo(this.endPrefix) <= 0))) { // Only make the next call if the prefix is still possible this.currentIterator = this.logDirectory.listBlobs(this.currentPrefixTime, true, this.details, this.options, this.opContext).iterator(); } else { // We are in the future. this.isExpired = true; } }
@Override public CompletableFuture<List<BaseLease>> getAllLeases() { CompletableFuture<List<BaseLease>> future = null; try { ArrayList<BaseLease> infos = new ArrayList<BaseLease>(); EnumSet<BlobListingDetails> details = EnumSet.of(BlobListingDetails.METADATA); Iterable<ListBlobItem> leaseBlobs = this.consumerGroupDirectory.listBlobs("", true, details, this.leaseOperationOptions, null); leaseBlobs.forEach((lbi) -> { CloudBlob blob = (CloudBlob)lbi; BlobProperties bp = blob.getProperties(); HashMap<String, String> metadata = blob.getMetadata(); Path p = Paths.get(lbi.getUri().getPath()); infos.add(new BaseLease(p.getFileName().toString(), metadata.get(AzureStorageCheckpointLeaseManager.METADATA_OWNER_NAME), (bp.getLeaseState() == LeaseState.LEASED))); }); future = CompletableFuture.completedFuture(infos); } catch (URISyntaxException | StorageException e) { TRACE_LOGGER.warn(this.hostContext.withHost("Failure while getting lease state details"), e); future = new CompletableFuture<List<BaseLease>>(); future.completeExceptionally(LoggingUtils.wrapException(e, EventProcessorHostActionStrings.GETTING_LEASE)); } return future; }
private CompletableFuture<Void> deleteStoreInternal(BlobRequestOptions options) { CompletableFuture<Void> future = null; try { for (ListBlobItem blob : this.eventHubContainer.listBlobs(null, false, EnumSet.noneOf(BlobListingDetails.class), options, null)) { if (blob instanceof CloudBlobDirectory) { for (ListBlobItem subBlob : ((CloudBlobDirectory) blob).listBlobs(null, false, EnumSet.noneOf(BlobListingDetails.class), options, null)) { ((CloudBlockBlob) subBlob).deleteIfExists(DeleteSnapshotsOption.NONE, null, options, null); } } else if (blob instanceof CloudBlockBlob) { ((CloudBlockBlob) blob).deleteIfExists(DeleteSnapshotsOption.NONE, null, options, null); } } this.eventHubContainer.deleteIfExists(null, options, null); future = CompletableFuture.completedFuture(null); } catch (StorageException | URISyntaxException e) { TRACE_LOGGER.error(this.hostContext.withHost("Failure while deleting lease store"), e); future = new CompletableFuture<Void>(); future.completeExceptionally(new CompletionException(e)); } return future; }
for (ListBlobItem item : metaDir.listBlobs(prefix)) { if (item instanceof CloudBlob) { CloudBlob blob = (CloudBlob) item;
private void testPrefixListingWithDirectory(String delimiter, CloudBlobContainer container) throws URISyntaxException, StorageException { // check output of list blobs with TopDir1 with prefix CloudBlobDirectory directory = container.getDirectoryReference("TopDir1"); Iterable<ListBlobItem> results = directory.listBlobs("Mid"); ArrayList<ListBlobItem> list1 = new ArrayList<ListBlobItem>(); Iterator<ListBlobItem> iter = results.iterator(); while (iter.hasNext()) { list1.add(iter.next()); } assertEquals(2, list1.size()); ListBlobItem get12 = list1.get(0); assertEquals(new URI(container.getUri().getScheme(), container.getUri().getAuthority(), container.getUri() .getPath() + "/TopDir1" + delimiter + "MidDir1" + delimiter, null, null), get12.getUri()); ListBlobItem get13 = list1.get(1); assertEquals(new URI(container.getUri().getScheme(), container.getUri().getAuthority(), container.getUri() .getPath() + "/TopDir1" + delimiter + "MidDir2" + delimiter, null, null), get13.getUri()); }
private void testListingWithDirectory(String delimiter, CloudBlobContainer container) throws URISyntaxException, StorageException { // check output of list blobs with TopDir1 with prefix CloudBlobDirectory directory = container.getDirectoryReference("TopDir1" + delimiter + "MidDir1" + delimiter); Iterable<ListBlobItem> results = directory.listBlobs(); ArrayList<ListBlobItem> list1 = new ArrayList<ListBlobItem>(); Iterator<ListBlobItem> iter = results.iterator(); while (iter.hasNext()) { list1.add(iter.next()); } assertEquals(2, list1.size()); ListBlobItem get21 = list1.get(0); assertEquals(new URI(container.getUri().getScheme(), container.getUri().getAuthority(), container.getUri() .getPath() + "/TopDir1" + delimiter + "MidDir1" + delimiter + "EndDir1" + delimiter, null, null), get21.getUri()); ListBlobItem get22 = list1.get(1); assertEquals(new URI(container.getUri().getScheme(), container.getUri().getAuthority(), container.getUri() .getPath() + "/TopDir1" + delimiter + "MidDir1" + delimiter + "EndDir2" + delimiter, null, null), get22.getUri()); }
return (buildVersion.length() != 0) && !(ctnr.getDirectoryReference(buildVersion).listBlobs().iterator() .hasNext());
private void testGetParentOnRoot(String delimiter, CloudBlobContainer container) throws URISyntaxException, StorageException { // get container as parent CloudBlobDirectory topDir = container.getDirectoryReference("TopDir1" + delimiter); CloudBlobDirectory root = topDir.getParent(); assertEquals("", root.getPrefix()); assertEquals(container.getUri().toString(), root.getUri().toString()); // make sure the parent of the container dir is null CloudBlobDirectory empty = root.getParent(); assertNull(empty); // from container, get directory reference to container root = container.getDirectoryReference(""); assertEquals("", root.getPrefix()); assertEquals(container.getUri().toString(), root.getUri().toString()); Iterable<ListBlobItem> results = root.listBlobs(); ArrayList<ListBlobItem> list1 = new ArrayList<ListBlobItem>(); Iterator<ListBlobItem> iter = results.iterator(); while (iter.hasNext()) { list1.add(iter.next()); } assertEquals(2, list1.size()); // make sure the parent of the container dir is null empty = root.getParent(); assertNull(empty); }