Skip to content
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

Feature - add set data factory trigger state #46

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b36824a
Feature - add set data factory trigger state
stijnmoreels Jun 15, 2020
6516961
pr-fix: update with correct testing values
stijnmoreels Jun 15, 2020
7b4e838
pr-docs: update docs with data factory
stijnmoreels Jun 15, 2020
a036038
pr-sug: split functionality into start/stop
stijnmoreels Jun 15, 2020
15f1c0c
Update docs/preview/features/powershell/datafactory.md
stijnmoreels Jun 16, 2020
a437ada
Update docs/preview/features/powershell/datafactory.md
stijnmoreels Jun 16, 2020
86f7b56
Update docs/preview/features/powershell/datafactory.md
stijnmoreels Jun 16, 2020
25ae272
Update docs/preview/features/powershell/datafactory.md
stijnmoreels Jun 16, 2020
a0f901e
Update docs/preview/features/powershell/datafactory.md
stijnmoreels Jun 16, 2020
b301436
Update docs/preview/features/powershell/datafactory.md
stijnmoreels Jun 16, 2020
2929b1a
Update src/Arcus.Scripting.DataFactory/Arcus.Scripting.DataFactory.psm1
stijnmoreels Jun 16, 2020
9a8f7a9
Update src/Arcus.Scripting.DataFactory/Arcus.Scripting.DataFactory.psm1
stijnmoreels Jun 16, 2020
69ba0e5
Update src/Arcus.Scripting.DataFactory/Arcus.Scripting.DataFactory.psm1
stijnmoreels Jun 16, 2020
7858291
Update Arcus.Scripting.DataFactory.psm1
stijnmoreels Jun 16, 2020
4be425b
Update Arcus.Scripting.DataFactory.tests.ps1
stijnmoreels Jun 16, 2020
fc3eb3a
pr-sug: use enable/disable io start/stop
stijnmoreels Jun 16, 2020
6ea9dab
Update docs/preview/features/powershell/azure-data-factory.md
stijnmoreels Jun 18, 2020
55bbc24
Update docs/preview/features/powershell/azure-data-factory.md
stijnmoreels Jun 18, 2020
072baff
Update docs/preview/features/powershell/azure-data-factory.md
stijnmoreels Jun 18, 2020
c6dfd1d
Update docs/preview/features/powershell/azure-data-factory.md
stijnmoreels Jun 18, 2020
a43008c
Update src/Arcus.Scripting.DataFactory/Arcus.Scripting.DataFactory.psm1
stijnmoreels Jun 18, 2020
a8179bc
Update src/Arcus.Scripting.DataFactory/Arcus.Scripting.DataFactory.psm1
stijnmoreels Jun 18, 2020
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
5 changes: 4 additions & 1 deletion build/templates/run-pester-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ steps:
script: |
Install-Module -Name Pester -Force -SkipPublisherCheck
Install-Module -Name Az -Force -SkipPublisherCheck
Import-Module -Name ./src/Arcus.Scripting.KeyVault -ErrorAction Stop

Get-ChildItem -Path ./src -Filter *.psm1 -Recurse |
% { Import-Module -Name $_.DirectoryName -ErrorAction Stop }

Invoke-Pester -Script "./src/${{ parameters.projectName }}/" -OutputFile "./pester.test.results.xml" -OutputFormat 'NUnitXML'
- task: PublishTestResults@2
displayName: 'Publish test results'
Expand Down
61 changes: 61 additions & 0 deletions docs/preview/features/powershell/azure-data-factory.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
title: "Scripts related to interacting with Azure Data Factory"
layout: default
---

# Azure Data Factory

## Installation

To have access to the following features, you have to import the module:

```powershell
PS> Import-Module -Name Arcus.Scripting.DataFactory
```

## Enable the trigger of a Azure Data Factory

Enable a Data Factory V2 Trigger.

| Parameter | Mandatory | Description |
| --------------------------- | --------- | ---------------------------------------------------------------------------------------- |
| `ResourceGroupName` | yes | The resource group containing the Azure Data Factory V2 |
| `DataFactoryName` | yes | The name of the Azure Data Factory V2 |
| `DataFactoryTriggerName` | yes | The name of the trigger to be enabled |
| `FailWhenTriggerIsNotFound` | no | Indicate whether to throw an exception if the trigger cannot be found (default: `false`) |

**Example**

```powershell
PS> Enable-AzDataFactoryTrigger -ResourceGroupName "my-resource-group" -DataFactoryName "my-data-factory-name" -DataFactoryTriggerName "my-data-factory-trigger-name"
# The trigger 'my-data-factory-trigger-name' has been enabled.
```

