public void SetDefaultDataLakeStoreAccount(string resourceGroupName, string accountName,
                                                   DataLakeStoreAccount storageToSet)
        {
            if (string.IsNullOrEmpty(resourceGroupName))
            {
                resourceGroupName = GetResourceGroupByAccountName(accountName);
            }

            var account = GetAccount(resourceGroupName, accountName);

            account.Properties.DefaultDataLakeStoreAccount = storageToSet.Name;

            if (
                !account.Properties.DataLakeStoreAccounts.Any(
                    acct => acct.Name.Equals(storageToSet.Name, StringComparison.InvariantCultureIgnoreCase)))
            {
                _accountClient.DataLakeAnalyticsAccount.AddDataLakeStoreAccount(resourceGroupName, accountName,
                                                                                storageToSet.Name, null);
            }

            // null out values that cannot be updated
            account.Properties.DataLakeStoreAccounts = null;
            account.Properties.StorageAccounts       = null;

            var updateParams = new DataLakeAnalyticsAccountCreateOrUpdateParameters
            {
                DataLakeAnalyticsAccount = account
            };

            _accountClient.DataLakeAnalyticsAccount.Update(resourceGroupName, updateParams);
        }
Exemplo n.º 2
0
        public PSDataLakeStoreAccount(DataLakeStoreAccount baseAccount) :
            base(
                baseAccount.Id,
                baseAccount.Name,
                baseAccount.Type,
                baseAccount.Location,
                baseAccount.Tags,
                baseAccount.Identity,
                baseAccount.AccountId,
                baseAccount.ProvisioningState,
                baseAccount.State,
                baseAccount.CreationTime,
                baseAccount.LastModifiedTime,
                baseAccount.Endpoint,
                baseAccount.DefaultGroup,

                // TODO: Work around to null out properties that are returned empty.
                // Swagger deserialization will put a default value of an enum in an empty object.
                // Once the server correctly returns nothing (instead of empty objects), this can
                // be removed.
                baseAccount.EncryptionState == Management.DataLake.Store.Models.EncryptionState.Disabled ? null : baseAccount.EncryptionConfig,

                baseAccount.EncryptionState,
                baseAccount.EncryptionProvisioningState,
                baseAccount.FirewallRules,
                baseAccount.VirtualNetworkRules,
                baseAccount.FirewallState,
                baseAccount.FirewallAllowAzureIps,
                baseAccount.TrustedIdProviders,
                baseAccount.TrustedIdProviderState,
                baseAccount.NewTier,
                baseAccount.CurrentTier)
        {
        }
Exemplo n.º 3
0
 public PSDataLakeStoreAccount(DataLakeStoreAccount baseAccount) :
     base(
         baseAccount.Location,
         baseAccount.Id,
         baseAccount.Name,
         baseAccount.Type,
         baseAccount.Tags,
         baseAccount.Identity,
         baseAccount.ProvisioningState,
         baseAccount.State,
         baseAccount.CreationTime,
         baseAccount.EncryptionState,
         baseAccount.EncryptionProvisioningState,
         baseAccount.EncryptionConfig,
         baseAccount.FirewallState,
         baseAccount.FirewallRules,
         baseAccount.TrustedIdProviderState,
         baseAccount.TrustedIdProviders,
         baseAccount.LastModifiedTime,
         baseAccount.Endpoint,
         baseAccount.DefaultGroup
         )
 {
     Properties = new PSDataLakeStoreAccountProperties(baseAccount);
 }
        protected override void ProcessRecord()
        {
            if (ParameterSetName.Equals(BlobParameterSetName, StringComparison.InvariantCultureIgnoreCase))
            {
                var toAdd = new StorageAccount
                {
                    Name       = Blob,
                    Properties = new StorageAccountProperties
                    {
                        AccessKey = AccessKey
                    }
                };

                DataLakeAnalyticsClient.AddStorageAccount(ResourceGroupName, Account, toAdd);
            }
            else
            {
                var toAdd = new DataLakeStoreAccount
                {
                    Name = DataLakeStore
                };

                DataLakeAnalyticsClient.AddDataLakeStoreAccount(ResourceGroupName, Account, toAdd);

                if (Default)
                {
                    DataLakeAnalyticsClient.SetDefaultDataLakeStoreAccount(ResourceGroupName, Account, toAdd);
                }
            }
        }
        public override void ExecuteCmdlet()
        {
            if (ParameterSetName.Equals(BlobParameterSetName, StringComparison.InvariantCultureIgnoreCase))
            {
                var toAdd = new StorageAccount
                {
                    Name       = Blob,
                    Properties = new StorageAccountProperties
                    {
                        AccessKey = AccessKey
                    }
                };

                DataLakeAnalyticsClient.SetStorageAccount(ResourceGroupName, Account, toAdd);
            }
            else if (Default)
            {
                var toAdd = new DataLakeStoreAccount
                {
                    Name = DataLakeStore
                };

                DataLakeAnalyticsClient.SetDefaultDataLakeStoreAccount(ResourceGroupName, Account, toAdd);
            }
            else
            {
                WriteWarning(Resources.InvalidDataLakeStoreAccountModificationAttempt);
            }
        }
Exemplo n.º 6
0
    static void Main(string[] args)
    {
        _adlsAccountName   = "test333";
        _resourceGroupName = "ivanrg";
        _location          = "East US 2";
        _subId             = "xxxx";

        string TENANT   = "xxxx";
        string CLIENTID = "xxxx";

        System.Uri ARM_TOKEN_AUDIENCE = new System.Uri(@"https://management.core.windows.net/");
        System.Uri ADL_TOKEN_AUDIENCE = new System.Uri(@"https://datalake.azure.net/");
        string     secret_key         = "xxxx";
        var        armCreds           = GetCreds_SPI_SecretKey(TENANT, ARM_TOKEN_AUDIENCE, CLIENTID, secret_key);

        // Create client objects and set the subscription ID
        _adlsClient = new DataLakeStoreAccountManagementClient(armCreds)
        {
            SubscriptionId = _subId
        };

        // Create Data Lake Storage Gen1 account
        var adlsParameters = new DataLakeStoreAccount(location: _location);

        _adlsClient.Account.Create(_resourceGroupName, _adlsAccountName, adlsParameters);

        Console.WriteLine("--completed--");
        Console.ReadLine();
    }
        public PSDataLakeStoreAccountProperties(DataLakeStoreAccount baseAccount)
        {
            ProvisioningState           = baseAccount.ProvisioningState;
            State                       = baseAccount.State;
            CreationTime                = baseAccount.CreationTime;
            EncryptionState             = baseAccount.EncryptionState;
            EncryptionProvisioningState = baseAccount.EncryptionProvisioningState;
            EncryptionConfig            = baseAccount.EncryptionConfig;
            FirewallState               = baseAccount.FirewallState;

            if (baseAccount.FirewallRules != null)
            {
                FirewallRules = new List <DataLakeStoreFirewallRule>(baseAccount.FirewallRules.Count);
                foreach (var entry in baseAccount.FirewallRules)
                {
                    FirewallRules.Add(new DataLakeStoreFirewallRule(entry));
                }
            }

            if (baseAccount.TrustedIdProviders != null)
            {
                TrustedIdProviders = new List <DataLakeStoreTrustedIdProvider>(baseAccount.TrustedIdProviders.Count);
                foreach (var entry in baseAccount.TrustedIdProviders)
                {
                    TrustedIdProviders.Add(new DataLakeStoreTrustedIdProvider(entry));
                }
            }

            TrustedIdProviderState = baseAccount.TrustedIdProviderState;
            LastModifiedTime       = baseAccount.LastModifiedTime;
            Endpoint     = baseAccount.Endpoint;
            DefaultGroup = baseAccount.DefaultGroup;
        }
        public string TryCreateDataLakeStoreAccount(string resourceGroupName, string location, string accountName)
        {
            bool exists = false;
            DataLakeStoreAccount accountGetResponse = null;

            try
            {
                accountGetResponse = dataLakeStoreManagementClient.Account.Get(resourceGroupName, accountName);
                exists             = true;
            }
            catch
            {
                // do nothing because it doesn't exist
            }


            if (!exists)
            {
                dataLakeStoreManagementClient.Account.Create(resourceGroupName, accountName,
                                                             new DataLakeStoreAccount {
                    Location = location, Name = accountName
                });

                accountGetResponse = dataLakeStoreManagementClient.Account.Get(resourceGroupName,
                                                                               accountName);

                // wait for provisioning state to be Succeeded
                // we will wait a maximum of 15 minutes for this to happen and then report failures
                int minutesWaited       = 0;
                int timeToWaitInMinutes = 15;
                while (accountGetResponse.Properties.ProvisioningState !=
                       DataLakeStoreAccountStatus.Succeeded &&
                       accountGetResponse.Properties.ProvisioningState !=
                       DataLakeStoreAccountStatus.Failed && minutesWaited <= timeToWaitInMinutes)
                {
                    TestUtilities.Wait(60000); // Wait for one minute and then go again.
                    minutesWaited++;
                    accountGetResponse = dataLakeStoreManagementClient.Account.Get(resourceGroupName,
                                                                                   accountName);
                }
            }

            // Confirm that the account creation did succeed
            ThrowIfTrue(
                accountGetResponse.Properties.ProvisioningState !=
                DataLakeStoreAccountStatus.Succeeded,
                "Account failed to be provisioned into the success state. Actual State: " +
                accountGetResponse.Properties.ProvisioningState);

            return(accountGetResponse.Properties.Endpoint);
        }
Exemplo n.º 9
0
        public DataLakeStoreAccount CreateAccount(
            string resourceGroupName,
            string accountName,
            string defaultGroup,
            string location,
            Hashtable customTags        = null,
            EncryptionIdentity identity = null,
            EncryptionConfig config     = null,
            IList <TrustedIdProvider> trustedProviders = null,
            IList <FirewallRule> firewallRules         = null)
        {
            if (string.IsNullOrEmpty(resourceGroupName))
            {
                resourceGroupName = GetResourceGroupByAccount(accountName);
            }

            var tags = TagsConversionHelper.CreateTagDictionary(customTags, true);

            var parameters = new DataLakeStoreAccount
            {
                Location     = location,
                DefaultGroup = defaultGroup,
                Tags         = tags ?? new Dictionary <string, string>()
            };

            if (identity != null)
            {
                parameters.EncryptionState  = EncryptionState.Enabled;
                parameters.Identity         = identity;
                parameters.EncryptionConfig = config ?? new EncryptionConfig
                {
                    Type = EncryptionConfigType.ServiceManaged
                };
            }

            if (trustedProviders != null && trustedProviders.Count > 0)
            {
                parameters.TrustedIdProviders     = trustedProviders;
                parameters.TrustedIdProviderState = TrustedIdProviderState.Enabled;
            }

            if (firewallRules != null && firewallRules.Count > 0)
            {
                parameters.FirewallRules = firewallRules;
                parameters.FirewallState = FirewallState.Enabled;
            }

            return(_client.Account.Create(resourceGroupName, accountName, parameters));
        }
Exemplo n.º 10
0
        protected override void ProcessRecord()
        {
            DataLakeStoreAccount defaultAccount = null;

            if (!string.IsNullOrEmpty(DefaultDataLakeStore))
            {
                defaultAccount = new DataLakeStoreAccount
                {
                    Name = DefaultDataLakeStore
                };
            }

            WriteObject(DataLakeAnalyticsClient.CreateOrUpdateAccount(ResourceGroupName, Name, null, defaultAccount,
                                                                      null, null, Tags));
        }
Exemplo n.º 11
0
        public static void CreateAccounts()
        {
            //ADLS account first, ADLA requires an ADLS account
            var adlsParameters = new DataLakeStoreAccount(location: _location);

            _adlsClient.Account.Create(_resourceGroupName, _adlsAccountName, adlsParameters);

            var defaultAdlsAccount = new List <DataLakeStoreAccountInfo> {
                new DataLakeStoreAccountInfo(_adlsAccountName, new DataLakeStoreAccountInfoProperties())
            };
            var adlaProperties = new DataLakeAnalyticsAccountProperties(defaultDataLakeStoreAccount: _adlsAccountName, dataLakeStoreAccounts: defaultAdlsAccount);
            var adlaParameters = new DataLakeAnalyticsAccount(properties: adlaProperties, location: _location);

            _adlaClient.Account.Create(_resourceGroupName, _adlaAccountName, adlaParameters);
        }
