|
| 1 | +using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; |
| 2 | +using Microsoft.Azure.Commands.Synapse.Common; |
| 3 | +using Microsoft.Azure.Commands.Synapse.Models; |
| 4 | +using Microsoft.Azure.Commands.Synapse.Properties; |
| 5 | +using Microsoft.Azure.Management.Internal.Resources.Utilities.Models; |
| 6 | +using Microsoft.WindowsAzure.Commands.Utilities.Common; |
| 7 | +using System.Management.Automation; |
| 8 | + |
| 9 | +namespace Microsoft.Azure.Commands.Synapse |
| 10 | +{ |
| 11 | + [Cmdlet(VerbsCommon.Remove, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + SynapseConstants.SynapsePrefix + SynapseConstants.SparkJobDefinition, |
| 12 | + DefaultParameterSetName = RemoveByName, SupportsShouldProcess = true)] |
| 13 | + [OutputType(typeof(bool))] |
| 14 | + public class RemoveAzureSynapseSparkJobDefinition : SynapseArtifactsCmdletBase |
| 15 | + { |
| 16 | + private const string RemoveByName = "RemoveByName"; |
| 17 | + private const string RemoveByObject = "RemoveByObject"; |
| 18 | + private const string RemoveByInputObject = "RemoveByInputObject"; |
| 19 | + |
| 20 | + [Parameter(ValueFromPipelineByPropertyName = false, ParameterSetName = RemoveByName, |
| 21 | + Mandatory = true, HelpMessage = HelpMessages.WorkspaceName)] |
| 22 | + [ResourceNameCompleter(ResourceTypes.Workspace, "ResourceGroupName")] |
| 23 | + [ValidateNotNullOrEmpty] |
| 24 | + public override string WorkspaceName { get; set; } |
| 25 | + |
| 26 | + [Parameter(ValueFromPipeline = true, ParameterSetName = RemoveByObject, |
| 27 | + Mandatory = true, HelpMessage = HelpMessages.WorkspaceObject)] |
| 28 | + [ValidateNotNull] |
| 29 | + public PSSynapseWorkspace WorkspaceObject { get; set; } |
| 30 | + |
| 31 | + [Parameter(ValueFromPipelineByPropertyName = false, ParameterSetName = RemoveByName, Mandatory = true, HelpMessage = HelpMessages.SparkJobDefinitionName)] |
| 32 | + [Parameter(ValueFromPipelineByPropertyName = false, ParameterSetName = RemoveByObject, Mandatory = true, HelpMessage = HelpMessages.SparkJobDefinitionName)] |
| 33 | + [ValidateNotNullOrEmpty] |
| 34 | + [Alias("SparkJobDefinitionName")] |
| 35 | + public string Name { get; set; } |
| 36 | + |
| 37 | + [Parameter(ValueFromPipeline = true, ParameterSetName = RemoveByInputObject, |
| 38 | + Mandatory = true, HelpMessage = HelpMessages.SparkJobDefinitionObject)] |
| 39 | + [ValidateNotNull] |
| 40 | + public PSSparkJobDefinitionResource InputObject { get; set; } |
| 41 | + |
| 42 | + [Parameter(Mandatory = false, HelpMessage = HelpMessages.PassThru)] |
| 43 | + public SwitchParameter PassThru { get; set; } |
| 44 | + |
| 45 | + [Parameter(Mandatory = false, HelpMessage = HelpMessages.AsJob)] |
| 46 | + public SwitchParameter AsJob { get; set; } |
| 47 | + |
| 48 | + [Parameter(Mandatory = false, HelpMessage = HelpMessages.Force)] |
| 49 | + public SwitchParameter Force { get; set; } |
| 50 | + |
| 51 | + public override void ExecuteCmdlet() |
| 52 | + { |
| 53 | + if (this.IsParameterBound(c => c.WorkspaceObject)) |
| 54 | + { |
| 55 | + this.WorkspaceName = this.WorkspaceObject.Name; |
| 56 | + } |
| 57 | + |
| 58 | + if (this.IsParameterBound(c => c.InputObject)) |
| 59 | + { |
| 60 | + var resourceIdentifier = new ResourceIdentifier(this.InputObject.Id); |
| 61 | + this.WorkspaceName = resourceIdentifier.ParentResource; |
| 62 | + this.WorkspaceName = this.WorkspaceName.Substring(this.WorkspaceName.LastIndexOf('/') + 1); |
| 63 | + this.Name = resourceIdentifier.ResourceName; |
| 64 | + } |
| 65 | + |
| 66 | + ConfirmAction( |
| 67 | + Force.IsPresent, |
| 68 | + string.Format(Resources.RemoveSynapseSparkJobDefinition, Name), |
| 69 | + string.Format(Resources.RemovingSynapseSparkJobDefinition, this.Name, this.WorkspaceName), |
| 70 | + Name, |
| 71 | + () => |
| 72 | + { |
| 73 | + SynapseAnalyticsClient.DeleteSparkJobDefinition(this.Name); |
| 74 | + if (PassThru) |
| 75 | + { |
| 76 | + WriteObject(true); |
| 77 | + } |
| 78 | + }); |
| 79 | + } |
| 80 | + } |
| 81 | +} |
0 commit comments