Skip to content

Commit

Permalink
Merge pull request AzureRT#31 from romahamu/makar/cmdlet_return_excep…
Browse files Browse the repository at this point in the history
…tion

If incorrect value is entered, return inner exception body message
  • Loading branch information
rebecca-makar authored Mar 11, 2020
2 parents f761467 + d48d6ef commit c307861
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 36 deletions.
15 changes: 12 additions & 3 deletions src/StorageCache/HPCCache/Commands/FlushAzHpcCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
/// Flush HPC Cache.
Expand Down Expand Up @@ -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));
}
}
}
Expand Down
13 changes: 11 additions & 2 deletions src/StorageCache/HPCCache/Commands/GetAzHpcCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
/// Get Cache / RG specific cache(s) / subscription wide caches.
Expand Down Expand Up @@ -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
{
Expand Down
13 changes: 11 additions & 2 deletions src/StorageCache/HPCCache/Commands/GetAzHpcCacheStorageTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
/// Get StorageTargets on Cache.
Expand Down Expand Up @@ -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
{
Expand Down
12 changes: 10 additions & 2 deletions src/StorageCache/HPCCache/Commands/NewAzHpcCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// ----------------------------------------------------------------------------------
namespace Microsoft.Azure.Commands.HPCCache
{
using System;
using System.Collections;
using System.Management.Automation;
using Microsoft.Azure.Management.StorageCache;
Expand Down Expand Up @@ -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));
}
}
}
}
15 changes: 12 additions & 3 deletions src/StorageCache/HPCCache/Commands/RemoveAzHpcCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
/// Remove HPC Cache.
Expand Down Expand Up @@ -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));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
/// Remove Storage Target.
Expand Down Expand Up @@ -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));
}
});
}
Expand Down
28 changes: 18 additions & 10 deletions src/StorageCache/HPCCache/Commands/SetAzHpcCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
/// SetHPCCache comandlet.
Expand Down Expand Up @@ -57,17 +58,24 @@ public class SetAzHpcCache : HpcCacheBaseCmdlet
/// </summary>
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));
}
}
}
Expand Down
15 changes: 12 additions & 3 deletions src/StorageCache/HPCCache/Commands/StartAzHpcCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
/// Remove HPC Cache.
Expand Down Expand Up @@ -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));
}
}
}
Expand Down
16 changes: 12 additions & 4 deletions src/StorageCache/HPCCache/Commands/StopAzHpcCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
/// Stop HPC Cache.
Expand Down Expand Up @@ -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));
}
}
}
Expand Down
16 changes: 12 additions & 4 deletions src/StorageCache/HPCCache/Commands/UpgradeAzHpcCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
/// Upgrade HPC Cache.
Expand Down Expand Up @@ -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));
}
}
}
Expand Down

0 comments on commit c307861

Please sign in to comment.