Skip to content

Commit db5e944

Browse files
author
Emil Einarsson
authored
Merge branch 'dev' into dev
2 parents 318dabb + da12ac5 commit db5e944

File tree

11 files changed

+278
-38
lines changed

11 files changed

+278
-38
lines changed

src/Microsoft.Azure.ServiceBus/Management/ManagementClient.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ public static HttpRequestMessage CloneRequest(HttpRequestMessage req)
7878
return clone;
7979
}
8080

81+
/// <summary>
82+
/// Gets information related to the currently used namespace.
83+
/// </summary>
84+
/// <param name="cancellationToken"></param>
85+
/// <returns><see cref="NamespaceInfo"/> containing namespace information.</returns>
86+
/// <remarks>Works with any claim (Send/Listen/Manage).</remarks>
87+
public virtual async Task<NamespaceInfo> GetNamespaceInfoAsync(CancellationToken cancellationToken = default)
88+
{
89+
var content = await GetEntity("$namespaceinfo", null, false, cancellationToken).ConfigureAwait(false);
90+
return NamespaceInfoExtensions.ParseFromContent(content);
91+
}
92+
8193
#region DeleteEntity
8294

8395
/// <summary>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace Microsoft.Azure.ServiceBus.Management
5+
{
6+
/// <summary>
7+
/// Specifies the SKU/tier of the messaging namespace.
8+
/// </summary>
9+
public enum MessagingSku
10+
{
11+
/// <summary>
12+
/// Basic namespace. Shared Resource. Only queues are available.
13+
/// </summary>
14+
Basic = 1,
15+
16+
/// <summary>
17+
/// Standard namespace. Shared Resource. Queues and topics.
18+
/// </summary>
19+
Standard = 2,
20+
21+
/// <summary>
22+
/// Premium namespace. Dedicated Resource. Queues and topics.
23+
/// </summary>
24+
Premium = 3,
25+
26+
/// <summary>
27+
/// Other SKUs.
28+
/// </summary>
29+
Others = 99
30+
}
31+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace Microsoft.Azure.ServiceBus.Management
5+
{
6+
using System;
7+
8+
/// <summary>
9+
/// Represents the metadata related to a service bus namespace.
10+
/// </summary>
11+
public class NamespaceInfo
12+
{
13+
/// <summary>
14+
/// Name of the namespace.
15+
/// </summary>
16+
public string Name { get; set; }
17+
18+
/// <summary>
19+
/// Type of entities present in the namespace.
20+
/// </summary>
21+
public NamespaceType NamespaceType { get; set; }
22+
23+
/// <summary>
24+
/// The time at which the namespace was created.
25+
/// </summary>
26+
public DateTime CreatedTime { get; set; }
27+
28+
/// <summary>
29+
/// The last time at which the namespace was modified.
30+
/// </summary>
31+
public DateTime ModifiedTime { get; set; }
32+
33+
/// <summary>
34+
/// The SKU/tier of the namespace. Valid only for <see cref="NamespaceType.ServiceBus"/>
35+
/// </summary>
36+
public MessagingSku MessagingSku { get; set; }
37+
38+
/// <summary>
39+
/// Number of messaging units allocated for namespace.
40+
/// Valid only for <see cref="NamespaceType.ServiceBus"/> and <see cref="MessagingSku.Premium"/>
41+
/// </summary>
42+
public int MessagingUnits { get; set; }
43+
44+
/// <summary>
45+
/// Alias for the namespace.
46+
/// </summary>
47+
public string Alias { get; set; }
48+
}
49+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace Microsoft.Azure.ServiceBus.Management
5+
{
6+
using System;
7+
using System.Xml.Linq;
8+
9+
internal class NamespaceInfoExtensions
10+
{
11+
public static NamespaceInfo ParseFromContent(string xml)
12+
{
13+
try
14+
{
15+
var xDoc = XElement.Parse(xml);
16+
if (!xDoc.IsEmpty)
17+
{
18+
if (xDoc.Name.LocalName == "entry")
19+
{
20+
return ParseFromEntryElement(xDoc);
21+
}
22+
}
23+
}
24+
catch (Exception ex) when (!(ex is ServiceBusException))
25+
{
26+
throw new ServiceBusException(false, ex);
27+
}
28+
29+
throw new ServiceBusException(false, "Unknown error.");
30+
}
31+
32+
private static NamespaceInfo ParseFromEntryElement(XElement xEntry)
33+
{
34+
var nsInfo = new NamespaceInfo();
35+
36+
var nsInfoXml = xEntry.Element(XName.Get("content", ManagementClientConstants.AtomNs))?
37+
.Element(XName.Get("NamespaceInfo", ManagementClientConstants.SbNs));
38+
39+
if (nsInfoXml == null)
40+
{
41+
throw new ServiceBusException(true);
42+
}
43+
44+
foreach (var element in nsInfoXml.Elements())
45+
{
46+
switch (element.Name.LocalName)
47+
{
48+
case "CreatedTime":
49+
nsInfo.CreatedTime = DateTime.Parse(element.Value);
50+
break;
51+
case "ModifiedTime":
52+
nsInfo.ModifiedTime = DateTime.Parse(element.Value);
53+
break;
54+
case "Name":
55+
nsInfo.Name = element.Value;
56+
break;
57+
case "Alias":
58+
nsInfo.Alias = element.Value;
59+
break;
60+
case "NamespaceType":
61+
if (Enum.TryParse<NamespaceType>(element.Value, out var nsType))
62+
{
63+
nsInfo.NamespaceType = nsType;
64+
}
65+
else
66+
{
67+
nsInfo.NamespaceType = NamespaceType.Others;
68+
}
69+
break;
70+
case "MessagingSKU":
71+
if (Enum.TryParse<MessagingSku>(element.Value, out var nsSku))
72+
{
73+
nsInfo.MessagingSku = nsSku;
74+
}
75+
else
76+
{
77+
nsInfo.MessagingSku = MessagingSku.Others;
78+
}
79+
break;
80+
}
81+
}
82+
83+
return nsInfo;
84+
}
85+
}
86+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace Microsoft.Azure.ServiceBus.Management
5+
{
6+
/// <summary>
7+
/// Specifies the type of entities the namespace can contain.
8+
/// </summary>
9+
public enum NamespaceType
10+
{
11+
/// <summary>
12+
/// Namespace contains service bus entities (queues, topics)
13+
/// </summary>
14+
ServiceBus = 0,
15+
16+
/// <summary>
17+
/// Supported only for backward compatibility.
18+
/// Namespace can contain mixture of messaging entities and notification hubs.
19+
/// </summary>
20+
Mixed = 2,
21+
22+
/// <summary>
23+
/// Other type of resource.
24+
/// </summary>
25+
Others = 99,
26+
}
27+
}

src/Microsoft.Azure.ServiceBus/Management/QueueDescription.cs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public class QueueDescription : IEquatable<QueueDescription>
2020
int maxDeliveryCount = 10;
2121
string forwardTo = null;
2222
string forwardDeadLetteredMessagesTo = null;
23-
AuthorizationRules authorizationRules = null;
2423
string userMetadata = null;
2524

2625
/// <summary>
@@ -185,17 +184,7 @@ public int MaxDeliveryCount
185184
/// <summary>
186185
/// The <see cref="AuthorizationRules"/> on the queue to control user access at entity level.
187186
/// </summary>
188-
public AuthorizationRules AuthorizationRules
189-
{
190-
get
191-
{
192-
return this.authorizationRules ?? (this.authorizationRules = new AuthorizationRules());
193-
}
194-
internal set
195-
{
196-
this.authorizationRules = value;
197-
}
198-
}
187+
public AuthorizationRules AuthorizationRules { get; internal set; } = new AuthorizationRules();
199188

200189
/// <summary>
201190
/// The current status of the queue (Enabled / Disabled).
@@ -320,9 +309,9 @@ public bool Equals(QueueDescription otherDescription)
320309
&& this.RequiresSession.Equals(other.RequiresSession)
321310
&& this.Status.Equals(other.Status)
322311
&& string.Equals(this.userMetadata, other.userMetadata, StringComparison.OrdinalIgnoreCase)
323-
&& (this.authorizationRules != null && other.authorizationRules != null
324-
|| this.authorizationRules == null && other.authorizationRules == null)
325-
&& (this.authorizationRules == null || this.AuthorizationRules.Equals(other.AuthorizationRules)))
312+
&& (this.AuthorizationRules != null && other.AuthorizationRules != null
313+
|| this.AuthorizationRules == null && other.AuthorizationRules == null)
314+
&& (this.AuthorizationRules == null || this.AuthorizationRules.Equals(other.AuthorizationRules)))
326315
{
327316
return true;
328317
}

src/Microsoft.Azure.ServiceBus/Management/TopicDescription.cs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public class TopicDescription : IEquatable<TopicDescription>
1515
internal string path;
1616
TimeSpan defaultMessageTimeToLive = TimeSpan.MaxValue;
1717
TimeSpan autoDeleteOnIdle = TimeSpan.MaxValue;
18-
AuthorizationRules authorizationRules = null;
1918
string userMetadata = null;
2019

2120
/// <summary>
@@ -123,22 +122,7 @@ public string Path
123122
/// <summary>
124123
/// The <see cref="AuthorizationRules"/> on the topic to control user access at entity level.
125124
/// </summary>
126-
public AuthorizationRules AuthorizationRules
127-
{
128-
get
129-
{
130-
if (this.authorizationRules == null)
131-
{
132-
this.authorizationRules = new AuthorizationRules();
133-
}
134-
135-
return this.authorizationRules;
136-
}
137-
internal set
138-
{
139-
this.authorizationRules = value;
140-
}
141-
}
125+
public AuthorizationRules AuthorizationRules { get; internal set; } = new AuthorizationRules();
142126

143127
/// <summary>
144128
/// The current status of the topic (Enabled / Disabled).
@@ -218,9 +202,9 @@ public bool Equals(TopicDescription otherDescription)
218202
&& this.RequiresDuplicateDetection.Equals(other.RequiresDuplicateDetection)
219203
&& this.Status.Equals(other.Status)
220204
&& string.Equals(this.userMetadata, other.userMetadata, StringComparison.OrdinalIgnoreCase)
221-
&& (this.authorizationRules != null && other.authorizationRules != null
222-
|| this.authorizationRules == null && other.authorizationRules == null)
223-
&& (this.authorizationRules == null || this.AuthorizationRules.Equals(other.AuthorizationRules)))
205+
&& (this.AuthorizationRules != null && other.AuthorizationRules != null
206+
|| this.AuthorizationRules == null && other.AuthorizationRules == null)
207+
&& (this.AuthorizationRules == null || this.AuthorizationRules.Equals(other.AuthorizationRules)))
224208
{
225209
return true;
226210
}

