你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
DataLakeServiceClient Class
- java.
lang. Object - com.
azure. storage. file. datalake. DataLakeServiceClient
- com.
public class DataLakeServiceClient
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 a data lake service account. Operations on a file system are available on DataLakeFileSystemClient through getFileSystemClient(String fileSystemName), and operations on a file or directory are available on DataLakeFileClient and DataLakeDirectoryClient respectively.
Method Summary
Methods inherited from java.lang.Object
Method Details
createFileSystem
public DataLakeFileSystemClient 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
DataLakeFileSystemClient dataLakeFileSystemClient = client.createFileSystem("fileSystemName");
Parameters:
Returns:
createFileSystemWithResponse
public Response
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:
Returns:
deleteFileSystem
public 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
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:
deleteFileSystemWithResponse
public Response
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:
Returns:
generateAccountSas
public String generateAccountSas(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:
Returns:
String
representing the SAS query parameters.generateAccountSas
public String generateAccountSas(AccountSasSignatureValues accountSasSignatureValues, 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:
Returns:
String
representing the SAS query parameters.generateAccountSas
public String generateAccountSas(AccountSasSignatureValues accountSasSignatureValues, Consumer
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.
Parameters:
Returns:
String
representing the SAS query parameters.getAccountName
public String getAccountName()
Get associated account name.
Returns:
getAccountUrl
public String getAccountUrl()
Gets the URL of the storage account represented by this client.
Returns:
getFileSystemClient
public DataLakeFileSystemClient getFileSystemClient(String fileSystemName)
Initializes a DataLakeFileSystemClient 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:
Returns:
getHttpPipeline
public HttpPipeline getHttpPipeline()
Gets the HttpPipeline powering this client.
Returns:
getProperties
public DataLakeServiceProperties 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:
getPropertiesWithResponse
public Response
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:
Returns:
getServiceVersion
public DataLakeServiceVersion getServiceVersion()
Gets the service version the client is using.
Returns:
getUserDelegationKey
public 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
System.out.printf("User delegation key: %s%n",
client.getUserDelegationKey(delegationKeyStartTime, delegationKeyExpiryTime));
Parameters:
Returns:
getUserDelegationKeyWithResponse
public Response
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
System.out.printf("User delegation key: %s%n",
client.getUserDelegationKeyWithResponse(delegationKeyStartTime, delegationKeyExpiryTime, timeout, context));
Parameters:
Returns:
listFileSystems
public PagedIterable
Returns a lazy loaded list of file systems in this account. The returned PagedIterable<T> 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:
listFileSystems
public PagedIterable
Returns a lazy loaded list of file systems in this account. The returned PagedIterable<T> 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:
Returns:
setProperties
public 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)
.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:
setPropertiesWithResponse
public Response
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:
Returns:
undeleteFileSystem
public DataLakeFileSystemClient 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, null).forEach(
deletedFileSystem -> {
DataLakeFileSystemClient fileSystemClient = client.undeleteFileSystem(
deletedFileSystem.getName(), deletedFileSystem.getVersion());
}
);
Parameters:
Returns:
undeleteFileSystemWithResponse
public Response
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 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, null).forEach(
deletedFileSystem -> {
DataLakeFileSystemClient fileSystemClient = client.undeleteFileSystemWithResponse(
new FileSystemUndeleteOptions(deletedFileSystem.getName(), deletedFileSystem.getVersion()), timeout,
context).getValue();
}
);
Parameters:
Returns: