Skip to content

Commit 077168e

Browse files
authored
Merge pull request #3569 from hyonholee/dev
[AzureRT] Update validation messages for Move-Azure* cmdlets
2 parents 490f9c7 + ed2128b commit 077168e

File tree

11 files changed

+162
-138
lines changed

11 files changed

+162
-138
lines changed

src/ServiceManagement/Common/Commands.ScenarioTest/Resources/ServiceManagement/ServiceManagementTests.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ function Test-MigrationAbortAzureDeployment
674674
Get-AzureVM -ServiceName $svcName -Name $vmName;
675675

676676
$result = Move-AzureService -Validate -ServiceName $svcName -DeploymentName $svcName -CreateNewVirtualNetwork;
677-
Assert-AreEqual "Succeeded" $result.Result;
677+
Assert-True {$result.Result.Contains("Validation Passed.")}
678678
$vm = Get-AzureVM -ServiceName $svcName -Name $vmName;
679679

680680
Move-AzureService -Prepare -ServiceName $svcName -DeploymentName $svcName -CreateNewVirtualNetwork;
@@ -712,7 +712,7 @@ function Test-MigrationValidateAzureDeployment
712712
Get-AzureVM -ServiceName $svcName -Name $vmName;
713713

714714
$result = Move-AzureService -Validate -ServiceName $svcName -DeploymentName $svcName -CreateNewVirtualNetwork;
715-
Assert-AreNotEqual "Succeeded" $result.Result;
715+
Assert-True {$result.Result.Contains("Validation Failed.")}
716716
Assert-AreNotEqual 0 $result.ValidationMessages.Count;
717717
}
718718

@@ -766,7 +766,7 @@ function Test-MigrationAbortAzureVNet
766766
Get-AzureVNetSite;
767767

768768
$result = Move-AzureVirtualNetwork -Validate -VirtualNetworkName $vnetName;
769-
Assert-AreEqual "Succeeded" $result.Result;
769+
Assert-True {$result.Result.Contains("Validation Passed.")}
770770
Get-AzureVNetSite;
771771

772772
Move-AzureVirtualNetwork -Prepare -VirtualNetworkName $vnetName;
@@ -813,7 +813,7 @@ function Test-MigrationAbortAzureStorageAccount
813813

814814
# Test
815815
$result = Move-AzureStorageAccount -Validate -StorageAccountName $storageName;
816-
Assert-AreEqual "Succeeded" $result.Result;
816+
Assert-True {$result.Result.Contains("Validation Passed.")}
817817
Get-AzureStorageAccount -StorageAccountName $storageName;
818818

819819
Move-AzureStorageAccount -Prepare -StorageAccountName $storageName;

src/ServiceManagement/Compute/Commands.ServiceManagement/Commands.ServiceManagement.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,6 @@
286286
<Compile Include="Migration\MoveAzureNetworkResourceBase.cs" />
287287
<Compile Include="Migration\MoveAzureNetworkSecurityGroup.cs" />
288288
<Compile Include="Migration\MoveAzureStorageAccount.cs" />
289-
<Compile Include="Migration\MigrationValidateContext.cs" />
290289
<Compile Include="Migration\MoveAzureReservedIP.cs" />
291290
<Compile Include="Migration\MoveAzureRouteTable.cs" />
292291
<Compile Include="Migration\MoveAzureVirtualNetwork.cs" />

src/ServiceManagement/Compute/Commands.ServiceManagement/Migration/MigrationValidateContext.cs

Lines changed: 0 additions & 59 deletions
This file was deleted.

src/ServiceManagement/Compute/Commands.ServiceManagement/Migration/MoveAzureNetworkSecurityGroup.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using Microsoft.Azure;
16+
using Microsoft.WindowsAzure.Commands.ServiceManagement.Model;
1617
using Microsoft.WindowsAzure.Commands.ServiceManagement.Properties;
1718
using Microsoft.WindowsAzure.Management.Network;
1819
using System.Management.Automation;

