-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathidr-data.sh
executable file
·66 lines (52 loc) · 2.15 KB
/
idr-data.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
#!/bin/sh
# chmod +x this file to make it executable
SERVICE_NAME="Identity Resolver"
# Max number of retries
MAX_RETRIES=3
RETRY_COUNT=0
# Path to the IDR identifier JSON file for gs1 namespace
GS1_IDENTIFIER_FILE="./seeding/idr-identifier.gs1.json"
# Path to the IDR identifier JSON file for nlis namespace
NLIS_IDENTIFIER_FILE="./seeding/idr-identifier.nlis.json"
# Path to the IDR identifier JSON file for nlis namespace
ATO_IDENTIFIER_FILE="./seeding/idr-identifier.ato.json"
# Wait for the service to be available
echo "Waiting for ${SERVICE_NAME} service to be ready..."
# Loop until the health API returns "status": "OK"
while true; do
# If max retries reached, exit with error
if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then
echo "${SERVICE_NAME} service did not become healthy after $MAX_RETRIES attempts. Exiting..."
exit 1
fi
# Make the health check request and store the status
HEALTH_STATUS=$(curl -s http://${IDR_SERVICE_HOST}:${IDR_SERVICE_PORT}/health-check | grep -o '"status":"OK"')
if [ "$HEALTH_STATUS" = '"status":"OK"' ]; then
echo "${SERVICE_NAME} service is healthy!"
break
fi
RETRY_COUNT=$((RETRY_COUNT+1))
echo "${SERVICE_NAME} service is not healthy yet. Retrying in 5 seconds..."
sleep 5 # Wait for 5 seconds before checking again
done
echo "${SERVICE_NAME} service is seeding data…"
# Execute create identifier request with JSON data from a file
curl -X POST \
http://${IDR_SERVICE_HOST}:${IDR_SERVICE_PORT}/api/identifiers \
-H 'accept: application/json' \
-H "Authorization: Bearer ${IDR_SERVICE_API_KEY}" \
-H 'Content-Type: application/json' \
-d @"$GS1_IDENTIFIER_FILE"
curl -X POST \
http://${IDR_SERVICE_HOST}:${IDR_SERVICE_PORT}/api/identifiers \
-H 'accept: application/json' \
-H "Authorization: Bearer ${IDR_SERVICE_API_KEY}" \
-H 'Content-Type: application/json' \
-d @"$NLIS_IDENTIFIER_FILE"
curl -X POST \
http://${IDR_SERVICE_HOST}:${IDR_SERVICE_PORT}/api/identifiers \
-H 'accept: application/json' \
-H "Authorization: Bearer ${IDR_SERVICE_API_KEY}" \
-H 'Content-Type: application/json' \
-d @"$ATO_IDENTIFIER_FILE"
printf "\nSeeding ${SERVICE_NAME} service data complete!\n\n"