From fe66efda908a93475a4d3ecb88b37947a2c35ca9 Mon Sep 17 00:00:00 2001 From: Dongwei Wang Date: Fri, 14 Aug 2020 01:14:02 -0700 Subject: [PATCH] [Synapse] - Support ShouldProcess for 3 cmdlets --- .../SparkJob/SubmitAzureSynapseSparkJob.cs | 9 ++-- .../StartAzureSynapseSparkSession.cs | 30 +++++++------ .../InvokeAzureSynapseSparkStatement.cs | 12 ++++-- .../Synapse/Properties/Resources.Designer.cs | 33 +++++++++------ src/Synapse/Synapse/Properties/Resources.resx | 15 ++++--- .../help/Invoke-AzSynapseSparkStatement.md | 42 ++++++++++++++++--- .../help/Start-AzSynapseSparkSession.md | 34 ++++++++++++++- .../Synapse/help/Submit-AzSynapseSparkJob.md | 34 ++++++++++++++- .../Exceptions/Az.Synapse/SignatureIssues.csv | 4 -- 9 files changed, 162 insertions(+), 51 deletions(-) delete mode 100644 tools/StaticAnalysis/Exceptions/Az.Synapse/SignatureIssues.csv diff --git a/src/Synapse/Synapse/Commands/DataPlaneCommands/SparkJob/SubmitAzureSynapseSparkJob.cs b/src/Synapse/Synapse/Commands/DataPlaneCommands/SparkJob/SubmitAzureSynapseSparkJob.cs index f93a9ea50941..5c3a0e7d96a9 100644 --- a/src/Synapse/Synapse/Commands/DataPlaneCommands/SparkJob/SubmitAzureSynapseSparkJob.cs +++ b/src/Synapse/Synapse/Commands/DataPlaneCommands/SparkJob/SubmitAzureSynapseSparkJob.cs @@ -14,7 +14,7 @@ namespace Microsoft.Azure.Commands.Synapse { - [Cmdlet(VerbsLifecycle.Submit, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + SynapseConstants.SynapsePrefix + SynapseConstants.SparkJob, DefaultParameterSetName = RunSparkJobParameterSetName)] + [Cmdlet(VerbsLifecycle.Submit, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + SynapseConstants.SynapsePrefix + SynapseConstants.SparkJob, DefaultParameterSetName = RunSparkJobParameterSetName, SupportsShouldProcess = true)] [OutputType(typeof(PSSynapseSparkJob))] public class SubmitAzureSynapseSparkJob : SynapseSparkCmdletBase { @@ -184,8 +184,11 @@ public override void ExecuteCmdlet() batchRequest.Configuration[SynapseConstants.SparkDotNetAssemblySearchPathsKey] = string.Join(",", paths); } - var jobInformation = SynapseAnalyticsClient.SubmitSparkBatchJob(batchRequest, waitForCompletion:false); - WriteObject(new PSSynapseSparkJob(jobInformation)); + if (this.ShouldProcess(this.SparkPoolName, string.Format(Resources.SubmittingSynapseSparkJob, this.SparkPoolName, this.WorkspaceName))) + { + var jobInformation = SynapseAnalyticsClient.SubmitSparkBatchJob(batchRequest, waitForCompletion: false); + WriteObject(new PSSynapseSparkJob(jobInformation)); + } } } } diff --git a/src/Synapse/Synapse/Commands/DataPlaneCommands/SparkSession/StartAzureSynapseSparkSession.cs b/src/Synapse/Synapse/Commands/DataPlaneCommands/SparkSession/StartAzureSynapseSparkSession.cs index 6dfd0989b536..57e6f4c905f1 100644 --- a/src/Synapse/Synapse/Commands/DataPlaneCommands/SparkSession/StartAzureSynapseSparkSession.cs +++ b/src/Synapse/Synapse/Commands/DataPlaneCommands/SparkSession/StartAzureSynapseSparkSession.cs @@ -2,6 +2,7 @@ using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; using Microsoft.Azure.Commands.Synapse.Common; using Microsoft.Azure.Commands.Synapse.Models; +using Microsoft.Azure.Commands.Synapse.Properties; using Microsoft.Azure.Management.Internal.Resources.Utilities.Models; using Microsoft.Azure.Management.Synapse.Models; using Microsoft.WindowsAzure.Commands.Utilities.Common; @@ -12,7 +13,7 @@ namespace Microsoft.Azure.Commands.Synapse { - [Cmdlet(VerbsLifecycle.Start, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + SynapseConstants.SynapsePrefix + SynapseConstants.SparkSession, DefaultParameterSetName = CreateByNameParameterSet)] + [Cmdlet(VerbsLifecycle.Start, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + SynapseConstants.SynapsePrefix + SynapseConstants.SparkSession, DefaultParameterSetName = CreateByNameParameterSet, SupportsShouldProcess = true)] [OutputType(typeof(PSSynapseSparkSession))] public class StartAzureSynapseSparkSession : SynapseSparkCmdletBase { @@ -101,20 +102,23 @@ public override void ExecuteCmdlet() ExecutorCount = this.ExecutorCount }; - var sparkSession = SynapseAnalyticsClient.CreateSparkSession(livyRequest, waitForCompletion:true); - - PSSynapseSparkSession psSparkSession = null; - if (this.IsParameterBound(c => c.Language)) - { - this.Language = LanguageType.Parse(this.Language); - psSparkSession = new PSSynapseSparkSession(this.Language, sparkSession); - } - else + if (this.ShouldProcess(this.SparkPoolName, string.Format(Resources.StartingSynapseSparkSession, this.SparkPoolName, this.WorkspaceName))) { - psSparkSession = new PSSynapseSparkSession(sparkSession); - } + var sparkSession = SynapseAnalyticsClient.CreateSparkSession(livyRequest, waitForCompletion: true); + + PSSynapseSparkSession psSparkSession = null; + if (this.IsParameterBound(c => c.Language)) + { + this.Language = LanguageType.Parse(this.Language); + psSparkSession = new PSSynapseSparkSession(this.Language, sparkSession); + } + else + { + psSparkSession = new PSSynapseSparkSession(sparkSession); + } - WriteObject(psSparkSession); + WriteObject(psSparkSession); + } } } } diff --git a/src/Synapse/Synapse/Commands/DataPlaneCommands/SparkStatement/InvokeAzureSynapseSparkStatement.cs b/src/Synapse/Synapse/Commands/DataPlaneCommands/SparkStatement/InvokeAzureSynapseSparkStatement.cs index 30ca2fa9f189..77dc2f7f27a4 100644 --- a/src/Synapse/Synapse/Commands/DataPlaneCommands/SparkStatement/InvokeAzureSynapseSparkStatement.cs +++ b/src/Synapse/Synapse/Commands/DataPlaneCommands/SparkStatement/InvokeAzureSynapseSparkStatement.cs @@ -2,12 +2,13 @@ using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; using Microsoft.Azure.Commands.Synapse.Common; using Microsoft.Azure.Commands.Synapse.Models; +using Microsoft.Azure.Commands.Synapse.Properties; using Microsoft.WindowsAzure.Commands.Utilities.Common; using System.Management.Automation; namespace Microsoft.Azure.Commands.Synapse { - [Cmdlet(VerbsLifecycle.Invoke, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + SynapseConstants.SynapsePrefix + SynapseConstants.SparkStatement, DefaultParameterSetName = RunSparkStatementByCodePathParameterSet)] + [Cmdlet(VerbsLifecycle.Invoke, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + SynapseConstants.SynapsePrefix + SynapseConstants.SparkStatement, DefaultParameterSetName = RunSparkStatementByCodePathParameterSet, SupportsShouldProcess = true)] [OutputType(typeof(PSSynapseExtendedSparkStatement))] public class InvokeAzureSynapseSparkStatement : SynapseSparkCmdletBase { @@ -105,9 +106,12 @@ public override void ExecuteCmdlet() Code = this.Code }; - var sessionStmt = SynapseAnalyticsClient.SubmitSparkSessionStatement(this.SessionId, livyRequest, waitForCompletion:true); - var psSessionStmt = new PSSynapseExtendedSparkStatement(sessionStmt); - WriteObject(psSessionStmt); + if (this.ShouldProcess(this.SparkPoolName, string.Format(Resources.InvokingSparkStatement, this.SparkPoolName, this.WorkspaceName))) + { + var sessionStmt = SynapseAnalyticsClient.SubmitSparkSessionStatement(this.SessionId, livyRequest, waitForCompletion:true); + var psSessionStmt = new PSSynapseExtendedSparkStatement(sessionStmt); + WriteObject(psSessionStmt); + } } } } diff --git a/src/Synapse/Synapse/Properties/Resources.Designer.cs b/src/Synapse/Synapse/Properties/Resources.Designer.cs index 66f0eedfe82e..0051358e26e2 100644 --- a/src/Synapse/Synapse/Properties/Resources.Designer.cs +++ b/src/Synapse/Synapse/Properties/Resources.Designer.cs @@ -339,15 +339,6 @@ internal static string FirewallRuleDoesNotExist { } } - /// - /// Looks up a localized string similar to InteractiveSparkSessionTips. - /// - internal static string InteractiveSparkSessionTips { - get { - return ResourceManager.GetString("InteractiveSparkSessionTips", resourceCulture); - } - } - /// /// Looks up a localized string similar to No default subscription has been designated. Use Select-AzSubscription -Default <subscriptionName> to set the default subscription.. /// @@ -384,6 +375,15 @@ internal static string InvalidStorageUri { } } + /// + /// Looks up a localized string similar to Invoking Spark statement in Spark pool '{0}' under workspace '{1}' .... + /// + internal static string InvokingSparkStatement { + get { + return ResourceManager.GetString("InvokingSparkStatement", resourceCulture); + } + } + /// /// Looks up a localized string similar to Cannot perform the requested operation because main class name or main executable file is not provided. Please specify -MainClassName for Spark job or -MainExecutableFile for .NET Spark job.. /// @@ -538,11 +538,11 @@ internal static string SqlPoolDoesNotExist { } /// - /// Looks up a localized string similar to {0} must be issued in interactive mode.. + /// Looks up a localized string similar to Starting Spark session in Spark pool '{0}' under workspace '{1}' .... /// - internal static string StartSparkSessionNonInteractiveMessage { + internal static string StartingSynapseSparkSession { get { - return ResourceManager.GetString("StartSparkSessionNonInteractiveMessage", resourceCulture); + return ResourceManager.GetString("StartingSynapseSparkSession", resourceCulture); } } @@ -573,6 +573,15 @@ internal static string StoppingSynapseSparkSession { } } + /// + /// Looks up a localized string similar to Submitting Spark job in Spark pool '{0}' under workspace '{1}' .... + /// + internal static string SubmittingSynapseSparkJob { + get { + return ResourceManager.GetString("SubmittingSynapseSparkJob", resourceCulture); + } + } + /// /// Looks up a localized string similar to Pausing SQL pool '{0}' in resource group '{1}' under workspace '{2}'.. /// diff --git a/src/Synapse/Synapse/Properties/Resources.resx b/src/Synapse/Synapse/Properties/Resources.resx index ed5a206c5d85..e89730abbe68 100644 --- a/src/Synapse/Synapse/Properties/Resources.resx +++ b/src/Synapse/Synapse/Properties/Resources.resx @@ -198,9 +198,6 @@ The file at path '{0}' does not exist or the current user does not have permission to it. Please ensure the path exists and is accessible. - - InteractiveSparkSessionTips - No default subscription has been designated. Use Select-AzSubscription -Default <subscriptionName> to set the default subscription. @@ -249,9 +246,6 @@ Cannot perform the requested operation because the specified SQL pool '{0}' does not exist. - - {0} must be issued in interactive mode. - Stopping Spark job with Id: '{0}' ... @@ -327,4 +321,13 @@ Updating SQL Database '{0}' in resource group '{1}' under Workspace '{2}'. + + Invoking Spark statement in Spark pool '{0}' under workspace '{1}' ... + + + Starting Spark session in Spark pool '{0}' under workspace '{1}' ... + + + Submitting Spark job in Spark pool '{0}' under workspace '{1}' ... + \ No newline at end of file diff --git a/src/Synapse/Synapse/help/Invoke-AzSynapseSparkStatement.md b/src/Synapse/Synapse/help/Invoke-AzSynapseSparkStatement.md index 4af890f1f6b0..06f46befe77c 100644 --- a/src/Synapse/Synapse/help/Invoke-AzSynapseSparkStatement.md +++ b/src/Synapse/Synapse/help/Invoke-AzSynapseSparkStatement.md @@ -16,26 +16,28 @@ Invokes a Synapse Analytics Spark statement. ``` Invoke-AzSynapseSparkStatement -WorkspaceName -SparkPoolName -Language -SessionId -FilePath [-Response] [-AsJob] [-DefaultProfile ] - [] + [-WhatIf] [-Confirm] [] ``` ### RunSparkStatementByCodeParameterSet ``` Invoke-AzSynapseSparkStatement -WorkspaceName -SparkPoolName -Language - -SessionId -Code [-Response] [-AsJob] [-DefaultProfile ] - [] + -SessionId -Code [-Response] [-AsJob] [-DefaultProfile ] [-WhatIf] + [-Confirm] [] ``` ### RunSparkStatementByCodeAndInputObjectParameterSet ``` Invoke-AzSynapseSparkStatement -Language -SessionObject [-SessionId ] - -Code [-Response] [-AsJob] [-DefaultProfile ] [] + -Code [-Response] [-AsJob] [-DefaultProfile ] [-WhatIf] [-Confirm] + [] ``` ### RunSparkStatementByCodePathAndInputObjectParameterSet ``` Invoke-AzSynapseSparkStatement -Language -SessionObject [-SessionId ] - -FilePath [-Response] [-AsJob] [-DefaultProfile ] [] + -FilePath [-Response] [-AsJob] [-DefaultProfile ] [-WhatIf] [-Confirm] + [] ``` ## DESCRIPTION @@ -250,6 +252,36 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: System.Management.Automation.SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. The cmdlet is not run. + +```yaml +Type: System.Management.Automation.SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/src/Synapse/Synapse/help/Start-AzSynapseSparkSession.md b/src/Synapse/Synapse/help/Start-AzSynapseSparkSession.md index 0090a3d1f4f3..74dce2557f41 100644 --- a/src/Synapse/Synapse/help/Start-AzSynapseSparkSession.md +++ b/src/Synapse/Synapse/help/Start-AzSynapseSparkSession.md @@ -16,14 +16,14 @@ Starts a Synapse Analytics Spark session. ``` Start-AzSynapseSparkSession -WorkspaceName -SparkPoolName [-Language ] -Name [-ReferenceFile ] -ExecutorCount -ExecutorSize [-Configuration ] - [-AsJob] [-DefaultProfile ] [] + [-AsJob] [-DefaultProfile ] [-WhatIf] [-Confirm] [] ``` ### CreateByParentObjectParameterSet ``` Start-AzSynapseSparkSession -SparkPoolObject [-Language ] -Name [-ReferenceFile ] -ExecutorCount -ExecutorSize [-Configuration ] - [-AsJob] [-DefaultProfile ] [] + [-AsJob] [-DefaultProfile ] [-WhatIf] [-Confirm] [] ``` ## DESCRIPTION @@ -215,6 +215,36 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: System.Management.Automation.SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. The cmdlet is not run. + +```yaml +Type: System.Management.Automation.SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/src/Synapse/Synapse/help/Submit-AzSynapseSparkJob.md b/src/Synapse/Synapse/help/Submit-AzSynapseSparkJob.md index 778fc0b17558..caa59dbee8e9 100644 --- a/src/Synapse/Synapse/help/Submit-AzSynapseSparkJob.md +++ b/src/Synapse/Synapse/help/Submit-AzSynapseSparkJob.md @@ -17,7 +17,7 @@ Submits a Synapse Analytics Spark job. Submit-AzSynapseSparkJob -WorkspaceName -SparkPoolName -Language -Name -MainDefinitionFile [-MainClassName ] [-CommandLineArgument ] [-ReferenceFile ] -ExecutorCount -ExecutorSize [-Configuration ] - [-DefaultProfile ] [] + [-DefaultProfile ] [-WhatIf] [-Confirm] [] ``` ### RunSparkJobByParentObjectParameterSet @@ -25,7 +25,7 @@ Submit-AzSynapseSparkJob -WorkspaceName -SparkPoolName -Langua Submit-AzSynapseSparkJob -SparkPoolObject -Language -Name -MainDefinitionFile [-MainClassName ] [-CommandLineArgument ] [-ReferenceFile ] -ExecutorCount -ExecutorSize [-Configuration ] - [-DefaultProfile ] [] + [-DefaultProfile ] [-WhatIf] [-Confirm] [] ``` ## DESCRIPTION @@ -258,6 +258,36 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: System.Management.Automation.SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. The cmdlet is not run. + +```yaml +Type: System.Management.Automation.SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/tools/StaticAnalysis/Exceptions/Az.Synapse/SignatureIssues.csv b/tools/StaticAnalysis/Exceptions/Az.Synapse/SignatureIssues.csv deleted file mode 100644 index 0b0da16160e8..000000000000 --- a/tools/StaticAnalysis/Exceptions/Az.Synapse/SignatureIssues.csv +++ /dev/null @@ -1,4 +0,0 @@ -"AssemblyFileName","ClassName","Target","Severity","ProblemId","Description","Remediation" -"D:\code\AzureSDK\azure-powershell\artifacts\Debug\Az.Synapse\Microsoft.Azure.PowerShell.Cmdlets.Synapse.dll","Microsoft.Azure.Commands.Synapse.SubmitAzureSynapseSparkJob","Submit-AzSynapseSparkJob","1","8100","Submit-AzSynapseSparkJob Does not support ShouldProcess but the cmdlet verb Submit indicates that it should.","Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue" -"D:\code\AzureSDK\azure-powershell\artifacts\Debug\Az.Synapse\Microsoft.Azure.PowerShell.Cmdlets.Synapse.dll","Microsoft.Azure.Commands.Synapse.StartAzureSynapseSparkSession","Start-AzSynapseSparkSession","1","8100","Start-AzSynapseSparkSession Does not support ShouldProcess but the cmdlet verb Start indicates that it should.","Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue" -"D:\code\AzureSDK\azure-powershell\artifacts\Debug\Az.Synapse\Microsoft.Azure.PowerShell.Cmdlets.Synapse.dll","Microsoft.Azure.Commands.Synapse.InvokeAzureSynapseSparkStatement","Invoke-AzSynapseSparkStatement","1","8100","Invoke-AzSynapseSparkStatement Does not support ShouldProcess but the cmdlet verb Invoke indicates that it should.","Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue"