예제 #1
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 DataLakeStoreAccountCreateOrUpdateParameters
            {
                DataLakeStoreAccount = 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.
            }

            var response = accountExists
                ? _client.DataLakeStoreAccount.Update(resourceGroupName, parameters)
                : _client.DataLakeStoreAccount.Create(resourceGroupName, parameters);

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

            return(_client.DataLakeStoreAccount.Get(resourceGroupName, accountName).DataLakeStoreAccount);
        }
예제 #2
0
        private string TryCreateDataLakeStoreAccount(string resourceGroupName, string dataLakeAccountName, string location)
        {
            var dataLakeCreateParameters = new DataLakeStoreAccountCreateOrUpdateParameters
            {
                DataLakeStoreAccount = new DataLakeStoreAccount
                {
                    Location = location,
                    Name     = dataLakeAccountName
                }
            };

            var createResponse = dataLakeStoreManagementClient.DataLakeStoreAccount.Create(resourceGroupName, dataLakeCreateParameters);

            ThrowIfTrue(createResponse.Status != OperationStatus.Succeeded, string.Format("Failed to provision a DataLake Store account in the success state. Actual State: {0}", createResponse.Status));
            var dataLakeAccountSuffix = dataLakeStoreManagementClient.DataLakeStoreAccount.Get(resourceGroupName, dataLakeAccountName).DataLakeStoreAccount.Properties.Endpoint.Replace(dataLakeAccountName + ".", "");

            ThrowIfTrue(string.IsNullOrEmpty(dataLakeAccountSuffix), "dataLakeStoreManagementClient.DataLakeStoreAccount.Create did not properly populate the suffix property");
            return(dataLakeAccountSuffix);
        }
