Skip to content

Commit d88cd12

Browse files
committed
Made exception unwrapping more robust.
1 parent faec0ca commit d88cd12

File tree

5 files changed

+122
-48
lines changed

5 files changed

+122
-48
lines changed

src/ResourceManager/MachineLearningCompute/Commands.MachineLearningCompute.Test/ScenarioTests/MLCTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public MLCTests(ITestOutputHelper output)
1616
XunitTracingInterceptor.AddToContext(interceptor);
1717
}
1818

19+
/*
1920
[Fact]
2021
[Trait(Category.AcceptanceType, Category.CheckIn)]
2122
public void TestNewGetRemove()
@@ -36,5 +37,13 @@ public void TestUpdateSystemServices()
3637
{
3738
TestController.NewInstance.RunPsTest(this.interceptor, "Test-UpdateSystemServices");
3839
}
40+
*/
41+
42+
[Fact]
43+
[Trait(Category.AcceptanceType, Category.CheckIn)]
44+
public void TestSandbox()
45+
{
46+
TestController.NewInstance.RunPsTest(this.interceptor, "Test-Sandbox");
47+
}
3948
}
4049
}

src/ResourceManager/MachineLearningCompute/Commands.MachineLearningCompute.Test/ScenarioTests/MLCTests.ps1

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,38 @@ function Test-UpdateSystemServices
231231
## Cleanup
232232
TeardownTest $resourceGroupName
233233
}
234+
235+
<#
236+
.SYNOPSIS
237+
TODO: DELETE ME
238+
#>
239+
function Test-Sandbox
240+
{
241+
# Setup
242+
$resourceGroupName = "mlcrp-cmdlet-test-sandbox"
243+
$clusterName = "mlcrp-cmdlet-test-sandbox"
244+
245+
SetupTest $resourceGroupName
246+
247+
# Create the cluster
248+
$cluster = GetDefaultClusterProperties
249+
$result = New-AzureRmMlOpCluster -ResourceGroupName $resourceGroupName -Name $clusterName -ClusterType Local -Location "East US 2"
250+
251+
# Test for updates
252+
#$updateAvailability = Test-AzureRmMlOpClusterSystemServicesUpdateAvailability -ResourceGroupName $resourceGroupName -Name $clusterName
253+
# Assert-NotNull { $updateAvailability }
254+
255+
# Test for updates - pipelining
256+
257+
# Update the cluster
258+
#$updateResult = Update-AzureRmMlOpClusterSystemService -ResourceGroupName $resourceGroupName -Name $clusterName
259+
# Assert-True { $updateResult.UpdateStatus -eq "Succeeded" }
260+
#Assert-NotNull { $updateResult.UpdateStartedOn }
261+
#Assert-NotNull { $updateResult.UpdateCompletedOn }
262+
263+
#$updateAvailability = Test-AzureRmMlOpClusterSystemServicesUpdateAvailability -ResourceGroupName $resourceGroupName -Name $clusterName
264+
# Assert-True { $updateAvailability.UpdatesAvailable -eq "No" }
265+
266+
## Cleanup
267+
#TeardownTest $resourceGroupName
268+
}

src/ResourceManager/MachineLearningCompute/Commands.MachineLearningCompute/Cmdlets/MachineLearningComputeCmdletBase.cs

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
using Microsoft.Azure.Commands.Common.Authentication.Models;
1717
using Microsoft.Azure.Commands.ResourceManager.Common;
1818
using Microsoft.Azure.Management.MachineLearningCompute;
19+
using Microsoft.Azure.Management.MachineLearningCompute.Models;
1920
using Microsoft.Rest.Azure;
21+
using System;
2022

2123
namespace Microsoft.Azure.Commands.MachineLearningCompute.Cmdlets
2224
{
@@ -65,18 +67,55 @@ public IMachineLearningComputeManagementClient MachineLearningComputeManagementC
6567
}
6668
}
6769

68-
protected void HandleNestedExceptionMessages(CloudException e)
70+
protected void HandleNestedExceptionMessages(Exception e)
6971
{
70-
var exceptionDetails = e.Message + ".";
72+
var unwrappedException = e;
7173

72-
foreach (var err in e.Body.Details)
74+
// Try to get the details out of the exception
75+
try
7376
{
74-
exceptionDetails += " " + err.Message + ".";
77+
if (e is ErrorResponseWrapperException)
78+
{
79+
var wrappedException = e as ErrorResponseWrapperException;
80+
81+
if (wrappedException.Body != null && wrappedException.Body.Error != null)
82+
{
83+
var exceptionDetails = e.Message + ": " + wrappedException.Body.Error.Message;
84+
85+
if (wrappedException.Body.Error.Details != null)
86+
{
87+
foreach (var err in wrappedException.Body.Error.Details)
88+
{
89+
exceptionDetails += $" {err.Message};";
90+
}
91+
}
92+
93+
unwrappedException = new ErrorResponseWrapperException(exceptionDetails);
94+
}
95+
}
96+
else if(e is CloudException)
97+
{
98+
var cloudException = e as CloudException;
99+
var exceptionDetails = e.Message;
100+
101+
if (cloudException.Body != null && cloudException.Body.Details != null)
102+
{
103+
exceptionDetails += ":";
104+
foreach (var err in cloudException.Body.Details)
105+
{
106+
exceptionDetails += $" {err.Message};";
107+
}
108+
109+
unwrappedException = new CloudException(exceptionDetails);
110+
}
111+
}
112+
}
113+
catch (Exception) // If there's trouble throw the original exception
114+
{
115+
throw e;
75116
}
76117

77-
var newException = new CloudException(exceptionDetails);
78-
79-
throw newException;
118+
throw unwrappedException;
80119
}
81120
}
82121
}

