public void CreateGetUpdateDeleteTest() { TestUtilities.StartTest(); try { UndoContext.Current.Start(); CommonTestFixture commonData = new CommonTestFixture(); var clientToUse = this.GetDataLakeAnalyticsManagementClient(); // Create a test account AzureAsyncOperationResponse responseCreate = clientToUse.DataLakeAnalyticsAccount.Create(commonData.ResourceGroupName, parameters: new DataLakeAnalyticsAccountCreateOrUpdateParameters { DataLakeAnalyticsAccount = new DataLakeAnalyticsAccount { Name = commonData.DataLakeAnalyticsAccountName, Location = commonData.Location, Properties = new DataLakeAnalyticsAccountProperties { DefaultDataLakeStoreAccount = commonData.DataLakeStoreAccountName, DataLakeStoreAccounts = new List<DataLakeStoreAccount> { new DataLakeStoreAccount { Name = commonData.DataLakeStoreAccountName, Properties = new DataLakeStoreAccountProperties { Suffix = commonData.DataLakeStoreAccountSuffix } } } }, Tags = new Dictionary<string, string> { { "testkey","testvalue" } } } }); Assert.Equal(HttpStatusCode.OK, responseCreate.StatusCode); // get the account and ensure that all the values are properly set. var responseGet = clientToUse.DataLakeAnalyticsAccount.Get(commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName); // validate the account creation process Assert.True(responseGet.DataLakeAnalyticsAccount.Properties.ProvisioningState == DataLakeAnalyticsAccountStatus.Creating || responseGet.DataLakeAnalyticsAccount.Properties.ProvisioningState == DataLakeAnalyticsAccountStatus.Succeeded); Assert.NotNull(responseCreate.RequestId); Assert.NotNull(responseGet.RequestId); Assert.Contains(commonData.DataLakeAnalyticsAccountName, responseGet.DataLakeAnalyticsAccount.Id); Assert.Equal(commonData.Location, responseGet.DataLakeAnalyticsAccount.Location); Assert.Equal(commonData.DataLakeAnalyticsAccountName, responseGet.DataLakeAnalyticsAccount.Name); Assert.Equal("Microsoft.DataLakeAnalytics/accounts", responseGet.DataLakeAnalyticsAccount.Type); Assert.True(responseGet.DataLakeAnalyticsAccount.Properties.DataLakeStoreAccounts.Count == 1); Assert.True(responseGet.DataLakeAnalyticsAccount.Properties.DataLakeStoreAccounts.ToList()[0].Name.Equals(commonData.DataLakeStoreAccountName)); // 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.DataLakeAnalyticsAccount.Properties.ProvisioningState != DataLakeAnalyticsAccountStatus.Succeeded && responseGet.DataLakeAnalyticsAccount.Properties.ProvisioningState != DataLakeAnalyticsAccountStatus.Failed && minutesWaited <= timeToWaitInMinutes) { TestUtilities.Wait(60000); // Wait for one minute and then go again. minutesWaited++; responseGet = clientToUse.DataLakeAnalyticsAccount.Get(commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName); } // Confirm that the account creation did succeed Assert.True(responseGet.DataLakeAnalyticsAccount.Properties.ProvisioningState == DataLakeAnalyticsAccountStatus.Succeeded); // Update the account and confirm the updates make it in. var newAccount = responseGet.DataLakeAnalyticsAccount; var firstStorageAccountName = newAccount.Properties.DataLakeStoreAccounts.ToList()[0].Name; newAccount.Tags = new Dictionary<string, string> { {"updatedKey", "updatedValue"} }; // need to null out deep properties to prevent an error newAccount.Properties.DataLakeStoreAccounts = null; newAccount.Properties.StorageAccounts = null; var updateResponse = clientToUse.DataLakeAnalyticsAccount.Update(commonData.ResourceGroupName, new DataLakeAnalyticsAccountCreateOrUpdateParameters { DataLakeAnalyticsAccount = newAccount, }); Assert.Equal(HttpStatusCode.OK, updateResponse.StatusCode); Assert.Equal(updateResponse.Status, OperationStatus.Succeeded); // get the account and ensure that all the values are properly set. var updateResponseGet = clientToUse.DataLakeAnalyticsAccount.Get(commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName); Assert.NotNull(updateResponse.RequestId); Assert.Contains(responseGet.DataLakeAnalyticsAccount.Id, updateResponseGet.DataLakeAnalyticsAccount.Id); Assert.Equal(responseGet.DataLakeAnalyticsAccount.Location, updateResponseGet.DataLakeAnalyticsAccount.Location); Assert.Equal(newAccount.Name, updateResponseGet.DataLakeAnalyticsAccount.Name); Assert.Equal(responseGet.DataLakeAnalyticsAccount.Type, updateResponseGet.DataLakeAnalyticsAccount.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.DataLakeAnalyticsAccount.Tags.SequenceEqual(newAccount.Tags)); Assert.True(updateResponseGet.DataLakeAnalyticsAccount.Properties.DataLakeStoreAccounts.Count == 1); Assert.True(updateResponseGet.DataLakeAnalyticsAccount.Properties.DataLakeStoreAccounts.ToList()[0].Name.Equals(firstStorageAccountName)); // Create another account and ensure that list account returns both var accountToChange = responseGet.DataLakeAnalyticsAccount; accountToChange.Name = accountToChange.Name + "secondacct"; var parameters = new DataLakeAnalyticsAccountCreateOrUpdateParameters { DataLakeAnalyticsAccount = accountToChange }; clientToUse.DataLakeAnalyticsAccount.Create(commonData.ResourceGroupName, parameters); DataLakeAnalyticsAccountListResponse listResponse = clientToUse.DataLakeAnalyticsAccount.List(commonData.ResourceGroupName, null); // Assert that there are at least two accounts in the list Assert.True(listResponse.Value.Count > 1); // Add, list and remove a data source to the first account var addDataSourceResponse = clientToUse.DataLakeAnalyticsAccount.AddDataLakeStoreAccount(commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName, commonData.SecondDataLakeStoreAccountName, new AddDataLakeStoreParameters { Properties = new DataLakeStoreAccountProperties {Suffix = commonData.DataLakeStoreAccountSuffix} }); Assert.Equal(HttpStatusCode.OK, addDataSourceResponse.StatusCode); // Get the data sources and confirm there are 2 var getDataSourceResponse = clientToUse.DataLakeAnalyticsAccount.ListDataLakeStoreAccounts(commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName, null); Assert.Equal(HttpStatusCode.OK, getDataSourceResponse.StatusCode); Assert.Equal(2, getDataSourceResponse.Value.Count); // get the specific data source var getSingleDataSourceResponse = clientToUse.DataLakeAnalyticsAccount.GetDataLakeStoreAccount(commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName, commonData.SecondDataLakeStoreAccountName); Assert.Equal(HttpStatusCode.OK, getSingleDataSourceResponse.StatusCode); Assert.Equal(commonData.SecondDataLakeStoreAccountName, getSingleDataSourceResponse.DataLakeStoreAccount.Name); Assert.Equal(commonData.SecondDataLakeStoreAccountSuffix, getSingleDataSourceResponse.DataLakeStoreAccount.Properties.Suffix); // Remove the data source we added var removeDataSourceResponse = clientToUse.DataLakeAnalyticsAccount.DeleteDataLakeStoreAccount(commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName, commonData.SecondDataLakeStoreAccountName); Assert.Equal(HttpStatusCode.OK, removeDataSourceResponse.StatusCode); // Confirm that there is now only one data source. getDataSourceResponse = clientToUse.DataLakeAnalyticsAccount.ListDataLakeStoreAccounts(commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName, null); Assert.Equal(HttpStatusCode.OK, getDataSourceResponse.StatusCode); Assert.Equal(1, getDataSourceResponse.Value.Count); // Add, list and remove an azure blob source to the first account var addDataSourceBlobResponse = clientToUse.DataLakeAnalyticsAccount.AddStorageAccount(commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName, commonData.StorageAccountName, new AddStorageAccountParameters { Properties = new StorageAccountProperties { Suffix = commonData.StorageAccountSuffix, AccessKey = commonData.StorageAccountAccessKey } }); Assert.Equal(HttpStatusCode.OK, addDataSourceBlobResponse.StatusCode); // Get the data sources and confirm there is 1 var getDataSourceBlobResponse = clientToUse.DataLakeAnalyticsAccount.ListStorageAccounts(commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName, null); Assert.Equal(HttpStatusCode.OK, getDataSourceBlobResponse.StatusCode); Assert.Equal(1, getDataSourceBlobResponse.Value.Count); // Get the specific data source we added and confirm that it has the same properties var getSingleDataSourceBlobResponse = clientToUse.DataLakeAnalyticsAccount.GetStorageAccount(commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName, commonData.StorageAccountName); Assert.Equal(HttpStatusCode.OK, getSingleDataSourceBlobResponse.StatusCode); Assert.Equal(commonData.StorageAccountName, getSingleDataSourceBlobResponse.StorageAccount.Name); Assert.True(string.IsNullOrEmpty(getSingleDataSourceBlobResponse.StorageAccount.Properties.AccessKey)); Assert.Equal(commonData.StorageAccountSuffix, getSingleDataSourceBlobResponse.StorageAccount.Properties.Suffix); // Remove the data source we added var removeDataSourceBlobResponse = clientToUse.DataLakeAnalyticsAccount.DeleteStorageAccount(commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName, commonData.StorageAccountName); Assert.Equal(HttpStatusCode.OK, removeDataSourceBlobResponse.StatusCode); // Confirm that there no azure data sources. getDataSourceBlobResponse = clientToUse.DataLakeAnalyticsAccount.ListStorageAccounts(commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName, null); Assert.Equal(HttpStatusCode.OK, getDataSourceResponse.StatusCode); Assert.Equal(0, getDataSourceBlobResponse.Value.Count); // Delete the account and confirm that it is deleted. AzureOperationResponse deleteResponse = clientToUse.DataLakeAnalyticsAccount.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.DataLakeAnalyticsAccount.Delete(commonData.ResourceGroupName, newAccount.Name); Assert.Contains<HttpStatusCode>(deleteResponse.StatusCode, acceptedStatusCodes); // delete the account with its old name, which should also succeed. deleteResponse = clientToUse.DataLakeAnalyticsAccount.Delete(commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName); Assert.Contains<HttpStatusCode>(deleteResponse.StatusCode, acceptedStatusCodes); // delete the second account that was created to ensure that we properly clean up after ourselves. deleteResponse = clientToUse.DataLakeAnalyticsAccount.Delete(commonData.ResourceGroupName, accountToChange.Name); Assert.Contains<HttpStatusCode>(deleteResponse.StatusCode, acceptedStatusCodes); } finally { // we don't catch any exceptions, those should all be bubbled up. UndoContext.Current.UndoAll(); TestUtilities.EndTest(); } }
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 (GetAcount(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; }
/// <summary> /// Creates the specified Data Lake Analytics account.This supplies the /// user with computation services for Data Lake Analytics workloads /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.DataLake.Analytics.IDataLakeAnalyticsAccountOperations. /// </param> /// <param name='resourceGroupName'> /// Required. The name of the resource group. /// </param> /// <param name='parameters'> /// Required. Parameters supplied to the create Data Lake Analytics /// 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> CreateAsync(this IDataLakeAnalyticsAccountOperations operations, string resourceGroupName, DataLakeAnalyticsAccountCreateOrUpdateParameters parameters) { return operations.CreateAsync(resourceGroupName, parameters, CancellationToken.None); }
public void SetDefaultDataLakeStoreAccount(string resourceGroupName, string accountName, DataLakeStoreAccount storageToSet) { if (string.IsNullOrEmpty(resourceGroupName)) { resourceGroupName = GetResourceGroupByAccountName(accountName); } var account = GetAcount(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); }
/// <summary> /// Creates the specified Data Lake Analytics account.This supplies the /// user with computation services for Data Lake Analytics workloads /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.DataLake.Analytics.IDataLakeAnalyticsAccountOperations. /// </param> /// <param name='resourceGroupName'> /// Required. The name of the resource group. /// </param> /// <param name='parameters'> /// Required. Parameters supplied to the create Data Lake Analytics /// 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 Create(this IDataLakeAnalyticsAccountOperations operations, string resourceGroupName, DataLakeAnalyticsAccountCreateOrUpdateParameters parameters) { return Task.Factory.StartNew((object s) => { return ((IDataLakeAnalyticsAccountOperations)s).CreateAsync(resourceGroupName, parameters); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult(); }