예제 #3
0
        public string TryCreateDataLakeAccount(string resourceGroupName, string dataLakeAccountName, string location)
        {
            var dataLakeCreateParameters = new DataLakeStoreAccountCreateOrUpdateParameters
            {
                DataLakeStoreAccount = new DataLakeStoreAccount
                {
                    Location = location,
                    Name     = dataLakeAccountName,
                }
            };

            var createResponse = dataLakeStoreManagementClient.DataLakeStoreAccount.Create(resourceGroupName, dataLakeCreateParameters);

            ThrowIfTrue(createResponse.Status != Microsoft.Azure.OperationStatus.Succeeded, "dataLakeManagementClient.Account.Create did not result in a fully provisioned account");
            var dataLakeAccountSuffix = dataLakeStoreManagementClient.DataLakeStoreAccount.Get(resourceGroupName, dataLakeAccountName).DataLakeStoreAccount.Properties.Endpoint.Replace(dataLakeAccountName + ".", "");

            ThrowIfTrue(string.IsNullOrEmpty(dataLakeAccountSuffix), "dataLakeManagementClient.Account.Create did not properly populate the host property");
            return(dataLakeAccountSuffix);
        }
        public void CreateGetUpdateDeleteTest()
        {
            TestUtilities.StartTest();
            var clientToUse = this.GetDataLakeStoreManagementClient();

            // Create a test account
            var responseCreate =
                clientToUse.DataLakeStoreAccount.Create(resourceGroupName: commonData.ResourceGroupName,
                                                        parameters: new DataLakeStoreAccountCreateOrUpdateParameters
            {
                DataLakeStoreAccount = new DataLakeStoreAccount
                {
                    Name     = commonData.DataLakeStoreAccountName,
                    Location = commonData.Location,
                    Tags     = new Dictionary <string, string>
                    {
                        { "testkey", "testvalue" }
                    }
                }
            });

            Assert.Equal(HttpStatusCode.OK, responseCreate.StatusCode);
            Assert.Equal(OperationStatus.Succeeded, responseCreate.Status);

            // get the account and ensure that all the values are properly set.
            var responseGet = clientToUse.DataLakeStoreAccount.Get(commonData.ResourceGroupName, commonData.DataLakeStoreAccountName);

            // validate the account creation process
            Assert.True(responseGet.DataLakeStoreAccount.Properties.ProvisioningState == DataLakeStoreAccountStatus.Creating || responseGet.DataLakeStoreAccount.Properties.ProvisioningState == DataLakeStoreAccountStatus.Succeeded);
            Assert.NotNull(responseCreate.RequestId);
            Assert.NotNull(responseGet.RequestId);
            Assert.Contains(commonData.DataLakeStoreAccountName, responseGet.DataLakeStoreAccount.Id);
            Assert.Contains(commonData.DataLakeStoreAccountName, responseGet.DataLakeStoreAccount.Properties.Endpoint);
            Assert.Equal(commonData.Location, responseGet.DataLakeStoreAccount.Location);
            Assert.Equal(commonData.DataLakeStoreAccountName, responseGet.DataLakeStoreAccount.Name);
            Assert.Equal("Microsoft.DataLakeStore/accounts", responseGet.DataLakeStoreAccount.Type);

            // wait for provisioning state to be Succeeded
            // we will wait a maximum of 15 minutes for this to happen and then report failures
            int timeToWaitInMinutes = 15;
            int minutesWaited       = 0;

            while (responseGet.DataLakeStoreAccount.Properties.ProvisioningState != DataLakeStoreAccountStatus.Succeeded && responseGet.DataLakeStoreAccount.Properties.ProvisioningState != DataLakeStoreAccountStatus.Failed && minutesWaited <= timeToWaitInMinutes)
            {
                TestUtilities.Wait(60000); // Wait for one minute and then go again.
                minutesWaited++;
                responseGet = clientToUse.DataLakeStoreAccount.Get(commonData.ResourceGroupName, commonData.DataLakeStoreAccountName);
            }

            // Confirm that the account creation did succeed
            Assert.True(responseGet.DataLakeStoreAccount.Properties.ProvisioningState == DataLakeStoreAccountStatus.Succeeded);

            // Update the account and confirm the updates make it in.
            var newAccount = responseGet.DataLakeStoreAccount;

            newAccount.Tags = new Dictionary <string, string>
            {
                { "updatedKey", "updatedValue" }
            };

            var updateResponse = clientToUse.DataLakeStoreAccount.Update(commonData.ResourceGroupName, new DataLakeStoreAccountCreateOrUpdateParameters
            {
                DataLakeStoreAccount = new DataLakeStoreAccount
                {
                    Name = newAccount.Name,
                    Tags = new Dictionary <string, string>
                    {
                        { "updatedKey", "updatedValue" }
                    }
                }
            });

            Assert.Equal(HttpStatusCode.OK, updateResponse.StatusCode);
            Assert.Equal(OperationStatus.Succeeded, updateResponse.Status);

            var updateResponseGet = clientToUse.DataLakeStoreAccount.Get(commonData.ResourceGroupName, commonData.DataLakeStoreAccountName);

            Assert.NotNull(updateResponse.RequestId);
            Assert.Contains(responseGet.DataLakeStoreAccount.Id, updateResponseGet.DataLakeStoreAccount.Id);
            Assert.Equal(responseGet.DataLakeStoreAccount.Location, updateResponseGet.DataLakeStoreAccount.Location);
            Assert.Equal(newAccount.Name, updateResponseGet.DataLakeStoreAccount.Name);
            Assert.Equal(responseGet.DataLakeStoreAccount.Type, updateResponseGet.DataLakeStoreAccount.Type);

            // verify the new tags. NOTE: sequence equal is not ideal if we have more than 1 tag, since the ordering can change.
            Assert.True(updateResponseGet.DataLakeStoreAccount.Tags.SequenceEqual(newAccount.Tags));

            // Create another account and ensure that list account returns both
            var accountToChange = updateResponseGet.DataLakeStoreAccount;

            accountToChange.Name = accountToChange.Name + "acct2";
            var parameters = new DataLakeStoreAccountCreateOrUpdateParameters
            {
                DataLakeStoreAccount = accountToChange
            };

            clientToUse.DataLakeStoreAccount.Create(commonData.ResourceGroupName, parameters);

            DataLakeStoreAccountListResponse listResponse = clientToUse.DataLakeStoreAccount.List(commonData.ResourceGroupName, null);

            // Assert that there are at least two accounts in the list
            Assert.True(listResponse.Value.Count > 1);

            // Delete the account and confirm that it is deleted.
            AzureOperationResponse deleteResponse = clientToUse.DataLakeStoreAccount.Delete(commonData.ResourceGroupName, newAccount.Name);

            // define the list of accepted status codes when deleting an account.
            List <HttpStatusCode> acceptedStatusCodes = new List <HttpStatusCode>
            {
                HttpStatusCode.OK,
                HttpStatusCode.Accepted,
                HttpStatusCode.NotFound,
                HttpStatusCode.NoContent
            };

            Assert.Contains <HttpStatusCode>(deleteResponse.StatusCode, acceptedStatusCodes);
            Assert.NotNull(deleteResponse.RequestId);

            // delete the account again and make sure it continues to result in a succesful code.
            deleteResponse = clientToUse.DataLakeStoreAccount.Delete(commonData.ResourceGroupName, newAccount.Name);
            Assert.Contains <HttpStatusCode>(deleteResponse.StatusCode, acceptedStatusCodes);

            // delete the account with its old name, which should also succeed.
            deleteResponse = clientToUse.DataLakeStoreAccount.Delete(commonData.ResourceGroupName, commonData.DataLakeStoreAccountName);
            Assert.Contains <HttpStatusCode>(deleteResponse.StatusCode, acceptedStatusCodes);

            TestUtilities.EndTest();
        }
