forked from vdesabou/kafka-docker-playground
-
Notifications
You must be signed in to change notification settings - Fork 1
/
azure-blob-storage.sh
executable file
·87 lines (72 loc) · 3.41 KB
/
azure-blob-storage.sh
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
#!/bin/bash
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
source ${DIR}/../../scripts/utils.sh
if [ ! -z "$AZ_USER" ] && [ ! -z "$AZ_PASS" ]
then
log "Logging to Azure using environment variables AZ_USER and AZ_PASS"
set +e
az logout
set -e
az login -u "$AZ_USER" -p "$AZ_PASS"
else
log "Logging to Azure using browser"
az login
fi
AZURE_NAME=playground$USER$TRAVIS_JOB_NUMBER
AZURE_NAME=${AZURE_NAME//[-._]/}
AZURE_RESOURCE_GROUP=$AZURE_NAME
AZURE_ACCOUNT_NAME=$AZURE_NAME
AZURE_CONTAINER_NAME=$AZURE_NAME
AZURE_REGION=westeurope
set +e
az group delete --name $AZURE_RESOURCE_GROUP --yes
set -e
log "Creating Azure Resource Group $AZURE_RESOURCE_GROUP"
az group create \
--name $AZURE_RESOURCE_GROUP \
--location $AZURE_REGION
log "Creating Azure Storage Account $AZURE_ACCOUNT_NAME"
az storage account create \
--name $AZURE_ACCOUNT_NAME \
--resource-group $AZURE_RESOURCE_GROUP \
--location $AZURE_REGION \
--sku Standard_LRS \
--encryption-services blob
log "Creating Azure Storage Container $AZURE_CONTAINER_NAME"
az storage container create \
--account-name $AZURE_ACCOUNT_NAME \
--name $AZURE_CONTAINER_NAME
AZURE_ACCOUNT_KEY=$(az storage account keys list \
--account-name $AZURE_ACCOUNT_NAME \
--resource-group $AZURE_RESOURCE_GROUP \
--output table \
| grep key1 | awk '{print $3}')
${DIR}/../../environment/plaintext/start.sh "${PWD}/docker-compose.plaintext.yml"
log "Creating Azure Blob Storage Sink connector"
curl -X PUT \
-H "Content-Type: application/json" \
--data '{
"connector.class": "io.confluent.connect.azure.blob.AzureBlobStorageSinkConnector",
"tasks.max": "1",
"topics": "blob_topic",
"flush.size": "3",
"azblob.account.name": "'"$AZURE_ACCOUNT_NAME"'",
"azblob.account.key": "'"$AZURE_ACCOUNT_KEY"'",
"azblob.container.name": "'"$AZURE_CONTAINER_NAME"'",
"format.class": "io.confluent.connect.azure.blob.format.avro.AvroFormat",
"confluent.license": "",
"confluent.topic.bootstrap.servers": "broker:9092",
"confluent.topic.replication.factor": "1"
}' \
http://localhost:8083/connectors/azure-blob-sink/config | jq .
log "Sending messages to topic blob_topic"
seq -f "{\"f1\": \"value%g\"}" 10 | docker exec -i connect kafka-avro-console-producer --broker-list broker:9092 --property schema.registry.url=http://schema-registry:8081 --topic blob_topic --property value.schema='{"type":"record","name":"myrecord","fields":[{"name":"f1","type":"string"}]}'
sleep 10
log "Listing objects of container ${AZURE_CONTAINER_NAME} in Azure Blob Storage"
az storage blob list --account-name "${AZURE_ACCOUNT_NAME}" --account-key "${AZURE_ACCOUNT_KEY}" --container-name "${AZURE_CONTAINER_NAME}" --output table
log "Getting one of the avro files locally and displaying content with avro-tools"
az storage blob download --account-name "${AZURE_ACCOUNT_NAME}" --account-key "${AZURE_ACCOUNT_KEY}" --container-name "${AZURE_CONTAINER_NAME}" --name topics/blob_topic/partition=0/blob_topic+0+0000000000.avro --file /tmp/blob_topic+0+0000000000.avro
docker run -v /tmp:/tmp actions/avro-tools tojson /tmp/blob_topic+0+0000000000.avro
log "Deleting resource group"
az group delete --name $AZURE_RESOURCE_GROUP --yes