Class DataLakeServiceAsyncClient

java.lang.Object
com.azure.storage.file.datalake.DataLakeServiceAsyncClient

public class DataLakeServiceAsyncClient extends Object
Client to a storage account. It may only be instantiated through a DataLakeServiceClientBuilder. This class does not hold any state about a particular storage account but is instead a convenient way of sending off appropriate requests to the resource on the service. It may also be used to construct URLs to file systems, files and directories.

This client contains operations on the main data lake service account. Operations on a file system are available on DataLakeFileSystemAsyncClient through getFileSystemAsyncClient(String), and operations on a file or directory are available on DataLakeFileAsyncClient or DataLakeDirectoryAsyncClient.

Note this client is an async client that returns reactive responses from Spring Reactor Core project (https://projectreactor.io/). Calling the methods in this client will NOT start the actual network operation, until .subscribe() is called on the reactive response. You can simply convert one of these responses to a CompletableFuture object through Mono.toFuture().

  • Method Details

    • getFileSystemAsyncClient

      public DataLakeFileSystemAsyncClient getFileSystemAsyncClient(String fileSystemName)
      Initializes a DataLakeFileSystemAsyncClient object pointing to the specified file system. This method does not create a file system. It simply constructs the URL to the file system and offers access to methods relevant to file systems.

      Code Samples

       DataLakeFileSystemAsyncClient dataLakeFileSystemAsyncClient = client.getFileSystemAsyncClient("fileSystemName");
       
      Parameters:
      fileSystemName - The name of the file system to point to. A value of null or empty string will be interpreted as pointing to the root file system and will be replaced by "$root".
      Returns:
      A DataLakeFileSystemAsyncClient object pointing to the specified file system
    • getHttpPipeline

      public com.azure.core.http.HttpPipeline getHttpPipeline()
      Gets the HttpPipeline powering this client.
      Returns:
      The pipeline.
    • getServiceVersion

      public DataLakeServiceVersion getServiceVersion()
      Gets the service version the client is using.
      Returns:
      the service version the client is using.
    • createFileSystem

      public Mono<DataLakeFileSystemAsyncClient> createFileSystem(String fileSystemName)
      Creates a new file system within a storage account. If a file system with the same name already exists, the operation fails. For more information, see the Azure Docs.

      Code Samples

       DataLakeFileSystemAsyncClient dataLakeFileSystemAsyncClient =
           client.createFileSystem("fileSystemName").block();
       
      Parameters:
      fileSystemName - Name of the file system to create
      Returns:
      A Mono containing a DataLakeFileSystemAsyncClient used to interact with the file system created.
    • createFileSystemWithResponse

      public Mono<com.azure.core.http.rest.Response<DataLakeFileSystemAsyncClient>> createFileSystemWithResponse(String fileSystemName, Map<String,String> metadata, PublicAccessType accessType)
      Creates a new file system within a storage account. If a file system with the same name already exists, the operation fails. For more information, see the Azure Docs.

      Code Samples

       Map<String, String> metadata = Collections.singletonMap("metadata", "value");
      
       DataLakeFileSystemAsyncClient dataLakeFileSystemAsyncClient = client
           .createFileSystemWithResponse("fileSystemName", metadata, PublicAccessType.CONTAINER).block().getValue();
       
      Parameters:
      fileSystemName - Name of the file system to create
      metadata - Metadata to associate with the file system. If there is leading or trailing whitespace in any metadata key or value, it must be removed or encoded.
      accessType - Specifies how the data in this file system is available to the public. See the x-ms-blob-public-access header in the Azure Docs for more information. Pass null for no public access.
      Returns:
      A Mono containing a Response whose value contains a DataLakeFileSystemAsyncClient used to interact with the file system created.
    • deleteFileSystem

      public Mono<Void> deleteFileSystem(String fileSystemName)
      Deletes the specified file system in the storage account. If the file system doesn't exist the operation fails. For more information see the Azure Docs.

      Code Samples

       client.deleteFileSystem("fileSystemName").subscribe(
           response -> System.out.printf("Delete file system completed%n"),
           error -> System.out.printf("Delete file system failed: %s%n", error));
       
      Parameters:
      fileSystemName - Name of the file system to delete
      Returns:
      A reactive response signalling completion.
    • deleteFileSystemWithResponse

      public Mono<com.azure.core.http.rest.Response<Void>> deleteFileSystemWithResponse(String fileSystemName, DataLakeRequestConditions requestConditions)
      Deletes the specified file system in the storage account. If the file system doesn't exist the operation fails. For more information see the Azure Docs.

      Code Samples

       client.deleteFileSystemWithResponse("fileSystemName", new DataLakeRequestConditions()).subscribe(response ->
           System.out.printf("Delete file system completed with status %d%n", response.getStatusCode()));
       
      Parameters:
      fileSystemName - Name of the file system to delete
      requestConditions - DataLakeRequestConditions
      Returns:
      A Mono containing status code and HTTP headers
    • getAccountUrl

      public String getAccountUrl()
      Gets the URL of the storage account represented by this client.
      Returns:
      the URL.
    • listFileSystems

      public com.azure.core.http.rest.PagedFlux<FileSystemItem> listFileSystems()
      Returns a reactive Publisher emitting all the file systems in this account lazily as needed. For more information, see the Azure Docs.

      Code Samples

       client.listFileSystems().subscribe(fileSystem -> System.out.printf("Name: %s%n", fileSystem.getName()));
       
      Returns:
      A reactive response emitting the list of file systems.
    • listFileSystems

      public com.azure.core.http.rest.PagedFlux<FileSystemItem> listFileSystems(ListFileSystemsOptions options)
      Returns a reactive Publisher emitting all the file systems in this account lazily as needed. For more information, see the Azure Docs.

      Code Samples

       ListFileSystemsOptions options = new ListFileSystemsOptions()
           .setPrefix("fileSystemNamePrefixToMatch")
           .setDetails(new FileSystemListDetails().setRetrieveMetadata(true));
      
       client.listFileSystems(options).subscribe(fileSystem -> System.out.printf("Name: %s%n", fileSystem.getName()));
       
      Parameters:
      options - A ListFileSystemsOptions which specifies what data should be returned by the service.
      Returns:
      A reactive response emitting the list of file systems.
    • getProperties

      public Mono<DataLakeServiceProperties> getProperties()
      Gets the properties of a storage account’s DataLake service. For more information, see the Azure Docs.

      Code Samples

       client.getProperties().subscribe(response ->
           System.out.printf("Hour metrics enabled: %b, Minute metrics enabled: %b%n",
               response.getHourMetrics().isEnabled(),
               response.getMinuteMetrics().isEnabled()));
       
      Returns:
      A reactive response containing the storage account properties.
    • getPropertiesWithResponse

      public Mono<com.azure.core.http.rest.Response<DataLakeServiceProperties>> getPropertiesWithResponse()
      Gets the properties of a storage account’s DataLake service. For more information, see the Azure Docs.

      Code Samples

       client.getPropertiesWithResponse().subscribe(response ->
           System.out.printf("Hour metrics enabled: %b, Minute metrics enabled: %b%n",
               response.getValue().getHourMetrics().isEnabled(),
               response.getValue().getMinuteMetrics().isEnabled()));
       
      Returns:
      A Mono containing a Response whose value contains the storage account properties.
    • setProperties

      public Mono<Void> setProperties(DataLakeServiceProperties properties)
      Sets properties for a storage account's DataLake service endpoint. For more information, see the Azure Docs. Note that setting the default service version has no effect when using this client because this client explicitly sets the version header on each request, overriding the default.

      This method checks to ensure the properties being sent follow the specifications indicated in the Azure Docs. If CORS policies are set, CORS parameters that are not set default to the empty string.

      Code Samples

       DataLakeRetentionPolicy loggingRetentionPolicy = new DataLakeRetentionPolicy().setEnabled(true).setDays(3);
       DataLakeRetentionPolicy metricsRetentionPolicy = new DataLakeRetentionPolicy().setEnabled(true).setDays(1);
      
       DataLakeServiceProperties properties = new DataLakeServiceProperties()
           .setLogging(new DataLakeAnalyticsLogging()
               .setWrite(true)
               .setDelete(true)
               .setRetentionPolicy(loggingRetentionPolicy))
           .setHourMetrics(new DataLakeMetrics()
               .setEnabled(true)
               .setRetentionPolicy(metricsRetentionPolicy))
           .setMinuteMetrics(new DataLakeMetrics()
               .setEnabled(true)
               .setRetentionPolicy(metricsRetentionPolicy));
      
       client.setProperties(properties).subscribe(
           response -> System.out.printf("Setting properties completed%n"),
           error -> System.out.printf("Setting properties failed: %s%n", error));
       
      Parameters:
      properties - Configures the service.
      Returns:
      A Mono containing the storage account properties.
    • setPropertiesWithResponse

      public Mono<com.azure.core.http.rest.Response<Void>> setPropertiesWithResponse(DataLakeServiceProperties properties)
      Sets properties for a storage account's DataLake service endpoint. For more information, see the Azure Docs. Note that setting the default service version has no effect when using this client because this client explicitly sets the version header on each request, overriding the default.

      This method checks to ensure the properties being sent follow the specifications indicated in the Azure Docs. If CORS policies are set, CORS parameters that are not set default to the empty string.

      Code Samples

       loggingRetentionPolicy = new DataLakeRetentionPolicy().setEnabled(true).setDays(3);
       metricsRetentionPolicy = new DataLakeRetentionPolicy().setEnabled(true).setDays(1);
      
       properties = new DataLakeServiceProperties()
           .setLogging(new DataLakeAnalyticsLogging()
               .setWrite(true)
               .setDelete(true)
               .setRetentionPolicy(loggingRetentionPolicy))
           .setHourMetrics(new DataLakeMetrics()
               .setEnabled(true)
               .setRetentionPolicy(metricsRetentionPolicy))
           .setMinuteMetrics(new DataLakeMetrics()
               .setEnabled(true)
               .setRetentionPolicy(metricsRetentionPolicy));
      
       client.setPropertiesWithResponse(properties).subscribe(response ->
           System.out.printf("Setting properties completed with status %d%n", response.getStatusCode()));
       
      Parameters:
      properties - Configures the service.
      Returns:
      A Mono containing the storage account properties.
    • getUserDelegationKey

      public Mono<UserDelegationKey> getUserDelegationKey(OffsetDateTime start, OffsetDateTime expiry)
      Gets a user delegation key for use with this account's data lake storage. Note: This method call is only valid when using TokenCredential in this object's HttpPipeline.

      Code Samples

       client.getUserDelegationKey(delegationKeyStartTime, delegationKeyExpiryTime).subscribe(response ->
           System.out.printf("User delegation key: %s%n", response.getValue()));
       
      Parameters:
      start - Start time for the key's validity. Null indicates immediate start.
      expiry - Expiration of the key's validity.
      Returns:
      A Mono containing the user delegation key.
      Throws:
      IllegalArgumentException - If start isn't null and is after expiry.
      NullPointerException - If expiry is null.
    • getUserDelegationKeyWithResponse

      public Mono<com.azure.core.http.rest.Response<UserDelegationKey>> getUserDelegationKeyWithResponse(OffsetDateTime start, OffsetDateTime expiry)
      Gets a user delegation key for use with this account's data lake storage. Note: This method call is only valid when using TokenCredential in this object's HttpPipeline.

      Code Samples

       client.getUserDelegationKeyWithResponse(delegationKeyStartTime, delegationKeyExpiryTime).subscribe(response ->
           System.out.printf("User delegation key: %s%n", response.getValue().getValue()));
       
      Parameters:
      start - Start time for the key's validity. Null indicates immediate start.
      expiry - Expiration of the key's validity.
      Returns:
      A Mono containing a Response whose value containing the user delegation key.
      Throws:
      IllegalArgumentException - If start isn't null and is after expiry.
      NullPointerException - If expiry is null.
    • getAccountName

      public String getAccountName()
      Get associated account name.
      Returns:
      account name associated with this storage resource.
    • generateAccountSas

      public String generateAccountSas(com.azure.storage.common.sas.AccountSasSignatureValues accountSasSignatureValues)
      Generates an account SAS for the Azure Storage account using the specified AccountSasSignatureValues.

      Note : The client must be authenticated via StorageSharedKeyCredential

      See AccountSasSignatureValues for more information on how to construct an account SAS.

      The snippet below generates a SAS that lasts for two days and gives the user read and list access to file systems and file shares.

       AccountSasPermission permissions = new AccountSasPermission()
           .setListPermission(true)
           .setReadPermission(true);
       AccountSasResourceType resourceTypes = new AccountSasResourceType().setContainer(true);
       AccountSasService services = new AccountSasService().setBlobAccess(true).setFileAccess(true);
       OffsetDateTime expiryTime = OffsetDateTime.now().plus(Duration.ofDays(2));
      
       AccountSasSignatureValues sasValues =
           new AccountSasSignatureValues(expiryTime, permissions, services, resourceTypes);
      
       // Client must be authenticated via StorageSharedKeyCredential
       String sas = client.generateAccountSas(sasValues);
       
      Parameters:
      accountSasSignatureValues - AccountSasSignatureValues
      Returns:
      A String representing the SAS query parameters.
    • generateAccountSas

      public String generateAccountSas(com.azure.storage.common.sas.AccountSasSignatureValues accountSasSignatureValues, com.azure.core.util.Context context)
      Generates an account SAS for the Azure Storage account using the specified AccountSasSignatureValues.

      Note : The client must be authenticated via StorageSharedKeyCredential

      See AccountSasSignatureValues for more information on how to construct an account SAS.

      The snippet below generates a SAS that lasts for two days and gives the user read and list access to file systems and file shares.

       AccountSasPermission permissions = new AccountSasPermission()
           .setListPermission(true)
           .setReadPermission(true);
       AccountSasResourceType resourceTypes = new AccountSasResourceType().setContainer(true);
       AccountSasService services = new AccountSasService().setBlobAccess(true).setFileAccess(true);
       OffsetDateTime expiryTime = OffsetDateTime.now().plus(Duration.ofDays(2));
      
       AccountSasSignatureValues sasValues =
           new AccountSasSignatureValues(expiryTime, permissions, services, resourceTypes);
      
       // Client must be authenticated via StorageSharedKeyCredential
       String sas = client.generateAccountSas(sasValues, new Context("key", "value"));
       
      Parameters:
      accountSasSignatureValues - AccountSasSignatureValues
      context - Additional context that is passed through the code when generating a SAS.
      Returns:
      A String representing the SAS query parameters.
    • undeleteFileSystem

      public Mono<DataLakeFileSystemAsyncClient> undeleteFileSystem(String deletedFileSystemName, String deletedFileSystemVersion)
      Restores a previously deleted file system. If the file system associated with provided deletedFileSystemName already exists, this call will result in a 409 (conflict). This API is only functional if Container Soft Delete is enabled for the storage account associated with the file system.

      Code Samples

       ListFileSystemsOptions listFileSystemsOptions = new ListFileSystemsOptions();
       listFileSystemsOptions.getDetails().setRetrieveDeleted(true);
       client.listFileSystems(listFileSystemsOptions).flatMap(
           deletedFileSystem -> {
               Mono<DataLakeFileSystemAsyncClient> fileSystemClient = client.undeleteFileSystem(
                   deletedFileSystem.getName(), deletedFileSystem.getVersion());
               return fileSystemClient;
           }
       ).then().block();
       
      Parameters:
      deletedFileSystemName - The name of the previously deleted file system.
      deletedFileSystemVersion - The version of the previously deleted file system.
      Returns:
      A Mono containing a DataLakeFileSystemAsyncClient used to interact with the restored file system.
    • undeleteFileSystemWithResponse

      public Mono<com.azure.core.http.rest.Response<DataLakeFileSystemAsyncClient>> undeleteFileSystemWithResponse(FileSystemUndeleteOptions options)
      Restores a previously deleted file system. The restored file system will be renamed to the destinationFileSystemName if provided in options. Otherwise deletedFileSystemName is used as the destination file system name. If the file system associated with provided destinationFileSystemName already exists, this call will result in a 409 (conflict). This API is only functional if Container Soft Delete is enabled for the storage account associated with the file system.

      Code Samples

       ListFileSystemsOptions listFileSystemsOptions = new ListFileSystemsOptions();
       listFileSystemsOptions.getDetails().setRetrieveDeleted(true);
       client.listFileSystems(listFileSystemsOptions).flatMap(
           deletedFileSystem -> {
               Mono<DataLakeFileSystemAsyncClient> fileSystemClient = client.undeleteFileSystemWithResponse(
                   new FileSystemUndeleteOptions(deletedFileSystem.getName(), deletedFileSystem.getVersion()))
                   .map(Response::getValue);
               return fileSystemClient;
           }
       ).then().block();
       
      Parameters:
      options - FileSystemUndeleteOptions.
      Returns:
      A Mono containing a Response whose value contains a DataLakeFileSystemAsyncClient used to interact with the restored file system.