```powershell
PS> Enable-AzDataFactoryTrigger -ResourceGroupName "my-resouce-group" -DataFactoryName "my-data-factory-name" -DataFactoryTriggerName "unknown-data-factory-trigger-name" -FailWhenTriggerIsNotFound
# Error: Error retrieving trigger 'unknown-data-factory-trigger-name' in data factory 'my-data-factory'.
```


## Disable the trigger of a Azure Data Factory

Disable a Data Factory V2 Trigger.

| Parameter | Mandatory | Description |
| --------------------------- | --------- | ---------------------------------------------------------------------------------------- |
| `ResourceGroupName` | yes | The resource group containing the Azure Data Factory V2 |
| `DataFactoryName` | yes | The name of the Azure Data Factory V2 |
| `DataFactoryTriggerName` | yes | The name of the trigger to be disabled |
| `FailWhenTriggerIsNotFound` | no | Indicate whether to throw an exception if the trigger cannot be found (default: `false`) |

**Example**

```powershell
PS> Disable-AzDataFactoryTrigger -ResourceGroupName "my-resource-group" -DataFactoryName "my-data-factory-name" -DataFactoryTriggerName "my-data-factory-trigger-name"
# The trigger 'my-data-factory-trigger-name' has been disabled.
```

```powershell
PS> Disable-AzDataFactoryTrigger -ResourceGroupName "my-resouce-group" -DataFactoryName "my-data-factory-name" -DataFactoryTriggerName "unknown-data-factory-trigger-name" -FailWhenTriggerIsNotFound
# Error: Error retrieving trigger 'unknown-data-factory-trigger-name' in data factory 'my-data-factory'.
```
3 changes: 2 additions & 1 deletion docs/preview/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ For more granular packages we recommend reading the documentation.

# Features

* Automate Azure Key Vault tasks ([powershell](features/powershell/key-vault))
* Automate Azure Data Factory tasks ([powershell](featues/powershell/azure-data-factory))
* Automate Azure Key Vault tasks ([powershell](features/powershell/azure-key-vault))

# License
This is licensed under The MIT License (MIT). Which means that you can use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the web application. But you always need to state that Codit is the original author of this web application.
Expand Down
Binary file not shown.
75 changes: 75 additions & 0 deletions src/Arcus.Scripting.DataFactory/Arcus.Scripting.DataFactory.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<#
.Synopsis
Change the state of a DataFactory V2 Trigger.

.Description
Enable a DataFactory V2 Trigger.

.Parameter ResourceGroupName
The resource group containing the DataFactory V2.

.Parameter DataFactoryName
The name of the DataFactory V2.

.Parameter DataFactoryTriggerName
The name of the trigger to be enabled.

.Parameter FailWhenTriggerIsNotFound
Indicate whether to throw an exception if the trigger cannot be found.
#>
function Enable-AzDataFactoryTrigger {
param(
[Parameter(Mandatory=$true)][string]$ResourceGroupName = $(throw "ResourceGroup is required"),
[Parameter(Mandatory=$true)][string]$DataFactoryName = $(throw "The name of the data factory is required"),
[Parameter(Mandatory=$true)][string]$DataFactoryTriggerName = $(throw "The name of the trigger is required"),
[Parameter(Mandatory=$false)][switch]$FailWhenTriggerIsNotFound = $false
)
if($FailWhenTriggerIsNotFound)
{
. $PSScriptRoot\Scripts\Set-AzDataFactoryTriggerState.ps1 -Action Start -ResourceGroupName $ResourceGroupName -DataFactoryName $DataFactoryName -DataFactoryTriggerName $DataFactoryTriggerName -FailWhenTriggerIsNotFound
}
else
{
. $PSScriptRoot\Scripts\Set-AzDataFactoryTriggerState.ps1 -Action Start -ResourceGroupName $ResourceGroupName -DataFactoryName $DataFactoryName -DataFactoryTriggerName $DataFactoryTriggerName
}
}

Export-ModuleMember Enable-AzDataFactoryTrigger

<#
.Synopsis
Change the state of a DataFactory V2 Trigger.

.Description
Disable a DataFactory V2 Trigger.

.Parameter ResourceGroupName
The resource group containing the DataFactory V2.

.Parameter DataFactoryName
The name of the DataFactory V2.

.Parameter DataFactoryTriggerName
The name of the trigger to be disabled.