예제 #5
0
 /// <summary>
 /// Creates the specified Data Lake Store account.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.DataLake.Store.IDataLakeStoreAccountOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group the account will be
 /// associated with.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the create Data Lake Store account
 /// operation.
 /// </param>
 /// <returns>
 /// The response body contains the status of the specified asynchronous
 /// operation, indicating whether it has succeeded, is inprogress, or
 /// has failed. Note that this status is distinct from the HTTP status
 /// code returned for the Get Operation Status operation itself. If
 /// the asynchronous operation succeeded, the response body includes
 /// the HTTP status code for the successful request. If the
 /// asynchronous operation failed, the response body includes the HTTP
 /// status code for the failed request and error information regarding
 /// the failure.
 /// </returns>
 public static Task <AzureAsyncOperationResponse> BeginCreateAsync(this IDataLakeStoreAccountOperations operations, string resourceGroupName, DataLakeStoreAccountCreateOrUpdateParameters parameters)
 {
     return(operations.BeginCreateAsync(resourceGroupName, parameters, CancellationToken.None));
 }
예제 #6
0
 /// <summary>
 /// Updates the Data Lake Store account object specified by the account
 /// name with the contents of the account object.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.DataLake.Store.IDataLakeStoreAccountOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the update Data Lake Store account
 /// operation.
 /// </param>
 /// <returns>
 /// The response body contains the status of the specified asynchronous
 /// operation, indicating whether it has succeeded, is inprogress, or
 /// has failed. Note that this status is distinct from the HTTP status
 /// code returned for the Get Operation Status operation itself. If
 /// the asynchronous operation succeeded, the response body includes
 /// the HTTP status code for the successful request. If the
 /// asynchronous operation failed, the response body includes the HTTP
 /// status code for the failed request and error information regarding
 /// the failure.
 /// </returns>
 public static AzureAsyncOperationResponse Update(this IDataLakeStoreAccountOperations operations, string resourceGroupName, DataLakeStoreAccountCreateOrUpdateParameters parameters)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((IDataLakeStoreAccountOperations)s).UpdateAsync(resourceGroupName, parameters);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }