com.microsoft.azure.storage.blob.DeleteSnapshotsOption Java Examples

The following examples show how to use com.microsoft.azure.storage.blob.DeleteSnapshotsOption. 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: AzureNativeFileSystemStore.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public void purge(String prefix) throws IOException {
  try {

    // Attempts to purge may occur before opening any streams so first,
    // check if a session exists, if not create a session with the Azure
    // storage server.
    if (null == storageInteractionLayer) {
      final String errMsg = String.format(
          "Storage session expected for URI '%s' but does not exist.",
          sessionUri);
      throw new AssertionError(errMsg);
    }

    if (checkContainer(ContainerAccessType.ReadThenWrite) == ContainerState.DoesntExist) {
      // Container doesn't exist, no need to do anything.
      return;
    }
    // Get all blob items with the given prefix from the container and delete
    // them.
    Iterable<ListBlobItem> objects = listRootBlobs(prefix, false);
    for (ListBlobItem blobItem : objects) {
      ((CloudBlob) blobItem).delete(DeleteSnapshotsOption.NONE, null, null,
          getInstrumentedContext());
    }
  } catch (Exception e) {
    // Re-throw as an Azure storage exception.
    //
    throw new AzureException(e);
  }
}
 
Example #2
Source File: AzureNativeFileSystemStore.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public void purge(String prefix) throws IOException {
  try {

    // Attempts to purge may occur before opening any streams so first,
    // check if a session exists, if not create a session with the Azure
    // storage server.
    if (null == storageInteractionLayer) {
      final String errMsg = String.format(
          "Storage session expected for URI '%s' but does not exist.",
          sessionUri);
      throw new AssertionError(errMsg);
    }

    if (checkContainer(ContainerAccessType.ReadThenWrite) == ContainerState.DoesntExist) {
      // Container doesn't exist, no need to do anything.
      return;
    }
    // Get all blob items with the given prefix from the container and delete
    // them.
    Iterable<ListBlobItem> objects = listRootBlobs(prefix, false);
    for (ListBlobItem blobItem : objects) {
      ((CloudBlob) blobItem).delete(DeleteSnapshotsOption.NONE, null, null,
          getInstrumentedContext());
    }
  } catch (Exception e) {
    // Re-throw as an Azure storage exception.
    //
    throw new AzureException(e);
  }
}
 
Example #3
Source File: DeleteAzureBlobStorage.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
    FlowFile flowFile = session.get();

    if(flowFile == null) {
        return;
    }

    final long startNanos = System.nanoTime();
    final String containerName = context.getProperty(AzureStorageUtils.CONTAINER).evaluateAttributeExpressions(flowFile).getValue();
    final String blobPath = context.getProperty(BLOB).evaluateAttributeExpressions(flowFile).getValue();
    final String deleteSnapshotOptions = context.getProperty(DELETE_SNAPSHOTS_OPTION).getValue();

    try {
        CloudBlobClient blobClient = AzureStorageUtils.createCloudBlobClient(context, getLogger(), flowFile);
        CloudBlobContainer container = blobClient.getContainerReference(containerName);
        CloudBlob blob = container.getBlockBlobReference(blobPath);

        final OperationContext operationContext = new OperationContext();
        AzureStorageUtils.setProxy(operationContext, context);
        blob.deleteIfExists(DeleteSnapshotsOption.valueOf(deleteSnapshotOptions), null, null, operationContext);
        session.transfer(flowFile, REL_SUCCESS);

        final long transferMillis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNanos);
        session.getProvenanceReporter().invokeRemoteProcess(flowFile, blob.getSnapshotQualifiedUri().toString(), "Blob deleted");
    } catch ( StorageException | URISyntaxException e) {
        getLogger().error("Failed to delete the specified blob {} from Azure Storage. Routing to failure", new Object[]{blobPath}, e);
        flowFile = session.penalize(flowFile);
        session.transfer(flowFile, REL_FAILURE);
    }
}
 
Example #4
Source File: AzureStorageService.java    From crate with Apache License 2.0 5 votes vote down vote up
public void deleteFiles(String container, String path) throws URISyntaxException, StorageException {
    final Tuple<CloudBlobClient, Supplier<OperationContext>> client = client();
    // container name must be lower case.
    LOGGER.trace(() -> new ParameterizedMessage("delete files container [{}], path [{}]", container, path));
    // list the blobs using a flat blob listing mode
    final CloudBlobContainer blobContainer = client.v1().getContainerReference(container);
    for (final ListBlobItem blobItem : blobContainer.listBlobs(path, true, EnumSet.noneOf(BlobListingDetails.class), null,
        client.v2().get())) {
        final String blobName = blobNameFromUri(blobItem.getUri());
        LOGGER.trace(() -> new ParameterizedMessage("removing blob [{}] full URI was [{}]", blobName, blobItem.getUri()));
        // don't call {@code #deleteBlob}, use the same client
        final CloudBlockBlob azureBlob = blobContainer.getBlockBlobReference(blobName);
        azureBlob.delete(DeleteSnapshotsOption.NONE, null, null, client.v2().get());
    }
}
 
Example #5
Source File: AzureStorageService.java    From crate with Apache License 2.0 5 votes vote down vote up
public void deleteBlob(String container, String blob) throws URISyntaxException, StorageException {
    final Tuple<CloudBlobClient, Supplier<OperationContext>> client = client();
    // Container name must be lower case.
    final CloudBlobContainer blobContainer = client.v1().getContainerReference(container);
    LOGGER.trace(() -> new ParameterizedMessage("delete blob for container [{}], blob [{}]", container, blob));
    final CloudBlockBlob azureBlob = blobContainer.getBlockBlobReference(blob);
    LOGGER.trace(() -> new ParameterizedMessage("container [{}]: blob [{}] found. removing.", container, blob));
    azureBlob.delete(DeleteSnapshotsOption.NONE, null, null, client.v2().get());
}
 
Example #6
Source File: StorageInterfaceImpl.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Override
public void delete(OperationContext opContext, SelfRenewingLease lease)
    throws StorageException {
  getBlob().delete(DeleteSnapshotsOption.NONE, getLeaseCondition(lease),
      null, opContext);
}
 
Example #7
Source File: StorageInterfaceImpl.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Override
public void delete(OperationContext opContext, SelfRenewingLease lease)
    throws StorageException {
  getBlob().delete(DeleteSnapshotsOption.NONE, getLeaseCondition(lease),
      null, opContext);
}
 
Example #8
Source File: AzureStorageBlobService.java    From components with Apache License 2.0 4 votes vote down vote up
public boolean deleteBlobBlockIfExist(final CloudBlockBlob block) throws StorageException {
    return block.deleteIfExists(DeleteSnapshotsOption.NONE, null, null, AzureStorageUtils.getTalendOperationContext());
}