-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathservices
executable file
·213 lines (195 loc) · 6.61 KB
/
services
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
205
206
207
208
209
210
211
212
213
#!/bin/bash
#
# Command Line Interface to start all services associated with the Entity-Relationships Tutorial
#
# For this tutorial the commands are merely a convenience script to run docker compose
#
set -e
SCORPIO="http://scorpio:9090/"
ORION="http://orion:1026/version"
STELLIO="http://localhost:8080/actuator/health"
CONTEXT="http://context/ngsi-context.jsonld"
CORE_CONTEXT="https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.8.jsonld"
dockerCmd="docker compose"
if (( $# == 2 )); then
dockerCmd="docker-compose"
fi
if (( $# < 1 )); then
echo "Illegal number of parameters"
echo "usage: services [create|orion|scorpio|stop]"
exit 1
fi
pause(){
printf " "
count="$1"
[ "$count" -gt 59 ] && printf "Waiting one minute " || printf " Waiting a few seconds ";
while [ "$count" -gt 0 ]
do
printf "."
sleep 3
count=$((count - 3))
done
echo ""
}
getHeartbeat(){
eval "response=$(docker run --network fiware_default --rm quay.io/curl/curl -s -o /dev/null -w "%{http_code}" "$1")"
}
waitForOrionLD () {
echo -e "\n⏳ Waiting for \033[1;34mOrion-LD\033[0m to be available\n"
while ! [ `docker inspect --format='{{.State.Health.Status}}' fiware-orion-ld` == "healthy" ]
do
echo -e "\nContext Broker HTTP state: ${response} (waiting for 200)"
pause 6
getHeartbeat "${ORION}"
done
}
waitForScorpio () {
echo -e "\n⏳ Waiting for \033[1;34mScorpio\033[0m to respond\n"
getHeartbeat "${SCORPIO}"
while [ "${response}" -eq 000 ]
do
echo -e "Context Broker HTTP state: ${response} (waiting for 404)"
pause 6
getHeartbeat "${SCORPIO}"
done
}
waitForStellio () {
echo -e "\n⏳ Waiting for \033[1;34mStellio\033[0m to respond\n"
waitSeconds=30
while [ `docker run --network fiware_default --rm quay.io/curl/curl -s -o /dev/null -w %{http_code} 'http://stellio:8080/ngsi-ld/v1/entities/?type=X'` -eq 000 ]
do
echo -e "Context Broker HTTP state: " `curl -s -o /dev/null -w %{http_code} 'http://localhost:8080/ngsi-ld/v1/entities/?type=X'` " (waiting for 500)"
echo -e "Waiting for ${waitSeconds} seconds ..."
sleep ${waitSeconds}
done
echo -e "\n⏳ Waiting for all \033[1;34mStellio\033[0m services to be available\n"
while [ `docker run --network fiware_default --rm quay.io/curl/curl -s -o /dev/null -w %{http_code} 'http://stellio:8080/ngsi-ld/v1/entities/?type=X'` -eq 500 ]
do
echo -e "Context Broker HTTP state: " `curl -s -o /dev/null -w %{http_code} 'http://localhost:8080/ngsi-ld/v1/entities/?type=X'` " (waiting for 200)"
echo -e "Waiting for ${waitSeconds} seconds ..."
sleep ${waitSeconds}
done
}
waitForUserContext () {
echo -e "\n⏳ Waiting for the data models \033[1m@context\033[0m to be available (Smart Supermarket)\n"
getHeartbeat "${CONTEXT}"
while [ "${response}" -eq 000 ]
do
echo -e "\n@context HTTP state: ${response} (waiting for 200)"
pause 3
getHeartbeat "${CONTEXT}"
done
}
waitForCoreContext () {
echo -e "\n⏳ Checking availability of \033[1m core @context\033[0m from ETSI\n"
eval "response=$(docker run --rm quay.io/curl/curl -s -o /dev/null -w "%{http_code}" "$CORE_CONTEXT")"
while [ "${response}" -eq 000 ]
do
echo -e "\n@context HTTP state: ${response} (waiting for 200)"
pause 3
eval "response=$(docker run --rm quay.io/curl/curl -s -o /dev/null -w "%{http_code}" "$CORE_CONTEXT")"
done
}
waitForMongo () {
echo -e "\n⏳ Waiting for \033[1mMongoDB\033[0m to be available\n"
while ! [ `docker inspect --format='{{.State.Health.Status}}' db-mongo` == "healthy" ]
do
sleep 1
done
}
loadData () {
echo ""
waitForUserContext
docker run --rm -v $(pwd)/import-data:/import-data \
--network fiware_default \
-e CONTEXT_BROKER=${CONTEXT_BROKER} \
-e TUTORIAL_DATA_MODELS_CONTEXT=${CONTEXT} \
--entrypoint /bin/ash quay.io/curl/curl /import-data
}
stoppingContainers () {
CONTAINERS=$(docker ps -aq)
if [[ -n $CONTAINERS ]]; then
echo "Stopping containers"
docker rm -f $CONTAINERS
fi
VOLUMES=$(docker volume ls -qf dangling=true)
if [[ -n $VOLUMES ]]; then
echo "Removing old volumes"
docker volume rm $VOLUMES
fi
}
displayServices () {
echo ""
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" --filter name=$1-*
echo ""
}
command="$1"
case "${command}" in
"help")
echo "usage: services [create|orion|scorpio|stop]"
;;
"orion")
export $(cat .env | grep "#" -v)
stoppingContainers
waitForCoreContext
echo -e "Starting containers: \033[1;34mOrion\033[0m, \033[1mTutorial\033[0m and a \033[1mMongoDB\033[0m database."
echo -e "- \033[1;34mOrion\033[0m is the context broker"
echo -e "- Data models \033[1m@context\033[0m (Smart Supermarket) is supplied externally"
echo ""
${dockerCmd} -f docker-compose/common.yml -f docker-compose/orion-ld.yml up -d --remove-orphans --renew-anon-volumes
waitForMongo
waitForOrionLD
export CONTEXT_BROKER=orion:1026
loadData
displayServices fiware
;;
"scorpio")
export $(cat .env | grep "#" -v)
stoppingContainers
waitForCoreContext
echo -e "Starting containers: \033[1;34mScorpio\033[0m, \033[1mKafka\033[0m, \033[1mZookeeper\033[0m and a \033[1mPostgres\033[0m database, \033[1;36mIoT-Agent\033[0m, \033[1mTutorial\033[0m and a \033[1mMongoDB\033[0m database."
echo -e "- \033[1;34mScorpio\033[0m is the context broker"
echo -e "- Data models \033[1m@context\033[0m (Smart Supermarket) is supplied externally"
echo ""
${dockerCmd} -f docker-compose/common.yml -f docker-compose/scorpio.yml up -d --remove-orphans --renew-anon-volumes
waitForMongo
waitForScorpio
export CONTEXT_BROKER=scorpio:9090
loadData
displayServices fiware
;;
"stellio")
export $(cat .env | grep "#" -v)
stoppingContainers
waitForCoreContext
echo -e "Starting containers: \033[1;34mStellio\033[0m, \033[1mKafka\033[0m, \033[1mPostgreSQL/TimescaleDB\033[0m, and a linked data \033[1mContext\033[0m."
echo -e "- \033[1;34mStellio\033[0m is the context broker\n"
echo -e "- Data models \033[1m@context\033[0m (Smart Supermarket) is supplied externally"
echo ""
${dockerCmd} -f docker-compose/common.yml -f docker-compose/stellio.yml up -d --remove-orphans --renew-anon-volumes
waitForMongo
waitForStellio
export CONTEXT_BROKER=stellio:8080
loadData
displayServices stellio
;;
"stop")
export $(cat .env | grep "#" -v)
stoppingContainers
;;
"start")
export $(cat .env | grep "#" -v)
./services orion $2
;;
"create")
export $(cat .env | grep "#" -v)
echo "Pulling Docker images"
docker pull -q quay.io/curl/curl
${dockerCmd} -f docker-compose/common.yml -f docker-compose/scorpio.yml -f docker-compose/orion-ld.yml -f docker-compose/stellio.yml pull
;;
*)
echo "Command not Found."
echo "usage: services [create|orion|scorpio|stop]"
exit 127;
;;
esac