src/ServiceManagement/Compute/Commands.ServiceManagement/Migration/MoveAzureReservedIP.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using Microsoft.Azure;
16+
using Microsoft.WindowsAzure.Commands.ServiceManagement.Model;
1617
using Microsoft.WindowsAzure.Commands.ServiceManagement.Properties;
1718
using Microsoft.WindowsAzure.Management.Network;
1819
using System.Management.Automation;

src/ServiceManagement/Compute/Commands.ServiceManagement/Migration/MoveAzureRouteTable.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using Microsoft.Azure;
16+
using Microsoft.WindowsAzure.Commands.ServiceManagement.Model;
1617
using Microsoft.WindowsAzure.Commands.ServiceManagement.Properties;
1718
using Microsoft.WindowsAzure.Management.Network;
1819
using System.Management.Automation;

src/ServiceManagement/Compute/Commands.ServiceManagement/Migration/MoveAzureService.cs

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ protected override void OnProcessRecord()
251251
() => this.ComputeClient.Deployments.ValidateMigration(this.ServiceName, DeploymentName, parameter),
252252
(operation, service) =>
253253
{
254-
var context = ConvertToContext(operation, service);
254+
var context = MigrationValidateContextHelper.ConvertToContext(operation, service);
255255
return context;
256256
});
257257
}
@@ -264,41 +264,5 @@ protected override void OnProcessRecord()
264264
}
265265
}
266266
}
267-
268-
private MigrationValidateContext ConvertToContext(
269-
OperationStatusResponse operationResponse, XrpMigrationValidateDeploymentResponse validationResponse)
270-
{
271-
if (operationResponse == null) return null;
272-
273-
var result = new MigrationValidateContext
274-
{
275-
OperationId = operationResponse.Id,
276-
Result = operationResponse.Status.ToString()
277-
};
278-
279-
if (validationResponse == null || validationResponse.ValidateDeploymentMessages == null) return result;
280-
281-
var errorCount = validationResponse.ValidateDeploymentMessages.Count;
282-
283-
if (errorCount > 0)
284-
{
285-
result.ValidationMessages = new ValidationMessage[errorCount];
286-
287-
for (int i = 0; i < errorCount; i++)
288-
{
289-
result.ValidationMessages[i] = new ValidationMessage
290-
{
291-
ResourceName = validationResponse.ValidateDeploymentMessages[i].ResourceName,
292-
ResourceType = validationResponse.ValidateDeploymentMessages[i].ResourceType,
293-
Category = validationResponse.ValidateDeploymentMessages[i].Category,
294-
Message = validationResponse.ValidateDeploymentMessages[i].Message,
295-
VirtualMachineName = validationResponse.ValidateDeploymentMessages[i].VirtualMachineName
296-
};
297-
}
298-
result.Result = "Validation failed. Please see ValidationMessages for details";
299-
}
300-
301-
return result;
302-
}
303267
}
304268
}