Exemplo n.º 12
0
        public override void ExecuteCmdlet()
        {
            DataLakeStoreAccount defaultAccount = null;

            if (!string.IsNullOrEmpty(DefaultDataLakeStore))
            {
                defaultAccount = new DataLakeStoreAccount
                {
                    Name = DefaultDataLakeStore
                };
            }

            WriteObject(DataLakeAnalyticsClient.CreateOrUpdateAccount(ResourceGroupName, Name, null, defaultAccount,
                                                                      null, null, Tags));
        }
        public void AddDataLakeStoreAccount(string resourceGroupName, string accountName,
                                            DataLakeStoreAccount storageToAdd)
        {
            if (string.IsNullOrEmpty(resourceGroupName))
            {
                resourceGroupName = GetResourceGroupByAccountName(accountName);
            }

            var storageParams = new AddDataLakeStoreParameters
            {
                Properties = storageToAdd.Properties
            };

            _accountClient.DataLakeAnalyticsAccount.AddDataLakeStoreAccount(resourceGroupName, accountName,
                                                                            storageToAdd.Name, storageParams);
        }
Exemplo n.º 14
0
        public DataLakeStoreAccount CreateOrUpdateAccount(string resourceGroupName, string accountName,
                                                          string defaultGroup, string location, Hashtable[] customTags = null)
        {
            if (string.IsNullOrEmpty(resourceGroupName))
            {
                resourceGroupName = GetResourceGroupByAccount(accountName);
            }

            var tags = TagsConversionHelper.CreateTagDictionary(customTags, true);

            var parameters = new DataLakeStoreAccount
            {
                Name       = accountName,
                Location   = location,
                Properties = new DataLakeStoreAccountProperties
                {
                    DefaultGroup = defaultGroup
                },
                Tags = tags ?? new Dictionary <string, string>()
            };

            var accountExists = false;

            try
            {
                if (GetAccount(resourceGroupName, accountName) != null)
                {
                    accountExists = true;
                }
            }
            catch
            {
                // intentionally empty since if there is any exception attempting to
                // get the account we know it doesn't exist and we will attempt to create it fresh.
            }

            return(accountExists
                ? _client.Account.Update(resourceGroupName, accountName, parameters)
                : _client.Account.Create(resourceGroupName, accountName, parameters));
        }
Exemplo n.º 15
0
        protected override void ProcessRecord()
        {
            try
            {
                if (DataLakeAnalyticsClient.GetAcount(ResourceGroupName, Name) != null)
                {
                    throw new CloudException(string.Format(Resources.DataLakeAnalyticsAccountExists, Name));
                }
            }
            catch (CloudException ex)
            {
                if (ex.Error != null && !string.IsNullOrEmpty(ex.Error.Code) && ex.Error.Code == "ResourceNotFound" ||
                    ex.Message.Contains("ResourceNotFound"))
                {
                    // account does not exists so go ahead and create one
                }
                else if (ex.Error != null && !string.IsNullOrEmpty(ex.Error.Code) &&
                         ex.Error.Code == "ResourceGroupNotFound" || ex.Message.Contains("ResourceGroupNotFound"))
                {
                    // resource group not found, let create throw error don't throw from here
                }
                else
                {
                    // all other exceptions should be thrown
                    throw;
                }
            }

            var defaultStorage = new DataLakeStoreAccount
            {
                Name = DefaultDataLakeStore
            };

            WriteObject(DataLakeAnalyticsClient.CreateOrUpdateAccount(ResourceGroupName, Name, Location, defaultStorage,
                                                                      customTags: Tags));
        }
