Skip to content

Commit 32d2e39

Browse files
authored
Merge pull request #7947 from afedyashov/preview
Task 3229876: Fix Eval Tool output format suitable for WAC
2 parents ca535d9 + cdc536a commit 32d2e39

34 files changed

+683
-326
lines changed

src/ResourceManager/StorageSync/Commands.StorageSync/Az.StorageSync.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ RequiredModules = @(@{ModuleName = 'Az.Profile'; ModuleVersion = '0.7.0'; })
6363
# TypesToProcess = @()
6464

6565
# Format files (.ps1xml) to be loaded when importing this module
66-
# FormatsToProcess = ''
66+
FormatsToProcess = '.\Microsoft.Azure.Commands.StorageSync.Evaluation.format.ps1xml'
6767

6868
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
6969
NestedModules = @('.\Microsoft.Azure.Commands.StorageSync.dll')

src/ResourceManager/StorageSync/Commands.StorageSync/AzureRM.StorageSync.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ RequiredModules = @(@{ModuleName = 'AzureRM.Profile'; ModuleVersion = '5.8.2'; }
6363
# TypesToProcess = @()
6464

6565
# Format files (.ps1xml) to be loaded when importing this module
66-
# FormatsToProcess = @()
66+
FormatsToProcess = '.\Microsoft.Azure.Commands.StorageSync.Evaluation.format.ps1xml'
6767

6868
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
6969
NestedModules = @('.\Microsoft.Azure.Commands.StorageSync.dll')

src/ResourceManager/StorageSync/Commands.StorageSync/ChangeLog.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,8 @@
1818
- Additional information about change #1
1919
-->
2020

21-
## Current Release
21+
## Current Release
22+
* Fixed a typo in the progress message.
23+
* Introduced the following breaking changes in Invoke-AzureRmStorageSyncCompatibilityCheck cmdlet:
24+
- Parameter 'Quiet' had been removed.
25+
- Return type has changed from list of PSValidationResult to PSStorageSyncValidation. Validation results are now stored in PSStorageSyncValidation.Results member.

src/ResourceManager/StorageSync/Commands.StorageSync/Cmdlets/InvokeCompatibilityCheckCmdlet.cs

Lines changed: 19 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace Microsoft.Azure.Commands.StorageSync.Evaluation.Cmdlets
2626
using Models;
2727

2828
[Cmdlet("Invoke", Azure.Commands.ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "StorageSyncCompatibilityCheck",DefaultParameterSetName="PathBased")]
29-
[OutputType(typeof(PSValidationResult))]
29+
[OutputType(typeof(PSStorageSyncValidation))]
3030
public class InvokeCompatibilityCheckCmdlet : Cmdlet, ICmdlet
3131
{
3232
#region Fields and Properties
@@ -94,9 +94,6 @@ private string UserName
9494
[Parameter(ParameterSetName = "PathBased")]
9595
public SwitchParameter SkipNamespaceChecks { get; set; }
9696

97-
[Parameter]
98-
public SwitchParameter Quiet { get; set; }
99-
10097
private bool CanRunNamespaceChecks => !string.IsNullOrEmpty(this.Path);
10198
private bool CanRunEstimation => this.CanRunNamespaceChecks;
10299
private bool CanRunSystemChecks => !string.IsNullOrEmpty(this.ComputerNameValue.Value);
@@ -111,36 +108,17 @@ protected override void ProcessRecord()
111108
Configuration configuration = new Configuration();
112109

113110
// prepare namespace validations
114-
var namespaceValidations = new List<INamespaceValidation>()
115-
{
116-
new InvalidFilenameValidation(configuration),
117-
new FilenamesCharactersValidation(configuration),
118-
new MaximumFileSizeValidation(configuration),
119-
new MaximumPathLengthValidation(configuration),
120-
new MaximumFilenameLengthValidation(configuration),
121-
new MaximumTreeDepthValidation(configuration),
122-
new MaximumDatasetSizeValidation(configuration),
123-
};
111+
IList<INamespaceValidation> namespaceValidations = ValidationsFactory.GetNamespaceValidations(configuration);
124112

125113
// prepare system validations
126-
var systemValidations = new List<ISystemValidation>
127-
{
128-
new OSVersionValidation(configuration),
129-
};
130-
131-
if (this.CanRunNamespaceChecks)
132-
{
133-
systemValidations.Add(new FileSystemValidation(configuration, this.Path));
134-
}
135-
136-
// construct validation descriptions
137-
List<IValidationDescription> validationDescriptions = new List<IValidationDescription>();
138-
namespaceValidations.ForEach(o => validationDescriptions.Add((IValidationDescription)o));
139-
systemValidations.ForEach(o => validationDescriptions.Add((IValidationDescription)o));
114+
IList<ISystemValidation> systemValidations = ValidationsFactory.GetSystemValidations(configuration, this.Path);
140115

141116
// output writers
142-
TextSummaryOutputWriter summaryWriter = new TextSummaryOutputWriter(new AfsConsoleWriter(), validationDescriptions);
143-
PsObjectsOutputWriter psObjectsWriter = new PsObjectsOutputWriter(this);
117+
var validationResultWriter = new PSValidationResultOutputWriter();
118+
var outputWriters = new List<IOutputWriter>
119+
{
120+
validationResultWriter
121+
};
144122

145123
this.WriteVerbose($"Path = {this.Path}");
146124
this.WriteVerbose($"ComputerName = {this.ComputerName}");
@@ -150,7 +128,6 @@ protected override void ProcessRecord()
150128
this.WriteVerbose($"CanRunEstimation = {this.CanRunEstimation}");
151129
this.WriteVerbose($"SkipNamespaceChecks = {this.SkipNamespaceChecks}");
152130
this.WriteVerbose($"SkipSystemChecks = {this.SkipSystemChecks}");
153-
this.WriteVerbose($"Quiet = {this.Quiet}");
154131
this.WriteVerbose($"NumberOfSystemChecks = {systemValidations.Count}");
155132
this.WriteVerbose($"NumberOfNamespaceChecks = {namespaceValidations.Count}");
156133

@@ -202,7 +179,7 @@ protected override void ProcessRecord()
202179

203180
progressReporter.AddSteps(systemValidations.Count);
204181
Stopwatch stopwatch = Stopwatch.StartNew();
205-
this.PerformSystemChecks(systemValidations, progressReporter, this, summaryWriter, psObjectsWriter);
182+
this.PerformSystemChecks(systemValidations, progressReporter, this, outputWriters);
206183
stopwatch.Stop();
207184
progressReporter.Complete();
208185
TimeSpan duration = stopwatch.Elapsed;
@@ -223,7 +200,7 @@ protected override void ProcessRecord()
223200

224201
Stopwatch stopwatch = Stopwatch.StartNew();
225202
namespaceInfo = this.RunActionWithUncConnectionIfNeeded<INamespaceInfo>(
226-
() => this.StorageEval(namespaceValidations, progressReporter, this, summaryWriter, psObjectsWriter));
203+
() => this.StorageEval(namespaceValidations, progressReporter, this, outputWriters));
227204
stopwatch.Stop();
228205
progressReporter.Complete();
229206

@@ -237,19 +214,20 @@ protected override void ProcessRecord()
237214
this.WriteVerbose("Skipping namespace checks.");
238215
}
239216

