Skip to content

[Synapse] - Support polling for artifacts cmdlets #13701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Synapse/Synapse/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
- Add `Get-AzSynapseSqlPoolTransparentDataEncryption` cmdlet
- Add `Set-AzSynapseSqlPoolTransparentDataEncryption` cmdlet
* Fixed deserialization error when create Pipeline/Dataset/Trigger through DefinitionFile
* Added polling for artifacts cmdlets

## Version 0.5.0
* Added support for operation of Synapse SQL Pool Restore Point
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public override void ExecuteCmdlet()

if (this.ShouldProcess(this.Name, String.Format(Resources.AddingSynapseTriggerSubscribe, this.Name)))
{
WriteObject(new PSTriggerSubscriptionOperationStatus(SynapseAnalyticsClient.StartSubscribeTriggerToEvents(this.Name)));
WriteObject(new PSTriggerSubscriptionOperationStatus(SynapseAnalyticsClient.SubscribeTriggerToEvents(this.Name)));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public override void ExecuteCmdlet()
Name,
() =>
{
SynapseAnalyticsClient.StartUnsubscribeTriggerFromEvents(this.Name);
SynapseAnalyticsClient.UnsubscribeTriggerFromEvents(this.Name);
if (PassThru)
{
WriteObject(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public override void ExecuteCmdlet()

if (this.ShouldProcess(this.Name, String.Format(Resources.StartingSynapseTrigger, this.Name, this.WorkspaceName)))
{
SynapseAnalyticsClient.StartStartTrigger(this.Name);
SynapseAnalyticsClient.StartTrigger(this.Name);
if (PassThru)
{
WriteObject(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public override void ExecuteCmdlet()

if (this.ShouldProcess(this.Name, String.Format(Resources.StoppingSynapseTrigger, this.Name, this.WorkspaceName)))
{
SynapseAnalyticsClient.StartStopTrigger(this.Name);
SynapseAnalyticsClient.StopTrigger(this.Name);
if (PassThru)
{
WriteObject(true);
Expand Down
15 changes: 13 additions & 2 deletions src/Synapse/Synapse/Common/Utils.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Azure.Commands.Common.Authentication;
using Azure;
using Microsoft.Azure.Commands.Common.Authentication;
using Microsoft.Azure.Commands.Synapse.Models;
using Microsoft.Azure.Commands.Synapse.Models.Exceptions;
using Microsoft.Azure.Commands.Synapse.Properties;
Expand All @@ -9,7 +10,6 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Text.RegularExpressions;

namespace Microsoft.Azure.Commands.Synapse.Common
Expand Down Expand Up @@ -172,5 +172,16 @@ public static string[] ProcessExcludedDetectionTypes(string[] excludedDetectionT
}
return excludedDetectionTypes;
}

public static Operation<T> Poll<T>(this Operation<T> operation)
{
while (!operation.HasValue)
{
operation.UpdateStatus();
System.Threading.Thread.Sleep(SynapseConstants.DefaultPollingInterval);
}

return operation;
}
}
}
79 changes: 24 additions & 55 deletions src/Synapse/Synapse/Models/SynapseAnalyticsArtifactsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json;

namespace Microsoft.Azure.Commands.Synapse.Models
{
Expand Down Expand Up @@ -73,11 +70,7 @@ public PipelineResource CreateOrUpdatePipeline(string pipelineName, string rawJs
PSPipelineResource psPipeline = JsonConvert.DeserializeObject<PSPipelineResource>(rawJsonContent,Settings);
PipelineResource pipeline = psPipeline.ToSdkObject();
var operation = _pipelineClient.StartCreateOrUpdatePipeline(pipelineName, pipeline);
while (!operation.HasValue)
{
operation.UpdateStatus();
}
return operation.Value;
return operation.Poll().Value;
}

public PipelineResource GetPipeline(string pipelineName)
Expand All @@ -92,18 +85,18 @@ public Pageable<PipelineResource> GetPipelinesByWorkspace()

public void DeletePipeline(string pipelineName)
{
_pipelineClient.StartDeletePipeline(pipelineName);
_pipelineClient.StartDeletePipeline(pipelineName).Poll();
}

#endregion

#region pipeline run

public CreateRunResponse CreatePipelineRun(string pipelineName, string referencePipelineRunId, bool? isRecovery, string startActivityName, IDictionary<string, object> parameters)
{
return _pipelineClient.CreatePipelineRun(pipelineName, referencePipelineRunId, isRecovery, startActivityName, parameters);
}

#endregion

#region pipeline run

public PipelineRun GetPipelineRun(string runId)
{
return _pipelineRunClient.GetPipelineRun(runId).Value;
Expand Down Expand Up @@ -143,16 +136,12 @@ public LinkedServiceResource CreateOrUpdateLinkedService(string linkedServiceNam
PSLinkedServiceResource psLinkedService = JsonConvert.DeserializeObject<PSLinkedServiceResource>(rawJsonContent, Settings);
LinkedServiceResource linkedService = psLinkedService.ToSdkObject();
var operation = _linkedServiceClient.StartCreateOrUpdateLinkedService(linkedServiceName, linkedService);
while (!operation.HasValue)
{
operation.UpdateStatus();
}
return operation.Value;
return operation.Poll().Value;
}

public void DeleteLinkedService(string linkedServiceName)
{
_linkedServiceClient.StartDeleteLinkedService(linkedServiceName);
_linkedServiceClient.StartDeleteLinkedService(linkedServiceName).Poll();
}

#endregion
Expand All @@ -162,16 +151,12 @@ public void DeleteLinkedService(string linkedServiceName)
public NotebookResource CreateOrUpdateNotebook(string notebookName, NotebookResource notebook)
{
var operation = _notebookClient.StartCreateOrUpdateNotebook(notebookName, notebook);
while (!operation.HasValue)
{
operation.UpdateStatus();
}
return operation.Value;
return operation.Poll().Value;
}

public void DeleteNotebook(string notebookName)
{
_notebookClient.StartDeleteNotebook(notebookName);
_notebookClient.StartDeleteNotebook(notebookName).Poll();
}

public NotebookResource GetNotebook(string notebookName)
Expand All @@ -193,11 +178,7 @@ public TriggerResource CreateOrUpdateTrigger(string triggerName, string rawJsonC
PSTriggerResource pSTrigger = JsonConvert.DeserializeObject<PSTriggerResource>(rawJsonContent, Settings);
TriggerResource trigger = pSTrigger.ToSdkObject();
var operation = _triggerClient.StartCreateOrUpdateTrigger(triggerName, trigger);
while (!operation.HasValue)
{
operation.UpdateStatus();
}
return operation.Value;
return operation.Poll().Value;
}

public TriggerResource GetTrigger(string triggerName)
Expand All @@ -212,37 +193,33 @@ public Pageable<TriggerResource> GetTriggersByWorkspace()

public void DeleteTrigger(string triggerName)
{
_triggerClient.StartDeleteTrigger(triggerName);
_triggerClient.StartDeleteTrigger(triggerName).Poll();
}

public TriggerSubscriptionOperationStatus GetEventSubscriptionStatus(string triggerName)
{
return _triggerClient.GetEventSubscriptionStatus(triggerName);
}

public TriggerSubscriptionOperationStatus StartSubscribeTriggerToEvents(string triggerName)
public TriggerSubscriptionOperationStatus SubscribeTriggerToEvents(string triggerName)
{
var operation = _triggerClient.StartSubscribeTriggerToEvents(triggerName);
while (!operation.HasValue)
{
operation.UpdateStatus();
}
return operation.Value;
return operation.Poll().Value;
}

public void StartUnsubscribeTriggerFromEvents(string triggerName)
public void UnsubscribeTriggerFromEvents(string triggerName)
{
_triggerClient.StartUnsubscribeTriggerFromEvents(triggerName);
_triggerClient.StartUnsubscribeTriggerFromEvents(triggerName).Poll();
}

public void StartStartTrigger(string triggerName)
public void StartTrigger(string triggerName)
{
_triggerClient.StartStartTrigger(triggerName);
_triggerClient.StartStartTrigger(triggerName).Poll();
}

public void StartStopTrigger(string triggerName)
public void StopTrigger(string triggerName)
{
_triggerClient.StartStopTrigger(triggerName);
_triggerClient.StartStopTrigger(triggerName).Poll();
}

public IReadOnlyList<TriggerRun> QueryTriggerRunsByWorkspace(RunFilterParameters filterParameters)
Expand All @@ -259,11 +236,7 @@ public DatasetResource CreateOrUpdateDataset(string datasetName, string rawJsonC
PSDatasetResource pSDatasetResource = JsonConvert.DeserializeObject<PSDatasetResource>(rawJsonContent, Settings);
DatasetResource dataset = pSDatasetResource.ToSdkObject();
var operation = _datasetClient.StartCreateOrUpdateDataset(datasetName, dataset);
while (!operation.HasValue)
{
operation.UpdateStatus();
}
return operation.Value;
return operation.Poll().Value;
}

public DatasetResource GetDataset(string datasetName)
Expand All @@ -278,7 +251,7 @@ public Pageable<DatasetResource> GetDatasetsByWorkspace()

public void DeleteDataset(string datasetName)
{
_datasetClient.StartDeleteDataset(datasetName);
_datasetClient.StartDeleteDataset(datasetName).Poll();
}

#endregion
Expand All @@ -290,11 +263,7 @@ public DataFlowResource CreateOrUpdateDataFlow(string dataFlowName, string rawJs
PSDataFlowResource pSDatasetResource = JsonConvert.DeserializeObject<PSDataFlowResource>(rawJsonContent, Settings);
DataFlowResource dataFlow = pSDatasetResource.ToSdkObject();
var operation = _dataFlowClient.StartCreateOrUpdateDataFlow(dataFlowName, dataFlow);
while (!operation.HasValue)
{
operation.UpdateStatus();
}
return operation.Value;
return operation.Poll().Value;
}

public DataFlowResource GetDataFlow(string dataFlowName)
Expand All @@ -309,7 +278,7 @@ public Pageable<DataFlowResource> GetDataFlowsByWorkspace()

public void DeleteDataFlow(string dataFlowName)
{
_dataFlowClient.StartDeleteDataFlow(dataFlowName);
_dataFlowClient.StartDeleteDataFlow(dataFlowName).Poll();
}

#endregion
Expand Down