Exemplo n.º 16
0
        public DataLakeStoreAccount CreateAccount(
            string resourceGroupName,
            string accountName,
            string defaultGroup,
            string location,
            Hashtable customTags        = null,
            EncryptionIdentity identity = null,
            EncryptionConfig config     = null,
            IList <TrustedIdProvider> trustedProviders = null,
            IList <FirewallRule> firewallRules         = null,
            EncryptionConfigType?encryptionType        = null,
            TierType?tier = null)
        {
            if (string.IsNullOrEmpty(resourceGroupName))
            {
                resourceGroupName = GetResourceGroupByAccount(accountName);
            }

            var tags = TagsConversionHelper.CreateTagDictionary(customTags, true);

            var parameters = new DataLakeStoreAccount
            {
                Location     = location,
                DefaultGroup = defaultGroup,
                Tags         = tags ?? new Dictionary <string, string>()
            };

            if (identity != null)
            {
                parameters.EncryptionState  = EncryptionState.Enabled;
                parameters.Identity         = identity;
                parameters.EncryptionConfig = config ?? new EncryptionConfig
                {
                    Type = EncryptionConfigType.ServiceManaged
                };
            }

            if (trustedProviders != null && trustedProviders.Count > 0)
            {
                parameters.TrustedIdProviders     = trustedProviders;
                parameters.TrustedIdProviderState = TrustedIdProviderState.Enabled;
            }

            if (firewallRules != null && firewallRules.Count > 0)
            {
                parameters.FirewallRules = firewallRules;
                parameters.FirewallState = FirewallState.Enabled;
            }

            // if there is no encryption value, then it was not set by the cmdlet which means encryption was explicitly disabled.
            if (!encryptionType.HasValue)
            {
                parameters.EncryptionState  = EncryptionState.Disabled;
                parameters.Identity         = null;
                parameters.EncryptionConfig = null;
            }

            if (tier.HasValue)
            {
                parameters.NewTier = tier;
            }

            var toReturn = _client.Account.Create(resourceGroupName, accountName, parameters);

            return(toReturn);
        }
Exemplo n.º 17
0
 /// <summary>
 /// Updates the specified Data Lake Store account information.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the Azure resource group that contains the Data Lake Store
 /// account.
 /// </param>
 /// <param name='name'>
 /// The name of the Data Lake Store account to update.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to update the Data Lake Store account.
 /// </param>
 public static DataLakeStoreAccount BeginUpdate(this IAccountOperations operations, string resourceGroupName, string name, DataLakeStoreAccount parameters)
 {
     return(Task.Factory.StartNew(s => ((IAccountOperations)s).BeginUpdateAsync(resourceGroupName, name, parameters), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
Exemplo n.º 18
0
 /// <summary>
 /// Updates the specified Data Lake Store account information.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the Azure resource group that contains the Data Lake Store
 /// account.
 /// </param>
 /// <param name='name'>
 /// The name of the Data Lake Store account to update.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to update the Data Lake Store account.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <DataLakeStoreAccount> BeginUpdateAsync(this IAccountOperations operations, string resourceGroupName, string name, DataLakeStoreAccount parameters, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.BeginUpdateWithHttpMessagesAsync(resourceGroupName, name, parameters, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
        public DataLakeStoreAccount CreateOrUpdateAccount(
            string resourceGroupName,
            string accountName,
            string defaultGroup,
            string location,
            Hashtable customTags        = null,
            EncryptionIdentity identity = null,
            EncryptionConfig config     = null,
            IList <TrustedIdProvider> trustedProviders = null,
            IList <FirewallRule> firewallRules         = null)
        {
            if (string.IsNullOrEmpty(resourceGroupName))
            {
                resourceGroupName = GetResourceGroupByAccount(accountName);
            }

            var tags = TagsConversionHelper.CreateTagDictionary(customTags, true);

            var parameters = new DataLakeStoreAccount
            {
                Name       = accountName,
                Location   = location,
                Properties = new DataLakeStoreAccountProperties
                {
                    DefaultGroup = defaultGroup,
                },
                Tags = tags ?? new Dictionary <string, string>()
            };

            if (identity != null)
            {
                parameters.Properties.EncryptionState = EncryptionState.Enabled;
                parameters.Identity = identity;
                parameters.Properties.EncryptionConfig = config ?? new EncryptionConfig
                {
                    Type = EncryptionConfigType.ServiceManaged
                };
            }

            if (trustedProviders != null && trustedProviders.Count > 0)
            {
                parameters.Properties.TrustedIdProviders     = trustedProviders;
                parameters.Properties.TrustedIdProviderState = TrustedIdProviderState.Enabled;
            }

            if (firewallRules != null && firewallRules.Count > 0)
            {
                parameters.Properties.FirewallRules = firewallRules;
                parameters.Properties.FirewallState = FirewallState.Enabled;
            }

            var accountExists = false;

            try
            {
                if (GetAccount(resourceGroupName, accountName) != null)
                {
                    accountExists = true;
                }
            }
            catch
            {
                // intentionally empty since if there is any exception attempting to
                // get the account we know it doesn't exist and we will attempt to create it fresh.
            }

            return(accountExists
                ? _client.Account.Update(resourceGroupName, accountName, parameters)
                : _client.Account.Create(resourceGroupName, accountName, parameters));
        }
        public DataLakeAnalyticsAccount CreateOrUpdateAccount(string resourceGroupName, string accountName,
                                                              string location,
                                                              DataLakeStoreAccount defaultDataLakeStoreAccount             = null,
                                                              IList <DataLakeStoreAccount> additionalDataLakeStoreAccounts = null,
                                                              IList <StorageAccount> additionalStorageAccounts             = null,
                                                              Hashtable[] customTags = null)
        {
            if (string.IsNullOrEmpty(resourceGroupName))
            {
                resourceGroupName = GetResourceGroupByAccountName(accountName);
            }

            var tags = TagsConversionHelper.CreateTagDictionary(customTags, true);

            var parameters = new DataLakeAnalyticsAccountCreateOrUpdateParameters
            {
                DataLakeAnalyticsAccount = new DataLakeAnalyticsAccount
                {
                    Name     = accountName,
                    Location = location,
                    Tags     = tags ?? new Dictionary <string, string>()
                }
            };


            parameters.DataLakeAnalyticsAccount.Properties = new DataLakeAnalyticsAccountProperties();

            if (defaultDataLakeStoreAccount != null)
            {
                parameters.DataLakeAnalyticsAccount.Properties.DefaultDataLakeStoreAccount =
                    defaultDataLakeStoreAccount.Name;
            }

            if (additionalStorageAccounts != null && additionalStorageAccounts.Count > 0)
            {
                parameters.DataLakeAnalyticsAccount.Properties.StorageAccounts = additionalStorageAccounts;
            }

            if (additionalDataLakeStoreAccounts != null && additionalDataLakeStoreAccounts.Count > 0)
            {
                if (defaultDataLakeStoreAccount != null)
                {
                    additionalDataLakeStoreAccounts.Add(defaultDataLakeStoreAccount);
                }

                parameters.DataLakeAnalyticsAccount.Properties.DataLakeStoreAccounts = additionalDataLakeStoreAccounts;
            }
            else if (defaultDataLakeStoreAccount != null)
            {
                parameters.DataLakeAnalyticsAccount.Properties.DataLakeStoreAccounts = new List <DataLakeStoreAccount>
                {
                    defaultDataLakeStoreAccount
                };
            }

            var accountExists = false;

            try
            {
                if (GetAccount(resourceGroupName, accountName) != null)
                {
                    accountExists = true;
                }
            }
            catch
            {
                // intentionally empty since if there is any exception attempting to
                // get the account we know it doesn't exist and we will attempt to create it fresh.
            }

            var response = accountExists
                ? _accountClient.DataLakeAnalyticsAccount.Update(resourceGroupName, parameters)
                : _accountClient.DataLakeAnalyticsAccount.Create(resourceGroupName, parameters);

            if (response.Status != OperationStatus.Succeeded)
            {
                throw new CloudException(string.Format(Properties.Resources.LongRunningOperationFailed,
                                                       response.Error.Code, response.Error.Message));
            }

            return
                (_accountClient.DataLakeAnalyticsAccount.Get(resourceGroupName, parameters.DataLakeAnalyticsAccount.Name)
                 .DataLakeAnalyticsAccount);
        }