Creating A Custom NET Activity PipeLine For Azure Data Factory
Creating A Custom NET Activity PipeLine For Azure Data Factory
12 6
Feodor
Creating a Custom .NET
Georgiev Activity Pipeline for
11 August
2017
Azure Data Factory
Azure Data Factory provides a radical new
1 cloud-based way of collecting and preparing
2
data in preparation for its storage and
6
analysis. How do you get started with it to
explore the possibilities it provides? Feodor
Georgiev shows the practicalities of how to
go about the task of preparing a pipeline for
use, from preparing the Azure environment
to downloading a le from a FTP to a blob
storage in the Azure environment
https://www.red-gate.com/simple-talk/cloud/cloud-development/creating-custom-net-activity-pipeline-azure-data-factory/ 1/18
3/1/2018 Creating a Custom .NET Activity Pipeline for Azure Data Factory - Simple Talk
https://www.red-gate.com/simple-talk/cloud/cloud-development/creating-custom-net-activity-pipeline-azure-data-factory/ 2/18
3/1/2018 Creating a Custom .NET Activity Pipeline for Azure Data Factory - Simple Talk
What we need:
Here is a high-level overview of what we need in
order to setup the custom .NET activity to work:
https://www.red-gate.com/simple-talk/cloud/cloud-development/creating-custom-net-activity-pipeline-azure-data-factory/ 3/18
3/1/2018 Creating a Custom .NET Activity Pipeline for Azure Data Factory - Simple Talk
us/azure/batch/batch-technical-overview. In
this case, we will create a batch pool with a
very simple Windows server VM to carry out
the FTP download task. In a real use-case, the
Batch service is very exible and can scale the
pool of virtual machines automatically.
https://www.red-gate.com/simple-talk/cloud/cloud-development/creating-custom-net-activity-pipeline-azure-data-factory/ 4/18
3/1/2018 Creating a Custom .NET Activity Pipeline for Azure Data Factory - Simple Talk
https://www.red-gate.com/simple-talk/cloud/cloud-development/creating-custom-net-activity-pipeline-azure-data-factory/ 5/18
3/1/2018 Creating a Custom .NET Activity Pipeline for Azure Data Factory - Simple Talk
https://www.red-gate.com/simple-talk/cloud/cloud-development/creating-custom-net-activity-pipeline-azure-data-factory/ 6/18
3/1/2018 Creating a Custom .NET Activity Pipeline for Azure Data Factory - Simple Talk
Install-Package Microsoft.Azure.Management.Da
taFactories
Install-Package Azure.Storage
using Microsoft.Azure.Management.DataFactories.Mode
ls;
using Microsoft.Azure.Management.DataFactories.Ru
ntime;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
namespace FTPDownloader
{
public class FTPActivity : IDotNetActivity
{
string ftpUserName = "";
string ftpPassword = "";
public IDictionary<string, string> Execut
e(IEnumerable<LinkedService> linkedServices,
IEnumerable<Dataset> da
tasets, Activity activity, IActivityLogger logger)
{
//Get FTP URL from extended propertie
s
var currentActivity = (DotNetActivit
)activity.TypeProperties;
var extendedProperties = currentActiv
ity.ExtendedProperties;
https://www.red-gate.com/simple-talk/cloud/cloud-development/creating-custom-net-activity-pipeline-azure-data-factory/ 7/18
3/1/2018 Creating a Custom .NET Activity Pipeline for Azure Data Factory - Simple Talk
var outputLocation = outputDataset.P
operties.TypeProperties as AzureBlobDataset;
var folderPath = outputLocation.Folde
rPath;
//Upload file to blob
UploadFileToBlob(ftpFileUrl, ftpUserN
ame, ftpPassword, blobConnectionString, folderPath
logger);
return new Dictionary<string, string>
();
}
public void UploadFileToBlob(string ftpF
leUrl, string ftpUserName, string ftpPassword,
string blobConne
tionString, string blobFolderPath, IActivityLogger
logger)
{
var request = (FtpWebRequest)WebReque
st.Create(new Uri(ftpFileUrl));
request.Credentials = new System.Net
NetworkCredential(ftpUserName, ftpPassword);
request.UseBinary = true;
request.UsePassive = true;
request.KeepAlive = true;
request.Method = WebRequestMethods.Ft
p.DownloadFile;
var outputValue = string.Empty;
using (var ftpResponse = (FtpWebRespo
nse)request.GetResponse())
{
using (var ftpStream = ftpRespon
e.GetResponseStream())
{
logger.Write("connecting to
he blob..");
var outputStorageAccount = C
oudStorageAccount.Parse(blobConnectionString);
var fileName = Path.GetFileNa
me(ftpFileUrl);
var outputBlobUri = new Uri(o
utputStorageAccount.BlobEndpoint,
b
lobFolderPath + "/" + fileName);
var outputBlob = new CloudBlo
ckBlob(outputBlobUri, outputStorageAccount.Credent
als);
logger.Write("uploading to th
e blob URI: {0}", outputBlobUri.ToString());
outputBlob.UploadFromStream(
tpStream);
logger.Write("upload succeede
d");
}
}
request = null;
}
}
}
https://www.red-gate.com/simple-talk/cloud/cloud-development/creating-custom-net-activity-pipeline-azure-data-factory/ 8/18
3/1/2018 Creating a Custom .NET Activity Pipeline for Azure Data Factory - Simple Talk
https://www.red-gate.com/simple-talk/cloud/cloud-development/creating-custom-net-activity-pipeline-azure-data-factory/ 9/18
3/1/2018 Creating a Custom .NET Activity Pipeline for Azure Data Factory - Simple Talk
Install-Package Microsoft.Azure.Management.Da
taFactories
Install-Package Azure.Storage
https://www.red-gate.com/simple-talk/cloud/cloud-development/creating-custom-net-activity-pipeline-azure-data-factory/ 10/18
3/1/2018 Creating a Custom .NET Activity Pipeline for Azure Data Factory - Simple Talk
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using FTPDownloader;
using Microsoft.Azure.Management.DataFacto
ries.Models;
using Microsoft.Azure.Management.DataFacto
ries.Runtime;
namespace ADFCustomActivityTest
{
class Program
{
static void Main(string[] args)
{
var ftpActivity = new FTPActiv
ity();
string ftpFileUrl = "ftp://spe
edtest.tele2.net/20MB.zip";
string ftpUserName = string.Em
pty;
string ftpPassword = string.Em
pty;
string blobConnectionString =
"[Your Storage Connectionstring]";
string blobFolderPath = "ftpda
ta";
ftpActivity.UploadFileToBlob(f
tpFileUrl, ftpUserName, ftpPassword, blobCon
nectionString,
b
lobFolderPath, new ConsoleActivityLogger());
Console.WriteLine("Press Any K
ey to Exit...");
Console.ReadKey();
}
}
public class ConsoleActivityLogger : I
ActivityLogger
{
public void Write(string format, p
arams object[] args)
{
Console.WriteLine(format, args
);
}
}
}
After you run the app, the breakpoint will be hit and
the local variables will be displayed:
https://www.red-gate.com/simple-talk/cloud/cloud-development/creating-custom-net-activity-pipeline-azure-data-factory/ 13/18
3/1/2018 Creating a Custom .NET Activity Pipeline for Azure Data Factory - Simple Talk
https://www.red-gate.com/simple-talk/cloud/cloud-development/creating-custom-net-activity-pipeline-azure-data-factory/ 14/18
3/1/2018 Creating a Custom .NET Activity Pipeline for Azure Data Factory - Simple Talk
FTPFileUrl
{
"$schema": "http://datafactories.schema.
management.azure.com/schemas/2015-09-01/Micr
osoft.DataFactory.Pipeline.json",
"name": "FTPDownloaderPipeline",
"properties": {
"description": "Download FTP Data and
Upload to Blob",
"activities": [
{
"name": "DotNetActivityTemplate",
"type": "DotNetActivity",
"outputs": [
{
"name": "FTPBlobOutput"
}
],
"typeProperties": {
"assemblyName": "FTPDownloader",
"entryPoint": "FTPDownloader.FTP
Activity",
"packageLinkedService": "AzureSt
orageLinkedService_FTPData",
https://www.red-gate.com/simple-talk/cloud/cloud-development/creating-custom-net-activity-pipeline-azure-data-factory/ 15/18
3/1/2018 Creating a Custom .NET Activity Pipeline for Azure Data Factory - Simple Talk
"packageFile": "customactivityco
ntainer/FTPDownloader.zip",
"extendedProperties": {
"FTPFileUrl": "ftp://speedtes
t.tele2.net/20MB.zip"
}
},
"linkedServiceName": "AzureBatchLi
nkedService_FTPData",
"policy": {
"concurrency": 1,
"executionPriorityOrder": "Oldes
tFirst",
"retry": 3,
"timeout": "00:05:00"
},
"scheduler": {
"frequency": "Day",
"interval": 1
}
}
],
"start": "2017-07-01T00:00:00Z",
"end": "2017-07-01T00:00:00Z"
}
}
https://www.red-gate.com/simple-talk/cloud/cloud-development/creating-custom-net-activity-pipeline-azure-data-factory/ 16/18
3/1/2018 Creating a Custom .NET Activity Pipeline for Azure Data Factory - Simple Talk
Conclusion
In this article, we covered the topic of setting up the
Azure environment and running a custom .NET
activity to download le from a FTP to a blob
storage in our Azure environment. We learned how
to debug our code locally and we also learned how
to create and deploy the ADF pipeline from the
Visual Studio environment. This is a very exible
way to extend the functionality of ADF and it gives
us the ability to write custom logic.
https://www.red-gate.com/simple-talk/cloud/cloud-development/creating-custom-net-activity-pipeline-azure-data-factory/ 17/18
3/1/2018 Creating a Custom .NET Activity Pipeline for Azure Data Factory - Simple Talk
https://www.red-gate.com/simple-talk/cloud/cloud-development/creating-custom-net-activity-pipeline-azure-data-factory/ 18/18