From 2888c339193bb54adeb72eb1d12b98ce4de48a92 Mon Sep 17 00:00:00 2001 From: Rebecca Makar Date: Fri, 14 Feb 2020 14:13:44 -0500 Subject: [PATCH] Changes made for code review --- .../HPCCache/Commands/GetAzHpcCache.cs | 58 ++++--------------- .../HPCCache/Commands/GetAzHpcCacheSku.cs | 4 +- .../Commands/GetAzHpcCacheUsageModels.cs | 6 +- .../HPCCache/Commands/NewAzHpcCache.cs | 21 +------ .../HPCCache/Commands/RemoveAzHpcCache.cs | 2 +- .../HPCCache/Commands/UpdateAzHpcCache.cs | 44 ++++---------- .../HPCCache/help/Get-AzHpcCacheSku.md | 2 +- .../HPCCache/help/New-AzHpcCache.md | 2 +- .../HPCCache/help/Update-AzHpcCache.md | 2 +- 9 files changed, 33 insertions(+), 108 deletions(-) diff --git a/src/StorageCache/HPCCache/Commands/GetAzHpcCache.cs b/src/StorageCache/HPCCache/Commands/GetAzHpcCache.cs index 0b3bac11aaaf..e73365f07467 100644 --- a/src/StorageCache/HPCCache/Commands/GetAzHpcCache.cs +++ b/src/StorageCache/HPCCache/Commands/GetAzHpcCache.cs @@ -50,62 +50,26 @@ public override void ExecuteCmdlet() { if (!string.IsNullOrEmpty(this.CacheName)) { - try - { - var singlecache = this.HpcCacheClient.Caches.Get(this.ResourceGroupName, this.CacheName); - var singlecache_ip = this.HpcCacheClient.Caches.Get(this.ResourceGroupName, this.CacheName).MountAddresses; - Console.WriteLine(singlecache_ip); - this.WriteObject(new PSHPCCache(singlecache, singlecache_ip), true); - } - catch (CloudException ce) - { - if (ce.Response.StatusCode == HttpStatusCode.NotFound) - { - { - // throw new PSArgumentException(string.Format(ce.Message)); - } - } - throw; - } - } + var singleCache = this.HpcCacheClient.Caches.Get(this.ResourceGroupName, this.CacheName); + var singleCacheIp = this.HpcCacheClient.Caches.Get(this.ResourceGroupName, this.CacheName).MountAddresses; + this.WriteObject(new PSHPCCache(singleCache, singleCacheIp), true); + + } else { - try - { - var resourgeGroupCaches = this.HpcCacheClient.Caches.ListByResourceGroup(this.ResourceGroupName); - foreach(var cache in resourgeGroupCaches.Value) - { - this.WriteObject(new PSHPCCache(cache, cache.MountAddresses),true); - } - } - catch (CloudException ce) + var resourgeGroupCaches = this.HpcCacheClient.Caches.ListByResourceGroup(this.ResourceGroupName); + foreach(var cache in resourgeGroupCaches.Value) { - if (ce.Response.StatusCode == HttpStatusCode.NotFound) - { - // throw new PSArgumentException(string.Format(ce.Message)); - } - throw; + this.WriteObject(new PSHPCCache(cache, cache.MountAddresses),true); } } } else { - try + var allCaches = this.HpcCacheClient.Caches.List(); + foreach (var cache in allCaches.Value) { - var allCaches = this.HpcCacheClient.Caches.List(); - foreach (var cache in allCaches.Value) - { - this.WriteObject(new PSHPCCache(cache, cache.MountAddresses), true); - } - } - catch (CloudException ce) - { - if (ce.Response.StatusCode == HttpStatusCode.NotFound) - { - // throw new PSArgumentException(string.Format(ce.Message)); - } - - throw; + this.WriteObject(new PSHPCCache(cache, cache.MountAddresses), true); } } } diff --git a/src/StorageCache/HPCCache/Commands/GetAzHpcCacheSku.cs b/src/StorageCache/HPCCache/Commands/GetAzHpcCacheSku.cs index fb53d010afb8..f2b876a39d57 100644 --- a/src/StorageCache/HPCCache/Commands/GetAzHpcCacheSku.cs +++ b/src/StorageCache/HPCCache/Commands/GetAzHpcCacheSku.cs @@ -30,9 +30,9 @@ public class GetAzSku : HpcCacheBaseCmdlet public override void ExecuteCmdlet() { var resourceSkus = this.HpcCacheClient.Skus.List().Value; - foreach(var r in resourceSkus) + foreach(var sku in resourceSkus) { - WriteObject(new PSSku(r)); + WriteObject(new PSSku(sku)); } } } diff --git a/src/StorageCache/HPCCache/Commands/GetAzHpcCacheUsageModels.cs b/src/StorageCache/HPCCache/Commands/GetAzHpcCacheUsageModels.cs index a129c6f1bdca..c301283f6965 100644 --- a/src/StorageCache/HPCCache/Commands/GetAzHpcCacheUsageModels.cs +++ b/src/StorageCache/HPCCache/Commands/GetAzHpcCacheUsageModels.cs @@ -28,10 +28,10 @@ public class GetAzUsageModels : HpcCacheBaseCmdlet /// public override void ExecuteCmdlet() { - var usagemodellist = this.HpcCacheClient.UsageModels.List().Value; - foreach (var usagemodel in usagemodellist) + var usageModelList = this.HpcCacheClient.UsageModels.List().Value; + foreach (var usageModel in usageModelList) { - WriteObject(new PSHpcCacheUsageModels(usagemodel)); + WriteObject(new PSHpcCacheUsageModels(usageModel)); } } } diff --git a/src/StorageCache/HPCCache/Commands/NewAzHpcCache.cs b/src/StorageCache/HPCCache/Commands/NewAzHpcCache.cs index b6aa35377657..229aca997e9d 100644 --- a/src/StorageCache/HPCCache/Commands/NewAzHpcCache.cs +++ b/src/StorageCache/HPCCache/Commands/NewAzHpcCache.cs @@ -86,27 +86,12 @@ public override void ExecuteCmdlet() { try { - var cache_exists = this.HpcCacheClient.Caches.Get(this.ResourceGroupName, this.CacheName); - if (cache_exists != null) - { - throw new CloudException("Cache already exists"); - } + var cacheExists = this.HpcCacheClient.Caches.Get(this.ResourceGroupName, this.CacheName); + throw new CloudException(string.Format("Cache name {0} already exists", this.CacheName)); } catch (CloudErrorException ex) { - if (ex.Body.Error.Code == "NotFound" || ex.Message.Contains("NotFound")) - { - // cache does not exists so go ahead and create one - } - else if (ex.Body.Error.Code == "ResourceNotFound" || ex.Message.Contains("ResourceNotFound")) - { - // cache does not exists so go ahead and create one - } - else if (ex.Body.Error.Code == "ResourceGroupNotFound" || ex.Message.Contains("ResourceGroupNotFound")) - { - // resource group not found, let create throw error don't throw from here - } - else + if (ex.Body.Error.Code != "ResourceNotFound") { throw; } diff --git a/src/StorageCache/HPCCache/Commands/RemoveAzHpcCache.cs b/src/StorageCache/HPCCache/Commands/RemoveAzHpcCache.cs index fdc2c6497b79..18bbda4c6cea 100644 --- a/src/StorageCache/HPCCache/Commands/RemoveAzHpcCache.cs +++ b/src/StorageCache/HPCCache/Commands/RemoveAzHpcCache.cs @@ -45,7 +45,7 @@ public class RemoveAzHpcCache : HpcCacheBaseCmdlet /// /// Delete Force - always set to false. /// - [Parameter(Mandatory = false, HelpMessage = "Indicates that the cmdlet does not prompt you for confirmation. By default, this cmdlet prompts you to confirm that you want to delete the key vault.")] + [Parameter(Mandatory = false, HelpMessage = "Indicates that the cmdlet does not prompt you for confirmation. By default, this cmdlet prompts you to confirm that you want to delete the cache.")] public SwitchParameter Force { get; set; } /// diff --git a/src/StorageCache/HPCCache/Commands/UpdateAzHpcCache.cs b/src/StorageCache/HPCCache/Commands/UpdateAzHpcCache.cs index d46d71413df2..4aaa5ee29833 100644 --- a/src/StorageCache/HPCCache/Commands/UpdateAzHpcCache.cs +++ b/src/StorageCache/HPCCache/Commands/UpdateAzHpcCache.cs @@ -56,42 +56,18 @@ public class UpdateAzHpcCache : HpcCacheBaseCmdlet /// public override void ExecuteCmdlet() { - try + var cacheExists = this.HpcCacheClient.Caches.Get(this.ResourceGroupName, this.CacheName); + if (cacheExists != null) { - var cache_exists = this.HpcCacheClient.Caches.Get(this.ResourceGroupName, this.CacheName); - if (cache_exists != null) - { - var location = cache_exists.Location; - var cacheSize = cache_exists.CacheSizeGB; - var sku = cache_exists.Sku; - var subnet = cache_exists.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.CreateOrUpdate(this.ResourceGroupName, this.CacheName, cacheParameters); - this.WriteObject(new PSHPCCache(cache, cache.MountAddresses)); - } + 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.CreateOrUpdate(this.ResourceGroupName, this.CacheName, cacheParameters); + this.WriteObject(new PSHPCCache(cache, cache.MountAddresses)); } - catch (CloudErrorException ex) - { - if (ex.Body.Error.Code == "NotFound" || ex.Message.Contains("NotFound")) - { - throw new PSArgumentException(string.Format(ex.Message)); - - } - else if (ex.Body.Error.Code == "ResourceNotFound" || ex.Message.Contains("ResourceNotFound")) - { - throw new PSArgumentException(string.Format(ex.Message)); - } - else if (ex.Body.Error.Code == "ResourceGroupNotFound" || ex.Message.Contains("ResourceGroupNotFound")) - { - throw new PSArgumentException(string.Format(ex.Message)); - } - else - { - throw; - } - } - } } } \ No newline at end of file diff --git a/src/StorageCache/HPCCache/help/Get-AzHpcCacheSku.md b/src/StorageCache/HPCCache/help/Get-AzHpcCacheSku.md index 0626124a788b..88d998f48de6 100644 --- a/src/StorageCache/HPCCache/help/Get-AzHpcCacheSku.md +++ b/src/StorageCache/HPCCache/help/Get-AzHpcCacheSku.md @@ -8,7 +8,7 @@ schema: 2.0.0 # Get-AzHpcCacheSku ## SYNOPSIS -Gets all SKUs availble in subscription. +Gets all SKUs available in subscription. ## SYNTAX diff --git a/src/StorageCache/HPCCache/help/New-AzHpcCache.md b/src/StorageCache/HPCCache/help/New-AzHpcCache.md index fcdd7f21a0eb..205e1a662202 100644 --- a/src/StorageCache/HPCCache/help/New-AzHpcCache.md +++ b/src/StorageCache/HPCCache/help/New-AzHpcCache.md @@ -135,7 +135,7 @@ Accept wildcard characters: False ``` ### -Tag -The tags to associate with the Azure CDN profile. +The tags to associate with the HPC Cache. ```yaml Type: System.Collections.Hashtable diff --git a/src/StorageCache/HPCCache/help/Update-AzHpcCache.md b/src/StorageCache/HPCCache/help/Update-AzHpcCache.md index dbd961221881..098680822128 100644 --- a/src/StorageCache/HPCCache/help/Update-AzHpcCache.md +++ b/src/StorageCache/HPCCache/help/Update-AzHpcCache.md @@ -76,7 +76,7 @@ Accept wildcard characters: False ``` ### -Tag -The tags to associate with the Azure CDN profile. +The tags to associate with the Azure HPC Cache. ```yaml Type: System.Collections.Hashtable