.Parameter FailWhenTriggerIsNotFound
Indicate whether to throw an exception if the trigger cannot be found.
#>
function Disable-AzDataFactoryTrigger {
param(
[Parameter(Mandatory=$true)][string]$ResourceGroupName = $(throw "ResourceGroup is required"),
[Parameter(Mandatory=$true)][string]$DataFactoryName = $(throw "The name of the data factory is required"),
[Parameter(Mandatory=$true)][string]$DataFactoryTriggerName = $(throw "The name of the trigger is required"),
[Parameter(Mandatory=$false)][switch]$FailWhenTriggerIsNotFound = $false
)
if($FailWhenTriggerIsNotFound)
{
. $PSScriptRoot\Scripts\Set-AzDataFactoryTriggerState.ps1 -Action Stop -ResourceGroupName $ResourceGroupName -DataFactoryName $DataFactoryName -DataFactoryTriggerName $DataFactoryTriggerName -FailWhenTriggerIsNotFound
}
else
{
. $PSScriptRoot\Scripts\Set-AzDataFactoryTriggerState.ps1 -Action Stop -ResourceGroupName $ResourceGroupName -DataFactoryName $DataFactoryName -DataFactoryTriggerName $DataFactoryTriggerName
}
}

Export-ModuleMember Disable-AzDataFactoryTrigger
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{87004bab-daac-4344-a719-2c8164da9b27}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>MyApplication</RootNamespace>
<AssemblyName>MyApplication</AssemblyName>
<Name>Arcus.Scripting.DataFactory</Name>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Folder Include="Scripts\" />
</ItemGroup>
<ItemGroup>
<Compile Include="Arcus.Scripting.DataFactory.psd1" />
<Compile Include="Arcus.Scripting.DataFactory.psm1" />
<Compile Include="Scripts\Set-AzDataFactoryTriggerState.ps1" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Target Name="Build" />
<Import Project="$(MSBuildExtensionsPath)\PowerShell Tools for Visual Studio\PowerShellTools.targets" Condition="Exists('$(MSBuildExtensionsPath)\PowerShell Tools for Visual Studio\PowerShellTools.targets')" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
param(
[Parameter(Mandatory=$true)][string]$Action = $(throw "Action is required [Start|Stop]"),
[Parameter(Mandatory=$true)][string]$ResourceGroupName = $(throw "ResourceGroup is required"),
[Parameter(Mandatory=$true)][string]$DataFactoryName = $(throw "The name of the data factory is required"),
[Parameter(Mandatory=$true)][string]$DataFactoryTriggerName = $(throw "The name of the trigger is required"),
[Parameter(Mandatory=$false)][switch]$FailWhenTriggerIsNotFound = $false
)

try
{
$dataFactory = Get-AzDataFactoryV2 -ResourceGroupName $ResourceGroupName -Name $DataFactoryName -ErrorAction Stop
}
catch
{
throw "Error finding data factory '$DataFactoryName' in resource group '$ResourceGroupName'"
}

try
{
$DataFactoryTrigger = Get-AzDataFactoryV2Trigger -ResourceGroupName $ResourceGroupName -DataFactoryName $DataFactoryName -Name $DataFactoryTriggerName -ErrorAction Stop
}
catch
{
$message = "Error retrieving trigger '$DataFactoryTriggerName' in data factory '$DataFactoryName'"
if($FailWhenTriggerIsNotFound)
{
throw $message
}
else
{
Write-Host $message
Write-Host "Skipping the '$Action'-operation."
return
}
}

if($Action -eq "Start")
{
try
{
if($null -ne $DataFactoryTrigger)
{
$succeeded = Start-AzDataFactoryV2Trigger -ResourceGroupName $ResourceGroupName -DataFactoryName $DataFactoryName -Name $DataFactoryTriggerName -Force -ErrorAction Stop
Write-Host "The trigger '$DataFactoryTriggerName' has been started."
}
}
catch
{
throw "Error starting trigger '$DataFactoryTriggerName' in data factory '$DataFactoryName'"
}
}

if($Action -eq "Stop")
{
try
{
if($null -ne $DataFactoryTrigger)
{
$succeeded = Stop-AzDataFactoryV2Trigger -ResourceGroupName $ResourceGroupName -DataFactoryName $DataFactoryName -Name $DataFactoryTriggerName -Force -ErrorAction Stop
Write-Host "The trigger '$DataFactoryTriggerName' has been stopped."
}
}
catch
{
throw "Error stopping trigger '$DataFactoryTrigger' in data factory '$DataFactoryName'"
}
}
Loading