From ad70c9774a82a141b601e6239c3523f12ba333d1 Mon Sep 17 00:00:00 2001 From: Rebecca Makar Date: Wed, 11 Mar 2020 13:34:25 -0400 Subject: [PATCH 1/2] If incorrect value is entered, return inner exception body message --- .../HPCCache/Commands/FlushAzHpcCache.cs | 15 ++++++++-- .../HPCCache/Commands/NewAzHpcCache.cs | 12 ++++++-- .../HPCCache/Commands/SetAzHpcCache.cs | 28 ++++++++++++------- .../HPCCache/Commands/StartAzHpcCache.cs | 15 ++++++++-- .../HPCCache/Commands/StopAzHpcCache.cs | 16 ++++++++--- .../HPCCache/Commands/UpgradeAzHpcCache.cs | 16 ++++++++--- 6 files changed, 76 insertions(+), 26 deletions(-) diff --git a/src/StorageCache/HPCCache/Commands/FlushAzHpcCache.cs b/src/StorageCache/HPCCache/Commands/FlushAzHpcCache.cs index fa8bd62a84aa..319af33278ea 100644 --- a/src/StorageCache/HPCCache/Commands/FlushAzHpcCache.cs +++ b/src/StorageCache/HPCCache/Commands/FlushAzHpcCache.cs @@ -16,7 +16,9 @@ namespace Microsoft.Azure.Commands.HPCCache using System.Management.Automation; using Microsoft.Azure.Commands.HPCCache.Properties; using Microsoft.Azure.Management.StorageCache; + using Microsoft.Azure.Management.StorageCache.Models; using Microsoft.Azure.PowerShell.Cmdlets.HPCCache.Models; + using Microsoft.Rest.Azure; /// /// Flush HPC Cache. @@ -82,10 +84,17 @@ public void FlushHpcCache() throw new PSArgumentNullException("CacheName"); } - this.HpcCacheClient.Caches.Flush(this.ResourceGroupName, this.CacheName); - if (this.PassThru) + try { - this.WriteObject(true); + this.HpcCacheClient.Caches.Flush(this.ResourceGroupName, this.CacheName); + if (this.PassThru) + { + this.WriteObject(true); + } + } + catch (CloudErrorException ex) + { + throw new CloudException(string.Format("Exception: {0}", ex.Body.Error.Message)); } } } diff --git a/src/StorageCache/HPCCache/Commands/NewAzHpcCache.cs b/src/StorageCache/HPCCache/Commands/NewAzHpcCache.cs index 68c3f652cc94..3c3eb5373156 100644 --- a/src/StorageCache/HPCCache/Commands/NewAzHpcCache.cs +++ b/src/StorageCache/HPCCache/Commands/NewAzHpcCache.cs @@ -13,6 +13,7 @@ // ---------------------------------------------------------------------------------- namespace Microsoft.Azure.Commands.HPCCache { + using System; using System.Collections; using System.Management.Automation; using Microsoft.Azure.Management.StorageCache; @@ -103,8 +104,15 @@ public override void ExecuteCmdlet() var cacheSku = new CacheSku() { Name = this.Sku }; var tag = this.Tag.ToDictionaryTags(); var cacheParameters = new Cache() { CacheSizeGB = this.CacheSize, Location = this.Location, Sku = cacheSku, Subnet = this.SubnetUri, Tags = tag }; - var cache = this.HpcCacheClient.Caches.CreateOrUpdate(this.ResourceGroupName, this.CacheName, cacheParameters); - this.WriteObject(new PSHPCCache(cache), enumerateCollection: true); + try + { + var cache = this.HpcCacheClient.Caches.CreateOrUpdate(this.ResourceGroupName, this.CacheName, cacheParameters); + this.WriteObject(new PSHPCCache(cache), enumerateCollection: true); + } + catch (CloudErrorException ex) + { + throw new CloudException(string.Format("Exception: {0}", ex.Body.Error.Message)); + } } } } \ No newline at end of file diff --git a/src/StorageCache/HPCCache/Commands/SetAzHpcCache.cs b/src/StorageCache/HPCCache/Commands/SetAzHpcCache.cs index 171e76a57bd9..0da32fe5a246 100644 --- a/src/StorageCache/HPCCache/Commands/SetAzHpcCache.cs +++ b/src/StorageCache/HPCCache/Commands/SetAzHpcCache.cs @@ -18,6 +18,7 @@ namespace Microsoft.Azure.Commands.HPCCache using Microsoft.Azure.Management.StorageCache; using Microsoft.Azure.Management.StorageCache.Models; using Microsoft.Azure.PowerShell.Cmdlets.HPCCache.Models; + using Microsoft.Rest.Azure; /// /// SetHPCCache comandlet. @@ -57,17 +58,24 @@ public class SetAzHpcCache : HpcCacheBaseCmdlet /// public override void ExecuteCmdlet() { - var cacheExists = this.HpcCacheClient.Caches.Get(this.ResourceGroupName, this.CacheName); - if (cacheExists != null) + try { - var location = cacheExists.Location; - var cacheSize = cacheExists.CacheSizeGB; - var sku = cacheExists.Sku; - var subnet = cacheExists.Subnet; - var tag = this.Tag.ToDictionaryTags(); - var cacheParameters = new Cache() { CacheSizeGB = cacheSize, Location = location, Sku = sku, Subnet = subnet, Tags = tag }; - var cache = this.HpcCacheClient.Caches.Update(this.ResourceGroupName, this.CacheName, cacheParameters); - this.WriteObject(new PSHPCCache(cache), enumerateCollection: true); + var cacheExists = this.HpcCacheClient.Caches.Get(this.ResourceGroupName, this.CacheName); + if (cacheExists != null) + { + var location = cacheExists.Location; + var cacheSize = cacheExists.CacheSizeGB; + var sku = cacheExists.Sku; + var subnet = cacheExists.Subnet; + var tag = this.Tag.ToDictionaryTags(); + var cacheParameters = new Cache() { CacheSizeGB = cacheSize, Location = location, Sku = sku, Subnet = subnet, Tags = tag }; + var cache = this.HpcCacheClient.Caches.Update(this.ResourceGroupName, this.CacheName, cacheParameters); + this.WriteObject(new PSHPCCache(cache), enumerateCollection: true); + } + } + catch (CloudErrorException ex) + { + throw new CloudException(string.Format("Exception: {0}", ex.Body.Error.Message)); } } } diff --git a/src/StorageCache/HPCCache/Commands/StartAzHpcCache.cs b/src/StorageCache/HPCCache/Commands/StartAzHpcCache.cs index 69bc1644b6b0..bd3c22cdd406 100644 --- a/src/StorageCache/HPCCache/Commands/StartAzHpcCache.cs +++ b/src/StorageCache/HPCCache/Commands/StartAzHpcCache.cs @@ -16,7 +16,9 @@ namespace Microsoft.Azure.Commands.HPCCache using System.Management.Automation; using Microsoft.Azure.Commands.HPCCache.Properties; using Microsoft.Azure.Management.StorageCache; + using Microsoft.Azure.Management.StorageCache.Models; using Microsoft.Azure.PowerShell.Cmdlets.HPCCache.Models; + using Microsoft.Rest.Azure; /// /// Remove HPC Cache. @@ -88,10 +90,17 @@ public void StartHpcCache() throw new PSArgumentNullException("CacheName"); } - this.HpcCacheClient.Caches.Start(this.ResourceGroupName, this.CacheName); - if (this.PassThru) + try { - this.WriteObject(true); + this.HpcCacheClient.Caches.Start(this.ResourceGroupName, this.CacheName); + if (this.PassThru) + { + this.WriteObject(true); + } + } + catch (CloudErrorException ex) + { + throw new CloudException(string.Format("Exception: {0}", ex.Body.Error.Message)); } } } diff --git a/src/StorageCache/HPCCache/Commands/StopAzHpcCache.cs b/src/StorageCache/HPCCache/Commands/StopAzHpcCache.cs index 200917cf0353..dd8b46393de5 100644 --- a/src/StorageCache/HPCCache/Commands/StopAzHpcCache.cs +++ b/src/StorageCache/HPCCache/Commands/StopAzHpcCache.cs @@ -17,7 +17,9 @@ namespace Microsoft.Azure.Commands.HPCCache using System.Management.Automation; using Microsoft.Azure.Commands.HPCCache.Properties; using Microsoft.Azure.Management.StorageCache; + using Microsoft.Azure.Management.StorageCache.Models; using Microsoft.Azure.PowerShell.Cmdlets.HPCCache.Models; + using Microsoft.Rest.Azure; /// /// Stop HPC Cache. @@ -82,11 +84,17 @@ private void StopHpcCache() { throw new PSArgumentNullException("CacheName"); } - - this.HpcCacheClient.Caches.Stop(this.ResourceGroupName, this.CacheName); - if (this.PassThru) + try + { + this.HpcCacheClient.Caches.Stop(this.ResourceGroupName, this.CacheName); + if (this.PassThru) + { + this.WriteObject(true); + } + } + catch (CloudErrorException ex) { - this.WriteObject(true); + throw new CloudException(string.Format("Exception: {0}", ex.Body.Error.Message)); } } } diff --git a/src/StorageCache/HPCCache/Commands/UpgradeAzHpcCache.cs b/src/StorageCache/HPCCache/Commands/UpgradeAzHpcCache.cs index 6a04b530bebb..97efdaf564fd 100644 --- a/src/StorageCache/HPCCache/Commands/UpgradeAzHpcCache.cs +++ b/src/StorageCache/HPCCache/Commands/UpgradeAzHpcCache.cs @@ -16,7 +16,9 @@ namespace Microsoft.Azure.Commands.HPCCache using System.Management.Automation; using Microsoft.Azure.Commands.HPCCache.Properties; using Microsoft.Azure.Management.StorageCache; + using Microsoft.Azure.Management.StorageCache.Models; using Microsoft.Azure.PowerShell.Cmdlets.HPCCache.Models; + using Microsoft.Rest.Azure; /// /// Upgrade HPC Cache. @@ -88,11 +90,17 @@ public void UpgradeHpcCache() { throw new PSArgumentNullException("CacheName"); } - - this.HpcCacheClient.Caches.UpgradeFirmware(this.ResourceGroupName, this.CacheName); - if (this.PassThru) + try + { + this.HpcCacheClient.Caches.UpgradeFirmware(this.ResourceGroupName, this.CacheName); + if (this.PassThru) + { + this.WriteObject(true); + } + } + catch (CloudErrorException ex) { - this.WriteObject(true); + throw new CloudException(string.Format("Exception: {0}", ex.Body.Error.Message)); } } } From d48d6ef96a7f4cc83d274bce7a4dddbec6fae5cf Mon Sep 17 00:00:00 2001 From: Rebecca Makar Date: Wed, 11 Mar 2020 14:02:37 -0400 Subject: [PATCH 2/2] For Get and Remove - return inner exception body message --- .../HPCCache/Commands/GetAzHpcCache.cs | 13 +++++++++++-- .../Commands/GetAzHpcCacheStorageTarget.cs | 13 +++++++++++-- .../HPCCache/Commands/RemoveAzHpcCache.cs | 15 ++++++++++++--- .../Commands/RemoveAzHpcCacheStorageTarget.cs | 15 ++++++++++++--- 4 files changed, 46 insertions(+), 10 deletions(-) diff --git a/src/StorageCache/HPCCache/Commands/GetAzHpcCache.cs b/src/StorageCache/HPCCache/Commands/GetAzHpcCache.cs index e74253ad25b0..0e5aa546528b 100644 --- a/src/StorageCache/HPCCache/Commands/GetAzHpcCache.cs +++ b/src/StorageCache/HPCCache/Commands/GetAzHpcCache.cs @@ -15,7 +15,9 @@ namespace Microsoft.Azure.Commands.HPCCache { using System.Management.Automation; using Microsoft.Azure.Management.StorageCache; + using Microsoft.Azure.Management.StorageCache.Models; using Microsoft.Azure.PowerShell.Cmdlets.HPCCache.Models; + using Microsoft.Rest.Azure; /// /// Get Cache / RG specific cache(s) / subscription wide caches. @@ -45,8 +47,15 @@ public override void ExecuteCmdlet() { if (!string.IsNullOrEmpty(this.CacheName)) { - var singleCache = this.HpcCacheClient.Caches.Get(this.ResourceGroupName, this.CacheName); - this.WriteObject(new PSHPCCache(singleCache), true); + try + { + var singleCache = this.HpcCacheClient.Caches.Get(this.ResourceGroupName, this.CacheName); + this.WriteObject(new PSHPCCache(singleCache), true); + } + catch (CloudErrorException ex) + { + throw new CloudException(string.Format("Exception: {0}", ex.Body.Error.Message)); + } } else { diff --git a/src/StorageCache/HPCCache/Commands/GetAzHpcCacheStorageTarget.cs b/src/StorageCache/HPCCache/Commands/GetAzHpcCacheStorageTarget.cs index efa8d2b64813..ed1d9cf8e150 100644 --- a/src/StorageCache/HPCCache/Commands/GetAzHpcCacheStorageTarget.cs +++ b/src/StorageCache/HPCCache/Commands/GetAzHpcCacheStorageTarget.cs @@ -15,7 +15,9 @@ namespace Microsoft.Azure.Commands.HPCCache { using System.Management.Automation; using Microsoft.Azure.Management.StorageCache; + using Microsoft.Azure.Management.StorageCache.Models; using Microsoft.Azure.PowerShell.Cmdlets.HPCCache.Models; + using Microsoft.Rest.Azure; /// /// Get StorageTargets on Cache. @@ -54,8 +56,15 @@ public override void ExecuteCmdlet() { if (!string.IsNullOrEmpty(this.StorageTargetName)) { - var singleST = this.HpcCacheClient.StorageTargets.Get(this.ResourceGroupName, this.CacheName, this.StorageTargetName); - this.WriteObject(new PSHpcStorageTarget(singleST), true); + try + { + var singleST = this.HpcCacheClient.StorageTargets.Get(this.ResourceGroupName, this.CacheName, this.StorageTargetName); + this.WriteObject(new PSHpcStorageTarget(singleST), true); + } + catch (CloudErrorException ex) + { + throw new CloudException(string.Format("Exception: {0}", ex.Body.Error.Message)); + } } else { diff --git a/src/StorageCache/HPCCache/Commands/RemoveAzHpcCache.cs b/src/StorageCache/HPCCache/Commands/RemoveAzHpcCache.cs index 6d3d728ccced..72491ec29ce9 100644 --- a/src/StorageCache/HPCCache/Commands/RemoveAzHpcCache.cs +++ b/src/StorageCache/HPCCache/Commands/RemoveAzHpcCache.cs @@ -16,7 +16,9 @@ namespace Microsoft.Azure.Commands.HPCCache using System.Management.Automation; using Microsoft.Azure.Commands.HPCCache.Properties; using Microsoft.Azure.Management.StorageCache; + using Microsoft.Azure.Management.StorageCache.Models; using Microsoft.Azure.PowerShell.Cmdlets.HPCCache.Models; + using Microsoft.Rest.Azure; /// /// Remove HPC Cache. @@ -69,10 +71,17 @@ public override void ExecuteCmdlet() this.CacheName, () => { - this.HpcCacheClient.Caches.Delete(this.ResourceGroupName, this.CacheName); - if (this.PassThru) + try { - this.WriteObject(true); + this.HpcCacheClient.Caches.Delete(this.ResourceGroupName, this.CacheName); + if (this.PassThru) + { + this.WriteObject(true); + } + } + catch (CloudErrorException ex) + { + throw new CloudException(string.Format("Exception: {0}", ex.Body.Error.Message)); } }); } diff --git a/src/StorageCache/HPCCache/Commands/RemoveAzHpcCacheStorageTarget.cs b/src/StorageCache/HPCCache/Commands/RemoveAzHpcCacheStorageTarget.cs index 6656fce4de0b..515aea41bc7d 100644 --- a/src/StorageCache/HPCCache/Commands/RemoveAzHpcCacheStorageTarget.cs +++ b/src/StorageCache/HPCCache/Commands/RemoveAzHpcCacheStorageTarget.cs @@ -16,7 +16,9 @@ namespace Microsoft.Azure.Commands.HPCCache using System.Management.Automation; using Microsoft.Azure.Commands.HPCCache.Properties; using Microsoft.Azure.Management.StorageCache; + using Microsoft.Azure.Management.StorageCache.Models; using Microsoft.Azure.PowerShell.Cmdlets.HPCCache.Models; + using Microsoft.Rest.Azure; /// /// Remove Storage Target. @@ -76,10 +78,17 @@ public override void ExecuteCmdlet() this.CacheName, () => { - this.HpcCacheClient.StorageTargets.Delete(this.ResourceGroupName, this.CacheName, this.StorageTargetName); - if (this.PassThru) + try { - this.WriteObject(true); + this.HpcCacheClient.StorageTargets.Delete(this.ResourceGroupName, this.CacheName, this.StorageTargetName); + if (this.PassThru) + { + this.WriteObject(true); + } + } + catch (CloudErrorException ex) + { + throw new CloudException(string.Format("Exception: {0}", ex.Body.Error.Message)); } }); }