240-
if (!this.Quiet.ToBool())
241-
{
242-
summaryWriter.WriteReport(this.ComputerNameValue.Value, namespaceInfo);
243-
}
244-
else
217+
var validationModel = validationResultWriter.Validation;
218+
validationModel.ComputerName = this.ComputerNameValue.Value;
219+
if (namespaceInfo != null)
245220
{
246-
this.WriteVerbose("Skipping report.");
221+
validationModel.NamespacePath = namespaceInfo.Path;
222+
validationModel.NamespaceDirectoryCount = namespaceInfo.NumberOfDirectories;
223+
validationModel.NamespaceFileCount = namespaceInfo.NumberOfFiles;
247224
}
225+
this.WriteObject(validationModel);
248226
}
249227
#endregion
250228

251229
#region Private methods
252-
private void PerformSystemChecks(IList<ISystemValidation> validations, IProgressReporter progressReporter, ICmdlet cmdlet, TextSummaryOutputWriter summaryWriter, PsObjectsOutputWriter psObjectsWriter)
230+
private void PerformSystemChecks(IList<ISystemValidation> validations, IProgressReporter progressReporter, ICmdlet cmdlet, IList<IOutputWriter> outputWriters)
253231
{
254232
PowerShellCommandRunner commandRunner = null;
255233

@@ -266,12 +244,6 @@ private void PerformSystemChecks(IList<ISystemValidation> validations, IProgress
266244
throw;
267245
}
268246

269-
var outputWriters = new List<IOutputWriter>
270-
{
271-
summaryWriter,
272-
psObjectsWriter
273-
};
274-
275247
SystemValidationsProcessor systemChecksProcessor = new SystemValidationsProcessor(commandRunner, validations, outputWriters, progressReporter);
276248

277249
systemChecksProcessor.Run();
@@ -305,16 +277,10 @@ private T RunActionWithUncConnectionIfNeeded<T>(Func<T> action)
305277
return result;
306278
}
307279

