public PSNamespaceAttributes UpdateNamespace(string resourceGroupName, string namespaceName, string location, string skuName, int?skuCapacity, Dictionary <string, string> tags, bool isDisableLocalAuth) { var parameter = Client.Namespaces.Get(resourceGroupName, namespaceName); parameter.Location = location; if (tags != null) { parameter.Tags = new Dictionary <string, string>(tags); } if (skuName != null) { parameter.Sku.Name = AzureServiceBusCmdletBase.ParseSkuName(skuName); parameter.Sku.Tier = AzureServiceBusCmdletBase.ParseSkuTier(skuName); } if (skuCapacity != null) { parameter.Sku.Capacity = skuCapacity; } if (isDisableLocalAuth) { parameter.DisableLocalAuth = isDisableLocalAuth; } SBNamespace response = Client.Namespaces.CreateOrUpdate(resourceGroupName, namespaceName, parameter); return(new PSNamespaceAttributes(response)); }
public PSNamespaceAttributes UpdateNamespace(string resourceGroupName, string namespaceName, string location, string skuName, int?skuCapacity, Dictionary <string, string> tags) { var parameter = new SBNamespace() { Location = location }; if (tags != null) { parameter.Tags = new Dictionary <string, string>(tags); } SBSku tempSku = new SBSku(); if (skuName != null) { tempSku.Name = AzureServiceBusCmdletBase.ParseSkuName(skuName); tempSku.Tier = AzureServiceBusCmdletBase.ParseSkuTier(skuName); } if (skuCapacity != null) { tempSku.Capacity = skuCapacity; } parameter.Sku = tempSku; SBNamespace response = Client.Namespaces.CreateOrUpdate(resourceGroupName, namespaceName, parameter); return(new PSNamespaceAttributes(response)); }
public PSNamespaceAttributes BeginCreateNamespace(string resourceGroupName, string namespaceName, string location, string skuName, Dictionary <string, string> tags, bool isZoneRedundant, bool isDisableLocalAuth, int?skuCapacity = null) { SBNamespace parameter = new SBNamespace(); parameter.Location = location; if (tags != null) { parameter.Tags = new Dictionary <string, string>(tags); } if (skuName != null) { parameter.Sku = new SBSku(); parameter.Sku.Name = AzureServiceBusCmdletBase.ParseSkuName(skuName); if (parameter.Sku.Name == SkuName.Premium && skuCapacity != null) { parameter.Sku.Capacity = skuCapacity; } } if (isDisableLocalAuth) { parameter.DisableLocalAuth = isDisableLocalAuth; } if (isZoneRedundant) { parameter.ZoneRedundant = isZoneRedundant; } SBNamespace response = Client.Namespaces.CreateOrUpdate(resourceGroupName, namespaceName, parameter); return(new PSNamespaceAttributes(response)); }
private async Task CreateServiceBus() { var serviceBusManagementClient = await CreateServiceBusManagementClientAsync(); var parameter = new SBNamespace() { Location = _configuration.DataCenterLocation, Sku = new SBSku() { Tier = GetSkuTier(_configuration.Sku), Name = GetSkuName(_configuration.Sku) } }; await serviceBusManagementClient.Namespaces.CreateOrUpdateAsync(_configuration.ResourceGroupName, _configuration.ServiceBusName, parameter); }
internal async Task <string> CreateNamespaceAsync(string location) { await EnsureAuthenticatedAsync(); var ns = $"squadron-{Guid.NewGuid().ToString("N").Substring(8)}"; var pars = new SBNamespace { Sku = new SBSku(SkuName.Standard), Location = location }; SBNamespace res = await _client.Namespaces .CreateOrUpdateAsync(_identifier.ResourceGroupName, ns, pars); _identifier.Name = res.Name; return(res.Name); }
public NamespaceAttributes(SBNamespace evResource) { if (evResource != null) { Sku = new SBSku { 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.Name != null) { Name = evResource.Name; } if (evResource.Id != null) { Id = evResource.Id; } #pragma warning disable 612, 618 Status = Microsoft.Azure.Commands.ServiceBus.Models.NamespaceState.Active; Enabled = true; #pragma warning restore 612, 618 ResourceGroup = Regex.Split(evResource.Id, @"/")[4]; } }
public PSNamespaceAttributes(SBNamespace evResource) { if (evResource != null) { Sku = new SBSku { 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.Name != null) { Name = evResource.Name; } if (evResource.Id != null) { Id = evResource.Id; } ResourceGroup = Regex.Split(evResource.Id, @"/")[4]; ResourceGroupName = Regex.Split(evResource.Id, @"/")[4]; Tags = new Dictionary <string, string>(evResource.Tags); ZoneRedundant = evResource.ZoneRedundant; DisableLocalAuth = evResource.DisableLocalAuth; } }
private static async Task CreateNamespace() { try { if (!String.IsNullOrEmpty(appOptions.BusNSpace)) { namespaceName = appOptions.BusNSpace; } else { 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 = appOptions.SubscriptionId, }; var namespaceParams = new SBNamespace { Location = appOptions.DataCenterLocation, Sku = new SBSku() { Tier = appOptions.ServiceBusSkuTier, Name = appOptions.ServiceBusSkuName, } }; 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; } }
public PSNamespaceAttributes BeginCreateNamespace(string resourceGroupName, string namespaceName, string location, string skuName, Dictionary <string, string> tags) { SBNamespace parameter = new SBNamespace(); parameter.Location = location; if (tags != null) { parameter.Tags = new Dictionary <string, string>(tags); } if (skuName != null) { parameter.Sku = new SBSku(); parameter.Sku.Name = AzureServiceBusCmdletBase.ParseSkuName(skuName); } SBNamespace response = Client.Namespaces.CreateOrUpdate(resourceGroupName, namespaceName, parameter); return(new PSNamespaceAttributes(response)); }
public NamespaceAttributes(SBNamespace evResource) { if (evResource != null) { Sku = new SBSku { 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.Name != null) { Name = evResource.Name; } if (evResource.Id != null) { Id = evResource.Id; } ResourceGroup = Regex.Split(evResource.Id, @"/")[4]; } }
/// <summary> /// Performs the tasks needed to create a new Service Bus namespace within a resource group, intended to be used as /// an ephemeral container for the queue and topic instances used in a given test run. /// </summary> /// /// <returns>The key attributes for identifying and accessing a dynamically created Service Bus namespace.</returns> /// public static async Task <ServiceBusTestEnvironment.NamespaceProperties> CreateNamespaceAsync() { var azureSubscription = ServiceBusTestEnvironment.Instance.SubscriptionId; var resourceGroup = ServiceBusTestEnvironment.Instance.ResourceGroup; var token = await AquireManagementTokenAsync().ConfigureAwait(false); string CreateName() => $"net-servicebus-{ Guid.NewGuid().ToString("D").Substring(0, 30) }"; using (var client = new ServiceBusManagementClient(ResourceManagerUri, new TokenCredentials(token)) { SubscriptionId = azureSubscription }) { var location = await QueryResourceGroupLocationAsync(token, resourceGroup, azureSubscription).ConfigureAwait(false); var serviceBusNamspace = new SBNamespace(sku: new SBSku(SkuName.Standard, SkuTier.Standard), tags: GenerateTags(), location: location); serviceBusNamspace = await CreateRetryPolicy <SBNamespace>().ExecuteAsync(() => client.Namespaces.CreateOrUpdateAsync(resourceGroup, CreateName(), serviceBusNamspace)).ConfigureAwait(false); var accessKey = await CreateRetryPolicy <AccessKeys>().ExecuteAsync(() => client.Namespaces.ListKeysAsync(resourceGroup, serviceBusNamspace.Name, ServiceBusTestEnvironment.ServiceBusDefaultSharedAccessKey)).ConfigureAwait(false); return(new ServiceBusTestEnvironment.NamespaceProperties(serviceBusNamspace.Name, accessKey.PrimaryConnectionString, shouldRemoveAtCompletion: true)); } }
public async Task CreateNamespace(string namespaceName) { try { using (var sbClient = await GetServiceManagementClient()) { var namespaceParams = new SBNamespace { Location = appOptions.DataCenterLocation, Sku = new SBSku() { Tier = appOptions.ServiceBusSkuTier, Name = appOptions.ServiceBusSkuName } }; var nameSpaceCreated = await sbClient.Namespaces.CreateOrUpdateAsync(appOptions.ResourceGroupName, namespaceName, namespaceParams); } } catch (Exception e) { throw e; } }
static async Task MainAsync() { // https://msdn.microsoft.com/en-us/library/azure/dn790557.aspx#bk_portal string token = await GetAuthorizationHeaderAsync().ConfigureAwait(false); TokenCredentials creds = new TokenCredentials(token); ServiceBusManagementClient client = new ServiceBusManagementClient(creds) { SubscriptionId = subscriptionId }; //// 1. Create Primary Namespace (optional) var namespaceParams = new SBNamespace { Location = "South Central US", Sku = new SBSku { Name = SkuName.Premium, Capacity = 1 } }; var namespace1 = await client.Namespaces.CreateOrUpdateAsync(resourceGroupName, geoDRPrimaryNS, namespaceParams) .ConfigureAwait(false); //// 2. Create Secondary Namespace (optional if you already have an empty namespace available) var namespaceParams2 = new SBNamespace { Location = "North Central US", Sku = new SBSku { Name = SkuName.Premium, Capacity = 1 } }; //// If you re-run this program while namespaces are still paired this operation will fail with a bad request. //// this is because we block all updates on secondary namespaces once it is paired var namespace2 = await client.Namespaces.CreateOrUpdateAsync(resourceGroupName, geoDRSecondaryNS, namespaceParams2) .ConfigureAwait(false); // 3. Pair the namespaces to enable DR. ArmDisasterRecovery drStatus = await client.DisasterRecoveryConfigs.CreateOrUpdateAsync( resourceGroupName, geoDRPrimaryNS, alias, new ArmDisasterRecovery { PartnerNamespace = geoDRSecondaryNS }) .ConfigureAwait(false); while (drStatus.ProvisioningState != ProvisioningStateDR.Succeeded) { Console.WriteLine("Waiting for DR to be setup. Current State: " + drStatus.ProvisioningState); drStatus = client.DisasterRecoveryConfigs.Get( resourceGroupName, geoDRPrimaryNS, alias); Thread.CurrentThread.Join(TimeSpan.FromSeconds(30)); } await client.Topics.CreateOrUpdateAsync(resourceGroupName, geoDRPrimaryNS, "myTopic", new SBTopic()) .ConfigureAwait(false); await client.Subscriptions.CreateOrUpdateAsync(resourceGroupName, geoDRPrimaryNS, "myTopic", "myTopic-Sub1", new SBSubscription()) .ConfigureAwait(false); // sleeping to allow metadata to sync across primary and secondary await Task.Delay(TimeSpan.FromSeconds(60)); // 6. Failover. Note that this Failover operations is ALWAYS run against the secondary ( because primary might be down at time of failover ) // client.DisasterRecoveryConfigs.FailOver(resourceGroupName, geoDRSecondaryNS, alias); // other possible DR operations // 7. Break Pairing // client.DisasterRecoveryConfigs.BreakPairing(resourceGroupName, geoDRPrimaryNS, alias); // 8. Delete DR config (alias) // note that this operation needs to run against the namespace that the alias is currently pointing to // client.DisasterRecoveryConfigs.Delete(resourceGroupName, geoDRPrimaryNS, alias); }
public PSNamespaceAttributes GetNamespace(string resourceGroupName, string namespaceName) { SBNamespace response = Client.Namespaces.Get(resourceGroupName, namespaceName); return(new PSNamespaceAttributes(response)); }
public PSNamespaceAttributes(SBNamespace evResource) { if (evResource != null) { Sku = new SBSku { 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.Name != null) { Name = evResource.Name; } if (evResource.Id != null) { Id = evResource.Id; } 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(); } } if (evResource.Tags != null) { var tagDictionary = new Dictionary <string, string>(evResource.Tags); Tag = new Hashtable(tagDictionary); } ResourceGroup = Regex.Split(evResource.Id, @"/")[4]; ResourceGroupName = Regex.Split(evResource.Id, @"/")[4]; Tags = new Dictionary <string, string>(evResource.Tags); if (evResource.ZoneRedundant != null) { ZoneRedundant = evResource.ZoneRedundant; } DisableLocalAuth = evResource.DisableLocalAuth; } }
static async Task CreatePairing() { // https://msdn.microsoft.com/en-us/library/azure/dn790557.aspx#bk_portal string token = await GetAuthorizationHeaderAsync().ConfigureAwait(false); TokenCredentials creds = new TokenCredentials(token); ServiceBusManagementClient client = new ServiceBusManagementClient(creds) { SubscriptionId = subscriptionId }; // 1. Create Primary Namespace (optional) Console.WriteLine("Create or update namespace 1"); var namespaceParams = new SBNamespace { Location = "South Central US", Sku = new SBSku { Name = SkuName.Premium, Capacity = 1 } }; var namespace1 = await client.Namespaces.CreateOrUpdateAsync(resourceGroupName, geoDRPrimaryNS, namespaceParams) .ConfigureAwait(false); // 2. Create Secondary Namespace (optional if you already have an empty namespace available) Console.WriteLine("Create or update namespace 2"); var namespaceParams2 = new SBNamespace { Location = "North Central US", Sku = new SBSku { Name = SkuName.Premium, Capacity = 1 } }; // If you re-run this program while namespaces are still paired this operation will fail with a bad request. // this is because we block all updates on secondary namespaces once it is paired var namespace2 = await client.Namespaces.CreateOrUpdateAsync(resourceGroupName, geoDRSecondaryNS, namespaceParams2) .ConfigureAwait(false); // 3. Pair the namespaces to enable DR. Console.WriteLine("Starting Pairing"); ArmDisasterRecovery drStatus = await client.DisasterRecoveryConfigs.CreateOrUpdateAsync( resourceGroupName, geoDRPrimaryNS, alias, new ArmDisasterRecovery { PartnerNamespace = namespace2.Id, AlternateName = alternateName }) // Note: The additional, optional parameter AlternateName is resposible for using the namespace name as alias and renaming the primary namespace. .ConfigureAwait(false); while (drStatus.ProvisioningState != ProvisioningStateDR.Succeeded) { Console.WriteLine("Waiting for DR to be setup. Current State: " + drStatus.ProvisioningState); drStatus = client.DisasterRecoveryConfigs.Get( resourceGroupName, geoDRPrimaryNS, alias); Thread.CurrentThread.Join(TimeSpan.FromSeconds(30)); } Console.WriteLine("Creating test entities to show pairing."); await client.Topics.CreateOrUpdateAsync(resourceGroupName, geoDRPrimaryNS, "myTopic", new SBTopic()) .ConfigureAwait(false); await client.Subscriptions.CreateOrUpdateAsync(resourceGroupName, geoDRPrimaryNS, "myTopic", "myTopic-Sub1", new SBSubscription()) .ConfigureAwait(false); // Sleeping to allow metadata to sync across primary and secondary await Task.Delay(TimeSpan.FromSeconds(60)); Console.WriteLine("Initial setup complete. Please see in the portal if all resources have been created as expected."); Console.WriteLine("Try creating a few additional entities in the primary in the portal."); Console.WriteLine("Press enter to exit."); Console.ReadLine(); }
/// <summary> /// Creates or updates a service namespace. Once created, this namespace's /// resource manifest is immutable. This operation is idempotent. /// <see href="https://msdn.microsoft.com/en-us/library/azure/mt639408.aspx" /> /// </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 supplied to create a namespace resource. /// </param> public static SBNamespace BeginCreateOrUpdate(this INamespacesOperations operations, string resourceGroupName, string namespaceName, SBNamespace parameters) { return(operations.BeginCreateOrUpdateAsync(resourceGroupName, namespaceName, parameters).GetAwaiter().GetResult()); }
/// <summary> /// Creates or updates a service namespace. Once created, this namespace's /// resource manifest is immutable. This operation is idempotent. /// <see href="https://msdn.microsoft.com/en-us/library/azure/mt639408.aspx" /> /// </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 supplied to create a namespace resource. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <SBNamespace> BeginCreateOrUpdateAsync(this INamespacesOperations operations, string resourceGroupName, string namespaceName, SBNamespace parameters, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.BeginCreateOrUpdateWithHttpMessagesAsync(resourceGroupName, namespaceName, parameters, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }