-
Notifications
You must be signed in to change notification settings - Fork 34
/
adf.azcli
190 lines (177 loc) · 6.87 KB
/
adf.azcli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
###################################
# Sample code to work with ADF
# networking config
#
# Feb 2023
###################################
# Variables
rg=adf
location=eastus
suffix=$RANDOM
adf_name="adf$suffix"
storage_account1_name="storage1$suffix"
storage_account1_cxfile="/tmp/storage1.json"
storage_account1_link_name=$storage_account1_name
storage_account2_name="storage1$suffix"
storage_account2_link_name=$storage_account2_name
storage_container_name=mycontainer
file1_name=/tmp/file1.txt
blob_name=helloworld.txt
input_dataset_file=/tmp/inputdataset.json
output_dataset_file=/tmp/outputdataset.json
pipeline_file=/tmp/pipeline.json
pipeline_name=BlobCopy
output_file_name=/tmp/outputfile.txt
managed_ir_file=/tmp/managedir.json
managed_ir_name=managedir
# Create RG
az group create -n $rg -l $location -o none
# Create storage account
az storage account create -n $storage_account1_name -g $rg -l $location -o none
az storage container create -n $storage_container_name --account-name $storage_account1_name --auth-mode key -o none
storage_account1_key=$(az storage account keys list -n $storage_account1_name --query '[0].value' -o tsv)
echo 'HelloWorld' > $file1_name
az storage blob upload --account-name $storage_account1_name --name input/$blob_name --container-name $storage_container_name --file $file1_name --auth-mode key --account-key $storage_account1_key --overwrite -o none
# Create ADF
az datafactory create --factory-name $adf_name -g $rg -o none
storage_account1_cx=$(az storage account show-connection-string -g $rg -n $storage_account1_name --key key1 -o tsv)
cat <<EOF > $storage_account1_cxfile
{
"type": "AzureBlobStorage",
"typeProperties": {
"connectionString": "$storage_account1_cx"
}
}
EOF
az datafactory linked-service create -g $rg --factory-name $adf_name --linked-service-name $storage_account1_link_name --properties @$storage_account1_cxfile -o none
# Input dataset
cat <<EOF > $input_dataset_file
{
"linkedServiceName": {
"referenceName": "$storage_account1_link_name",
"type": "LinkedServiceReference"
},
"annotations": [],
"type": "Binary",
"typeProperties": {
"location": {
"type": "AzureBlobStorageLocation",
"fileName": "$blob_name",
"folderPath": "input",
"container": "$storage_container_name"
}
}
}
EOF
az datafactory dataset create -g $rg --dataset-name InputDataset --factory-name $adf_name --properties @$input_dataset_file -o none
# Output dataset
cat <<EOF > $output_dataset_file
{
"linkedServiceName": {
"referenceName": "$storage_account1_link_name",
"type": "LinkedServiceReference"
},
"annotations": [],
"type": "Binary",
"typeProperties": {
"location": {
"type": "AzureBlobStorageLocation",
"folderPath": "output",
"container": "$storage_container_name"
}
}
}
EOF
az datafactory dataset create -g $rg --dataset-name OutputDataset --factory-name $adf_name --properties @$output_dataset_file -o none
# Pipeline
cat <<EOF > $pipeline_file
{
"name": "Adfv2QuickStartPipeline",
"properties": {
"activities": [
{
"name": "CopyFromBlobToBlob",
"type": "Copy",
"dependsOn": [],
"policy": {
"timeout": "7.00:00:00",
"retry": 0,
"retryIntervalInSeconds": 30,
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"source": {
"type": "BinarySource",
"storeSettings": {
"type": "AzureBlobStorageReadSettings",
"recursive": true
}
},
"sink": {
"type": "BinarySink",
"storeSettings": {
"type": "AzureBlobStorageWriteSettings"
}
},
"enableStaging": false
},
"inputs": [
{
"referenceName": "InputDataset",
"type": "DatasetReference"
}
],
"outputs": [
{
"referenceName": "OutputDataset",
"type": "DatasetReference"
}
]
}
],
"annotations": []
}
}
EOF
az datafactory pipeline create -g $rg --factory-name $adf_name --name $pipeline_name --pipeline @$pipeline_file -o none
# Integration runtime
cat <<EOF > $managed_ir_file
{
"type": "Managed",
"typeProperties": {
"computeProperties": {
"location": "$location",
"dataFlowProperties": {
"computeType": "General",
"coreCount": 8,
"timeToLive": 10
}
}
},
"managedVirtualNetwork": {
"type": "ManagedVirtualNetworkReference",
"referenceName": "default"
}
}
EOF
az datafactory integration-runtime managed create -g $rg --factory-name $adf_name --name $managed_ir_name --compute-properties @$managed_ir_file -o none
# Run pipeline
run_id=$(az datafactory pipeline create-run -g $rg --factory-name $adf_name --name $pipeline_name --query runId -o tsv)
az datafactory pipeline-run show -g $rg --factory-name $adf_name --run-id $run_id
# az storage blob show --account-name $storage_account1_name --account-key $storage_account1_key --container-name $storage_container_name --name output/$blob_name
az storage blob download --account-name $storage_account1_name --account-key $storage_account1_key --container-name $storage_container_name --name output/$blob_name
###############
# Diagnostics #
###############
az datafactory list -g $rg -o table
az datafactory dataset list -g $rg --factory-name $adf_name -o table
az datafactory pipeline list -g $rg --factory-name $adf_name -o table
az datafactory integration-runtime list -g $rg --factory-name $adf_name -o table
az datafactory integration-runtime show -n $managed_ir_name -g $rg --factory-name $adf_name
az datafactory managed-virtual-network list -g $rg --factory-name $adf_name -o table
managed_vnet_name=$(az datafactory managed-virtual-network list -g $rg --factory-name $adf_name --query '[0].name' -o tsv)
az datafactory managed-private-endpoint list -g $rg --factory-name $adf_name --managed-virtual-network-name $managed_vnet_name -o table
az datafactory managed-private-endpoint show -g $rg --factory-name $adf_name --managed-virtual-network-name $managed_vnet_name -n AzureFunction544
az storage blog list --account-name $storage_account1_name --account-key $storage_account1_key --container-name $storage_container_name -o table