Skip to content

Commit 5043733

Browse files
author
begoldsm
committed
Updates based on PR feedback for ADL
1. Move all logging related logic into the logger constructor and dispose() methods to reduce duplication 2. Add parameter sets for diagnostic logging and make the log path required. Also update the default log level to be Error (the least verbose logging that actually logs, since None does not log). 3. Updated help to reflect these changes. 4. Removed parameter sets from passthru.
1 parent 6131ba9 commit 5043733

9 files changed

+399
-127
lines changed

src/ResourceManager/DataLakeStore/Commands.DataLakeStore/Commands/ExportAzureRmDataLakeStoreItem.cs

Lines changed: 55 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,85 +12,119 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using System.IO;
1615
using Microsoft.Azure.Commands.DataLakeStore.Models;
1716
using Microsoft.Azure.Commands.DataLakeStore.Properties;
1817
using Microsoft.Azure.Management.DataLake.Store.Models;
1918
using Microsoft.Rest.Azure;
20-
using System;
2119
using System.Management.Automation;
22-
using System.Net;
23-
using Microsoft.Rest;
2420
using Microsoft.IdentityModel.Clients.ActiveDirectory;
2521

2622
namespace Microsoft.Azure.Commands.DataLakeStore
2723
{
28-
[Cmdlet(VerbsData.Export, "AzureRmDataLakeStoreItem", SupportsShouldProcess = true), OutputType(typeof(string))]
24+
[Cmdlet(VerbsData.Export, "AzureRmDataLakeStoreItem", SupportsShouldProcess = true, DefaultParameterSetName = BaseParameterSetName), OutputType(typeof(string))]
2925
[Alias("Export-AdlStoreItem")]
3026
public class ExportAzureDataLakeStoreItem : DataLakeStoreFileSystemCmdletBase
3127
{
28+
// define parameter sets.
29+
internal const string BaseParameterSetName = "No diagnostic logging";
30+
internal const string DiagnosticParameterSetName = "Include diagnostic logging";
31+
3232
// default number of threads
3333
private int numThreadsPerFile = 10;
3434
private int fileCount = 5;
35-
private LogLevel logLevel = LogLevel.None;
35+
private LogLevel logLevel = LogLevel.Error;
3636

3737
[Parameter(ValueFromPipelineByPropertyName = true, Position = 0, Mandatory = true,
38-
HelpMessage = "The DataLakeStore account to execute the filesystem operation in")]
38+
HelpMessage = "The DataLakeStore account to execute the filesystem operation in",
39+
ParameterSetName = BaseParameterSetName)]
40+
[Parameter(ValueFromPipelineByPropertyName = true, Position = 0, Mandatory = true,
41+
HelpMessage = "The DataLakeStore account to execute the filesystem operation in",
42+
ParameterSetName = DiagnosticParameterSetName)]
3943
[ValidateNotNullOrEmpty]
4044
[Alias("AccountName")]
4145
public string Account { get; set; }
4246

4347
[Parameter(ValueFromPipelineByPropertyName = true, Position = 1, Mandatory = true,
44-
HelpMessage = "The path to the file or folder to download")]
48+
HelpMessage = "The path to the file or folder to download",
49+
ParameterSetName = BaseParameterSetName)]
50+
[Parameter(ValueFromPipelineByPropertyName = true, Position = 1, Mandatory = true,
51+
HelpMessage = "The path to the file or folder to download",
52+
ParameterSetName = DiagnosticParameterSetName)]
4553
[ValidateNotNull]
4654
public DataLakeStorePathInstance Path { get; set; }
4755

4856
[Parameter(ValueFromPipelineByPropertyName = true, Position = 2, Mandatory = true,
49-
HelpMessage = "The local path to download the file or folder to")]
57+
HelpMessage = "The local path to download the file or folder to",
58+
ParameterSetName = BaseParameterSetName)]
59+
[Parameter(ValueFromPipelineByPropertyName = true, Position = 2, Mandatory = true,
60+
HelpMessage = "The local path to download the file or folder to",
61+
ParameterSetName = DiagnosticParameterSetName)]
5062
[ValidateNotNullOrEmpty]
5163
public string Destination { get; set; }
5264

5365
[Parameter(ValueFromPipelineByPropertyName = true, Position = 3, Mandatory = false,
54-
HelpMessage = "Indicates if the download should be recursive for folder downloads. The default is false.")]
66+
HelpMessage = "Indicates if the download should be recursive for folder downloads. The default is false.",
67+
ParameterSetName = BaseParameterSetName)]
68+
[Parameter(ValueFromPipelineByPropertyName = true, Position = 3, Mandatory = false,
69+
HelpMessage = "Indicates if the download should be recursive for folder downloads. The default is false.",
70+
ParameterSetName = DiagnosticParameterSetName)]
5571
[ValidateNotNullOrEmpty]
5672
public SwitchParameter Recurse { get; set; }
5773

5874
[Parameter(ValueFromPipelineByPropertyName = true, Position = 4, Mandatory = false,
5975
HelpMessage =
60-
"Indicates that the file(s) being copied are a continuation of a previous download. This will cause the system to attempt to resume from the last file that was not fully downloaded."
61-
)]
76+
"Indicates that the file(s) being copied are a continuation of a previous download. This will cause the system to attempt to resume from the last file that was not fully downloaded.",
77+
ParameterSetName = BaseParameterSetName)]
78+
[Parameter(ValueFromPipelineByPropertyName = true, Position = 4, Mandatory = false,
79+
HelpMessage =
80+
"Indicates that the file(s) being copied are a continuation of a previous download. This will cause the system to attempt to resume from the last file that was not fully downloaded.",
81+
ParameterSetName = DiagnosticParameterSetName)]
6282
public SwitchParameter Resume { get; set; }
6383

6484
[Parameter(ValueFromPipelineByPropertyName = true, Position = 5, Mandatory = false,
65-
HelpMessage = "Indicates the maximum number of threads to use per file. Default is 10")]
85+
HelpMessage = "Indicates the maximum number of threads to use per file. Default is 10",
86+
ParameterSetName = BaseParameterSetName)]
87+
[Parameter(ValueFromPipelineByPropertyName = true, Position = 5, Mandatory = false,
88+
HelpMessage = "Indicates the maximum number of threads to use per file. Default is 10",
89+
ParameterSetName = DiagnosticParameterSetName)]
6690
public int PerFileThreadCount
6791
{
6892
get { return numThreadsPerFile; }
6993
set { numThreadsPerFile = value; }
7094
}
7195

7296
[Parameter(ValueFromPipelineByPropertyName = true, Position = 6, Mandatory = false,
73-
HelpMessage = "Indicates the maximum number of files to download in parallel for a folder download. Default is 5")]
97+
HelpMessage = "Indicates the maximum number of files to download in parallel for a folder download. Default is 5",
98+
ParameterSetName = BaseParameterSetName)]
99+
[Parameter(ValueFromPipelineByPropertyName = true, Position = 6, Mandatory = false,
100+
HelpMessage = "Indicates the maximum number of files to download in parallel for a folder download. Default is 5",
101+
ParameterSetName = DiagnosticParameterSetName)]
74102
public int ConcurrentFileCount
75103
{
76104
get { return fileCount; }
77105
set { fileCount = value; }
78106
}
79107

80108
[Parameter(ValueFromPipelineByPropertyName = true, Position = 7, Mandatory = false,
81-
HelpMessage = "Indicates that, if the file or folder exists, it should be overwritten")]
109+
HelpMessage = "Indicates that, if the file or folder exists, it should be overwritten",
110+
ParameterSetName = BaseParameterSetName)]
111+
[Parameter(ValueFromPipelineByPropertyName = true, Position = 7, Mandatory = false,
112+
HelpMessage = "Indicates that, if the file or folder exists, it should be overwritten",
113+
ParameterSetName = DiagnosticParameterSetName)]
82114
public SwitchParameter Force { get; set; }
83115

84116
[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = false,
85-
HelpMessage = "Optionally indicates the diagnostic log level to use to record events during the file or folder import. Default is none, and specifying -Debug overwrites this value and sets it to Debug.")]
117+
HelpMessage = "Optionally indicates the diagnostic log level to use to record events during the file or folder import. Default is Error.",
118+
ParameterSetName = DiagnosticParameterSetName)]
86119
public LogLevel DiagnosticLogLevel
87120
{
88121
get { return logLevel; }
89122
set { logLevel = value; }
90123
}
91124

92-
[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = false,
93-
HelpMessage = "Optionally specifies the path for the diagnostic log to record events to during the file or folder import. If logging is enabled, the default is in %LOCALAPPDATA%\\ADLDataTransfer.")]
125+
[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true,
126+
HelpMessage = "Specifies the path for the diagnostic log to record events to during the file or folder import.",
127+
ParameterSetName = DiagnosticParameterSetName)]
94128
[ValidateNotNullOrEmpty]
95129
public string DiagnosticLogPath { get; set; }
96130

@@ -99,11 +133,6 @@ public override void ExecuteCmdlet()
99133
// We will let this throw itself if the path they give us is invalid
100134
// TODO: perhaps in the future catch this and throw a cmdlet specific exception
101135
var powerShellReadyPath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(Destination);
102-
string diagnosticPath = string.Empty;
103-
if (!string.IsNullOrEmpty(DiagnosticLogPath))
104-
{
105-
diagnosticPath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(DiagnosticLogPath);
106-
}
107136

108137
FileType type;
109138
ConfirmAction(
@@ -121,22 +150,12 @@ public override void ExecuteCmdlet()
121150
var originalLegacyLevel = AdalTrace.LegacyTraceSwitch.Level;
122151
try
123152
{
124-
if (DiagnosticLogLevel != LogLevel.None)
153+
if (ParameterSetName.Equals(DiagnosticParameterSetName) && DiagnosticLogLevel != LogLevel.None)
125154
{
155+
var diagnosticPath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(DiagnosticLogPath);
126156
logger = new DataLakeStoreTraceLogger(this, diagnosticPath, DiagnosticLogLevel);
127-
if (logger.SdkTracingInterceptor != null)
128-
{
129-
ServiceClientTracing.AddTracingInterceptor(logger.SdkTracingInterceptor);
130-
}
131-
132-
// only log all ADAL messages when the level is debug.
133-
// In all other cases only log Warning and above.
134-
if (DiagnosticLogLevel != LogLevel.Debug)
135-
{
136-
AdalTrace.TraceSource.Switch.Level = System.Diagnostics.SourceLevels.Warning;
137-
AdalTrace.LegacyTraceSwitch.Level = System.Diagnostics.TraceLevel.Warning;
138-
}
139157
}
158+
140159
if (type == FileType.FILE)
141160
{
142161
DataLakeStoreFileSystemClient.CopyFile(powerShellReadyPath, Account, Path.TransformedPath, CmdletCancellationToken,
@@ -156,18 +175,10 @@ public override void ExecuteCmdlet()
156175
{
157176
if (logger != null)
158177
{
159-
if (logger.SdkTracingInterceptor != null)
160-
{
161-
ServiceClientTracing.RemoveTracingInterceptor(logger.SdkTracingInterceptor);
162-
}
163-
164178
// dispose and free the logger.
165179
logger.Dispose();
166180
logger = null;
167181
}
168-
169-
AdalTrace.TraceSource.Switch.Level = originalLevel;
170-
AdalTrace.LegacyTraceSwitch.Level = originalLegacyLevel;
171182
}
172183
});
173184
}

0 commit comments

Comments
 (0)