public NamespaceAttributes BeginCreateNamespace(string resourceGroupName, string namespaceName, string location, string skuName, int?skuCapacity, Dictionary <string, string> tags) { NamespaceCreateOrUpdateParameters parameter = new NamespaceCreateOrUpdateParameters(); 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; } var response = Client.Namespaces.CreateOrUpdate(resourceGroupName, namespaceName, parameter); return(new NamespaceAttributes(response)); }
public NamespaceAttributes UpdateNamespace(string resourceGroupName, string namespaceName, string location, string skuName, int?skuCapacity, Dictionary <string, string> tags) { var parameter = new NamespaceCreateOrUpdateParameters() { Location = location }; if (tags != null) { parameter.Tags = new Dictionary <string, string>(tags); } Sku tempSku = new Sku(); if (skuName != null) { tempSku.Name = skuName; tempSku.Tier = skuName; } if (skuCapacity != null) { tempSku.Capacity = skuCapacity; } parameter.Sku = tempSku; NamespaceResource response = Client.Namespaces.CreateOrUpdate(resourceGroupName, namespaceName, parameter); return(new NamespaceAttributes(response)); }
public NamespaceAttributes UpdateNamespace(string resourceGroupName, string namespaceName, string location, NamespaceState state, bool critical, Dictionary <string, string> tags) { var parameter = new NamespaceCreateOrUpdateParameters() { Location = location, Properties = new NamespaceProperties() { NamespaceType = NamespaceType.NotificationHub, Status = ((state == NamespaceState.Disabled) ? state : NamespaceState.Active).ToString(), Enabled = (state == NamespaceState.Disabled) ? false : true } }; if (critical) { parameter.Properties.Critical = critical; } if (tags != null && tags.Count() > 0) { parameter.Tags = new Dictionary <string, string>(tags); } var response = Client.Namespaces.CreateOrUpdate(resourceGroupName, namespaceName, parameter); return(new NamespaceAttributes(resourceGroupName, response.Value)); }
public static void TryCreateNamespace( this NotificationHubsManagementClient client, string resourceGroupName, string namespaceName, string location, string scaleUnit = null) { var namespaceParameter = new NamespaceCreateOrUpdateParameters() { Location = location, Properties = new NamespaceProperties { NamespaceType = NamespaceType.NotificationHub } }; if (!string.IsNullOrEmpty(scaleUnit)) { namespaceParameter.Properties.ScaleUnit = scaleUnit; } client.Namespaces.CreateOrUpdate( resourceGroupName, namespaceName, namespaceParameter ); var response = client.Namespaces.Get(resourceGroupName, namespaceName); ThrowIfTrue(!response.Value.Name.Equals(namespaceName), string.Format("Namespace name is not equal to {0}", namespaceName)); }
public NamespaceAttributes UpdateNamespace(string resourceGroupName, string namespaceName, string location, string skuName, int?skuCapacity, Management.EventHub.Models.NamespaceState?state, Dictionary <string, string> tags) { var parameter = new NamespaceCreateOrUpdateParameters() { Location = location }; if (state.HasValue) { parameter.Status = state; } if (skuName != null) { parameter.Sku.Name = skuName; parameter.Sku.Tier = skuName; } if (skuCapacity.HasValue) { parameter.Sku.Capacity = skuCapacity; } if (tags != null && tags.Count() > 0) { parameter.Tags = new Dictionary <string, string>(tags); } var response = Client.Namespaces.CreateOrUpdate(resourceGroupName, namespaceName, parameter); return(new NamespaceAttributes(response)); }
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 NamespaceCreateOrUpdateParameters() { 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; } }
public NamespaceAttributes CreateNamespace(string resourceGroupName, string namespaceName, string location, Dictionary <string, string> tags) { var parameter = new NamespaceCreateOrUpdateParameters() { Location = location }; if (tags != null) { parameter.Tags = new Dictionary <string, string>(tags); } var response = Client.Namespaces.CreateOrUpdate(resourceGroupName, namespaceName, parameter); return(new NamespaceAttributes(resourceGroupName, response)); }
public NamespaceAttributes BeginCreateNamespace(string resourceGroupName, string namespaceName, string location, Dictionary <string, string> tags) { var parameter = new NamespaceCreateOrUpdateParameters() { Location = location, Properties = new NamespaceProperties() { NamespaceType = NamespaceType.NotificationHub } }; if (tags != null) { parameter.Tags = new Dictionary <string, string>(tags); } var response = Client.Namespaces.CreateOrUpdate(resourceGroupName, namespaceName, parameter); return(new NamespaceAttributes(resourceGroupName, response.Value)); }
private static async Task CreateNamespace() { try { Console.WriteLine("What would you like to call your Service Bus namespace?"); namespaceName = Console.ReadLine(); var token = await GetToken(); var creds = new TokenCredentials(token); var sbClient = new ServiceBusManagementClient(creds) { SubscriptionId = SettingsCache["SubscriptionId"] }; var namespaceParams = new NamespaceCreateOrUpdateParameters() { Location = SettingsCache["DataCenterLocation"], Sku = new Microsoft.Azure.Management.ServiceBus.Models.Sku() { Tier = SettingsCache["ServiceBusSku"], Name = SettingsCache["ServiceBusSku"] } }; Console.WriteLine("Creating namespace..."); await sbClient.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> /// Creates/Updates a service 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'> /// The name of the resource group. /// </param> /// <param name='namespaceName'> /// The namespace name. /// </param> /// <param name='parameters'> /// Parameters supplied to create a Namespace Resource. /// </param> public static NamespaceResource CreateOrUpdate(this INamespacesOperations operations, string resourceGroupName, string namespaceName, NamespaceCreateOrUpdateParameters parameters) { return(Task.Factory.StartNew(s => ((INamespacesOperations)s).CreateOrUpdateAsync(resourceGroupName, namespaceName, parameters), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
/// <summary> /// Creates/Updates a service 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'> /// The name of the resource group. /// </param> /// <param name='namespaceName'> /// The namespace name. /// </param> /// <param name='parameters'> /// Parameters supplied to create a Namespace Resource. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <NamespaceResource> CreateOrUpdateAsync(this INamespacesOperations operations, string resourceGroupName, string namespaceName, NamespaceCreateOrUpdateParameters parameters, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.CreateOrUpdateWithHttpMessagesAsync(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 = NotificationHubsManagementHelper.DefaultLocation; var resourceGroup = this.ResourceManagementClient.TryGetResourceGroup(location); if (string.IsNullOrWhiteSpace(resourceGroup)) { resourceGroup = TestUtilities.GenerateName(NotificationHubsManagementHelper.ResourceGroupPrefix); this.ResourceManagementClient.TryRegisterResourceGroup(location, resourceGroup); } var namespaceName = TestUtilities.GenerateName(NotificationHubsManagementHelper.NamespacePrefix); var createNamespaceResponse = this.NotificationHubsManagementClient.Namespaces.CreateOrUpdate(resourceGroup, namespaceName, new NamespaceCreateOrUpdateParameters() { Location = location, Properties = new NamespaceProperties() { NamespaceType = NamespaceType.NotificationHub } }); Assert.NotNull(createNamespaceResponse); Assert.Equal(createNamespaceResponse.Name, namespaceName); TestUtilities.Wait(TimeSpan.FromSeconds(5)); //Get the created namespace var getNamespaceResponse = NotificationHubsManagementClient.Namespaces.Get(resourceGroup, namespaceName); if (string.Compare(getNamespaceResponse.Properties.ProvisioningState, "Succeeded", true) != 0) { TestUtilities.Wait(TimeSpan.FromSeconds(5)); } getNamespaceResponse = NotificationHubsManagementClient.Namespaces.Get(resourceGroup, namespaceName); Assert.NotNull(getNamespaceResponse); Assert.Equal("Succeeded", getNamespaceResponse.Properties.ProvisioningState, StringComparer.CurrentCultureIgnoreCase); Assert.Equal("Active", getNamespaceResponse.Properties.Status, StringComparer.CurrentCultureIgnoreCase); Assert.Equal(NamespaceType.NotificationHub, getNamespaceResponse.Properties.NamespaceType); Assert.Equal(location, getNamespaceResponse.Location, StringComparer.CurrentCultureIgnoreCase); //Get all namespaces created within a resourceGroup var getAllNamespacesResponse = NotificationHubsManagementClient.Namespaces.List(resourceGroup); Assert.NotNull(getAllNamespacesResponse); Assert.True(getAllNamespacesResponse.Count() >= 1); Assert.True(getAllNamespacesResponse.Any(ns => ns.Name == namespaceName)); Assert.True(getAllNamespacesResponse.All(ns => ns.Id.Contains(resourceGroup))); //Get all namespaces created within the subscription irrespective of the resourceGroup getAllNamespacesResponse = NotificationHubsManagementClient.Namespaces.ListAll(); Assert.NotNull(getAllNamespacesResponse); Assert.True(getAllNamespacesResponse.Count() >= 1); Assert.True(getAllNamespacesResponse.Any(ns => ns.Name == namespaceName)); //Update namespace tags and make the namespace critical var updateNamespaceParameter = new NamespaceCreateOrUpdateParameters() { Location = location, Tags = new Dictionary <string, string>() { { "tag1", "value1" }, { "tag2", "value2" }, { "tag3", "value3" }, { "tag4", "value4" } }, Properties = new NamespaceProperties() }; var updateNamespaceResponse = NotificationHubsManagementClient.Namespaces.CreateOrUpdate(resourceGroup, namespaceName, updateNamespaceParameter); Assert.NotNull(updateNamespaceResponse); Assert.True(updateNamespaceResponse.Properties.ProvisioningState.Equals("Active", StringComparison.CurrentCultureIgnoreCase) || updateNamespaceResponse.Properties.ProvisioningState.Equals("Succeeded", StringComparison.CurrentCultureIgnoreCase)); Assert.Equal(namespaceName, updateNamespaceResponse.Name); //Regression in the service . uncomment after the fix goes out //Assert.Equal(updateNamespaceResponse.Tags.Count, 4); //foreach (var tag in updateNamespaceParameter.Tags) //{ // Assert.True(updateNamespaceResponse.Tags.Any(t => t.Key.Equals(tag.Key))); // Assert.True(updateNamespaceResponse.Tags.Any(t => t.Value.Equals(tag.Value))); //} TestUtilities.Wait(TimeSpan.FromSeconds(5)); //Get the updated namespace getNamespaceResponse = NotificationHubsManagementClient.Namespaces.Get(resourceGroup, namespaceName); Assert.NotNull(getNamespaceResponse); Assert.Equal(NamespaceType.NotificationHub, getNamespaceResponse.Properties.NamespaceType); Assert.Equal(location, getNamespaceResponse.Location, StringComparer.CurrentCultureIgnoreCase); Assert.Equal(namespaceName, getNamespaceResponse.Name); Assert.Equal(getNamespaceResponse.Tags.Count, 4); foreach (var tag in updateNamespaceParameter.Tags) { Assert.True(getNamespaceResponse.Tags.Any(t => t.Key.Equals(tag.Key))); Assert.True(getNamespaceResponse.Tags.Any(t => t.Value.Equals(tag.Value))); } try { //Delete namespace NotificationHubsManagementClient.Namespaces.Delete(resourceGroup, namespaceName); } catch (Exception ex) { Assert.True(ex.Message.Contains("NotFound")); } } }
/// <summary> /// Creates/Updates a service namespace. Once created, this namespace's /// resource manifest is immutable. This operation is idempotent. /// <see href="http://msdn.microsoft.com/en-us/library/windowsazure/jj856303.aspx" /> /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='namespaceName'> /// The namespace name. /// </param> /// <param name='parameters'> /// Parameters supplied to create a Namespace Resource. /// </param> public static NamespaceResource CreateOrUpdate(this INamespacesOperations operations, string resourceGroupName, string namespaceName, NamespaceCreateOrUpdateParameters parameters) { return(operations.CreateOrUpdateAsync(resourceGroupName, namespaceName, parameters).GetAwaiter().GetResult()); }
public void NamespaceCreateGetUpdateDelete() { using (var context = UndoContext.Current) { context.Start("ScenarioTests", "NamespaceCreateGetUpdateDelete"); var location = NotificationHubsManagementHelper.DefaultLocation; var resourceGroup = this.ResourceManagementClient.TryGetResourceGroup(location); if (string.IsNullOrWhiteSpace(resourceGroup)) { resourceGroup = TestUtilities.GenerateName(NotificationHubsManagementHelper.ResourceGroupPrefix); this.ResourceManagementClient.TryRegisterResourceGroup(location, resourceGroup); } var namespaceName = TestUtilities.GenerateName(NotificationHubsManagementHelper.NamespacePrefix); var createNamespaceResponse = this.NotificationHubsManagementClient.Namespaces.CreateOrUpdate(resourceGroup, namespaceName, new NamespaceCreateOrUpdateParameters() { Location = location, Properties = new NamespaceProperties() { NamespaceType = NamespaceType.NotificationHub } }); Assert.NotNull(createNamespaceResponse); Assert.NotNull(createNamespaceResponse.Value); Assert.Equal(createNamespaceResponse.Value.Properties.Name, namespaceName); TestUtilities.Wait(TimeSpan.FromSeconds(5)); //Get the created namespace var getNamespaceResponse = NotificationHubsManagementClient.Namespaces.Get(resourceGroup, namespaceName); if (string.Compare(getNamespaceResponse.Value.Properties.ProvisioningState, "Succeeded", true) != 0) { TestUtilities.Wait(TimeSpan.FromSeconds(5)); } getNamespaceResponse = NotificationHubsManagementClient.Namespaces.Get(resourceGroup, namespaceName); Assert.NotNull(getNamespaceResponse); Assert.NotNull(getNamespaceResponse.Value); Assert.Equal("Succeeded", getNamespaceResponse.Value.Properties.ProvisioningState, StringComparer.CurrentCultureIgnoreCase); Assert.Equal("Active", getNamespaceResponse.Value.Properties.Status, StringComparer.CurrentCultureIgnoreCase); Assert.Equal(NamespaceType.NotificationHub, getNamespaceResponse.Value.Properties.NamespaceType); Assert.Equal(location, getNamespaceResponse.Value.Properties.Region, StringComparer.CurrentCultureIgnoreCase); //Get all namespaces created within a resourceGroup var getAllNamespacesResponse = NotificationHubsManagementClient.Namespaces.List(resourceGroup); Assert.NotNull(getAllNamespacesResponse); Assert.NotNull(getAllNamespacesResponse.Value); Assert.True(getAllNamespacesResponse.Value.Count >= 1); Assert.True(getAllNamespacesResponse.Value.Any(ns => ns.Name == namespaceName)); Assert.True(getAllNamespacesResponse.Value.All(ns => ns.Id.Contains(resourceGroup))); //Get all namespaces created within the subscription irrespective of the resourceGroup getAllNamespacesResponse = NotificationHubsManagementClient.Namespaces.ListAll(); Assert.NotNull(getAllNamespacesResponse); Assert.NotNull(getAllNamespacesResponse.Value); Assert.True(getAllNamespacesResponse.Value.Count >= 1); Assert.True(getAllNamespacesResponse.Value.Any(ns => ns.Name == namespaceName)); //Update namespace tags and make the namespace critical var updateNamespaceParameter = new NamespaceCreateOrUpdateParameters() { Location = location, Tags = { { "tag1", "value1" }, { "tag2", "value2" }, { "tag3", "value3" }, { "tag4", "value4" } }, Properties = new NamespaceProperties() }; var updateNamespaceResponse = NotificationHubsManagementClient.Namespaces.CreateOrUpdate(resourceGroup, namespaceName, updateNamespaceParameter); Assert.NotNull(updateNamespaceResponse); Assert.NotNull(updateNamespaceResponse.Value); Assert.Equal("Active", updateNamespaceResponse.Value.Properties.ProvisioningState, StringComparer.CurrentCultureIgnoreCase); Assert.Equal(namespaceName, updateNamespaceResponse.Value.Properties.Name); //Assert.True(updateNamespaceResponse.Value.Properties.Critical); Assert.Equal(updateNamespaceResponse.Value.Tags.Count, 4); foreach (var tag in updateNamespaceParameter.Tags) { Assert.True(updateNamespaceResponse.Value.Tags.Any(t => t.Key.Equals(tag.Key))); Assert.True(updateNamespaceResponse.Value.Tags.Any(t => t.Value.Equals(tag.Value))); } TestUtilities.Wait(TimeSpan.FromSeconds(5)); //Get the updated namespace getNamespaceResponse = NotificationHubsManagementClient.Namespaces.Get(resourceGroup, namespaceName); Assert.NotNull(getNamespaceResponse); Assert.NotNull(getNamespaceResponse.Value); Assert.Equal(NamespaceType.NotificationHub, getNamespaceResponse.Value.Properties.NamespaceType); Assert.Equal(location, getNamespaceResponse.Value.Properties.Region, StringComparer.CurrentCultureIgnoreCase); Assert.Equal(namespaceName, getNamespaceResponse.Value.Name); //Assert.True(getNamespaceResponse.Value.Properties.Critical); Assert.Equal(getNamespaceResponse.Value.Tags.Count, 4); foreach (var tag in updateNamespaceParameter.Tags) { Assert.True(getNamespaceResponse.Value.Tags.Any(t => t.Key.Equals(tag.Key))); Assert.True(getNamespaceResponse.Value.Tags.Any(t => t.Value.Equals(tag.Value))); } //create Namespace 2 var namespaceName2 = TestUtilities.GenerateName(NotificationHubsManagementHelper.NamespacePrefix); var createNamespaceResponse2 = this.NotificationHubsManagementClient.Namespaces.CreateOrUpdate(resourceGroup, namespaceName2, new NamespaceCreateOrUpdateParameters() { Location = location, Properties = new NamespaceProperties() { NamespaceType = NamespaceType.NotificationHub } }); Assert.NotNull(createNamespaceResponse2); Assert.NotNull(createNamespaceResponse2.Value); Assert.Equal(createNamespaceResponse2.Value.Properties.Name, namespaceName2); TestUtilities.Wait(TimeSpan.FromSeconds(10)); //Delete namespace var deleteNSResponse = NotificationHubsManagementClient.Namespaces.Delete(resourceGroup, namespaceName2); Assert.NotNull(deleteNSResponse); Assert.True(HttpStatusCode.NotFound == deleteNSResponse.StatusCode || HttpStatusCode.OK == deleteNSResponse.StatusCode); deleteNSResponse = NotificationHubsManagementClient.Namespaces.Delete(resourceGroup, namespaceName); Assert.NotNull(deleteNSResponse); Assert.True(HttpStatusCode.NotFound == deleteNSResponse.StatusCode || HttpStatusCode.OK == deleteNSResponse.StatusCode); } }
/// <summary> /// Creates/Updates a service namespace. Once created, this namespace's /// resource manifest is immutable. This operation is idempotent. /// (see http://msdn.microsoft.com/en-us/library/windowsazure/jj856303.aspx /// for more information) /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.NotificationHubs.INamespaceOperations. /// </param> /// <param name='resourceGroupName'> /// Required. The name of the resource group. /// </param> /// <param name='namespaceName'> /// Required. The namespace name. /// </param> /// <param name='parameters'> /// Required. Parameters supplied to the create a Namespace Resource. /// </param> /// <returns> /// The response of the CreateOrUpdate Namespace. /// </returns> public static Task <NamespaceCreateOrUpdateResponse> CreateOrUpdateAsync(this INamespaceOperations operations, string resourceGroupName, string namespaceName, NamespaceCreateOrUpdateParameters parameters) { return(operations.CreateOrUpdateAsync(resourceGroupName, namespaceName, parameters, CancellationToken.None)); }