src/ResourceManager/MachineLearningCompute/Commands.MachineLearningCompute/Cmdlets/NewAzureRmMlOpCluster.cs

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -149,73 +149,68 @@ public override void ExecuteCmdlet()
149149
{
150150
if (ShouldProcess(Name, @"Creating operationalization cluster..."))
151151
{
152-
// If we have an object, go ahead and create
152+
var cluster = new OperationalizationCluster();
153+
153154
if (string.Equals(this.ParameterSetName, CreateFromObjectParameterSet, StringComparison.OrdinalIgnoreCase))
154155
{
155-
var cluster = InputObject.ConvertToOperationalizationCluster();
156-
157-
WriteObject(new PSOperationalizationCluster(MachineLearningComputeManagementClient.OperationalizationClusters.CreateOrUpdate(ResourceGroupName, Name, cluster)));
156+
cluster = InputObject.ConvertToOperationalizationCluster();
158157
}
159-
160-
// If it's parameters create the cluster object and then create
161-
if (string.Equals(this.ParameterSetName, CreateFromCmdletParametersParameterSet, StringComparison.OrdinalIgnoreCase))
158+
else if (string.Equals(this.ParameterSetName, CreateFromCmdletParametersParameterSet, StringComparison.OrdinalIgnoreCase))
162159
{
163-
var newCluster = new OperationalizationCluster();
164-
165-
newCluster.Location = Location;
166-
newCluster.ClusterType = ClusterType;
167-
newCluster.Description = Description;
160+
cluster.Location = Location;
161+
cluster.ClusterType = ClusterType;
162+
cluster.Description = Description;
168163

169164
if (StorageAccount != null)
170165
{
171-
newCluster.StorageAccount = new StorageAccountProperties(StorageAccount);
166+
cluster.StorageAccount = new StorageAccountProperties(StorageAccount);
172167
}
173168

174169
if (AzureContainerRegistry != null)
175170
{
176-
newCluster.ContainerRegistry = new ContainerRegistryProperties(AzureContainerRegistry);
171+
cluster.ContainerRegistry = new ContainerRegistryProperties(AzureContainerRegistry);
177172
}
178173

179174
if (GlobalServiceConfigurationETag != null)
180175
{
181-
newCluster.GlobalServiceConfiguration = newCluster.GlobalServiceConfiguration ?? new GlobalServiceConfiguration();
182-
newCluster.GlobalServiceConfiguration.Etag = GlobalServiceConfigurationETag;
176+
cluster.GlobalServiceConfiguration = cluster.GlobalServiceConfiguration ?? new GlobalServiceConfiguration();
177+
cluster.GlobalServiceConfiguration.Etag = GlobalServiceConfigurationETag;
183178
}
184179

185180
if (GlobalServiceConfigurationAdditionalProperties != null)
186181
{
187-
newCluster.GlobalServiceConfiguration = newCluster.GlobalServiceConfiguration ?? new GlobalServiceConfiguration();
188-
newCluster.GlobalServiceConfiguration.AdditionalProperties = GlobalServiceConfigurationAdditionalProperties.Cast<DictionaryEntry>().ToDictionary(kvp => (string)kvp.Key, kvp => kvp.Value);
182+
cluster.GlobalServiceConfiguration = cluster.GlobalServiceConfiguration ?? new GlobalServiceConfiguration();
183+
cluster.GlobalServiceConfiguration.AdditionalProperties = GlobalServiceConfigurationAdditionalProperties.Cast<DictionaryEntry>().ToDictionary(kvp => (string)kvp.Key, kvp => kvp.Value);
189184
}
190185

191186
if (SslStatus != null)
192187
{
193-
newCluster.GlobalServiceConfiguration.Ssl = newCluster.GlobalServiceConfiguration.Ssl ?? new SslConfiguration();
194-
newCluster.GlobalServiceConfiguration.Ssl.Status = SslStatus;
188+
cluster.GlobalServiceConfiguration.Ssl = cluster.GlobalServiceConfiguration.Ssl ?? new SslConfiguration();
189+
cluster.GlobalServiceConfiguration.Ssl.Status = SslStatus;
195190
}
196191

197192
if (SslCertificate != null)
198193
{
199-
newCluster.GlobalServiceConfiguration.Ssl = newCluster.GlobalServiceConfiguration.Ssl ?? new SslConfiguration();
200-
newCluster.GlobalServiceConfiguration.Ssl.Cert = SslCertificate;
194+
cluster.GlobalServiceConfiguration.Ssl = cluster.GlobalServiceConfiguration.Ssl ?? new SslConfiguration();
195+
cluster.GlobalServiceConfiguration.Ssl.Cert = SslCertificate;
201196
}
202197

203198
if (SslKey != null)
204199
{
205-
newCluster.GlobalServiceConfiguration.Ssl = newCluster.GlobalServiceConfiguration.Ssl ?? new SslConfiguration();
206-
newCluster.GlobalServiceConfiguration.Ssl.Key = SslKey;
200+
cluster.GlobalServiceConfiguration.Ssl = cluster.GlobalServiceConfiguration.Ssl ?? new SslConfiguration();
201+
cluster.GlobalServiceConfiguration.Ssl.Key = SslKey;
207202
}
208203

209204
if (SslCName != null)
210205
{
211-
newCluster.GlobalServiceConfiguration.Ssl = newCluster.GlobalServiceConfiguration.Ssl ?? new SslConfiguration();
212-
newCluster.GlobalServiceConfiguration.Ssl.Cname = SslCName;
206+
cluster.GlobalServiceConfiguration.Ssl = cluster.GlobalServiceConfiguration.Ssl ?? new SslConfiguration();
207+
cluster.GlobalServiceConfiguration.Ssl.Cname = SslCName;
213208
}
214209

215210
switch (ClusterType)
216211
{
217212
case Management.MachineLearningCompute.Models.ClusterType.ACS:
218-
newCluster.ContainerService = new AcsClusterProperties
213+
cluster.ContainerService = new AcsClusterProperties
219214
{
220215
OrchestratorType = OrchestratorType,
221216
OrchestratorProperties = new KubernetesClusterProperties
@@ -239,14 +234,15 @@ public override void ExecuteCmdlet()
239234
break;
240235
}
241236

242-
try
243-
{
244-
WriteObject(new PSOperationalizationCluster(MachineLearningComputeManagementClient.OperationalizationClusters.CreateOrUpdate(ResourceGroupName, Name, newCluster)));
245-
}
246-
catch (CloudException e)
247-
{
248-
HandleNestedExceptionMessages(e);
249-
}
237+
}
238+
239+
try
240+
{
241+
WriteObject(new PSOperationalizationCluster(MachineLearningComputeManagementClient.OperationalizationClusters.CreateOrUpdate(ResourceGroupName, Name, cluster)));
242+
}
243+
catch (Exception e)
244+
{
245+
HandleNestedExceptionMessages(e);
250246
}
251247
}
252248
}

src/ResourceManager/MachineLearningCompute/Commands.MachineLearningCompute/Commands.MachineLearningCompute.csproj

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,6 @@
7676
<Reference Include="Microsoft.Azure.Management.MachineLearningCompute, Version=0.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
7777
<HintPath>..\..\..\packages\Microsoft.Azure.Management.MachineLearningCompute.0.1.0\lib\net452\Microsoft.Azure.Management.MachineLearningCompute.dll</HintPath>
7878
</Reference>
79-
<Reference Include="Microsoft.Rest.ClientRuntime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
80-
<Reference Include="Microsoft.Rest.ClientRuntime.Azure, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
81-
<Reference Include="Microsoft.Rest.ClientRuntime.Azure.Authentication, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
82-
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.Authentication.2.3.1\lib\net452\Microsoft.Rest.ClientRuntime.Azure.Authentication.dll</HintPath>
83-
</Reference>
84-
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL" />
8579
<Reference Include="System.Web" />
8680
<Reference Include="System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
8781
</ItemGroup>
@@ -94,6 +88,7 @@
9488
<Compile Include="Cmdlets\RemoveAzureRmMlOpCluster.cs" />
9589
<Compile Include="Cmdlets\UpdateAzureRmMlOpClusterSystemService.cs" />
9690
<Compile Include="Models\PSOperationalizationCluster.cs" />
91+
<Compile Include="Models\PSOperationalizationClusterCredential.cs" />
9792
<Compile Include="Properties\AssemblyInfo.cs" />
9893
<Compile Include="Resources.Designer.cs">
9994
<AutoGen>True</AutoGen>

0 commit comments

Comments
 (0)