private static async Task CreateNamespace() { try { Console.WriteLine("What would you like to call your Event Hubs namespace?"); namespaceName = Console.ReadLine(); var token = await GetToken(); var creds = new TokenCredentials(token); var ehClient = new EventHubManagementClient(creds) { SubscriptionId = SettingsCache["SubscriptionId"] }; var namespaceParams = new EHNamespace() { Location = SettingsCache["DataCenterLocation"] }; Console.WriteLine("Creating namespace..."); await ehClient.Namespaces.CreateOrUpdateAsync(resourceGroupName, namespaceName, namespaceParams); Console.WriteLine("Created namespace successfully."); } catch (Exception e) { Console.WriteLine("Could not create a namespace..."); Console.WriteLine(e.Message); throw e; } }
/// <summary> /// Performs the tasks needed to create a new Event Hubs namespace within a resource group, intended to be used as /// an ephemeral container for the Event Hub instances used in a given test run. /// </summary> /// /// <returns>The key attributes for identifying and accessing a dynamically created Event Hubs namespace.</returns> /// public static async Task <NamespaceProperties> CreateNamespaceAsync() { var subscription = TestEnvironment.EventHubsSubscription; var resourceGroup = TestEnvironment.EventHubsResourceGroup; var token = await AquireManagementTokenAsync(); string CreateName() => $"net-eventhubs-{ Guid.NewGuid().ToString("D") }"; using (var client = new EventHubManagementClient(new TokenCredentials(token)) { SubscriptionId = subscription }) { var location = await QueryResourceGroupLocationAsync(token, resourceGroup, subscription); var tags = new Dictionary <string, string> { { "source", typeof(EventHubScope).Assembly.GetName().Name }, { "platform", System.Runtime.InteropServices.RuntimeInformation.OSDescription }, { "framework", System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription }, { "created", $"{ DateTimeOffset.UtcNow.ToString("s") }Z" }, { "cleanup-after", $"{ DateTimeOffset.UtcNow.AddDays(1).ToString("s") }Z" } }; var eventHubsNamespace = new EHNamespace(sku: new Sku("Standard", "Standard", 12), tags: tags, isAutoInflateEnabled: true, maximumThroughputUnits: 20, location: location); eventHubsNamespace = await CreateRetryPolicy <EHNamespace>().ExecuteAsync(() => client.Namespaces.CreateOrUpdateAsync(resourceGroup, CreateName(), eventHubsNamespace)); var accessKey = await CreateRetryPolicy <AccessKeys>().ExecuteAsync(() => client.Namespaces.ListKeysAsync(resourceGroup, eventHubsNamespace.Name, TestEnvironment.EventHubsDefaultSharedAccessKey)); return(new NamespaceProperties(eventHubsNamespace.Name, accessKey.PrimaryConnectionString)); } }
public PSNamespaceAttributes(EHNamespace evResource) { if (evResource != null) { Sku = new Sku { Capacity = evResource.Sku.Capacity, Name = evResource.Sku.Name, Tier = evResource.Sku.Tier }; if (evResource.ProvisioningState != null) { ProvisioningState = evResource.ProvisioningState; } if (evResource.CreatedAt.HasValue) { CreatedAt = evResource.CreatedAt; } if (evResource.UpdatedAt.HasValue) { UpdatedAt = evResource.UpdatedAt; } if (evResource.ServiceBusEndpoint != null) { ServiceBusEndpoint = evResource.ServiceBusEndpoint; } if (evResource.Location != null) { Location = evResource.Location; } if (evResource.Id != null) { Id = evResource.Id; } if (evResource.Name != null) { Name = evResource.Name; } if (evResource.IsAutoInflateEnabled.HasValue) { IsAutoInflateEnabled = evResource.IsAutoInflateEnabled; } if (evResource.MaximumThroughputUnits.HasValue) { MaximumThroughputUnits = evResource.MaximumThroughputUnits; } ResourceGroup = Regex.Split(evResource.Id, @"/")[4]; } }
public static void Print(EHNamespace resource) { StringBuilder eh = new StringBuilder("Eventhub Namespace: ") .Append("Eventhub Namespace: ").Append(resource.Id) .Append("\n\tName: ").Append(resource.Name) .Append("\n\tLocation: ").Append(resource.Location) .Append("\n\tTags: ").Append(resource.Tags.ToString()) .Append("\n\tAzureInsightMetricId: ").Append(resource.MetricId) .Append("\n\tIsAutoInflate enabled: ").Append(resource.IsAutoInflateEnabled) .Append("\n\tServiceBus endpoint: ").Append(resource.ServiceBusEndpoint) .Append("\n\tMaximum Throughput Units: ").Append(resource.MaximumThroughputUnits) .Append("\n\tCreated time: ").Append(resource.CreatedAt) .Append("\n\tUpdated time: ").Append(resource.UpdatedAt); Utilities.Log(eh.ToString()); }
public PSNamespaceAttributes BeginCreateNamespace(string resourceGroupName, string namespaceName, string location, string skuName, int?skuCapacity, Dictionary <string, string> tags, bool?isAutoInflateEnabled, int?maximumThroughputUnits, bool?isKafkaEnabled) { EHNamespace parameter = new EHNamespace(); parameter.Location = location; if (tags != null) { parameter.Tags = new Dictionary <string, string>(tags); } if (skuName != null) { parameter.Sku = new Sku { Name = skuName, Tier = skuName }; } if (skuCapacity.HasValue) { parameter.Sku.Capacity = skuCapacity; } if (isAutoInflateEnabled.HasValue) { parameter.IsAutoInflateEnabled = isAutoInflateEnabled; } if (maximumThroughputUnits.HasValue) { parameter.MaximumThroughputUnits = maximumThroughputUnits; } if (isKafkaEnabled.HasValue) { parameter.KafkaEnabled = isKafkaEnabled; } var response = Client.Namespaces.CreateOrUpdate(resourceGroupName, namespaceName, parameter); return(new PSNamespaceAttributes(response)); }
internal async Task <string> CreateNamespaceAsync(string location) { await EnsureAuthenticatedAsync(); var ns = $"squadron-{Guid.NewGuid().ToString("N").Substring(8)}"; var pars = new EHNamespace { Sku = new Sku(SkuName.Standard), Location = location }; EHNamespace res = await _client.Namespaces .CreateOrUpdateAsync(_azureResourceIdentifier.ResourceGroupName, ns, pars); res.KafkaEnabled = true; _azureResourceIdentifier.Name = res.Name; return(res.Name); }
/// <summary> /// Performs the tasks needed to create a new Event Hubs namespace within a resource group, intended to be used as /// an ephemeral container for the Event Hub instances used in a given test run. /// </summary> /// /// <returns>The key attributes for identifying and accessing a dynamically created Event Hubs namespace.</returns> /// public static async Task<NamespaceProperties> CreateNamespaceAsync() { var subscription = TestEnvironment.EventHubsSubscription; var resourceGroup = TestEnvironment.EventHubsResourceGroup; var token = await ResourceManager.AquireManagementTokenAsync(); string CreateName() => $"net-eventhubs-{ Guid.NewGuid().ToString("D") }"; using (var client = new EventHubManagementClient(new TokenCredentials(token)) { SubscriptionId = subscription }) { var location = await ResourceManager.QueryResourceGroupLocationAsync(token, resourceGroup, subscription); var eventHubsNamespace = new EHNamespace(sku: new Sku("Standard", "Standard", 12), tags: ResourceManager.GenerateTags(), isAutoInflateEnabled: true, maximumThroughputUnits: 20, location: location); eventHubsNamespace = await ResourceManager.CreateRetryPolicy<EHNamespace>().ExecuteAsync(() => client.Namespaces.CreateOrUpdateAsync(resourceGroup, CreateName(), eventHubsNamespace)); AccessKeys accessKey = await ResourceManager.CreateRetryPolicy<AccessKeys>().ExecuteAsync(() => client.Namespaces.ListKeysAsync(resourceGroup, eventHubsNamespace.Name, TestEnvironment.EventHubsDefaultSharedAccessKey)); return new NamespaceProperties(eventHubsNamespace.Name, accessKey.PrimaryConnectionString); } }
private static void ScaleDownNamespace(EventhubNamespace ns, EventHubManagementClient ehClient, ILogger log) { log.LogInformation($"ScaleDownNamespace for ns:{ns.Namespace}"); var nsInfo = ehClient.Namespaces.Get(ns.ResourceGroup, ns.Namespace); if (nsInfo.Sku.Capacity <= ns.TargetThroughputUnits) { log.LogInformation($"Namespace:{ns.Namespace} in RG:{ns.ResourceGroup} already at or below target capacity (Current:{nsInfo.Sku.Capacity} Target:{ns.TargetThroughputUnits})"); return; } var nsUpdate = new EHNamespace() { Sku = new Sku(nsInfo.Sku.Name, capacity: ns.TargetThroughputUnits) }; log.LogInformation($"Updating Namespace:{ns.Namespace} in RG:{ns.ResourceGroup} from:{nsInfo.Sku.Capacity} to:{nsUpdate.Sku.Capacity}"); ehClient.Namespaces.Update(ns.ResourceGroup, ns.Namespace, nsUpdate); }
public PSNamespaceAttributes UpdateNamespace(string resourceGroupName, string namespaceName, string location, string skuName, int?skuCapacity, NamespaceState?state, Dictionary <string, string> tags, bool?isAutoInflateEnabled, int?maximumThroughputUnits) { var parameter = new EHNamespace() { Location = location }; Sku tempSku = new Sku(); if (skuName != null) { tempSku.Name = skuName; tempSku.Tier = skuName; } if (skuCapacity.HasValue) { tempSku.Capacity = skuCapacity; } parameter.Sku = tempSku; if (tags != null && tags.Count() > 0) { parameter.Tags = new Dictionary <string, string>(tags); } if (isAutoInflateEnabled.HasValue) { parameter.IsAutoInflateEnabled = isAutoInflateEnabled; } if (maximumThroughputUnits.HasValue) { parameter.MaximumThroughputUnits = maximumThroughputUnits; } var response = Client.Namespaces.Update(resourceGroupName, namespaceName, parameter); return(new PSNamespaceAttributes(response)); }
private static async Task CreateOrUpdateNamespaceAsync( EventHubManagementClient client, string rgName, string ns, string location, string skuName) { var namespaceParams = new EHNamespace { Location = location, Sku = new Sku { Tier = skuName, Name = skuName } }; var namespace1 = await client.Namespaces.CreateOrUpdateAsync(rgName, ns, namespaceParams); Console.WriteLine($"{namespace1.Name} create/update completed"); }
public static async Task <AzureResourceProperties> CreateNamespaceAsync() { var subscription = TestUtility.EventHubsSubscription; var resourceGroup = TestUtility.EventHubsResourceGroup; var token = await AquireManagementTokenAsync(); string CreateName() => $"net-eventhubs-track-one-{ Guid.NewGuid().ToString("D").Substring(0, 8) }"; using (var client = new EventHubManagementClient(TestUtility.ResourceManager, new TokenCredentials(token)) { SubscriptionId = subscription }) { var location = await QueryResourceGroupLocationAsync(token, resourceGroup, subscription); var eventHubsNamespace = new EHNamespace(sku: new Sku("Standard", "Standard", 12), tags: GetResourceTags(), isAutoInflateEnabled: true, maximumThroughputUnits: 20, location: location); eventHubsNamespace = await CreateRetryPolicy <EHNamespace>().ExecuteAsync(() => client.Namespaces.CreateOrUpdateAsync(resourceGroup, CreateName(), eventHubsNamespace)); var accessKey = await CreateRetryPolicy <AccessKeys>().ExecuteAsync(() => client.Namespaces.ListKeysAsync(resourceGroup, eventHubsNamespace.Name, "RootManageSharedAccessKey")); return(new AzureResourceProperties(eventHubsNamespace.Name, accessKey.PrimaryConnectionString, true)); } }
public PSNamespaceAttributes BeginCreateNamespace(string resourceGroupName, string namespaceName, string location, string skuName, int?skuCapacity, Dictionary <string, string> tags, bool isAutoInflateEnabled, int?maximumThroughputUnits, bool isKafkaEnabled, string clusterARMId, bool isZoneRedundant, bool isDisableLocalAuth, bool isIdentity , string identityType, string[] identityId, PSEncryptionConfigAttributes[] encryptionConfigs) { EHNamespace parameter = new EHNamespace(); parameter.Location = location; if (tags != null) { parameter.Tags = new Dictionary <string, string>(tags); } if (skuName != null) { parameter.Sku = new Sku { Name = skuName, Tier = skuName }; } if (clusterARMId != null) { parameter.ClusterArmId = clusterARMId; } if (skuCapacity.HasValue) { parameter.Sku.Capacity = skuCapacity; } if (isAutoInflateEnabled) { parameter.IsAutoInflateEnabled = isAutoInflateEnabled; } if (maximumThroughputUnits.HasValue) { parameter.MaximumThroughputUnits = maximumThroughputUnits; } if (isKafkaEnabled) { parameter.KafkaEnabled = isKafkaEnabled; } if (isZoneRedundant) { parameter.ZoneRedundant = isZoneRedundant; } if (isDisableLocalAuth) { parameter.DisableLocalAuth = isDisableLocalAuth; } if (isIdentity) { parameter.Identity = new Identity() { Type = ManagedServiceIdentityType.SystemAssigned } } ; if (identityType != null) { parameter.Identity = new Identity(); parameter.Identity.Type = FindIdentity(identityType); } if (identityId != null) { Dictionary <string, UserAssignedIdentity> UserAssignedIdentities = new Dictionary <string, UserAssignedIdentity>(); UserAssignedIdentities = identityId.Where(id => id != null).ToDictionary(id => id, id => new UserAssignedIdentity()); if (parameter.Identity == null) { parameter.Identity = new Identity() { UserAssignedIdentities = UserAssignedIdentities }; } else { parameter.Identity.UserAssignedIdentities = UserAssignedIdentities; } if (parameter.Identity.Type == ManagedServiceIdentityType.None || parameter.Identity.Type == ManagedServiceIdentityType.SystemAssigned) { throw new Exception("Please change -IdentityType to 'UserAssigned' or 'SystemAssigned, UserAssigned' if you want to add User Assigned Identities"); } } if (encryptionConfigs != null) { if (parameter.Encryption == null) { parameter.Encryption = new Encryption() { KeySource = KeySource.MicrosoftKeyVault }; } parameter.Encryption.KeyVaultProperties = new List <KeyVaultProperties>(); parameter.Encryption.KeyVaultProperties = encryptionConfigs.Where(x => x != null) .Select(x => { KeyVaultProperties kvp = new KeyVaultProperties(); if (x.KeyName == null || x.KeyVaultUri == null) { throw new Exception("KeyName and KeyVaultUri cannot be null"); } kvp.KeyName = x.KeyName; kvp.KeyVaultUri = x.KeyVaultUri; kvp.KeyVersion = x?.KeyVersion; if (x.UserAssignedIdentity != null) { kvp.Identity = new UserAssignedIdentityProperties(x.UserAssignedIdentity); } return(kvp); }) .ToList(); } var response = Client.Namespaces.CreateOrUpdate(resourceGroupName, namespaceName, parameter); return(new PSNamespaceAttributes(response)); }
// Update Namespace (ResourceGroupName, Name, Location, SkuName, SkuCapacity, tagDictionary, EnableAutoInflate.IsPresent, MaximumThroughputUnits, EnableKafka.IsPresent, ZoneRedundant.IsPresent, Identity.IsPresent, IdentityUserDefined, KeySource, KeyProperties)); public PSNamespaceAttributes BeginUpdateNamespace(string resourceGroupName, string namespaceName, string location, string skuName, int?skuCapacity, Dictionary <string, string> tags, bool isAutoInflateEnabled, int?maximumThroughputUnits, bool isKafkaEnabled, bool isIdentity, string identityUserDefined, string keySource, List <string []> KeyProperties, bool isDisableLocalAuth, string[] identityId, string identityType, PSEncryptionConfigAttributes[] encryptionConfigs) { EHNamespace parameter = Client.Namespaces.Get(resourceGroupName, namespaceName); if (parameter.Identity != null && parameter.Encryption != null && KeyProperties != null) { parameter.Encryption = new Encryption(); parameter.Encryption.KeyVaultProperties = new List <KeyVaultProperties>(); } if (location != null) { parameter.Location = location; } if (tags != null) { parameter.Tags = new Dictionary <string, string>(tags); } if (skuName != null) { parameter.Sku = new Sku { Name = skuName, Tier = skuName }; } if (skuCapacity.HasValue) { parameter.Sku.Capacity = skuCapacity; } if (isAutoInflateEnabled) { parameter.IsAutoInflateEnabled = isAutoInflateEnabled; } if (maximumThroughputUnits.HasValue) { parameter.MaximumThroughputUnits = maximumThroughputUnits; } if (isKafkaEnabled) { parameter.KafkaEnabled = isKafkaEnabled; } if (isIdentity) { if (parameter.Identity == null) { parameter.Identity = new Identity() { Type = ManagedServiceIdentityType.SystemAssigned }; } else { if (parameter.Identity.Type == ManagedServiceIdentityType.None) { parameter.Identity = new Identity() { Type = ManagedServiceIdentityType.SystemAssigned }; } if (parameter.Identity.Type == ManagedServiceIdentityType.UserAssigned) { parameter.Identity = new Identity() { Type = ManagedServiceIdentityType.SystemAssignedUserAssigned }; } } } if (isDisableLocalAuth) { parameter.DisableLocalAuth = isDisableLocalAuth; } //IdentityUserDefined, KeySource, KeyProperties if (!String.IsNullOrEmpty(identityUserDefined) && identityUserDefined.ToLower() == "none") { parameter.Identity = new Identity() { Type = null }; } if (!String.IsNullOrEmpty(keySource)) { if (parameter.Encryption == null) { parameter.Encryption = new Encryption() { KeySource = KeySource.MicrosoftKeyVault }; } else { parameter.Encryption.KeySource = KeySource.MicrosoftKeyVault; } } if (KeyProperties != null) { parameter.Encryption.KeyVaultProperties = new List <KeyVaultProperties>(); if (KeyProperties.Count > 2) { if (KeyProperties[0].Length == 1) { KeyVaultProperties item = new KeyVaultProperties(); switch (KeyProperties.Count) { case 2: { item.KeyName = KeyProperties[0].ToString(); item.KeyVaultUri = KeyProperties[0].ToString(); break; } case 3: { item.KeyName = KeyProperties[0].GetValue(0).ToString(); item.KeyVaultUri = KeyProperties[1].GetValue(0).ToString(); item.KeyVersion = KeyProperties[2].GetValue(0).ToString(); break; } } parameter.Encryption.KeyVaultProperties.Add(item); } else { foreach (string[] item in KeyProperties) { KeyVaultProperties singleItem = new KeyVaultProperties(); switch (item.Length) { case 2: { singleItem.KeyName = item[0]; singleItem.KeyVaultUri = item[1]; break; } case 3: { singleItem.KeyName = item[0]; singleItem.KeyVaultUri = item[1]; singleItem.KeyVersion = item[2]; break; } } parameter.Encryption.KeyVaultProperties.Add(singleItem); } } } } if (identityType != null) { if (parameter.Identity == null) { parameter.Identity = new Identity(); } parameter.Identity.Type = FindIdentity(identityType); if (parameter.Identity.Type == ManagedServiceIdentityType.None || parameter.Identity.Type == ManagedServiceIdentityType.SystemAssigned) { parameter.Identity.UserAssignedIdentities = null; } } if (identityId != null) { Dictionary <string, UserAssignedIdentity> UserAssignedIdentities = new Dictionary <string, UserAssignedIdentity>(); UserAssignedIdentities = identityId.Where(id => id != null).ToDictionary(id => id, id => new UserAssignedIdentity()); if (parameter.Identity == null) { parameter.Identity = new Identity() { UserAssignedIdentities = UserAssignedIdentities }; } else { parameter.Identity.UserAssignedIdentities = UserAssignedIdentities; } if (parameter.Identity.Type == ManagedServiceIdentityType.None || parameter.Identity.Type == ManagedServiceIdentityType.SystemAssigned) { throw new Exception("Please change -IdentityType to UserAssigned or 'SystemAssigned, UserAssigned' if you want to add User Assigned Identities"); } } if (encryptionConfigs != null) { if (parameter.Encryption == null) { parameter.Encryption = new Encryption() { KeySource = KeySource.MicrosoftKeyVault }; } parameter.Encryption.KeyVaultProperties = new List <KeyVaultProperties>(); parameter.Encryption.KeyVaultProperties = encryptionConfigs.Where(x => x != null) .Select(x => { KeyVaultProperties kvp = new KeyVaultProperties(); if (x.KeyName == null || x.KeyVaultUri == null) { throw new Exception("KeyName and KeyVaultUri cannot be null"); } kvp.KeyName = x.KeyName; kvp.KeyVaultUri = x.KeyVaultUri; kvp.KeyVersion = x?.KeyVersion; if (x.UserAssignedIdentity != null) { kvp.Identity = new UserAssignedIdentityProperties(x.UserAssignedIdentity); } return(kvp); }) .ToList(); } var response = Client.Namespaces.CreateOrUpdate(resourceGroupName, namespaceName, parameter); return(new PSNamespaceAttributes(response)); }
public async Task NamespaceCreateGetUpdateDelete() { var location = GetLocation(); var resourceGroup = Recording.GenerateAssetName(Helper.ResourceGroupPrefix); await Helper.TryRegisterResourceGroupAsync(ResourceGroupsOperations, location.Result, resourceGroup); var namespaceName = Recording.GenerateAssetName(Helper.NamespacePrefix); var operationsResponse = Operations.ListAsync(); var checkNameAvailable = NamespacesOperations.CheckNameAvailabilityAsync(new CheckNameAvailabilityParameter(namespaceName)); var createNamespaceResponse = await NamespacesOperations.StartCreateOrUpdateAsync(resourceGroup, namespaceName, new EHNamespace() { Location = location.Result } ); var np = (await WaitForCompletionAsync(createNamespaceResponse)).Value; Assert.NotNull(createNamespaceResponse); Assert.AreEqual(np.Name, namespaceName); DelayInTest(60); //get the created namespace var getNamespaceResponse = await NamespacesOperations.GetAsync(resourceGroup, namespaceName); if (string.Compare(getNamespaceResponse.Value.ProvisioningState, "Succeeded", true) != 0) { DelayInTest(10); } getNamespaceResponse = await NamespacesOperations.GetAsync(resourceGroup, namespaceName); Assert.NotNull(getNamespaceResponse); Assert.AreEqual("Succeeded", getNamespaceResponse.Value.ProvisioningState, StringComparer.CurrentCultureIgnoreCase.ToString()); Assert.AreEqual(location.Result, getNamespaceResponse.Value.Location); // Get all namespaces created within a resourceGroup var getAllNamespacesResponse = NamespacesOperations.ListByResourceGroupAsync(resourceGroup); Assert.NotNull(getAllNamespacesResponse); //Assert.True(getAllNamespacesResponse.AsPages.c >= 1); bool isContainnamespaceName = false; bool isContainresourceGroup = false; var list = await getAllNamespacesResponse.ToEnumerableAsync(); foreach (var name in list) { if (name.Name == namespaceName) { isContainnamespaceName = true; } } foreach (var name in list) { if (name.Id.Contains(resourceGroup)) { isContainresourceGroup = true; break; } } Assert.True(isContainnamespaceName); Assert.True(isContainresourceGroup); // Get all namespaces created within the subscription irrespective of the resourceGroup var getAllNpResponse = NamespacesOperations.ListAsync(); Assert.NotNull(getAllNamespacesResponse); // Update namespace tags and make the namespace critical var updateNamespaceParameter = new EHNamespace() { Tags = new Dictionary <string, string>() { { "tag3", "value3" }, { "tag4", "value4" } } }; // Will uncomment the assertions once the service is deployed var updateNamespaceResponse = NamespacesOperations.UpdateAsync(resourceGroup, namespaceName, updateNamespaceParameter); Assert.NotNull(updateNamespaceResponse); // Get the updated namespace and also verify the Tags. getNamespaceResponse = await NamespacesOperations.GetAsync(resourceGroup, namespaceName); DelayInTest(15); Assert.NotNull(getNamespaceResponse); Assert.AreEqual(location.Result, getNamespaceResponse.Value.Location); Assert.AreEqual(namespaceName, getNamespaceResponse.Value.Name); Assert.AreEqual(2, getNamespaceResponse.Value.Tags.Count); bool IsContainKey = false; bool IsContainValue = false; foreach (var tag in updateNamespaceParameter.Tags) { foreach (var t in getNamespaceResponse.Value.Tags) { if (t.Key == tag.Key) { IsContainKey = true; break; } } foreach (var t in getNamespaceResponse.Value.Tags) { if (t.Value == tag.Value) { IsContainValue = true; break; } } } Assert.True(IsContainKey); Assert.True(IsContainValue); //delete namespace await WaitForCompletionAsync(await NamespacesOperations.StartDeleteAsync(resourceGroup, namespaceName)); }
public async Task NamespaceKafkaCreateGetUpdateDelete() { var location = "West US"; var resourceGroupName = Recording.GenerateAssetName(Helper.ResourceGroupPrefix); await ArmClient.DefaultSubscription.GetResourceGroups().CreateOrUpdateAsync(resourceGroupName, new ResourceGroupData(location)); var namespaceName = Recording.GenerateAssetName(Helper.NamespacePrefix); var createNamespaceResponse = await NamespacesOperations.StartCreateOrUpdateAsync(resourceGroupName, namespaceName, new EHNamespace() { Location = location, Tags = { { "tag1", "value1" }, { "tag2", "value2" } }, IsAutoInflateEnabled = true, MaximumThroughputUnits = 10, KafkaEnabled = true } ); var np = (await WaitForCompletionAsync(createNamespaceResponse)).Value; Assert.NotNull(createNamespaceResponse); Assert.AreEqual(np.Name, namespaceName); Assert.True(np.KafkaEnabled, "KafkaEnabled is false"); DelayInTest(5); //get the created namespace var getNamespaceResponse = await NamespacesOperations.GetAsync(resourceGroupName, namespaceName); if (string.Compare(getNamespaceResponse.Value.ProvisioningState, "Succeeded", true) != 0) { DelayInTest(5); } getNamespaceResponse = await NamespacesOperations.GetAsync(resourceGroupName, namespaceName); Assert.NotNull(getNamespaceResponse); Assert.AreEqual("Succeeded", getNamespaceResponse.Value.ProvisioningState, StringComparer.CurrentCultureIgnoreCase.ToString()); Assert.AreEqual(location, getNamespaceResponse.Value.Location); // Get all namespaces created within a resourceGroupName var getAllNamespacesResponse = NamespacesOperations.ListByResourceGroupAsync(resourceGroupName); Assert.NotNull(getAllNamespacesResponse); //Assert.True(getAllNamespacesResponse.AsPages.c >= 1); var getAllNamespRespList = await getAllNamespacesResponse.ToEnumerableAsync(); bool isContainnamespaceName = false; bool isContainresourceGroup = false; foreach (var name in getAllNamespRespList) { if (name.Name == namespaceName) { isContainnamespaceName = true; break; } } foreach (var name in getAllNamespRespList) { if (name.Id.Contains(resourceGroupName)) { isContainresourceGroup = true; break; } } Assert.True(isContainnamespaceName); Assert.True(isContainresourceGroup); // Get all namespaces created within the subscription irrespective of the resourceGroupName getAllNamespacesResponse = NamespacesOperations.ListAsync(); Assert.NotNull(getAllNamespacesResponse); bool isContainNamespacename = false; getAllNamespRespList = await getAllNamespacesResponse.ToEnumerableAsync(); foreach (var getNameSpResp in getAllNamespRespList) { if (getNameSpResp.Name == namespaceName) { isContainNamespacename = true; break; } } Assert.IsTrue(isContainNamespacename); // Update namespace tags and make the namespace critical var updateNamespaceParameter = new EHNamespace() { Tags = { { "tag3", "value3" }, { "tag4", "value4" } } }; // Will uncomment the assertions once the service is deployed var updateNamespaceResponse = await NamespacesOperations.UpdateAsync(resourceGroupName, namespaceName, updateNamespaceParameter); Assert.NotNull(updateNamespaceResponse); Assert.True(updateNamespaceResponse.Value.ProvisioningState.Equals("Active", StringComparison.CurrentCultureIgnoreCase) || updateNamespaceResponse.Value.ProvisioningState.Equals("Updating", StringComparison.CurrentCultureIgnoreCase)); Assert.AreEqual(namespaceName, updateNamespaceResponse.Value.Name); // Get the updated namespace and also verify the Tags. getNamespaceResponse = await NamespacesOperations.GetAsync(resourceGroupName, namespaceName); Assert.NotNull(getNamespaceResponse); Assert.AreEqual(location, getNamespaceResponse.Value.Location); Assert.AreEqual(namespaceName, getNamespaceResponse.Value.Name); Assert.AreEqual(2, getNamespaceResponse.Value.Tags.Count); bool isContainKey = false; bool isContainValue = false; foreach (var tag in updateNamespaceParameter.Tags) { foreach (var key in getNamespaceResponse.Value.Tags) { if (key.Key == tag.Key) { isContainKey = true; break; } } foreach (var value in getNamespaceResponse.Value.Tags) { if (value.Value == tag.Value) { isContainValue = true; break; } } //Assert.Contains(getNamespaceResponse.Value.Tags, t => t.Key.Equals(tag.Key)); //Assert.Contains(getNamespaceResponse.Value.Tags, t => t.Value.Equals(tag.Value)); } Assert.True(isContainKey); Assert.True(isContainValue); DelayInTest(5); // Delete namespace await WaitForCompletionAsync(await NamespacesOperations.StartDeleteAsync(resourceGroupName, namespaceName)); }
public PSNamespaceAttributes BeginCreateNamespace(string resourceGroupName, string namespaceName, string location, string skuName, int?skuCapacity, Dictionary <string, string> tags, bool isAutoInflateEnabled, int?maximumThroughputUnits, bool isKafkaEnabled, string clusterARMId, bool isZoneRedundant, bool isIdentity) { EHNamespace parameter = new EHNamespace(); parameter.Location = location; if (tags != null) { parameter.Tags = new Dictionary <string, string>(tags); } if (skuName != null) { parameter.Sku = new Sku { Name = skuName, Tier = skuName }; } if (clusterARMId != null) { parameter.ClusterArmId = clusterARMId; } if (skuCapacity.HasValue) { parameter.Sku.Capacity = skuCapacity; } if (isAutoInflateEnabled) { parameter.IsAutoInflateEnabled = isAutoInflateEnabled; } if (maximumThroughputUnits.HasValue) { parameter.MaximumThroughputUnits = maximumThroughputUnits; } if (isKafkaEnabled) { parameter.KafkaEnabled = isKafkaEnabled; } if (isZoneRedundant) { parameter.ZoneRedundant = isZoneRedundant; } if (isIdentity) { parameter.Identity = new Identity() { Type = IdentityType.SystemAssigned } } ; var response = Client.Namespaces.CreateOrUpdate(resourceGroupName, namespaceName, parameter); return(new PSNamespaceAttributes(response)); }
// Update Namespace (ResourceGroupName, Name, Location, SkuName, SkuCapacity, tagDictionary, EnableAutoInflate.IsPresent, MaximumThroughputUnits, EnableKafka.IsPresent, ZoneRedundant.IsPresent, Identity.IsPresent, IdentityUserDefined, KeySource, KeyProperties)); public PSNamespaceAttributes BeginUpdateNamespace(string resourceGroupName, string namespaceName, string location, string skuName, int?skuCapacity, Dictionary <string, string> tags, bool isAutoInflateEnabled, int?maximumThroughputUnits, bool isKafkaEnabled, bool isIdentity, string identityUserDefined, string keySource, List <string []> KeyProperties) { EHNamespace parameter = Client.Namespaces.Get(resourceGroupName, namespaceName); if (parameter.Identity != null && parameter.Encryption == null) { parameter.Encryption = new Encryption(); parameter.Encryption.KeyVaultProperties = new List <KeyVaultProperties>(); } parameter.Location = location; if (tags != null) { parameter.Tags = new Dictionary <string, string>(tags); } if (skuName != null) { parameter.Sku = new Sku { Name = skuName, Tier = skuName }; } if (skuCapacity.HasValue) { parameter.Sku.Capacity = skuCapacity; } if (isAutoInflateEnabled) { parameter.IsAutoInflateEnabled = isAutoInflateEnabled; } if (maximumThroughputUnits.HasValue) { parameter.MaximumThroughputUnits = maximumThroughputUnits; } if (isKafkaEnabled) { parameter.KafkaEnabled = isKafkaEnabled; } if (isIdentity) { parameter.Identity = new Identity() { Type = IdentityType.SystemAssigned } } ; //IdentityUserDefined, KeySource, KeyProperties if (!String.IsNullOrEmpty(identityUserDefined) && identityUserDefined.ToLower() == "none") { parameter.Identity = new Identity() { Type = null }; } if (!String.IsNullOrEmpty(keySource)) { if (parameter.Encryption == null) { parameter.Encryption = new Encryption() { KeySource = KeySource.MicrosoftKeyVault }; } else { parameter.Encryption.KeySource = KeySource.MicrosoftKeyVault; } } if (KeyProperties != null) { parameter.Encryption.KeyVaultProperties = new List <KeyVaultProperties>(); if (KeyProperties.Count > 2) { if (KeyProperties[0].Length == 1) { KeyVaultProperties item = new KeyVaultProperties(); switch (KeyProperties.Count) { case 2: { item.KeyName = KeyProperties[0].ToString(); item.KeyVaultUri = KeyProperties[0].ToString(); break; } case 3: { item.KeyName = KeyProperties[0].GetValue(0).ToString(); item.KeyVaultUri = KeyProperties[1].GetValue(0).ToString(); item.KeyVersion = KeyProperties[2].GetValue(0).ToString(); break; } } parameter.Encryption.KeyVaultProperties.Add(item); } else { foreach (string[] item in KeyProperties) { KeyVaultProperties singleItem = new KeyVaultProperties(); switch (item.Length) { case 2: { singleItem.KeyName = item[0]; singleItem.KeyVaultUri = item[1]; break; } case 3: { singleItem.KeyName = item[0]; singleItem.KeyVaultUri = item[1]; singleItem.KeyVersion = item[2]; break; } } parameter.Encryption.KeyVaultProperties.Add(singleItem); } } } } var response = Client.Namespaces.CreateOrUpdate(resourceGroupName, namespaceName, parameter); return(new PSNamespaceAttributes(response)); }
public PSNamespaceAttributes(EHNamespace evResource) { if (evResource != null) { Sku = new Sku { Capacity = evResource.Sku.Capacity, Name = evResource.Sku.Name, Tier = evResource.Sku.Tier }; if (evResource.ProvisioningState != null) { ProvisioningState = evResource.ProvisioningState; } if (evResource.CreatedAt.HasValue) { CreatedAt = evResource.CreatedAt; } if (evResource.UpdatedAt.HasValue) { UpdatedAt = evResource.UpdatedAt; } if (evResource.ServiceBusEndpoint != null) { ServiceBusEndpoint = evResource.ServiceBusEndpoint; } if (evResource.Location != null) { Location = evResource.Location; } if (evResource.Id != null) { Id = evResource.Id; } if (evResource.Name != null) { Name = evResource.Name; } if (evResource.IsAutoInflateEnabled.HasValue) { IsAutoInflateEnabled = evResource.IsAutoInflateEnabled; } if (evResource.MaximumThroughputUnits.HasValue) { MaximumThroughputUnits = evResource.MaximumThroughputUnits; } if (evResource.KafkaEnabled.HasValue) { KafkaEnabled = evResource.KafkaEnabled; } if (evResource.Tags.Count > 0) { Tags = new Dictionary <string, string>(evResource.Tags); } ResourceGroup = Regex.Split(evResource.Id, @"/")[4]; ResourceGroupName = Regex.Split(evResource.Id, @"/")[4]; Identity = new PSIdentityAttributes(evResource.Identity); ZoneRedundant = evResource.ZoneRedundant; ClusterArmId = evResource.ClusterArmId; Encryption = new PSEncryptionAttributes(evResource.Encryption); } }
/// <summary> /// Creates or updates a namespace. Once created, this namespace's resource /// manifest is immutable. This operation is idempotent. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// Name of the resource group within the azure subscription. /// </param> /// <param name='namespaceName'> /// The Namespace name /// </param> /// <param name='parameters'> /// Parameters for creating a namespace resource. /// </param> public static EHNamespace BeginCreateOrUpdate(this INamespacesOperations operations, string resourceGroupName, string namespaceName, EHNamespace parameters) { return(operations.BeginCreateOrUpdateAsync(resourceGroupName, namespaceName, parameters).GetAwaiter().GetResult()); }
/// <summary> /// Creates or updates a namespace. Once created, this namespace's resource /// manifest is immutable. This operation is idempotent. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// Name of the resource group within the azure subscription. /// </param> /// <param name='namespaceName'> /// The Namespace name /// </param> /// <param name='parameters'> /// Parameters for creating a namespace resource. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <EHNamespace> BeginCreateOrUpdateAsync(this INamespacesOperations operations, string resourceGroupName, string namespaceName, EHNamespace parameters, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.BeginCreateOrUpdateWithHttpMessagesAsync(resourceGroupName, namespaceName, parameters, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
public void NamespaceCreateGetUpdateDelete() { using (MockContext context = MockContext.Start(this.GetType().FullName)) { InitializeClients(context); var location = this.ResourceManagementClient.GetLocationFromProvider(); var resourceGroup = this.ResourceManagementClient.TryGetResourceGroup(location); if (string.IsNullOrWhiteSpace(resourceGroup)) { resourceGroup = TestUtilities.GenerateName(EventHubManagementHelper.ResourceGroupPrefix); this.ResourceManagementClient.TryRegisterResourceGroup(location, resourceGroup); } var namespaceName = TestUtilities.GenerateName(EventHubManagementHelper.NamespacePrefix); var operationsResponse = EventHubManagementClient.Operations.List(); var checkNameAvailable = EventHubManagementClient.Namespaces.CheckNameAvailability(new CheckNameAvailabilityParameter() { Name = namespaceName }); var createNamespaceResponse = this.EventHubManagementClient.Namespaces.CreateOrUpdate(resourceGroup, namespaceName, new EHNamespace() { Location = location, Sku = new Sku { Name = SkuName.Standard, Tier = SkuTier.Standard }, Tags = new Dictionary <string, string>() { { "tag1", "value1" }, { "tag2", "value2" } }, IsAutoInflateEnabled = true, MaximumThroughputUnits = 10 }); Assert.NotNull(createNamespaceResponse); Assert.Equal(createNamespaceResponse.Name, namespaceName); TestUtilities.Wait(TimeSpan.FromSeconds(5)); // Get the created namespace var getNamespaceResponse = EventHubManagementClient.Namespaces.Get(resourceGroup, namespaceName); if (string.Compare(getNamespaceResponse.ProvisioningState, "Succeeded", true) != 0) { TestUtilities.Wait(TimeSpan.FromSeconds(5)); } getNamespaceResponse = EventHubManagementClient.Namespaces.Get(resourceGroup, namespaceName); Assert.NotNull(getNamespaceResponse); Assert.Equal("Succeeded", getNamespaceResponse.ProvisioningState, StringComparer.CurrentCultureIgnoreCase); Assert.Equal(location, getNamespaceResponse.Location, StringComparer.CurrentCultureIgnoreCase); // Get all namespaces created within a resourceGroup var getAllNamespacesResponse = EventHubManagementClient.Namespaces.ListByResourceGroupAsync(resourceGroup).Result; Assert.NotNull(getAllNamespacesResponse); Assert.True(getAllNamespacesResponse.Count() >= 1); Assert.Contains(getAllNamespacesResponse, ns => ns.Name == namespaceName); Assert.Contains(getAllNamespacesResponse, ns => ns.Id.Contains(resourceGroup)); // Get all namespaces created within the subscription irrespective of the resourceGroup getAllNamespacesResponse = EventHubManagementClient.Namespaces.List(); Assert.NotNull(getAllNamespacesResponse); Assert.True(getAllNamespacesResponse.Count() >= 1); Assert.Contains(getAllNamespacesResponse, ns => ns.Name == namespaceName); // Update namespace tags and make the namespace critical var updateNamespaceParameter = new EHNamespace() { Tags = new Dictionary <string, string>() { { "tag3", "value3" }, { "tag4", "value4" } } }; // Will uncomment the assertions once the service is deployed var updateNamespaceResponse = EventHubManagementClient.Namespaces.Update(resourceGroup, namespaceName, updateNamespaceParameter); Assert.NotNull(updateNamespaceResponse); Assert.Equal(namespaceName, updateNamespaceResponse.Name); // Get the updated namespace and also verify the Tags. getNamespaceResponse = EventHubManagementClient.Namespaces.Get(resourceGroup, namespaceName); Assert.NotNull(getNamespaceResponse); Assert.Equal(location, getNamespaceResponse.Location, StringComparer.CurrentCultureIgnoreCase); Assert.Equal(namespaceName, getNamespaceResponse.Name); Assert.Equal(2, getNamespaceResponse.Tags.Count); foreach (var tag in updateNamespaceParameter.Tags) { Assert.Contains(getNamespaceResponse.Tags, t => t.Key.Equals(tag.Key)); Assert.Contains(getNamespaceResponse.Tags, t => t.Value.Equals(tag.Value)); } TestUtilities.Wait(TimeSpan.FromSeconds(10)); // Delete namespace EventHubManagementClient.Namespaces.Delete(resourceGroup, namespaceName); } }
public PSNamespaceAttributes(EHNamespace evResource) { if (evResource != null) { Sku = new Sku { Capacity = evResource.Sku.Capacity, Name = evResource.Sku.Name, Tier = evResource.Sku.Tier }; if (evResource.ProvisioningState != null) { ProvisioningState = evResource.ProvisioningState; } if (evResource.CreatedAt.HasValue) { CreatedAt = evResource.CreatedAt; } if (evResource.UpdatedAt.HasValue) { UpdatedAt = evResource.UpdatedAt; } if (evResource.ServiceBusEndpoint != null) { ServiceBusEndpoint = evResource.ServiceBusEndpoint; } if (evResource.Location != null) { Location = evResource.Location; } if (evResource.Id != null) { Id = evResource.Id; } if (evResource.Name != null) { Name = evResource.Name; } if (evResource.IsAutoInflateEnabled.HasValue) { IsAutoInflateEnabled = evResource.IsAutoInflateEnabled; } if (evResource.MaximumThroughputUnits.HasValue) { MaximumThroughputUnits = evResource.MaximumThroughputUnits; } if (evResource.KafkaEnabled.HasValue) { KafkaEnabled = evResource.KafkaEnabled; } if (evResource.Tags.Count > 0) { Tags = new Dictionary <string, string>(evResource.Tags); } if (evResource.Identity != null) { Identity = new PSIdentityAttributes(evResource.Identity); IdentityType = evResource.Identity.Type.ToString(); if (evResource.Identity.UserAssignedIdentities != null) { IdentityId = evResource.Identity.UserAssignedIdentities.Keys.ToArray(); } } if (evResource.Encryption != null) { if (evResource.Encryption.KeyVaultProperties != null) { EncryptionConfig = evResource.Encryption.KeyVaultProperties.Where(x => x != null).Select(x => { PSEncryptionConfigAttributes kvproperty = new PSEncryptionConfigAttributes(x); return(kvproperty); }).ToArray(); } } ResourceGroup = Regex.Split(evResource.Id, @"/")[4]; ResourceGroupName = Regex.Split(evResource.Id, @"/")[4]; ZoneRedundant = evResource.ZoneRedundant; DisableLocalAuth = evResource.DisableLocalAuth; ClusterArmId = evResource.ClusterArmId; Encryption = new PSEncryptionAttributes(evResource.Encryption); } }
public void NamespaceCreateGetUpdateDelete() { using (MockContext context = MockContext.Start(this.GetType())) { InitializeClients(context); var location = this.ResourceManagementClient.GetLocationFromProvider(); var resourceGroup = string.Empty; if (string.IsNullOrWhiteSpace(resourceGroup)) { resourceGroup = TestUtilities.GenerateName(EventHubManagementHelper.ResourceGroupPrefix); this.ResourceManagementClient.TryRegisterResourceGroup(location, resourceGroup); } var namespaceName = TestUtilities.GenerateName(EventHubManagementHelper.NamespacePrefix); try { var operationsResponse = EventHubManagementClient.Operations.List(); var checkNameAvailable = EventHubManagementClient.Namespaces.CheckNameAvailability(namespaceName); var createNamespaceResponse = this.EventHubManagementClient.Namespaces.CreateOrUpdate(resourceGroup, namespaceName, new EHNamespace() { Location = location, Sku = new Sku { Name = SkuName.Standard, Tier = SkuTier.Standard, Capacity = 1 }, Tags = new Dictionary <string, string>() { { "tag1", "value1" }, { "tag2", "value2" } }, IsAutoInflateEnabled = true, MaximumThroughputUnits = 10, }); Assert.NotNull(createNamespaceResponse); Assert.Equal(createNamespaceResponse.Name, namespaceName); Assert.Equal(SkuName.Standard, createNamespaceResponse.Sku.Name); Assert.Equal(SkuName.Standard, createNamespaceResponse.Sku.Tier); Assert.Equal(1, createNamespaceResponse.Sku.Capacity); Assert.Equal(new Dictionary <string, string>() { { "tag1", "value1" }, { "tag2", "value2" } }, createNamespaceResponse.Tags); Assert.True(createNamespaceResponse.IsAutoInflateEnabled); Assert.Equal(10, createNamespaceResponse.MaximumThroughputUnits); Assert.Equal("Enabled", createNamespaceResponse.PublicNetworkAccess); createNamespaceResponse.PublicNetworkAccess = "Disabled"; createNamespaceResponse = EventHubManagementClient.Namespaces.CreateOrUpdate(resourceGroup, namespaceName, createNamespaceResponse); Assert.NotNull(createNamespaceResponse); Assert.Equal(createNamespaceResponse.Name, namespaceName); Assert.Equal(SkuName.Standard, createNamespaceResponse.Sku.Name); Assert.Equal(SkuName.Standard, createNamespaceResponse.Sku.Tier); Assert.Equal(1, createNamespaceResponse.Sku.Capacity); Assert.Equal(new Dictionary <string, string>() { { "tag1", "value1" }, { "tag2", "value2" } }, createNamespaceResponse.Tags); Assert.True(createNamespaceResponse.IsAutoInflateEnabled); Assert.Equal(10, createNamespaceResponse.MaximumThroughputUnits); Assert.Equal("Disabled", createNamespaceResponse.PublicNetworkAccess); var getNamespaceResponse = EventHubManagementClient.Namespaces.Get(resourceGroup, namespaceName); Assert.NotNull(getNamespaceResponse); Assert.Equal("Succeeded", getNamespaceResponse.ProvisioningState, StringComparer.CurrentCultureIgnoreCase); Assert.Equal(location, getNamespaceResponse.Location, StringComparer.CurrentCultureIgnoreCase); // Get all namespaces created within a resourceGroup var getAllNamespacesResponse = EventHubManagementClient.Namespaces.ListByResourceGroupAsync(resourceGroup).Result; Assert.NotNull(getAllNamespacesResponse); Assert.True(getAllNamespacesResponse.Count() == 1); Assert.Contains(getAllNamespacesResponse, ns => ns.Name == namespaceName); Assert.Contains(getAllNamespacesResponse, ns => ns.Id.Contains(resourceGroup)); // Get all namespaces created within the subscription irrespective of the resourceGroup getAllNamespacesResponse = EventHubManagementClient.Namespaces.List(); Assert.NotNull(getAllNamespacesResponse); Assert.True(getAllNamespacesResponse.Count() >= 1); // Update namespace tags and make the namespace critical var updateNamespaceParameter = new EHNamespace() { Tags = new Dictionary <string, string>() { { "tag3", "value3" }, { "tag4", "value4" } } }; var updateNamespaceResponse = EventHubManagementClient.Namespaces.Update(resourceGroup, namespaceName, updateNamespaceParameter); Assert.NotNull(updateNamespaceResponse); Assert.Equal(updateNamespaceResponse.Name, namespaceName); Assert.Equal(SkuName.Standard, updateNamespaceResponse.Sku.Name); Assert.Equal(new Dictionary <string, string>() { { "tag3", "value3" }, { "tag4", "value4" } }, updateNamespaceResponse.Tags); Assert.True(updateNamespaceResponse.IsAutoInflateEnabled); Assert.Equal(10, updateNamespaceResponse.MaximumThroughputUnits); // Will uncomment the assertions once the service is deployed TestUtilities.Wait(10000); updateNamespaceResponse.DisableLocalAuth = true; updateNamespaceResponse = EventHubManagementClient.Namespaces.CreateOrUpdate(resourceGroup, namespaceName, updateNamespaceResponse); Assert.NotNull(updateNamespaceResponse); Assert.Equal(updateNamespaceResponse.Name, namespaceName); Assert.Equal(SkuName.Standard, updateNamespaceResponse.Sku.Name); Assert.Equal(new Dictionary <string, string>() { { "tag3", "value3" }, { "tag4", "value4" } }, updateNamespaceResponse.Tags); Assert.True(updateNamespaceResponse.IsAutoInflateEnabled); Assert.Equal(10, updateNamespaceResponse.MaximumThroughputUnits); Assert.True(updateNamespaceResponse.DisableLocalAuth); updateNamespaceResponse.DisableLocalAuth = false; updateNamespaceResponse = EventHubManagementClient.Namespaces.CreateOrUpdate(resourceGroup, namespaceName, updateNamespaceResponse); Assert.NotNull(updateNamespaceResponse); Assert.Equal(updateNamespaceResponse.Name, namespaceName); Assert.Equal(SkuName.Standard, updateNamespaceResponse.Sku.Name); Assert.Equal(new Dictionary <string, string>() { { "tag3", "value3" }, { "tag4", "value4" } }, updateNamespaceResponse.Tags); Assert.True(updateNamespaceResponse.IsAutoInflateEnabled); Assert.Equal(10, updateNamespaceResponse.MaximumThroughputUnits); Assert.False(updateNamespaceResponse.DisableLocalAuth); // Will uncomment the assertions once the service is deployed TestUtilities.Wait(10000); // Get the updated namespace and also verify the Tags. getNamespaceResponse = EventHubManagementClient.Namespaces.Get(resourceGroup, namespaceName); Assert.NotNull(getNamespaceResponse); Assert.Equal(location, getNamespaceResponse.Location, StringComparer.CurrentCultureIgnoreCase); Assert.Equal(namespaceName, getNamespaceResponse.Name); Assert.Equal(2, getNamespaceResponse.Tags.Count); foreach (var tag in updateNamespaceParameter.Tags) { Assert.Contains(getNamespaceResponse.Tags, t => t.Key.Equals(tag.Key)); Assert.Contains(getNamespaceResponse.Tags, t => t.Value.Equals(tag.Value)); } // Delete namespace EventHubManagementClient.Namespaces.Delete(resourceGroup, namespaceName); } finally { //Delete Resource Group this.ResourceManagementClient.ResourceGroups.DeleteWithHttpMessagesAsync(resourceGroup, null, default(CancellationToken)).ConfigureAwait(false); Console.WriteLine("End of EH2018 Namespace CRUD IPFilter Rules test"); } } }
public void NamespaceKafkaCreateGetUpdateDelete() { using (MockContext context = MockContext.Start(this.GetType())) { InitializeClients(context); var location = "West US"; // Kafka is enabled in few regions and West US is one the region so hardcodded, will remove the KAfka is available in all regions. var resourceGroup = string.Empty; if (string.IsNullOrWhiteSpace(resourceGroup)) { resourceGroup = TestUtilities.GenerateName(EventHubManagementHelper.ResourceGroupPrefix); this.ResourceManagementClient.TryRegisterResourceGroup(location, resourceGroup); } var namespaceName = TestUtilities.GenerateName(EventHubManagementHelper.NamespacePrefix); try { var operationsResponse = EventHubManagementClient.Operations.List(); var checkNameAvailable = EventHubManagementClient.Namespaces.CheckNameAvailability(new CheckNameAvailabilityParameter() { Name = namespaceName }); var createNamespaceResponse = this.EventHubManagementClient.Namespaces.CreateOrUpdate(resourceGroup, namespaceName, new EHNamespace() { Location = location, Sku = new Sku { Name = SkuName.Standard, Tier = SkuTier.Standard }, Tags = new Dictionary <string, string>() { { "tag1", "value1" }, { "tag2", "value2" } }, IsAutoInflateEnabled = true, MaximumThroughputUnits = 10, KafkaEnabled = true }); Assert.NotNull(createNamespaceResponse); Assert.Equal(createNamespaceResponse.Name, namespaceName); Assert.True(createNamespaceResponse.KafkaEnabled, "KafkaEnabled is false"); TestUtilities.Wait(TimeSpan.FromSeconds(5)); // Get the created namespace var getNamespaceResponse = EventHubManagementClient.Namespaces.Get(resourceGroup, namespaceName); if (string.Compare(getNamespaceResponse.ProvisioningState, "Succeeded", true) != 0) { TestUtilities.Wait(TimeSpan.FromSeconds(5)); } getNamespaceResponse = EventHubManagementClient.Namespaces.Get(resourceGroup, namespaceName); Assert.NotNull(getNamespaceResponse); Assert.Equal("Succeeded", getNamespaceResponse.ProvisioningState, StringComparer.CurrentCultureIgnoreCase); Assert.Equal(location, getNamespaceResponse.Location, StringComparer.CurrentCultureIgnoreCase); // Get all namespaces created within a resourceGroup var getAllNamespacesResponse = EventHubManagementClient.Namespaces.ListByResourceGroupAsync(resourceGroup).Result; Assert.NotNull(getAllNamespacesResponse); Assert.True(getAllNamespacesResponse.Count() >= 1); Assert.Contains(getAllNamespacesResponse, ns => ns.Name == namespaceName); Assert.Contains(getAllNamespacesResponse, ns => ns.Id.Contains(resourceGroup)); // Get all namespaces created within the subscription irrespective of the resourceGroup getAllNamespacesResponse = EventHubManagementClient.Namespaces.List(); Assert.NotNull(getAllNamespacesResponse); Assert.True(getAllNamespacesResponse.Count() >= 1); Assert.Contains(getAllNamespacesResponse, ns => ns.Name == namespaceName); // Update namespace tags and make the namespace critical var updateNamespaceParameter = new EHNamespace() { Tags = new Dictionary <string, string>() { { "tag3", "value3" }, { "tag4", "value4" } } }; // Will uncomment the assertions once the service is deployed var updateNamespaceResponse = EventHubManagementClient.Namespaces.Update(resourceGroup, namespaceName, updateNamespaceParameter); Assert.NotNull(updateNamespaceResponse); Assert.True(updateNamespaceResponse.ProvisioningState.Equals("Active", StringComparison.CurrentCultureIgnoreCase) || updateNamespaceResponse.ProvisioningState.Equals("Updating", StringComparison.CurrentCultureIgnoreCase)); Assert.Equal(namespaceName, updateNamespaceResponse.Name); // Get the updated namespace and also verify the Tags. getNamespaceResponse = EventHubManagementClient.Namespaces.Get(resourceGroup, namespaceName); Assert.NotNull(getNamespaceResponse); Assert.Equal(location, getNamespaceResponse.Location, StringComparer.CurrentCultureIgnoreCase); Assert.Equal(namespaceName, getNamespaceResponse.Name); Assert.Equal(2, getNamespaceResponse.Tags.Count); foreach (var tag in updateNamespaceParameter.Tags) { Assert.Contains(getNamespaceResponse.Tags, t => t.Key.Equals(tag.Key)); Assert.Contains(getNamespaceResponse.Tags, t => t.Value.Equals(tag.Value)); } TestUtilities.Wait(TimeSpan.FromSeconds(10)); // Delete namespace EventHubManagementClient.Namespaces.Delete(resourceGroup, namespaceName); } finally { //Delete Resource Group this.ResourceManagementClient.ResourceGroups.DeleteWithHttpMessagesAsync(resourceGroup, null, default(CancellationToken)).ConfigureAwait(false); Console.WriteLine("End of EH2018 Namespace CRUD IPFilter Rules test"); } } }
public NamespaceAttributes(EHNamespace evResource) { if (evResource != null) { Sku = new Sku { Capacity = evResource.Sku.Capacity, Name = evResource.Sku.Name, Tier = evResource.Sku.Tier }; if (evResource.ProvisioningState != null) { ProvisioningState = evResource.ProvisioningState; } #pragma warning disable 612, 618 Status = Microsoft.Azure.Commands.EventHub.Models.NamespaceState.Active; #pragma warning restore 612, 618 if (evResource.CreatedAt.HasValue) { CreatedAt = evResource.CreatedAt; } if (evResource.UpdatedAt.HasValue) { UpdatedAt = evResource.UpdatedAt; } if (evResource.ServiceBusEndpoint != null) { ServiceBusEndpoint = evResource.ServiceBusEndpoint; } #pragma warning disable 612, 618 Enabled = true; #pragma warning restore 612,618 if (evResource.Location != null) { Location = evResource.Location; } if (evResource.Id != null) { Id = evResource.Id; } if (evResource.Name != null) { Name = evResource.Name; } if (evResource.IsAutoInflateEnabled.HasValue) { IsAutoInflateEnabled = evResource.IsAutoInflateEnabled; } if (evResource.MaximumThroughputUnits.HasValue) { MaximumThroughputUnits = evResource.MaximumThroughputUnits; } ResourceGroup = Regex.Split(evResource.Id, @"/")[4]; } }