src/Microsoft.Azure.ServiceBus/Microsoft.Azure.ServiceBus.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<Description>This is the next generation Azure Service Bus .NET Standard client library that focuses on queues &amp; topics. For more information about Service Bus, see https://azure.microsoft.com/en-us/services/service-bus/</Description>
5-
<Version>3.2.1</Version>
5+
<Version>3.3.0</Version>
66
<Authors>Microsoft</Authors>
77
<copyright>© Microsoft Corporation. All rights reserved.</copyright>
88
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks>

test/Microsoft.Azure.ServiceBus.UnitTests/API/ApiApprovals.ApproveAzureServiceBus.approved.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,7 @@ namespace Microsoft.Azure.ServiceBus.Management
675675
public virtual System.Threading.Tasks.Task DeleteRuleAsync(string topicPath, string subscriptionName, string ruleName, System.Threading.CancellationToken cancellationToken = null) { }
676676
public virtual System.Threading.Tasks.Task DeleteSubscriptionAsync(string topicPath, string subscriptionName, System.Threading.CancellationToken cancellationToken = null) { }
677677
public virtual System.Threading.Tasks.Task DeleteTopicAsync(string topicPath, System.Threading.CancellationToken cancellationToken = null) { }
678+
public virtual System.Threading.Tasks.Task<Microsoft.Azure.ServiceBus.Management.NamespaceInfo> GetNamespaceInfoAsync(System.Threading.CancellationToken cancellationToken = null) { }
678679
public virtual System.Threading.Tasks.Task<Microsoft.Azure.ServiceBus.Management.QueueDescription> GetQueueAsync(string queuePath, System.Threading.CancellationToken cancellationToken = null) { }
679680
public virtual System.Threading.Tasks.Task<Microsoft.Azure.ServiceBus.Management.QueueRuntimeInfo> GetQueueRuntimeInfoAsync(string queuePath, System.Threading.CancellationToken cancellationToken = null) { }
680681
public virtual System.Threading.Tasks.Task<System.Collections.Generic.IList<Microsoft.Azure.ServiceBus.Management.QueueDescription>> GetQueuesAsync(int count = 100, int skip = 0, System.Threading.CancellationToken cancellationToken = null) { }
@@ -708,6 +709,30 @@ namespace Microsoft.Azure.ServiceBus.Management
708709
public MessagingEntityAlreadyExistsException(string message) { }
709710
public MessagingEntityAlreadyExistsException(string message, System.Exception innerException) { }
710711
}
712+
public enum MessagingSku
713+
{
714+
Basic = 1,
715+
Standard = 2,
716+
Premium = 3,
717+
Others = 99,
718+
}
719+
public class NamespaceInfo
720+
{
721+
public NamespaceInfo() { }
722+
public string Alias { get; set; }
723+
public System.DateTime CreatedTime { get; set; }
724+
public Microsoft.Azure.ServiceBus.Management.MessagingSku MessagingSku { get; set; }
725+
public int MessagingUnits { get; set; }
726+
public System.DateTime ModifiedTime { get; set; }
727+
public string Name { get; set; }
728+
public Microsoft.Azure.ServiceBus.Management.NamespaceType NamespaceType { get; set; }
729+
}
730+
public enum NamespaceType
731+
{
732+
ServiceBus = 0,
733+
Mixed = 2,
734+
Others = 99,
735+
}
711736
public class QueueDescription : System.IEquatable<Microsoft.Azure.ServiceBus.Management.QueueDescription>
712737
{
713738
public QueueDescription(string path) { }

test/Microsoft.Azure.ServiceBus.UnitTests/Management/ManagementClientTests.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,34 @@ public void AuthRulesEqualityCheckTest()
550550
Assert.Equal(qd, qd2);
551551
}
552552

553+
[Fact]
554+
[DisplayTestMethodName]
555+
public async Task QueueDescriptionParsedFromResponseEqualityCheckTest()
556+
{
557+
var name = Guid.NewGuid().ToString("D").Substring(0, 8);
558+
var queueDescription = new QueueDescription(name);
559+
var createdQueueDescription = await client.CreateQueueAsync(queueDescription);
560+
561+
var identicalQueueDescription = new QueueDescription(name);
562+
Assert.Equal(identicalQueueDescription, createdQueueDescription);
563+
564+
await client.DeleteQueueAsync(name);
565+
}
566+
567+
[Fact]
568+
[DisplayTestMethodName]
569+
public async Task TopicDescriptionParsedFromResponseEqualityCheckTest()
570+
{
571+
var name = Guid.NewGuid().ToString("D").Substring(0, 8);
572+
var topicDescription = new TopicDescription(name);
573+
var createdTopicDescription = await client.CreateTopicAsync(topicDescription);
574+
575+
var identicalTopicDescription = new TopicDescription(name);
576+
Assert.Equal(identicalTopicDescription, createdTopicDescription);
577+
578+
await client.DeleteTopicAsync(name);
579+
}
580+
553581
[Fact]
554582
[DisplayTestMethodName]
555583
public async Task SqlFilterParamsTest()
@@ -605,6 +633,15 @@ public async Task CorrelationFilterPropertiesTest()
605633
await client.DeleteTopicAsync(topicName);
606634
}
607635

636+
[Fact]
637+
[DisplayTestMethodName]
638+
public async Task GetNamespaceInfoTest()
639+
{
640+
var nsInfo = await client.GetNamespaceInfoAsync();
641+
Assert.NotNull(nsInfo);
642+
Assert.Equal(MessagingSku.Standard, nsInfo.MessagingSku); // Most CI systems generally use standard, hence this check just to ensure the API is working.
643+
}
644+
608645
public void Dispose()
609646
{
610647
client.CloseAsync().Wait();

0 commit comments

Comments
 (0)