Skip to content

Commit 372b318

Browse files
committed
Merge pull request Azure#1587 from dihan0604/dev
#5532005 Fix stats API when access type is not given
2 parents b5e60b7 + 6cf1f6c commit 372b318

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

src/ServiceManagement/ExpressRoute/Commands.ExpressRoute/DedicatedCircuitStats/GetAzureDedicatedCircuitStats.cs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,15 @@ public override void ExecuteCmdlet()
4444
SecondaryBytesIn = (ulong)0,
4545
SecondaryBytesOut = (ulong)0
4646
};
47-
AzureBgpPeering peering= ExpressRouteClient.GetAzureBGPPeering(ServiceKey, BgpPeeringAccessType.Private);
48-
if (peering != null)
49-
{
50-
stats = compute(stats, ServiceKey, BgpPeeringAccessType.Private);
51-
}
52-
peering = ExpressRouteClient.GetAzureBGPPeering(ServiceKey, BgpPeeringAccessType.Public);
53-
if (peering != null)
54-
{
55-
stats = compute(stats, ServiceKey, BgpPeeringAccessType.Public);
56-
}
57-
peering = ExpressRouteClient.GetAzureBGPPeering(ServiceKey, BgpPeeringAccessType.Microsoft);
58-
if (peering != null)
59-
{
60-
stats = compute(stats, ServiceKey, BgpPeeringAccessType.Microsoft);
61-
}
47+
stats = compute(stats, ServiceKey, BgpPeeringAccessType.Private);
48+
stats = compute(stats, ServiceKey, BgpPeeringAccessType.Public);
49+
stats = compute(stats, ServiceKey, BgpPeeringAccessType.Microsoft);
50+
6251
WriteObject(stats);
6352

6453
}
6554
BgpPeeringAccessType type;
66-
if (BgpPeeringAccessType.TryParse(AccessType, out type))
55+
if (BgpPeeringAccessType.TryParse(AccessType, true, out type))
6756
{
6857
var stats = ExpressRouteClient.GetAzureDedicatedCircuitStatsInfo(ServiceKey, type);
6958
WriteObject(stats);
@@ -72,12 +61,24 @@ public override void ExecuteCmdlet()
7261

7362
private AzureDedicatedCircuitStats compute(AzureDedicatedCircuitStats stats, Guid key, BgpPeeringAccessType type)
7463
{
75-
var tempstats = ExpressRouteClient.GetAzureDedicatedCircuitStatsInfo(key,type);
76-
stats.PrimaryBytesIn += tempstats.PrimaryBytesIn;
77-
stats.PrimaryBytesOut += tempstats.PrimaryBytesOut;
78-
stats.SecondaryBytesIn += tempstats.SecondaryBytesIn;
79-
stats.SecondaryBytesOut += tempstats.SecondaryBytesOut;
80-
return stats;
64+
try
65+
{
66+
AzureBgpPeering peering = ExpressRouteClient.GetAzureBGPPeering(ServiceKey, type);
67+
if (peering != null)
68+
{
69+
var tempstats = ExpressRouteClient.GetAzureDedicatedCircuitStatsInfo(key, type);
70+
stats.PrimaryBytesIn += tempstats.PrimaryBytesIn;
71+
stats.PrimaryBytesOut += tempstats.PrimaryBytesOut;
72+
stats.SecondaryBytesIn += tempstats.SecondaryBytesIn;
73+
stats.SecondaryBytesOut += tempstats.SecondaryBytesOut;
74+
}
75+
return stats;
76+
}
77+
catch
78+
{
79+
// The cirucit might not have corresponding peering
80+
return stats;
81+
}
8182
}
8283
}
8384
}

0 commit comments

Comments
 (0)