308-
private INamespaceInfo StorageEval(IList<INamespaceValidation> validations, IProgressReporter progressReporter, ICmdlet cmdlet, TextSummaryOutputWriter summaryWriter, PsObjectsOutputWriter psObjectsWriter)
280+
private INamespaceInfo StorageEval(IList<INamespaceValidation> validations, IProgressReporter progressReporter, ICmdlet cmdlet, IList<IOutputWriter> outputWriters)
309281
{
310282
IDirectoryInfo root = new AfsDirectoryInfo(this.Path);
311283

312-
var outputWriters = new List<IOutputWriter>
313-
{
314-
psObjectsWriter,
315-
summaryWriter
316-
};
317-
318284
NamespaceValidationsProcessor validationsProcessor = new NamespaceValidationsProcessor(validations, outputWriters, progressReporter);
319285

320286
List<INamespaceEnumeratorListener> namespaceEnumeratorListeners = new List<INamespaceEnumeratorListener>

src/ResourceManager/StorageSync/Commands.StorageSync/Commands.StorageSync.Netcore.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,10 @@
5353
<Content Include="help\**\*" CopyToOutputDirectory="PreserveNewest" />
5454
</ItemGroup>
5555

56+
<ItemGroup>
57+
<None Update="Microsoft.Azure.Commands.StorageSync.Evaluation.format.ps1xml">
58+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
59+
</None>
60+
</ItemGroup>
61+
5662
</Project>

src/ResourceManager/StorageSync/Commands.StorageSync/Commands.StorageSync.csproj

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,19 @@
6060
<Compile Include="AfsDirectoryInfo.cs" />
6161
<Compile Include="AfsFileInfo.cs" />
6262
<Compile Include="AfsNamedObjectInfo.cs" />
63+
<Compile Include="Formatting\StorageSyncValidationPowerShellFormatting.cs" />
6364
<Compile Include="Interfaces\IValidationDescription.cs" />
6465
<Compile Include="ListFiles.cs" />
66+
<Compile Include="Models\PSStorageSyncValidation.cs" />
67+
<Compile Include="OutputWriters\PSValidationResultOutputWriter.cs" />
6568
<Compile Include="Validations\BaseNamespaceValidation.cs" />
6669
<Compile Include="Cmdlets\InvokeCompatibilityCheckCmdlet.cs" />
6770
<Compile Include="Interfaces\INamespaceInfo.cs" />
6871
<Compile Include="Interfaces\IProgressReporter.cs" />
6972
<Compile Include="Models\PSValidationResult.cs" />
7073
<Compile Include="NamespaceInfo.cs" />
71-
<Compile Include="OutputWriters\AFSConsoleWriter.cs" />
7274
<Compile Include="Interfaces\ICmdlet.cs" />
73-
<Compile Include="Interfaces\IConsoleWriter.cs" />
7475
<Compile Include="Interfaces\IOutputWriter.cs" />
75-
<Compile Include="OutputWriters\PSObjectsOutputWriter.cs" />
76-
<Compile Include="OutputWriters\TextSummaryOutputWriter.cs" />
7776
<Compile Include="ProgressReporter.cs" />
7877
<Compile Include="Configuration.cs" />
7978
<Compile Include="Interfaces\IConfiguration.cs" />
@@ -104,13 +103,17 @@
104103
<Compile Include="Interfaces\ISystemValidation.cs" />
105104
<Compile Include="Validations\SystemValidations\OSVersionValidation.cs" />
106105
<Compile Include="Validations\ValidationResult.cs" />
106+
<Compile Include="Validations\ValidationsFactory.cs" />
107107
</ItemGroup>
108108
<ItemGroup>
109109
<None Include="debug.ps1" />
110110
<None Include="AzureRM.StorageSync.psd1">
111111
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
112112
</None>
113113
<EmbeddedResource Include="Config.json" />
114+
<None Include="Microsoft.Azure.Commands.StorageSync.Evaluation.format.ps1xml">
115+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
116+
</None>
114117
</ItemGroup>
115118
<ItemGroup>
116119
<ProjectReference Include="..\..\Profile\Commands.Profile\Commands.Profile.csproj">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
namespace Microsoft.Azure.Commands.StorageSync.Evaluation
16+
{
17+
using System.Collections.Generic;
18+
using System.Text;
19+
using System.Linq;
20+
21+
using Microsoft.Azure.Commands.StorageSync.Evaluation.Models;
22+
using Microsoft.Azure.Commands.StorageSync.Evaluation.Interfaces;
23+
24+
public static class StorageSyncValidationPowerShellFormatting
25+
{
26+
#region Public methods
27+
28+
public static string Format(PSStorageSyncValidation validation, int depth = 0)
29+
{
30+
Configuration configuration = new Configuration();
31+
StringBuilder output = new StringBuilder();
32+
33+
var validationTypeDescriptions = new Dictionary<string, string>();
34+
foreach (IValidationDescription validationDescription in ValidationsFactory.GetValidationDescriptions(configuration))
35+
{
36+
validationTypeDescriptions[validationDescription.ValidationType.ToString()] = validationDescription.DisplayName;
37+
}
38+
39+
var systemValidationResults = validation.Results.Where(o => o.Kind == PSValidationKind.SystemValidation).ToList();
40+
41+
if (systemValidationResults.Any())
42+
{
43+
output.AppendLine(" ");
44+
output.AppendLine("Environment validation results:");
45+
output.AppendLine(" ");
46+
output.AppendLine($"Computer name: {validation.ComputerName}");
47+
foreach (PSValidationResult validatonResult in systemValidationResults)
48+
{
49+
string result = validatonResult.Level == PSResultLevel.Error ? "Failed" : (validatonResult.Level == PSResultLevel.Warning ? "Warning" : "Passed");
50+
string displayName;
51+
string description = validationTypeDescriptions.TryGetValue(validatonResult.Type.ToString(), out displayName) ? displayName : validatonResult.Type.ToString();
52+
output.AppendLine($"{description}: {result}.");
53+
}
54+
}
55+
56+
if (!string.IsNullOrEmpty(validation.NamespacePath))
57+
{
58+
var namespaceValidationResults = validation.Results.Where(o => o.Kind == PSValidationKind.NamespaceValidation).ToList();
59+
var validationErrorsHistogram = new Dictionary<PSValidationType, long>();
60+
foreach (PSValidationResult validationResult in namespaceValidationResults.Where(o => o.Level == PSResultLevel.Error))
61+
{
62+
if (!validationErrorsHistogram.ContainsKey(validationResult.Type))
63+
{
64+
validationErrorsHistogram[validationResult.Type] = 0;
65+
}
66+
validationErrorsHistogram[validationResult.Type] += 1;
67+
}
68+
69+
output.AppendLine(" ");
70+
output.AppendLine("Namespace validation results:");
71+
output.AppendLine(" ");
72+
output.AppendLine($"Path: {validation.NamespacePath}");
73+
output.AppendLine($"Number of files scanned: {validation.NamespaceFileCount}");
74+
output.AppendLine($"Number of directories scanned: {validation.NamespaceDirectoryCount}");
75+
output.AppendLine(" ");
76+
if (!validationErrorsHistogram.Any())
77+
{
78+
output.AppendLine("There were no compatibility issues found with your files.");
79+
}
80+
else
81+
{
82+
output.AppendLine("The following compatibility issues were found:");
83+
output.AppendLine("");
84+
foreach (KeyValuePair<PSValidationType, long> entry in validationErrorsHistogram)
85+
{
86+
string displayName;
87+
string description = validationTypeDescriptions.TryGetValue(entry.Key.ToString(), out displayName) ? displayName : entry.Key.ToString();
88+
output.AppendLine($"{description}: {entry.Value}");
89+
}
90+
}
91+
}
92+
93+
return output.ToString();
94+
}
95+
#endregion
96+
}
97+
}

src/ResourceManager/StorageSync/Commands.StorageSync/Interfaces/IConsoleWriter.cs

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

src/ResourceManager/StorageSync/Commands.StorageSync/Interfaces/IValidationResult.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace Microsoft.Azure.Commands.StorageSync.Evaluation.Interfaces
1919

2020
public interface IValidationResult
2121
{
22+
ValidationKind Kind { get; }
2223
ValidationType Type { get; }
2324
ResultLevel Level { get; }
2425
List<int> Positions { get; }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<Configuration>
3+
<ViewDefinitions>
4+
<View>
5+
<Name>Microsoft.Azure.Commands.StorageSync.Evaluation.Models.PSStorageSyncValidation</Name>
6+
<ViewSelectedBy>
7+
<TypeName>Microsoft.Azure.Commands.StorageSync.Evaluation.Models.PSStorageSyncValidation</TypeName>
8+
</ViewSelectedBy>
9+
<CustomControl>
10+
<CustomEntries>
11+
<CustomEntry>
12+
<CustomItem>
13+
<ExpressionBinding>
14+
<ScriptBlock>
15+
[Microsoft.Azure.Commands.StorageSync.Evaluation.StorageSyncValidationPowerShellFormatting]::Format($_, 0)
16+
</ScriptBlock>
17+
</ExpressionBinding>
18+
</CustomItem>
19+
</CustomEntry>
20+
</CustomEntries>
21+
</CustomControl>
22+
</View>
23+
</ViewDefinitions>
24+
</Configuration>

0 commit comments

Comments
 (0)