This repository was archived by the owner on Jun 12, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathvalidate_code_servicebusallactive.sh
More file actions
executable file
·205 lines (170 loc) · 6.77 KB
/
Copy pathvalidate_code_servicebusallactive.sh
File metadata and controls
executable file
·205 lines (170 loc) · 6.77 KB
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/bin/bash
echo "ServiceBusAllActive Validation (Code). (Patience! This will take a while!)"
# start in script dir
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
pushd $DIR > /dev/null
LOGFILE=$DIR/servicebusallactive_code.log
rm -f $LOGFILE
USER_SUFFIX=$(date +"%03j%02y%02H%02M%02S")
if [ "$AZURE_LOCATION" == '' ]; then
AZURE_LOCATION=westeurope
fi
CREATE_RESOURCE_GROUP=false
if [ ! $USER_RESOURCE_GROUP ]; then
CREATE_RESOURCE_GROUP=true
USER_RESOURCE_GROUP='sballactsmp-'$USER_SUFFIX
fi
USER_LEFT_NAMESPACE_NAME='sballactsmp-left-'$USER_SUFFIX
USER_RIGHT_NAMESPACE_NAME='sballactsmp-right-'$USER_SUFFIX
USER_FUNCTIONS_APP_NAME='sballactsmp-'$USER_SUFFIX
USER_STORAGE_ACCOUNT='sballactsmp'$USER_SUFFIX
quit() {
echo "error, quitting"
if [ $CREATE_RESOURCE_GROUP ]; then
az group delete --name $USER_RESOURCE_GROUP --yes >> $LOGFILE 2>&1
fi
exit $1
}
# go into project dir
pushd ../functions/code/ServiceBusAllActive > /dev/null
if [ $CREATE_RESOURCE_GROUP ]; then
echo "Creating resource group ..."
az group create --name $USER_RESOURCE_GROUP --location $AZURE_LOCATION >> $LOGFILE 2>&1
retval=$?
if [ $retval -ne 0 ]; then
exit $retval
fi
echo "Resource group $USER_RESOURCE_GROUP created"
fi
echo "Deploying resource template ..."
az deployment group create --resource-group "$USER_RESOURCE_GROUP" \
--template-file="template/azuredeploy.json" \
--parameters leftNamespaceName="$USER_LEFT_NAMESPACE_NAME" \
rightNamespaceName="$USER_RIGHT_NAMESPACE_NAME" >> $LOGFILE 2>&1
retval=$?
if [ $retval -ne 0 ]; then
quit $retval
fi
echo "Resource template deployed"
echo "Creating storage account ..."
az storage account create --name "$USER_STORAGE_ACCOUNT" \
--location "$AZURE_LOCATION" \
--resource-group "$USER_RESOURCE_GROUP" \
--sku Standard_LRS >> $LOGFILE 2>&1
retval=$?
if [ $retval -ne 0 ]; then
quit $retval
fi
echo "Storage account $USER_STORAGE_ACCOUNT created"
echo "Creating functions application ..."
az functionapp create --resource-group $USER_RESOURCE_GROUP \
--consumption-plan-location $AZURE_LOCATION \
--runtime dotnet --functions-version 3 \
--name $USER_FUNCTIONS_APP_NAME \
--storage-account $USER_STORAGE_ACCOUNT >> $LOGFILE 2>&1
retval=$?
if [ $retval -ne 0 ]; then
quit $retval
fi
echo "Functions application $USER_FUNCTIONS_APP_NAME created"
echo "Creating and setting authorization rule on namespace $USER_LEFT_NAMESPACE_NAME ..."
az servicebus topic authorization-rule create \
--resource-group $USER_RESOURCE_GROUP \
--namespace-name $USER_LEFT_NAMESPACE_NAME \
--topic-name jobs \
--name replication-sendlistenlisten \
--rights {send,listen} >> $LOGFILE 2>&1
retval=$?
if [ $retval -ne 0 ]; then
quit $retval
fi
cxnstring_left=$(az servicebus topic authorization-rule keys list \
--resource-group $USER_RESOURCE_GROUP \
--namespace-name $USER_LEFT_NAMESPACE_NAME \
--topic-name jobs \
--name replication-sendlistenlisten \
--output=json | jq -r .primaryConnectionString)
retval=$?
if [ $retval -ne 0 ]; then
quit $retval
fi
regex_strip_entity_name="(.*);EntityPath=.*;*(.*)$"
if [[ $cxnstring_left =~ $regex_strip_entity_name ]]; then
cxnstring_left="${BASH_REMATCH[1]};${BASH_REMATCH[2]}"
fi
az functionapp config appsettings set --name $USER_FUNCTIONS_APP_NAME \
--resource-group $USER_RESOURCE_GROUP \
--settings "jobs-left-connection=$cxnstring_left" >> $LOGFILE 2>&1
retval=$?
if [ $retval -ne 0 ]; then
quit $retval
fi
echo "Authorization rule set"
echo "Creating and setting authorization rule on namespace $USER_RIGHT_NAMESPACE_NAME ..."
az servicebus topic authorization-rule create \
--resource-group $USER_RESOURCE_GROUP \
--namespace-name $USER_RIGHT_NAMESPACE_NAME \
--topic-name jobs \
--name replication-sendlisten \
--rights {send,listen} >> $LOGFILE 2>&1
retval=$?
if [ $retval -ne 0 ]; then
quit $retval
fi
cxnstring_right=$(az servicebus topic authorization-rule keys list \
--resource-group $USER_RESOURCE_GROUP \
--namespace-name $USER_RIGHT_NAMESPACE_NAME \
--topic-name jobs \
--name replication-sendlisten \
--output=json | jq -r .primaryConnectionString)
retval=$?
if [ $retval -ne 0 ]; then
quit $retval
fi
regex_strip_entity_name="(.*);EntityPath=.*;*(.*)$"
if [[ $cxnstring_right =~ $regex_strip_entity_name ]]; then
cxnstring_right="${BASH_REMATCH[1]};${BASH_REMATCH[2]}"
fi
az functionapp config appsettings set --name $USER_FUNCTIONS_APP_NAME \
--resource-group $USER_RESOURCE_GROUP \
--settings "jobs-right-connection=$cxnstring_right" >> $LOGFILE 2>&1
retval=$?
if [ $retval -ne 0 ]; then
quit $retval
fi
echo "Authorization rule set"
echo "Publishing functions app $USER_FUNCTIONS_APP_NAME ..."
func azure functionapp publish "$USER_FUNCTIONS_APP_NAME" --force >> $LOGFILE 2>&1
retval=$?
if [ $retval -ne 0 ]; then
quit $retval
fi
echo "Functions app deployed"
popd > /dev/null
pushd "$DIR/ServiceBusCopyValidation" > /dev/null
echo "Building validation app ..."
dotnet build >> $LOGFILE 2>&1
echo "Running validation app ..."
cxnstring_left=$(az servicebus namespace authorization-rule keys list \
--resource-group $USER_RESOURCE_GROUP \
--namespace-name $USER_LEFT_NAMESPACE_NAME \
--name RootManageSharedAccessKey \
--output=json | jq -r .primaryConnectionString)
cxnstring_right=$(az servicebus namespace authorization-rule keys list \
--resource-group $USER_RESOURCE_GROUP \
--namespace-name $USER_RIGHT_NAMESPACE_NAME \
--name RootManageSharedAccessKey \
--output=json | jq -r .primaryConnectionString)
dotnet bin/Debug/netcoreapp3.1/ServiceBusCopyValidation.dll \
-t "$cxnstring_left" -s "$cxnstring_right" \
-qt jobs -qs jobs/subscriptions/main >> $LOGFILE 2>&1
retval=$?
if [ $retval -ne 0 ]; then
quit $retval
fi
echo "Validation done"
echo "Deleting resource group ..."
az group delete --name $USER_RESOURCE_GROUP --yes >> $LOGFILE 2>&1
echo "Resource group deleted"
popd > /dev/null
popd > /dev/null