src/ServiceManagement/Compute/Commands.ServiceManagement/Migration/MoveAzureStorageAccount.cs

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ protected override void OnProcessRecord()
9999
() => this.StorageClient.StorageAccounts.ValidateMigration(this.StorageAccountName),
100100
(operation, service) =>
101101
{
102-
var context = ConvertToContext(operation, service);
102+
var context = MigrationValidateContextHelper.ConvertToContext(operation, service);
103103
return context;
104104
});
105105
}
@@ -125,41 +125,5 @@ protected override void OnProcessRecord()
125125
() => this.StorageClient.StorageAccounts.PrepareMigration(this.StorageAccountName));
126126
}
127127
}
128-
129-
private MigrationValidateContext ConvertToContext(
130-
OperationStatusResponse operationResponse, XrpMigrationValidateStorageResponse validationResponse)
131-
{
132-
if (operationResponse == null) return null;
133-
134-
var result = new MigrationValidateContext
135-
{
136-
OperationId = operationResponse.Id,
137-
Result = operationResponse.Status.ToString()
138-
};
139-
140-
if (validationResponse == null || validationResponse.ValidateStorageMessages == null) return result;
141-
142-
var errorCount = validationResponse.ValidateStorageMessages.Count;
143-
144-
if (errorCount > 0)
145-
{
146-
result.ValidationMessages = new ValidationMessage[errorCount];
147-
148-
for (int i = 0; i < errorCount; i++)
149-
{
150-
result.ValidationMessages[i] = new ValidationMessage
151-
{
152-
ResourceName = validationResponse.ValidateStorageMessages[i].ResourceName,
153-
ResourceType = validationResponse.ValidateStorageMessages[i].ResourceType,
154-
Category = validationResponse.ValidateStorageMessages[i].Category,
155-
Message = validationResponse.ValidateStorageMessages[i].Message,
156-
VirtualMachineName = validationResponse.ValidateStorageMessages[i].VirtualMachineName
157-
};
158-
}
159-
result.Result = "Validation failed. Please see ValidationMessages for details";
160-
}
161-
162-
return result;
163-
}
164128
}
165129
}

src/ServiceManagement/Compute/Commands.ServiceManagement/Migration/MoveAzureVirtualNetwork.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using Microsoft.Azure;
16+
using Microsoft.WindowsAzure.Commands.ServiceManagement.Model;
1617
using Microsoft.WindowsAzure.Commands.ServiceManagement.Properties;
1718
using Microsoft.WindowsAzure.Management.Network;
1819
using System.Management.Automation;

src/ServiceManagement/Compute/Commands.ServiceManagement/Model/MigrationValidateContext.cs

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414

