Class DataLakeServiceClient
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 a data lake service account. Operations on a file system are available on
DataLakeFileSystemClient
through getFileSystemClient(String)
, and operations on a file or directory
are available on DataLakeFileClient
and DataLakeDirectoryClient
respectively.
-
Method Summary
Modifier and TypeMethodDescriptioncreateFileSystem
(String fileSystemName) Creates a new file system within a storage account.com.azure.core.http.rest.Response
<DataLakeFileSystemClient> createFileSystemWithResponse
(String fileSystemName, Map<String, String> metadata, PublicAccessType accessType, com.azure.core.util.Context context) Creates a new file system within a storage account.void
deleteFileSystem
(String fileSystemName) Deletes the specified file system in the storage account.com.azure.core.http.rest.Response
<Void> deleteFileSystemWithResponse
(String fileSystemName, DataLakeRequestConditions requestConditions, com.azure.core.util.Context context) Deletes the specified file system in the storage account.generateAccountSas
(com.azure.storage.common.sas.AccountSasSignatureValues accountSasSignatureValues) Generates an account SAS for the Azure Storage account using the specifiedAccountSasSignatureValues
.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 specifiedAccountSasSignatureValues
.generateAccountSas
(com.azure.storage.common.sas.AccountSasSignatureValues accountSasSignatureValues, Consumer<String> stringToSignHandler, com.azure.core.util.Context context) Generates an account SAS for the Azure Storage account using the specifiedAccountSasSignatureValues
.Get associated account name.Gets the URL of the storage account represented by this client.getFileSystemClient
(String fileSystemName) Initializes aDataLakeFileSystemClient
object pointing to the specified file system.com.azure.core.http.HttpPipeline
Gets theHttpPipeline
powering this client.Returns the resource's metadata and properties.com.azure.core.http.rest.Response
<DataLakeServiceProperties> getPropertiesWithResponse
(Duration timeout, com.azure.core.util.Context context) Returns the resource's metadata and properties.Gets the service version the client is using.getUserDelegationKey
(OffsetDateTime start, OffsetDateTime expiry) Gets a user delegation key for use with this account's data lake storage.com.azure.core.http.rest.Response
<UserDelegationKey> getUserDelegationKeyWithResponse
(OffsetDateTime start, OffsetDateTime expiry, Duration timeout, com.azure.core.util.Context context) Gets a user delegation key for use with this account's data lake storage.com.azure.core.http.rest.PagedIterable
<FileSystemItem> Returns a lazy loaded list of file systems in this account.com.azure.core.http.rest.PagedIterable
<FileSystemItem> listFileSystems
(ListFileSystemsOptions options, Duration timeout) Returns a lazy loaded list of file systems in this account.void
setProperties
(DataLakeServiceProperties properties) Sets properties for a storage account's DataLake service endpoint.com.azure.core.http.rest.Response
<Void> setPropertiesWithResponse
(DataLakeServiceProperties properties, Duration timeout, com.azure.core.util.Context context) Sets properties for a storage account's DataLake service endpoint.undeleteFileSystem
(String deletedFileSystemName, String deletedFileSystemVersion) Restores a previously deleted file system.com.azure.core.http.rest.Response
<DataLakeFileSystemClient> undeleteFileSystemWithResponse
(FileSystemUndeleteOptions options, Duration timeout, com.azure.core.util.Context context) Restores a previously deleted file system.
-
Method Details
-
getFileSystemClient
Initializes aDataLakeFileSystemClient
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
DataLakeFileSystemClient dataLakeFileSystemClient = client.getFileSystemClient("fileSystemName");
- Parameters:
fileSystemName
- The name of the file system to point to.- Returns:
- A
DataLakeFileSystemClient
object pointing to the specified file system
-
getHttpPipeline
public com.azure.core.http.HttpPipeline getHttpPipeline()Gets theHttpPipeline
powering this client.- Returns:
- The pipeline.
-
getServiceVersion
Gets the service version the client is using.- Returns:
- the service version the client is using.
-
createFileSystem
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
DataLakeFileSystemClient dataLakeFileSystemClient = client.createFileSystem("fileSystemName");
- Parameters:
fileSystemName
- Name of the file system to create- Returns:
- The
DataLakeFileSystemClient
used to interact with the file system created.
-
createFileSystemWithResponse
public com.azure.core.http.rest.Response<DataLakeFileSystemClient> createFileSystemWithResponse(String fileSystemName, Map<String, String> metadata, PublicAccessType accessType, com.azure.core.util.Context context) 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"); Context context = new Context("Key", "Value"); DataLakeFileSystemClient dataLakeFileSystemClient = client.createFileSystemWithResponse( "fileSystemName", metadata, PublicAccessType.CONTAINER, context).getValue();
- Parameters:
fileSystemName
- Name of the file system to createmetadata
- 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.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A
Response
whosevalue
contains theDataLakeFileSystemClient
used to interact with the file system created.
-
deleteFileSystem
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
try { client.deleteFileSystem("fileSystemName"); System.out.printf("Delete file system completed with status %n"); } catch (UnsupportedOperationException error) { System.out.printf("Delete file system failed: %s%n", error); }
- Parameters:
fileSystemName
- Name of the file system to delete
-
deleteFileSystemWithResponse
public com.azure.core.http.rest.Response<Void> deleteFileSystemWithResponse(String fileSystemName, DataLakeRequestConditions requestConditions, com.azure.core.util.Context context) 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
Context context = new Context("Key", "Value"); System.out.printf("Delete file system completed with status %d%n", client.deleteFileSystemWithResponse("fileSystemName", new DataLakeRequestConditions(), context) .getStatusCode());
- Parameters:
fileSystemName
- Name of the file system to deleterequestConditions
-DataLakeRequestConditions
context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response containing status code and HTTP headers
-
getAccountUrl
Gets the URL of the storage account represented by this client.- Returns:
- the URL.
-
listFileSystems
Returns a lazy loaded list of file systems in this account. The returnedPagedIterable
can be consumed while new items are automatically retrieved as needed. For more information, see the Azure Docs.Code Samples
client.listFileSystems().forEach(fileSystem -> System.out.printf("Name: %s%n", fileSystem.getName()));
- Returns:
- The list of file systems.
-
listFileSystems
public com.azure.core.http.rest.PagedIterable<FileSystemItem> listFileSystems(ListFileSystemsOptions options, Duration timeout) Returns a lazy loaded list of file systems in this account. The returnedPagedIterable
can be consumed while new items are automatically retrieved as needed. For more information, see the Azure Docs.Code Samples
ListFileSystemsOptions options = new ListFileSystemsOptions() .setPrefix("filSystemNamePrefixToMatch") .setDetails(new FileSystemListDetails().setRetrieveMetadata(true)); client.listFileSystems(options, timeout).forEach(fileSystem -> System.out.printf("Name: %s%n", fileSystem.getName()));
- Parameters:
options
- AListFileSystemsOptions
which specifies what data should be returned by the service. If iterating by page, the page size passed to byPage methods such asContinuablePagedIterable.iterableByPage(int)
will be preferred over the value set on these options.timeout
- An optional timeout value beyond which aRuntimeException
will be raised.- Returns:
- The list of file systems.
-
getProperties
Returns the resource's metadata and properties.Code Samples
DataLakeServiceProperties properties = client.getProperties(); System.out.printf("Hour metrics enabled: %b, Minute metrics enabled: %b%n", properties.getHourMetrics().isEnabled(), properties.getMinuteMetrics().isEnabled());
For more information, see the Azure Docs
- Returns:
- The resource properties and metadata.
-
getPropertiesWithResponse
public com.azure.core.http.rest.Response<DataLakeServiceProperties> getPropertiesWithResponse(Duration timeout, com.azure.core.util.Context context) Returns the resource's metadata and properties.Code Samples
Context context = new Context("Key", "Value"); properties = client.getPropertiesWithResponse(timeout, context).getValue(); System.out.printf("Hour metrics enabled: %b, Minute metrics enabled: %b%n", properties.getHourMetrics().isEnabled(), properties.getMinuteMetrics().isEnabled());
For more information, see the Azure Docs
- Parameters:
timeout
- An optional timeout value beyond which aRuntimeException
will be raised.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response containing the resource properties and metadata.
-
setProperties
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) .setVersion("1.0") .setRetentionPolicy(loggingRetentionPolicy)) .setHourMetrics(new DataLakeMetrics() .setEnabled(true) .setVersion("1.0") .setIncludeApis(true) .setRetentionPolicy(metricsRetentionPolicy)) .setMinuteMetrics(new DataLakeMetrics() .setEnabled(true) .setVersion("1.0") .setIncludeApis(true) .setRetentionPolicy(metricsRetentionPolicy)); try { client.setProperties(properties); System.out.printf("Setting properties completed%n"); } catch (UnsupportedOperationException error) { System.out.printf("Setting properties failed: %s%n", error); }
- Parameters:
properties
- Configures the service.
-
setPropertiesWithResponse
public com.azure.core.http.rest.Response<Void> setPropertiesWithResponse(DataLakeServiceProperties properties, Duration timeout, com.azure.core.util.Context context) 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) .setVersion("1.0") .setRetentionPolicy(loggingRetentionPolicy)) .setHourMetrics(new DataLakeMetrics() .setEnabled(true) .setVersion("1.0") .setIncludeApis(true) .setRetentionPolicy(metricsRetentionPolicy)) .setMinuteMetrics(new DataLakeMetrics() .setEnabled(true) .setVersion("1.0") .setIncludeApis(true) .setRetentionPolicy(metricsRetentionPolicy)); Context context = new Context("Key", "Value"); System.out.printf("Setting properties completed with status %d%n", client.setPropertiesWithResponse(properties, timeout, context).getStatusCode());
- Parameters:
properties
- Configures the service.timeout
- An optional timeout value beyond which aRuntimeException
will be raised.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- The storage account properties.
-
getUserDelegationKey
Gets a user delegation key for use with this account's data lake storage. Note: This method call is only valid when usingTokenCredential
in this object'sHttpPipeline
.Code Samples
System.out.printf("User delegation key: %s%n", client.getUserDelegationKey(delegationKeyStartTime, delegationKeyExpiryTime));
- Parameters:
start
- Start time for the key's validity. Null indicates immediate start.expiry
- Expiration of the key's validity.- Returns:
- The user delegation key.
-
getUserDelegationKeyWithResponse
public com.azure.core.http.rest.Response<UserDelegationKey> getUserDelegationKeyWithResponse(OffsetDateTime start, OffsetDateTime expiry, Duration timeout, com.azure.core.util.Context context) Gets a user delegation key for use with this account's data lake storage. Note: This method call is only valid when usingTokenCredential
in this object'sHttpPipeline
.Code Samples
System.out.printf("User delegation key: %s%n", client.getUserDelegationKeyWithResponse(delegationKeyStartTime, delegationKeyExpiryTime, timeout, context));
- Parameters:
start
- Start time for the key's validity. Null indicates immediate start.expiry
- Expiration of the key's validity.timeout
- An optional timeout value beyond which aRuntimeException
will be raised.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A
Response
whosevalue
contains the user delegation key.
-
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 specifiedAccountSasSignatureValues
.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 specifiedAccountSasSignatureValues
.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.
-
generateAccountSas
public String generateAccountSas(com.azure.storage.common.sas.AccountSasSignatureValues accountSasSignatureValues, Consumer<String> stringToSignHandler, com.azure.core.util.Context context) Generates an account SAS for the Azure Storage account using the specifiedAccountSasSignatureValues
.Note : The client must be authenticated via
StorageSharedKeyCredential
See
AccountSasSignatureValues
for more information on how to construct an account SAS.- Parameters:
accountSasSignatureValues
-AccountSasSignatureValues
stringToSignHandler
- For debugging purposes only. Returns the string to sign that was used to generate the signature.context
- Additional context that is passed through the code when generating a SAS.- Returns:
- A
String
representing the SAS query parameters.
-
undeleteFileSystem
public DataLakeFileSystemClient undeleteFileSystem(String deletedFileSystemName, String deletedFileSystemVersion) Restores a previously deleted file system. If the file system associated with provideddeletedFileSystemName
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, null).forEach( deletedFileSystem -> { DataLakeFileSystemClient fileSystemClient = client.undeleteFileSystem( deletedFileSystem.getName(), deletedFileSystem.getVersion()); } );
- Parameters:
deletedFileSystemName
- The name of the previously deleted file system.deletedFileSystemVersion
- The version of the previously deleted file system.- Returns:
- The
DataLakeFileSystemClient
used to interact with the restored file system.
-
undeleteFileSystemWithResponse
public com.azure.core.http.rest.Response<DataLakeFileSystemClient> undeleteFileSystemWithResponse(FileSystemUndeleteOptions options, Duration timeout, com.azure.core.util.Context context) Restores a previously deleted file system. The restored file system will be renamed to thedestinationFileSystemName
if provided inoptions
. OtherwisedeletedFileSystemName
is used as destination file system name. If the file system associated with provideddestinationFileSystemName
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, null).forEach( deletedFileSystem -> { DataLakeFileSystemClient fileSystemClient = client.undeleteFileSystemWithResponse( new FileSystemUndeleteOptions(deletedFileSystem.getName(), deletedFileSystem.getVersion()), timeout, context).getValue(); } );
- Parameters:
options
-FileSystemUndeleteOptions
.timeout
- An optional timeout value beyond which aRuntimeException
will be raised.context
- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A
Response
whosevalue
contains theDataLakeFileSystemClient
used to interact with the restored file system.
-