Skip to content

Commit

Permalink
Changes made for code review
Browse files Browse the repository at this point in the history
  • Loading branch information
rebecca-makar committed Feb 14, 2020
1 parent beaae64 commit 2888c33
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 108 deletions.
58 changes: 11 additions & 47 deletions src/StorageCache/HPCCache/Commands/GetAzHpcCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/StorageCache/HPCCache/Commands/GetAzHpcCacheSku.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public class GetAzUsageModels : HpcCacheBaseCmdlet
/// </summary>
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));
}
}
}
Expand Down
21 changes: 3 additions & 18 deletions src/StorageCache/HPCCache/Commands/NewAzHpcCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/StorageCache/HPCCache/Commands/RemoveAzHpcCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class RemoveAzHpcCache : HpcCacheBaseCmdlet
/// <summary>
/// Delete Force - always set to false.
/// </summary>
[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; }

/// <summary>
Expand Down
44 changes: 10 additions & 34 deletions src/StorageCache/HPCCache/Commands/UpdateAzHpcCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,42 +56,18 @@ public class UpdateAzHpcCache : HpcCacheBaseCmdlet
/// </summary>
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;
}
}

}
}
}
2 changes: 1 addition & 1 deletion src/StorageCache/HPCCache/help/Get-AzHpcCacheSku.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ schema: 2.0.0
# Get-AzHpcCacheSku

## SYNOPSIS
Gets all SKUs availble in subscription.
Gets all SKUs available in subscription.

## SYNTAX

Expand Down
2 changes: 1 addition & 1 deletion src/StorageCache/HPCCache/help/New-AzHpcCache.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/StorageCache/HPCCache/help/Update-AzHpcCache.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2888c33

Please sign in to comment.