Search in sources :

Example 1 with DataLakeStoreAccountManagementClient

use of com.microsoft.azure.management.datalake.store.DataLakeStoreAccountManagementClient in project cloudbreak by hortonworks.

the class AzureSetup method validateAdlsFileSystem.

private void validateAdlsFileSystem(CloudCredential credential, FileSystem fileSystem) {
    Map<String, Object> credentialAttributes = credential.getParameters();
    String clientSecret = String.valueOf(credentialAttributes.get(AdlsFileSystemConfiguration.CREDENTIAL_SECRET_KEY));
    String subscriptionId = String.valueOf(credentialAttributes.get(AdlsFileSystemConfiguration.SUBSCRIPTION_ID));
    String clientId = String.valueOf(credentialAttributes.get(AdlsFileSystemConfiguration.ACCESS_KEY));
    String tenantId = fileSystem.getStringParameter(AdlsFileSystemConfiguration.TENANT_ID);
    String accountName = fileSystem.getStringParameter(FileSystemConfiguration.ACCOUNT_NAME);
    ApplicationTokenCredentials creds = new ApplicationTokenCredentials(clientId, tenantId, clientSecret, AzureEnvironment.AZURE);
    DataLakeStoreAccountManagementClient adlsClient = new DataLakeStoreAccountManagementClientImpl(creds);
    adlsClient.withSubscriptionId(subscriptionId);
    List<DataLakeStoreAccount> dataLakeStoreAccounts = adlsClient.accounts().list();
    boolean validAccountname = false;
    for (DataLakeStoreAccount account : dataLakeStoreAccounts) {
        if (account.name().equalsIgnoreCase(accountName)) {
            validAccountname = true;
            break;
        }
    }
    if (!validAccountname) {
        throw new CloudConnectorException("The provided file system account name does not belong to a valid ADLS account");
    }
}
Also used : DataLakeStoreAccount(com.microsoft.azure.management.datalake.store.models.DataLakeStoreAccount) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) DataLakeStoreAccountManagementClient(com.microsoft.azure.management.datalake.store.DataLakeStoreAccountManagementClient) ApplicationTokenCredentials(com.microsoft.azure.credentials.ApplicationTokenCredentials) DataLakeStoreAccountManagementClientImpl(com.microsoft.azure.management.datalake.store.implementation.DataLakeStoreAccountManagementClientImpl)

Aggregations

ApplicationTokenCredentials (com.microsoft.azure.credentials.ApplicationTokenCredentials)1 DataLakeStoreAccountManagementClient (com.microsoft.azure.management.datalake.store.DataLakeStoreAccountManagementClient)1 DataLakeStoreAccountManagementClientImpl (com.microsoft.azure.management.datalake.store.implementation.DataLakeStoreAccountManagementClientImpl)1 DataLakeStoreAccount (com.microsoft.azure.management.datalake.store.models.DataLakeStoreAccount)1 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1