/// <summary> /// Converts the <see cref="sourceValue" /> parameter to the <see cref="destinationType" /> parameter using <see cref="formatProvider" /// /> and <see cref="ignoreCase" /> /// </summary> /// <param name="sourceValue">the value to convert into an instance of <see cref="CheckNameAvailabilityParameters" />.</param> /// <returns> /// an instance of <see cref="CheckNameAvailabilityParameters" />, or <c>null</c> if there is no suitable conversion. /// </returns> public static object ConvertFrom(dynamic sourceValue) { if (null == sourceValue) { return(null); } try { CheckNameAvailabilityParameters.FromJsonString(typeof(string) == sourceValue.GetType() ? sourceValue : sourceValue.ToJsonString()); } catch { // Unable to use JSON pattern } try { return(new CheckNameAvailabilityParameters { Name = sourceValue.Name, Type = sourceValue.Type, }); } catch { } return(null); }
private void EnsureNameAvailabilityOrThrow() { var checkNameInputs = new CheckNameAvailabilityParameters(this.Name, ResourceTypeName); var nameAvailabilityInfo = this.HealthcareApisClient.Services.CheckNameAvailability(checkNameInputs); if (nameAvailabilityInfo.NameAvailable != true) { throw new PSArgumentException(nameAvailabilityInfo.Message); } }
public virtual Response <NameAvailabilityStatus> CheckNameAvailability(CheckNameAvailabilityParameters checkNameAvailabilityParameters, CancellationToken cancellationToken = default) { using var scope = _clientDiagnostics.CreateScope("OperationsClient.CheckNameAvailability"); scope.Start(); try { return(RestClient.CheckNameAvailability(checkNameAvailabilityParameters, cancellationToken)); } catch (Exception e) { scope.Failed(e); throw; } }
public void HealthcareApisCheckNameAvailabilityTest() { var handler = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType().Name)) { var resourcesClient = HealthcareApisManagementTestUtilities.GetResourceManagementClient(context, handler); var healthCareApisMgmtClient = HealthcareApisManagementTestUtilities.GetHealthcareApisManagementClient(context, handler); CheckNameAvailabilityParameters checkNameAvailabilityParameters = new CheckNameAvailabilityParameters { Name = "hca1234", Type = "Microsoft.HealthcareApis/services" }; var servicesNameAvailabilityInfo = healthCareApisMgmtClient.Services.CheckNameAvailability(checkNameAvailabilityParameters); Assert.True(servicesNameAvailabilityInfo.NameAvailable); } }
internal HttpMessage CreateCheckNameAvailabilityRequest(CheckNameAvailabilityParameters checkNameAvailabilityParameters) { var message = _pipeline.CreateMessage(); var request = message.Request; request.Method = RequestMethod.Post; var uri = new RawRequestUriBuilder(); uri.Reset(endpoint); uri.AppendPath("/subscriptions/", false); uri.AppendPath(subscriptionId, true); uri.AppendPath("/providers/Microsoft.AppConfiguration/checkNameAvailability", false); uri.AppendQuery("api-version", apiVersion, true); request.Uri = uri; request.Headers.Add("Content-Type", "application/json"); using var content = new Utf8JsonRequestContent(); content.JsonWriter.WriteObjectValue(checkNameAvailabilityParameters); request.Content = content; return(message); }
/// <summary> /// Check the availability of the resource name. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='locationName'> /// Location. /// </param> /// <param name='checkNameAvailabilityParameters'> /// The name and type of the resource. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <CheckNameAvailabilityResult> CheckNameAvailabilityAsync(this IWorkspaceOperations operations, string locationName, CheckNameAvailabilityParameters checkNameAvailabilityParameters, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.CheckNameAvailabilityWithHttpMessagesAsync(locationName, checkNameAvailabilityParameters, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Checks whether the specified account name is available or taken. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='location'> /// The resource location without whitespace. /// </param> /// <param name='parameters'> /// Parameters supplied to check the Data Lake Store account name availability. /// </param> public static NameAvailabilityInformation CheckNameAvailability(this IAccountsOperations operations, string location, CheckNameAvailabilityParameters parameters) { return(operations.CheckNameAvailabilityAsync(location, parameters).GetAwaiter().GetResult()); }
public static async Task <Response <NameAvailabilityStatus> > CheckAppConfigurationNameAvailabilityAsync(this Subscription subscription, CheckNameAvailabilityParameters checkNameAvailabilityParameters, CancellationToken cancellationToken = default) { return(await GetExtensionClient(subscription).CheckAppConfigurationNameAvailabilityAsync(checkNameAvailabilityParameters, cancellationToken).ConfigureAwait(false)); }
public static Response <NameAvailabilityStatus> CheckAppConfigurationNameAvailability(this SubscriptionResource subscriptionResource, CheckNameAvailabilityParameters checkNameAvailabilityParameters, CancellationToken cancellationToken = default) { Argument.AssertNotNull(checkNameAvailabilityParameters, nameof(checkNameAvailabilityParameters)); return(GetExtensionClient(subscriptionResource).CheckAppConfigurationNameAvailability(checkNameAvailabilityParameters, cancellationToken)); }
public virtual async Task <Response <NameAvailabilityStatus> > CheckAppConfigurationNameAvailabilityAsync(CheckNameAvailabilityParameters checkNameAvailabilityParameters, CancellationToken cancellationToken = default) { using var scope = DefaultClientDiagnostics.CreateScope("SubscriptionExtensionClient.CheckAppConfigurationNameAvailability"); scope.Start(); try { var response = await DefaultRestClient.CheckAppConfigurationNameAvailabilityAsync(Id.SubscriptionId, checkNameAvailabilityParameters, cancellationToken).ConfigureAwait(false); return(response); } catch (Exception e) { scope.Failed(e); throw; } }
public void AccountCRUDTest() { using (var context = MockContext.Start(this.GetType())) { commonData = new CommonTestFixture(context); var clientToUse = this.GetDataLakeStoreAccountManagementClient(context); // Ensure that the account name is available var checkNameParam = new CheckNameAvailabilityParameters { Name = commonData.DataLakeStoreAccountName }; var responseNameCheck = clientToUse.Accounts.CheckNameAvailability( commonData.Location.Replace(" ", ""), checkNameParam ); Assert.True(responseNameCheck.NameAvailable); // Create a test account var responseCreate = clientToUse.Accounts.Create( resourceGroupName: commonData.ResourceGroupName, accountName: commonData.DataLakeStoreAccountName, parameters: new CreateDataLakeStoreAccountParameters { Location = commonData.Location, Tags = new Dictionary <string, string> { { "testkey", "testvalue" } }, Identity = new EncryptionIdentity(), EncryptionConfig = new EncryptionConfig { Type = EncryptionConfigType.ServiceManaged }, EncryptionState = EncryptionState.Enabled, NewTier = TierType.Commitment1TB } ); Assert.Equal(DataLakeStoreAccountStatus.Succeeded, responseCreate.ProvisioningState); // Verify that the account name is no longer available responseNameCheck = clientToUse.Accounts.CheckNameAvailability( commonData.Location.Replace(" ", ""), checkNameParam ); Assert.False(responseNameCheck.NameAvailable); // Get the account and ensure that all the values are properly set. var responseGet = clientToUse.Accounts.Get( commonData.ResourceGroupName, commonData.DataLakeStoreAccountName ); // Validate the account creation process Assert.Equal(DataLakeStoreAccountStatus.Succeeded, responseGet.ProvisioningState); Assert.NotNull(responseCreate.Id); Assert.NotNull(responseGet.Id); Assert.Contains(commonData.DataLakeStoreAccountName, responseGet.Id); Assert.Contains(commonData.DataLakeStoreAccountName, responseGet.Endpoint); Assert.Equal(commonData.Location, responseGet.Location); Assert.Equal(commonData.DataLakeStoreAccountName, responseGet.Name); Assert.Equal("Microsoft.DataLakeStore/accounts", responseGet.Type); Assert.Equal(TierType.Commitment1TB, responseGet.CurrentTier); Assert.Equal(TierType.Commitment1TB, responseGet.NewTier); // 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.ProvisioningState != DataLakeStoreAccountStatus.Succeeded && responseGet.ProvisioningState != DataLakeStoreAccountStatus.Failed && minutesWaited <= timeToWaitInMinutes) { TestUtilities.Wait(60000); // Wait for one minute and then go again. minutesWaited++; responseGet = clientToUse.Accounts.Get( commonData.ResourceGroupName, commonData.DataLakeStoreAccountName ); } // Confirm that the account creation did succeed Assert.True(responseGet.ProvisioningState == DataLakeStoreAccountStatus.Succeeded); // Validate the encryption state is set Assert.Equal(EncryptionState.Enabled, responseGet.EncryptionState.GetValueOrDefault()); Assert.True(responseGet.Identity.PrincipalId.HasValue); Assert.True(responseGet.Identity.TenantId.HasValue); Assert.Equal(EncryptionConfigType.ServiceManaged, responseGet.EncryptionConfig.Type); // Update the account and confirm the updates make it in. var responseUpdate = clientToUse.Accounts.Update( commonData.ResourceGroupName, commonData.DataLakeStoreAccountName, new UpdateDataLakeStoreAccountParameters { Tags = new Dictionary <string, string> { { "updatedKey", "updatedValue" } }, NewTier = TierType.Consumption } ); Assert.Equal(DataLakeStoreAccountStatus.Succeeded, responseUpdate.ProvisioningState); var responseUpdateGet = clientToUse.Accounts.Get( commonData.ResourceGroupName, commonData.DataLakeStoreAccountName ); Assert.NotNull(responseUpdate.Id); Assert.Contains(responseGet.Id, responseUpdateGet.Id); Assert.Equal(responseGet.Location, responseUpdateGet.Location); Assert.Equal(responseGet.Name, responseUpdateGet.Name); Assert.Equal(responseGet.Type, responseUpdateGet.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(responseUpdateGet.Tags.Count == 1); Assert.True(responseUpdateGet.Tags.ContainsKey("updatedKey")); Assert.True(responseUpdateGet.Tags.Values.Contains("updatedValue")); Assert.Equal(TierType.Commitment1TB, responseUpdateGet.CurrentTier); Assert.Equal(TierType.Consumption, responseUpdateGet.NewTier); // Create another account and ensure that list account returns both clientToUse.Accounts.Create( commonData.ResourceGroupName, commonData.DataLakeStoreAccountName + "acct2", new CreateDataLakeStoreAccountParameters { Location = commonData.Location } ); var listResponse = clientToUse.Accounts.List(); // Assert that there are at least two accounts in the list Assert.True(listResponse.Count() > 1); // Now list by resource group: listResponse = clientToUse.Accounts.ListByResourceGroup( commonData.ResourceGroupName ); // Assert that there are at least two accounts in the list Assert.True(listResponse.Count() > 1); // Test that the account exists Assert.True( clientToUse.Accounts.Exists( commonData.ResourceGroupName, commonData.DataLakeStoreAccountName + "acct2" ) ); // Check that Locations_GetCapability and Operations_List are functional var responseGetCapability = clientToUse.Locations.GetCapability( commonData.Location.Replace(" ", "") ); Assert.NotNull(responseGetCapability); var responseListOps = clientToUse.Operations.List(); Assert.NotNull(responseListOps); // Delete the account and confirm that it is deleted. clientToUse.Accounts.Delete( commonData.ResourceGroupName, commonData.DataLakeStoreAccountName + "acct2" ); // Delete the account again and make sure it continues to result in a succesful code. clientToUse.Accounts.Delete( commonData.ResourceGroupName, commonData.DataLakeStoreAccountName + "acct2" ); // Delete the account with its old name, which should also succeed. clientToUse.Accounts.Delete( commonData.ResourceGroupName, commonData.DataLakeStoreAccountName ); // Test that the account is gone Assert.False( clientToUse.Accounts.Exists( commonData.ResourceGroupName, commonData.DataLakeStoreAccountName + "acct2" ) ); } }
/// <summary> /// Checks that the redis cache name is valid and is not already in use. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='parameters'> /// Parameters supplied to the CheckNameAvailability Redis operation. The only /// supported resource type is 'Microsoft.Cache/redis' /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task CheckNameAvailabilityAsync(this IRedisOperations operations, CheckNameAvailabilityParameters parameters, CancellationToken cancellationToken = default(CancellationToken)) { (await operations.CheckNameAvailabilityWithHttpMessagesAsync(parameters, null, cancellationToken).ConfigureAwait(false)).Dispose(); }
/// <summary> /// Checks that the redis cache name is valid and is not already in use. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='parameters'> /// Parameters supplied to the CheckNameAvailability Redis operation. The only /// supported resource type is 'Microsoft.Cache/redis' /// </param> public static void CheckNameAvailability(this IRedisOperations operations, CheckNameAvailabilityParameters parameters) { operations.CheckNameAvailabilityAsync(parameters).GetAwaiter().GetResult(); }
/// <summary> /// API to check for resource name availability. /// A name is available if no other resource exists that has the same /// SubscriptionId, Resource Name and Type /// or if one or more such resources exist, each of these must be GC'd and /// their time of deletion be more than 24 Hours Ago /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group where the recovery services vault is /// present. /// </param> /// <param name='location'> /// Location of the resource /// </param> /// <param name='input'> /// Contains information about Resource type and Resource name /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <CheckNameAvailabilityResult> CheckNameAvailabilityAsync(this IRecoveryServicesOperations operations, string resourceGroupName, string location, CheckNameAvailabilityParameters input, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.CheckNameAvailabilityWithHttpMessagesAsync(resourceGroupName, location, input, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// API to check for resource name availability. /// A name is available if no other resource exists that has the same /// SubscriptionId, Resource Name and Type /// or if one or more such resources exist, each of these must be GC'd and /// their time of deletion be more than 24 Hours Ago /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group where the recovery services vault is /// present. /// </param> /// <param name='location'> /// Location of the resource /// </param> /// <param name='input'> /// Contains information about Resource type and Resource name /// </param> public static CheckNameAvailabilityResult CheckNameAvailability(this IRecoveryServicesOperations operations, string resourceGroupName, string location, CheckNameAvailabilityParameters input) { return(operations.CheckNameAvailabilityAsync(resourceGroupName, location, input).GetAwaiter().GetResult()); }
/// <summary> /// Check if a service instance name is available. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='checkNameAvailabilityInputs'> /// Set the name parameter in the CheckNameAvailabilityParameters structure to /// the name of the service instance to check. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <ServicesNameAvailabilityInfo> CheckNameAvailabilityAsync(this IServicesOperations operations, CheckNameAvailabilityParameters checkNameAvailabilityInputs, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.CheckNameAvailabilityWithHttpMessagesAsync(checkNameAvailabilityInputs, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
public static async Task <Response <NameAvailabilityStatus> > CheckAppConfigurationNameAvailabilityAsync(this SubscriptionResource subscriptionResource, CheckNameAvailabilityParameters checkNameAvailabilityParameters, CancellationToken cancellationToken = default) { Argument.AssertNotNull(checkNameAvailabilityParameters, nameof(checkNameAvailabilityParameters)); return(await GetExtensionClient(subscriptionResource).CheckAppConfigurationNameAvailabilityAsync(checkNameAvailabilityParameters, cancellationToken).ConfigureAwait(false)); }
public async Task <Response <NameAvailabilityStatus> > CheckAppConfigurationNameAvailabilityAsync(string subscriptionId, CheckNameAvailabilityParameters checkNameAvailabilityParameters, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(subscriptionId, nameof(subscriptionId)); Argument.AssertNotNull(checkNameAvailabilityParameters, nameof(checkNameAvailabilityParameters)); using var message = CreateCheckAppConfigurationNameAvailabilityRequest(subscriptionId, checkNameAvailabilityParameters); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); switch (message.Response.Status) { case 200: { NameAvailabilityStatus value = default; using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); value = NameAvailabilityStatus.DeserializeNameAvailabilityStatus(document.RootElement); return(Response.FromValue(value, message.Response)); }
public virtual Response <NameAvailabilityStatus> CheckAppConfigurationNameAvailability(CheckNameAvailabilityParameters checkNameAvailabilityParameters, CancellationToken cancellationToken = default) { if (checkNameAvailabilityParameters == null) { throw new ArgumentNullException(nameof(checkNameAvailabilityParameters)); } using var scope = DefaultClientDiagnostics.CreateScope("SubscriptionExtensionClient.CheckAppConfigurationNameAvailability"); scope.Start(); try { var response = DefaultRestClient.CheckAppConfigurationNameAvailability(Id.SubscriptionId, checkNameAvailabilityParameters, cancellationToken); return(response); } catch (Exception e) { scope.Failed(e); throw; } }
public void AccountCRUDTest() { using (var context = MockContext.Start(this.GetType())) { commonData = new CommonTestFixture(context, true); var clientToUse = this.GetDataLakeAnalyticsAccountManagementClient(context); // Ensure that the account doesn't exist and that the account name is available Assert.False( clientToUse.Accounts.Exists( commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName ) ); var checkNameParam = new CheckNameAvailabilityParameters { Name = commonData.DataLakeAnalyticsAccountName }; var responseNameCheck = clientToUse.Accounts.CheckNameAvailability( commonData.Location.Replace(" ", ""), checkNameParam ); Assert.True(responseNameCheck.NameAvailable); // Create a test account var responseCreate = clientToUse.Accounts.Create( commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName, parameters: new CreateDataLakeAnalyticsAccountParameters { Location = commonData.Location, Tags = new Dictionary <string, string> { { "testkey", "testvalue" } }, DefaultDataLakeStoreAccount = commonData.DataLakeStoreAccountName, DataLakeStoreAccounts = new List <AddDataLakeStoreWithAccountParameters> { new AddDataLakeStoreWithAccountParameters { Name = commonData.DataLakeStoreAccountName, Suffix = commonData.DataLakeStoreAccountSuffix } }, NewTier = TierType.Commitment100AUHours } ); // Verify that the account exists and that the account name is no longer available Assert.True( clientToUse.Accounts.Exists( commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName ) ); responseNameCheck = clientToUse.Accounts.CheckNameAvailability( commonData.Location.Replace(" ", ""), checkNameParam ); Assert.False(responseNameCheck.NameAvailable); // Get the account and ensure that all the values are properly set. var responseGet = clientToUse.Accounts.Get( commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName ); // Validate the account creation process Assert.True(responseGet.ProvisioningState == DataLakeAnalyticsAccountStatus.Creating || responseGet.ProvisioningState == DataLakeAnalyticsAccountStatus.Succeeded); Assert.NotNull(responseCreate.Id); Assert.NotNull(responseGet.Id); Assert.Contains(commonData.DataLakeAnalyticsAccountName, responseGet.Id); Assert.Equal(commonData.Location, responseGet.Location); Assert.Equal(commonData.DataLakeAnalyticsAccountName, responseGet.Name); Assert.Equal("Microsoft.DataLakeAnalytics/accounts", responseGet.Type); Assert.True(responseGet.DataLakeStoreAccounts.Count == 1); Assert.Equal(responseGet.DataLakeStoreAccounts.ToList()[0].Name, 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.ProvisioningState != DataLakeAnalyticsAccountStatus.Succeeded && responseGet.ProvisioningState != DataLakeAnalyticsAccountStatus.Failed && minutesWaited <= timeToWaitInMinutes) { TestUtilities.Wait(60000); // Wait for one minute and then go again. minutesWaited++; responseGet = clientToUse.Accounts.Get( commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName ); } // Confirm that the account creation did succeed Assert.True(responseGet.ProvisioningState == DataLakeAnalyticsAccountStatus.Succeeded); Assert.Equal(TierType.Commitment100AUHours, responseGet.CurrentTier); Assert.Equal(TierType.Commitment100AUHours, responseGet.NewTier); // Update the account and confirm that the updates make it in. var responseUpdate = clientToUse.Accounts.Update( commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName, parameters: new UpdateDataLakeAnalyticsAccountParameters { Tags = new Dictionary <string, string> { { "updatedKey", "updatedValue" } }, NewTier = TierType.Consumption } ); Assert.Equal(DataLakeAnalyticsAccountStatus.Succeeded, responseUpdate.ProvisioningState); // Get the account and ensure that all the values are properly set. var responseUpdateGet = clientToUse.Accounts.Get( commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName ); Assert.NotNull(responseUpdate.Id); Assert.Contains(responseGet.Id, responseUpdateGet.Id); Assert.Equal(responseGet.Location, responseUpdateGet.Location); Assert.Equal(responseGet.Name, responseUpdateGet.Name); Assert.Equal(responseGet.Type, responseUpdateGet.Type); // Verify the new tags and tier Assert.True(responseUpdateGet.Tags.Count == 1); Assert.True(responseUpdateGet.Tags.ContainsKey("updatedKey")); Assert.True(responseUpdateGet.Tags.Values.Contains("updatedValue")); Assert.Equal(TierType.Commitment100AUHours, responseUpdateGet.CurrentTier); Assert.Equal(TierType.Consumption, responseUpdateGet.NewTier); // Create another account and ensure that list account returns both clientToUse.Accounts.Create( commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName + "secondacct", new CreateDataLakeAnalyticsAccountParameters { Location = commonData.Location, DefaultDataLakeStoreAccount = commonData.DataLakeStoreAccountName, DataLakeStoreAccounts = new List <AddDataLakeStoreWithAccountParameters> { new AddDataLakeStoreWithAccountParameters { Name = commonData.DataLakeStoreAccountName, Suffix = commonData.DataLakeStoreAccountSuffix } }, } ); var listResponse = clientToUse.Accounts.List(); // Assert that there are at least two accounts in the list Assert.True(listResponse.Count() > 1); // Now list with the resource group listResponse = clientToUse.Accounts.ListByResourceGroup(commonData.ResourceGroupName); // Assert that there are at least two accounts in the list Assert.True(listResponse.Count() > 1); // Add, list and remove a data source to the first account // Validate the data source doesn't exist first Assert.False( clientToUse.Accounts.DataLakeStoreAccountExists( commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName, commonData.SecondDataLakeStoreAccountName ) ); clientToUse.DataLakeStoreAccounts.Add( commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName, commonData.SecondDataLakeStoreAccountName, new AddDataLakeStoreParameters { Suffix = commonData.DataLakeStoreAccountSuffix } ); // Verify that the store account does exist now Assert.True( clientToUse.Accounts.DataLakeStoreAccountExists( commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName, commonData.SecondDataLakeStoreAccountName ) ); // Get the data sources and confirm there are 2 var getDataSourceResponse = clientToUse.DataLakeStoreAccounts.ListByAccount( commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName ); Assert.Equal(2, getDataSourceResponse.Count()); // Get the specific data source var getSingleDataSourceResponse = clientToUse.DataLakeStoreAccounts.Get( commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName, commonData.SecondDataLakeStoreAccountName ); Assert.Equal(commonData.SecondDataLakeStoreAccountName, getSingleDataSourceResponse.Name); Assert.Equal(commonData.SecondDataLakeStoreAccountSuffix, getSingleDataSourceResponse.Suffix); // Remove the data source we added clientToUse.DataLakeStoreAccounts.Delete( commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName, commonData.SecondDataLakeStoreAccountName ); // Confirm that there is now only one data source. getDataSourceResponse = clientToUse.DataLakeStoreAccounts.ListByAccount( commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName ); Assert.True(getDataSourceResponse.Count() == 1); // Add, list and remove an azure blob source to the first account // Verify the blob doesn't exist Assert.False( clientToUse.Accounts.StorageAccountExists( commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName, commonData.StorageAccountName ) ); clientToUse.StorageAccounts.Add( commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName, commonData.StorageAccountName, new AddStorageAccountParameters { Suffix = commonData.StorageAccountSuffix, AccessKey = commonData.StorageAccountAccessKey } ); // Verify the blob exists now Assert.True( clientToUse.Accounts.StorageAccountExists( commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName, commonData.StorageAccountName ) ); // Get the data sources and confirm there is 1 var getDataSourceBlobResponse = clientToUse.StorageAccounts.ListByAccount( commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName ); Assert.True(getDataSourceBlobResponse.Count() == 1); // Get the specific data source we added and confirm that it has the same properties var getSingleDataSourceBlobResponse = clientToUse.StorageAccounts.Get( commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName, commonData.StorageAccountName ); Assert.Equal(commonData.StorageAccountName, getSingleDataSourceBlobResponse.Name); Assert.Equal(commonData.StorageAccountSuffix, getSingleDataSourceBlobResponse.Suffix); // Remove the data source we added clientToUse.StorageAccounts.Delete( commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName, commonData.StorageAccountName ); // Confirm that there no azure data sources. getDataSourceBlobResponse = clientToUse.StorageAccounts.ListByAccount( commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName ); Assert.True(getDataSourceBlobResponse.Count() == 0); // Check that Locations_GetCapability and Operations_List are functional var responseGetCapability = clientToUse.Locations.GetCapability( commonData.Location.Replace(" ", "") ); Assert.NotNull(responseGetCapability); var responseListOps = clientToUse.Operations.List(); Assert.NotNull(responseListOps); // Delete the account and confirm that it is deleted. clientToUse.Accounts.Delete( commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName + "secondacct" ); // Delete the account again and make sure it continues to result in a successful code. clientToUse.Accounts.Delete( commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName + "secondacct" ); // Delete the account with its old name, which should also succeed. clientToUse.Accounts.Delete( commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName ); } }
public static Response <NameAvailabilityStatus> CheckAppConfigurationNameAvailability(this Subscription subscription, CheckNameAvailabilityParameters checkNameAvailabilityParameters, CancellationToken cancellationToken = default) { return(GetExtensionClient(subscription).CheckAppConfigurationNameAvailability(checkNameAvailabilityParameters, cancellationToken)); }
public async static Task <Response <NameAvailabilityStatus> > CheckAppConfigurationNameAvailabilityAsync(this Subscription subscription, CheckNameAvailabilityParameters checkNameAvailabilityParameters, CancellationToken cancellationToken = default) { if (checkNameAvailabilityParameters == null) { throw new ArgumentNullException(nameof(checkNameAvailabilityParameters)); } return(await GetExtensionClient(subscription).CheckAppConfigurationNameAvailabilityAsync(checkNameAvailabilityParameters, cancellationToken).ConfigureAwait(false)); }
public virtual async Task <Response <NameAvailabilityStatus> > CheckNameAvailabilityAsync(CheckNameAvailabilityParameters checkNameAvailabilityParameters, CancellationToken cancellationToken = default) { using var scope = _clientDiagnostics.CreateScope("OperationsClient.CheckNameAvailability"); scope.Start(); try { return(await RestClient.CheckNameAvailabilityAsync(checkNameAvailabilityParameters, cancellationToken).ConfigureAwait(false)); } catch (Exception e) { scope.Failed(e); throw; } }
public static Response <NameAvailabilityStatus> CheckAppConfigurationNameAvailability(this Subscription subscription, CheckNameAvailabilityParameters checkNameAvailabilityParameters, CancellationToken cancellationToken = default) { if (checkNameAvailabilityParameters == null) { throw new ArgumentNullException(nameof(checkNameAvailabilityParameters)); } return(GetExtensionClient(subscription).CheckAppConfigurationNameAvailability(checkNameAvailabilityParameters, cancellationToken)); }
/// <summary> /// Serializes the state of this cmdlet to a <see cref="Microsoft.Azure.AzConfig.Runtime.Json.JsonNode" /> object. /// </summary> /// <param name="container">The <see cref="Microsoft.Azure.AzConfig.Runtime.Json.JsonObject"/> container to serialize this object into. If the caller /// passes in <c>null</c>, a new instance will be created and returned to the caller.</param> /// <param name="serializationMode">Allows the caller to choose the depth of the serialization. See <see cref="Microsoft.Azure.AzConfig.Runtime.SerializationMode"/>.</param> /// <returns> /// a serialized instance of <see cref="TestAzOperationNameAvailability_NameAvailabilityNameType" /> as a <see cref="Microsoft.Azure.AzConfig.Runtime.Json.JsonNode" /// />. /// </returns> public Microsoft.Azure.AzConfig.Runtime.Json.JsonNode ToJson(Microsoft.Azure.AzConfig.Runtime.Json.JsonObject container, Microsoft.Azure.AzConfig.Runtime.SerializationMode serializationMode) { // serialization method container = container ?? new Microsoft.Azure.AzConfig.Runtime.Json.JsonObject(); AddIf(null != (((object)SubscriptionId)?.ToString()) ? (Microsoft.Azure.AzConfig.Runtime.Json.JsonNode) new Microsoft.Azure.AzConfig.Runtime.Json.JsonString(SubscriptionId.ToString()) : null, "SubscriptionId", container.Add); AddIf(null != CheckNameAvailabilityParameters ? (Microsoft.Azure.AzConfig.Runtime.Json.JsonNode)CheckNameAvailabilityParameters.ToJson(null) : null, "CheckNameAvailabilityParameters", container.Add); return(container); }
/// <summary> /// Checks whether the Batch account name is available in the specified region. /// </summary> /// <param name='locationName'> /// The desired region for the name check. /// </param> /// <param name='name'> /// The name to check for availability /// </param> /// <param name='customHeaders'> /// Headers that will be added to request. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> /// <exception cref="CloudException"> /// Thrown when the operation returned an invalid status code /// </exception> /// <exception cref="SerializationException"> /// Thrown when unable to deserialize the response /// </exception> /// <exception cref="ValidationException"> /// Thrown when a required parameter is null /// </exception> /// <exception cref="System.ArgumentNullException"> /// Thrown when a required parameter is null /// </exception> /// <return> /// A response object containing the response body and response headers. /// </return> public async Task <AzureOperationResponse <CheckNameAvailabilityResultInner> > CheckNameAvailabilityWithHttpMessagesAsync(string locationName, string name, Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) { if (locationName == null) { throw new ValidationException(ValidationRules.CannotBeNull, "locationName"); } if (Client.ApiVersion == null) { throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); } if (Client.SubscriptionId == null) { throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SubscriptionId"); } if (name == null) { throw new ValidationException(ValidationRules.CannotBeNull, "name"); } CheckNameAvailabilityParameters parameters = new CheckNameAvailabilityParameters(); if (name != null) { parameters.Name = name; } // Tracing bool _shouldTrace = ServiceClientTracing.IsEnabled; string _invocationId = null; if (_shouldTrace) { _invocationId = ServiceClientTracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("locationName", locationName); tracingParameters.Add("parameters", parameters); tracingParameters.Add("cancellationToken", cancellationToken); ServiceClientTracing.Enter(_invocationId, this, "CheckNameAvailability", tracingParameters); } // Construct URL var _baseUrl = Client.BaseUri.AbsoluteUri; var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "subscriptions/{subscriptionId}/providers/Microsoft.Batch/locations/{locationName}/checkNameAvailability").ToString(); _url = _url.Replace("{locationName}", System.Uri.EscapeDataString(locationName)); _url = _url.Replace("{subscriptionId}", System.Uri.EscapeDataString(Client.SubscriptionId)); List <string> _queryParameters = new List <string>(); if (Client.ApiVersion != null) { _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); } if (_queryParameters.Count > 0) { _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); } // Create HTTP transport objects var _httpRequest = new HttpRequestMessage(); HttpResponseMessage _httpResponse = null; _httpRequest.Method = new HttpMethod("POST"); _httpRequest.RequestUri = new System.Uri(_url); // Set Headers if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) { _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()); } if (Client.AcceptLanguage != null) { if (_httpRequest.Headers.Contains("accept-language")) { _httpRequest.Headers.Remove("accept-language"); } _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); } if (customHeaders != null) { foreach (var _header in customHeaders) { if (_httpRequest.Headers.Contains(_header.Key)) { _httpRequest.Headers.Remove(_header.Key); } _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); } } // Serialize Request string _requestContent = null; if (parameters != null) { _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(parameters, Client.SerializationSettings); _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); _httpRequest.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); } // Set Credentials if (Client.Credentials != null) { cancellationToken.ThrowIfCancellationRequested(); await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); } // Send Request if (_shouldTrace) { ServiceClientTracing.SendRequest(_invocationId, _httpRequest); } cancellationToken.ThrowIfCancellationRequested(); _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); if (_shouldTrace) { ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); } HttpStatusCode _statusCode = _httpResponse.StatusCode; cancellationToken.ThrowIfCancellationRequested(); string _responseContent = null; if ((int)_statusCode != 200) { var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); try { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject <CloudError>(_responseContent, Client.DeserializationSettings); if (_errorBody != null) { ex = new CloudException(_errorBody.Message); ex.Body = _errorBody; } } catch (JsonException) { // Ignore the exception } ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); if (_httpResponse.Headers.Contains("x-ms-request-id")) { ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } if (_shouldTrace) { ServiceClientTracing.Error(_invocationId, ex); } _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw ex; } // Create Result var _result = new AzureOperationResponse <CheckNameAvailabilityResultInner>(); _result.Request = _httpRequest; _result.Response = _httpResponse; if (_httpResponse.Headers.Contains("x-ms-request-id")) { _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } // Deserialize Response if ((int)_statusCode == 200) { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); try { _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject <CheckNameAvailabilityResultInner>(_responseContent, Client.DeserializationSettings); } catch (JsonException ex) { _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); } } if (_shouldTrace) { ServiceClientTracing.Exit(_invocationId, _result); } return(_result); }
/// <summary> /// Checks whether the specified account name is available or taken. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='location'> /// The resource location without whitespace. /// </param> /// <param name='parameters'> /// Parameters supplied to check the Data Lake Store account name availability. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <NameAvailabilityInformation> CheckNameAvailabilityAsync(this IAccountsOperations operations, string location, CheckNameAvailabilityParameters parameters, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.CheckNameAvailabilityWithHttpMessagesAsync(location, parameters, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Check if a service instance name is available. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='checkNameAvailabilityInputs'> /// Set the name parameter in the CheckNameAvailabilityParameters structure to /// the name of the service instance to check. /// </param> public static ServicesNameAvailabilityInfo CheckNameAvailability(this IServicesOperations operations, CheckNameAvailabilityParameters checkNameAvailabilityInputs) { return(operations.CheckNameAvailabilityAsync(checkNameAvailabilityInputs).GetAwaiter().GetResult()); }
public async Task <Response <NameAvailabilityStatus> > CheckNameAvailabilityAsync(CheckNameAvailabilityParameters checkNameAvailabilityParameters, CancellationToken cancellationToken = default) { if (checkNameAvailabilityParameters == null) { throw new ArgumentNullException(nameof(checkNameAvailabilityParameters)); } using var message = CreateCheckNameAvailabilityRequest(checkNameAvailabilityParameters); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); switch (message.Response.Status) { case 200: { NameAvailabilityStatus value = default; using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); value = NameAvailabilityStatus.DeserializeNameAvailabilityStatus(document.RootElement); return(Response.FromValue(value, message.Response)); }
/// <summary> /// Check the availability of the resource name. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='locationName'> /// Location. /// </param> /// <param name='checkNameAvailabilityParameters'> /// The name and type of the resource. /// </param> public static CheckNameAvailabilityResult CheckNameAvailability(this IWorkspaceOperations operations, string locationName, CheckNameAvailabilityParameters checkNameAvailabilityParameters) { return(operations.CheckNameAvailabilityAsync(locationName, checkNameAvailabilityParameters).GetAwaiter().GetResult()); }