Skip to content

Commit

Permalink
[Data Factory] Adding Chaining Trigger (#7469)
Browse files Browse the repository at this point in the history
* Adding Chaining Trigger

* Updated after running generate.ps1
  • Loading branch information
haricr authored and isra-fel committed Sep 12, 2019
1 parent 3166083 commit 29841c3
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 3 deletions.
14 changes: 14 additions & 0 deletions sdk/SDKs/_metadata/datafactory_resource-manager.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Installing AutoRest version: latest
AutoRest installed successfully.
Commencing code generation
Generating CSharp code
Executing AutoRest command
cmd.exe /c autorest.cmd https://github.com/Azure/azure-rest-api-specs/blob/master/specification/datafactory/resource-manager/readme.md --csharp --version=latest --reflect-api-versions --tag=package-2018-06 --csharp-sdks-folder=E:\GitHub\azure-sdk-for-net\sdk
2019-09-11 03:53:44 UTC
Azure-rest-api-specs repository information
GitHub fork: Azure
Branch: master
Commit: d46d469dc7a9a9462a03649d01c48fe9f422a74f
AutoRest information
Requested version: latest
Bootstrapper version: [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
- Added outputColumns property to Office365Source
- Added support for ORC dataset in ADF


## Version 4.1.3
### Feature Additions
- Added RunDimnesion to Pipeline
- Added Chaining Trigger
- Added Dependency Status property in Pipeline and Trigger Run

## Version 4.1.2
### Feature Additions
- Added SapBwCube and Sybase dataset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,35 @@ namespace DataFactory.Tests.JsonSamples
{
public class TriggerJsonSamples : JsonSampleCollection<TriggerJsonSamples>
{
[JsonSample]
public const string ChainingTriggerSample = @"
{
""name"": ""chainingTrigger"",
""properties"": {
""type"": ""ChainingTrigger"",
""pipeline"": {
""pipelineReference"": {
""referenceName"": ""childPipeline"",
""type"": ""PipelineReference""
},
""parameters"": {}
},
""typeProperties"": {
""dependsOn"": [
{
""referenceName"": ""parentPipeline1"",
""type"": ""PipelineReference""
},
{
""referenceName"": ""parentPipeline2"",
""type"": ""PipelineReference""
}
],
""runDimension"": ""JobId""
}
}
}";

[JsonSample]
public const string BlobTriggerSample = @"
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for
// license information.

using DataFactory.Tests.Utils;

namespace DataFactory.Tests.JsonSamples
{
public class TriggerRunJsonSamples : JsonSampleCollection<TriggerRunJsonSamples>
{
[JsonSample]
public const string ChainingTriggerRunSample = @"
{
""value"": [
{
""triggerName"": ""chainingTrigger"",
""triggerRunId"": ""8e2dc34d-2c0d-455a-a339-c48531129f1d"",
""triggerType"": ""ChainingTrigger"",
""triggerRunTimestamp"": ""2019-09-03T19:21:25.696491Z"",
""status"": ""Succeeded"",
""message"": null,
""properties"": {
""TriggerTime"": ""9/3/2019 7:23:44 PM""
},
""triggeredPipelines"": {
""childPipeline"": ""d93fc338-d2ac-4e81-9f2a-0af9d1347d5b""
},
""groupId"": ""8e2dc34d-2c0d-455a-a339-c48531129f1d"",
""dependencyStatus"": {
""parentPipeline1"": {
""Id"": ""46e0c003-e1c5-4d44-abd3-433177c41684"",
""Status"": ""Succeeded"",
""RunStart"": ""2019-09-03T19:21:25.696491Z""
},
""parentPipeline2"": {
""Id"": ""9353ea77-4ce0-458c-8431-21033494475e"",
""Status"": ""Succeeded"",
""RunStart"": ""2019-09-03T19:23:31.8215466Z""
}
},
""runDimension"": {
""JobId"": ""bc5df11f-1e94-4d86-b0bf-d99c786f1419""
}
}
]
}";

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,13 @@ public void Trigger_SerializationTest(JsonSampleInfo jsonSample)
{
TestJsonSample<TriggerResource>(jsonSample);
}

[Theory]
[ClassData(typeof(TriggerRunJsonSamples))]
[Trait(TraitName.TestType, TestType.Unit)]
public void TriggerRun_SerializationTest(JsonSampleInfo jsonSample)
{
TestJsonSample<TriggerRunsQueryResponse>(jsonSample);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public class ExampleCapture
private const string eventTriggerName = "exampleEventTrigger";
private const string datasetName = "exampleDataset";
private const string pipelineName = "examplePipeline";
private const string parentPipeline1Name = "parentPipeline1";
private const string parentPipeline2Name = "parentPipeline2";
private const string childPipelineName = "childPipeline";
private const string chainingTriggerName = "chainingTrigger";
private const string outputBlobName = "exampleoutput.csv";
private ExampleSecrets secrets;
private string outputFolder;
Expand Down Expand Up @@ -154,6 +158,8 @@ public void CaptureAllExamples()
CaptureIntegrationRuntimes_Delete(); // 202
CaptureIntegrationRuntimes_Delete(); // 204

CaptureChainingTrigger();

// Finish Factories operations, deleting factory
CaptureFactories_Delete(); // 200
CaptureFactories_Delete(); // 204
Expand Down Expand Up @@ -732,6 +738,29 @@ private PipelineResource GetPipelineResource(string description)
return resource;
}

private PipelineResource GetWaitPipelineResource()
{
PipelineResource resource = new PipelineResource
{
Parameters = new Dictionary<string, ParameterSpecification>
{
{ "JobId", new ParameterSpecification { Type = ParameterType.String } }
},
Activities = new List<Activity>(),
RunDimensions = new Dictionary<string, object>
{
{ "JobId", new Expression("@pipeline().parameters.JobId") }
}
};
WaitActivity waitActivity = new WaitActivity
{
Name = "ExampleWaitActivity",
WaitTimeInSeconds = 10
};
resource.Activities.Add(waitActivity);
return resource;
}

private void CapturePipelines_Create()
{
interceptor.CurrentExampleName = "Pipelines_Create";
Expand Down Expand Up @@ -777,7 +806,7 @@ private string CapturePipelines_CreateRun()
isRecovery: true, referencePipelineRunId: rtr1.RunId);
return rtr2.RunId;
}

private void CapturePipelineRuns_Cancel()
{
string runId = this.CapturePipelines_CreateRun();
Expand Down Expand Up @@ -958,13 +987,37 @@ private TriggerResource GetTWTriggerResource(string description)
return resource;
}

private TriggerResource GetChainingTriggerResource()
{
ChainingTrigger chainingTrigger = new ChainingTrigger()
{
DependsOn = new List<PipelineReference>(),
RunDimension = "JobId",
};

chainingTrigger.Pipeline = new TriggerPipelineReference()
{
PipelineReference = new PipelineReference(childPipelineName),
Parameters = new Dictionary<string, object>()
};
chainingTrigger.DependsOn.Add(new PipelineReference(parentPipeline1Name));
chainingTrigger.DependsOn.Add(new PipelineReference(parentPipeline2Name));

TriggerResource resource = new TriggerResource()
{
Properties = chainingTrigger,
};

return resource;
}

private void CaptureTriggers_CreateEventful()
{
interceptor.CurrentExampleName = "Triggers_CreateEventTrigger";
TriggerResource resourceIn = this.GetEventTriggerResource(null);
TriggerResource resource = client.Triggers.CreateOrUpdate(secrets.ResourceGroupName, secrets.FactoryName, eventTriggerName, resourceIn);
}

private void CaptureTriggers_Create()
{
interceptor.CurrentExampleName = "Triggers_Create";
Expand Down Expand Up @@ -1021,7 +1074,7 @@ private void CaptureTriggers_Stop()
client.Triggers.Stop(secrets.ResourceGroupName, secrets.FactoryName, triggerName);
}

private void CaptureTriggerRuns_QueryByFactory(DateTime lastUpdatedAfter, DateTime lastUpdatedBefore)
private void CaptureTriggerRuns_QueryByFactory(DateTime lastUpdatedAfter, DateTime lastUpdatedBefore, string triggerName = triggerName)
{
interceptor.CurrentExampleName = "TriggerRuns_QueryByFactory";

Expand Down Expand Up @@ -1076,5 +1129,46 @@ private void CaptureOperations_List()
IPage<Operation> operations = client.Operations.List();
}

private void CaptureChainingTrigger()
{
PipelineResource resourceIn = GetWaitPipelineResource();

interceptor.CurrentExampleName = "ParentPipeline1_Create";
PipelineResource resource = client.Pipelines.CreateOrUpdate(secrets.ResourceGroupName, secrets.FactoryName, parentPipeline1Name, resourceIn);

interceptor.CurrentExampleName = "ParentPipeline2_Create";
resource = client.Pipelines.CreateOrUpdate(secrets.ResourceGroupName, secrets.FactoryName, parentPipeline2Name, resourceIn);

interceptor.CurrentExampleName = "ChildPipeline_Create";
resource = client.Pipelines.CreateOrUpdate(secrets.ResourceGroupName, secrets.FactoryName, childPipelineName, resourceIn);

interceptor.CurrentExampleName = "Triggers_CreateChainingTrigger";
TriggerResource triggerResource = this.GetChainingTriggerResource();
triggerResource = client.Triggers.CreateOrUpdate(secrets.ResourceGroupName, secrets.FactoryName, chainingTriggerName, triggerResource);

client.Triggers.Start(secrets.ResourceGroupName, secrets.FactoryName, chainingTriggerName);

DateTime startTime = DateTime.UtcNow;

string jobId = Guid.NewGuid().ToString();
interceptor.CurrentExampleName = "Pipelines_CreateRunJobId";

Dictionary<string, object> arguments = new Dictionary<string, object>
{
{ "JobId", jobId }
};

CreateRunResponse rtr1 = client.Pipelines.CreateRun(secrets.ResourceGroupName, secrets.FactoryName, parentPipeline1Name, parameters: arguments);

System.Threading.Thread.Sleep(TimeSpan.FromSeconds(60));
this.CaptureTriggerRuns_QueryByFactory(startTime, startTime.AddMinutes(10), chainingTriggerName);

CreateRunResponse rtr2 = client.Pipelines.CreateRun(secrets.ResourceGroupName, secrets.FactoryName, parentPipeline2Name, parameters: arguments);

System.Threading.Thread.Sleep(TimeSpan.FromSeconds(60));
this.CaptureTriggerRuns_QueryByFactory(startTime, startTime.AddMinutes(10), chainingTriggerName);

client.Triggers.Stop(secrets.ResourceGroupName, secrets.FactoryName, chainingTriggerName);
}
}
}

0 comments on commit 29841c3

Please sign in to comment.