1515
namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Model
1616
{
17+
using Microsoft.Azure;
18+
using Microsoft.WindowsAzure.Management.Compute.Models;
19+
using Microsoft.WindowsAzure.Management.Network.Models;
20+
using Microsoft.WindowsAzure.Management.Storage.Models;
21+
1722
public class MigrationValidateContext
1823
{
1924
public ValidationMessage [] ValidationMessages { get; set; }
@@ -29,4 +34,148 @@ public class ValidationMessage
2934
public string Message { get; set; }
3035
public string VirtualMachineName { get; set; }
3136
}
37+
38+
public class MigrationValidateContextHelper
39+
{
40+
public static MigrationValidateContext ConvertToContext(OperationStatusResponse operationResponse,
41+
XrpMigrationValidateDeploymentResponse validationResponse)
42+
{
43+
if (operationResponse == null) return null;
44+
45+
var result = new MigrationValidateContext();
46+
bool errorOccurred = false;
47+
bool warningOccurred = false;
48+
49+
if (validationResponse == null || validationResponse.ValidateDeploymentMessages == null)
50+
{
51+
return getResult(result, operationResponse, noMessage: true);
52+
};
53+
54+
int messageCount = validationResponse.ValidateDeploymentMessages.Count;
55+
result.ValidationMessages = new ValidationMessage[messageCount];
56+
for (int i = 0; i < messageCount; i++)
57+
{
58+
var validateMessage = validationResponse.ValidateDeploymentMessages[i];
59+
60+
result.ValidationMessages[i] = new ValidationMessage
61+
{
62+
ResourceName = validateMessage.ResourceName,
63+
ResourceType = validateMessage.ResourceType,
64+
Category = validateMessage.Category,
65+
Message = validateMessage.Message,
66+
VirtualMachineName = validateMessage.VirtualMachineName
67+
};
68+
69+
setFlag(validateMessage.Category, ref errorOccurred, ref warningOccurred);
70+
}
71+
72+
return getResult(result, operationResponse, errorOccurred, warningOccurred); ;
73+
}
74+
75+
public static MigrationValidateContext ConvertToContext(OperationStatusResponse operationResponse,
76+
NetworkMigrationValidationResponse validationResponse)
77+
{
78+
if (operationResponse == null) return null;
79+
80+
var result = new MigrationValidateContext();
81+
bool errorOccurred = false;
82+
bool warningOccurred = false;
83+
84+
if (validationResponse == null || validationResponse.ValidationMessages == null)
85+
{
86+
return getResult(result, operationResponse, noMessage: true);
87+
};
88+
89+
int messageCount = validationResponse.ValidationMessages.Count;
90+
result.ValidationMessages = new ValidationMessage[messageCount];
91+
for (int i = 0; i < messageCount; i++)
92+
{
93+
var validateMessage = validationResponse.ValidationMessages[i];
94+
95+
result.ValidationMessages[i] = new ValidationMessage
96+
{
97+
ResourceName = validateMessage.ResourceName,
98+
ResourceType = validateMessage.ResourceType,
99+
Category = validateMessage.Category,
100+
Message = validateMessage.Message,
101+
VirtualMachineName = validateMessage.VirtualMachineName
102+
};
103+
104+
setFlag(validateMessage.Category, ref errorOccurred, ref warningOccurred);
105+
}
106+
107+
return getResult(result, operationResponse, errorOccurred, warningOccurred); ;
108+
}
109+
110+
public static MigrationValidateContext ConvertToContext(OperationStatusResponse operationResponse,
111+
XrpMigrationValidateStorageResponse validationResponse)
112+
{
113+
if (operationResponse == null) return null;
114+
115+
var result = new MigrationValidateContext();
116+
bool errorOccurred = false;
117+
bool warningOccurred = false;
118+
119+
if (validationResponse == null || validationResponse.ValidateStorageMessages == null)
120+
{
121+
return getResult(result, operationResponse, noMessage:true);
122+
};
123+
124+
int messageCount = validationResponse.ValidateStorageMessages.Count;
125+
result.ValidationMessages = new ValidationMessage[messageCount];
126+
for (int i = 0; i < messageCount; i++)
127+
{
128+
var validateMessage = validationResponse.ValidateStorageMessages[i];
129+
130+
result.ValidationMessages[i] = new ValidationMessage
131+
{
132+
ResourceName = validateMessage.ResourceName,
133+
ResourceType = validateMessage.ResourceType,
134+
Category = validateMessage.Category,
135+
Message = validateMessage.Message,
136+
VirtualMachineName = validateMessage.VirtualMachineName
137+
};
138+
139+
setFlag(validateMessage.Category, ref errorOccurred, ref warningOccurred);
140+
}
141+
142+
return getResult(result, operationResponse, errorOccurred, warningOccurred);
143+
}
144+
145+
private static MigrationValidateContext getResult(MigrationValidateContext result, OperationStatusResponse operationResponse,
146+
bool errorOccurred = false, bool warningOccurred = false, bool noMessage = false)
147+
{
148+
result.OperationId = operationResponse.Id;
149+
150+
if (noMessage)
151+
{
152+
result.Result = "There are no ValidationMessages.";
153+
}
154+
else if (errorOccurred)
155+
{
156+
result.Result = "Validation Failed. Please see ValidationMessages object for additional details.";
157+
}
158+
else if (warningOccurred)
159+
{
160+
result.Result = "Validation Passed with warnings. Please see ValidationMessages object for a list of resources that will be migrated and additional detail on the warnings.";
161+
}
162+
else
163+
{
164+
result.Result = "Validation Passed. Please see ValidationMessages object for a list of resources that will be migrated.";
165+
}
166+
return result;
167+
}
168+
169+
private static void setFlag(string category, ref bool errorOccurred, ref bool warningOccurred)
170+
{
171+
if (category.Equals("Error", System.StringComparison.InvariantCultureIgnoreCase))
172+
{
173+
errorOccurred = true;
174+
}
175+
else if (category.Equals("Warning", System.StringComparison.InvariantCultureIgnoreCase))
176+
{
177+
warningOccurred = true;
178+
}
179+
}
180+
}
32181
}

0 commit comments

Comments
 (0)