7
7
8
8
set -e
9
9
10
+ if (( $# != 1 )) ; then
11
+ echo " Illegal number of parameters"
12
+ echo " usage: services [create|start|stop]"
13
+ exit 1
14
+ fi
15
+
10
16
loadData () {
11
17
./import-data
18
+ waitForIoTAgent
12
19
echo " "
13
20
}
14
21
@@ -25,11 +32,57 @@ displayServices () {
25
32
echo " "
26
33
}
27
34
28
- if (( $# != 1 )) ; then
29
- echo " Illegal number of parameters"
30
- echo " usage: services [create|start|stop]"
31
- exit 1
32
- fi
35
+ addDatabaseIndex () {
36
+ printf " Adding appropriate \033[1mMongoDB\033[0m indexes for \033[1;34mOrion\033[0m ..."
37
+ docker exec db-mongo mongo --eval '
38
+ conn = new Mongo();db.createCollection("orion");
39
+ db = conn.getDB("orion");
40
+ db.createCollection("entities");
41
+ db.entities.createIndex({"_id.servicePath": 1, "_id.id": 1, "_id.type": 1}, {unique: true});
42
+ db.entities.createIndex({"_id.type": 1});
43
+ db.entities.createIndex({"_id.id": 1});' > /dev/null
44
+
45
+ docker exec db-mongo mongo --eval '
46
+ conn = new Mongo();db.createCollection("orion-openiot");
47
+ db = conn.getDB("orion-openiot");
48
+ db.createCollection("entities");
49
+ db.entities.createIndex({"_id.servicePath": 1, "_id.id": 1, "_id.type": 1}, {unique: true});
50
+ db.entities.createIndex({"_id.type": 1});
51
+ db.entities.createIndex({"_id.id": 1});' > /dev/null
52
+ echo -e " \033[1;32mdone\033[0m"
53
+
54
+ printf " Adding appropriate \033[1mMongoDB\033[0m indexes for \033[1;36mIoT-Agent\033[0m ..."
55
+ docker exec db-mongo mongo --eval '
56
+ conn = new Mongo();
57
+ db = conn.getDB("iotagentul");
58
+ db.createCollection("devices");
59
+ db.devices.createIndex({"_id.service": 1, "_id.id": 1, "_id.type": 1});
60
+ db.devices.createIndex({"_id.type": 1});
61
+ db.devices.createIndex({"_id.id": 1});
62
+ db.createCollection("groups");
63
+ db.groups.createIndex({"_id.resource": 1, "_id.apikey": 1, "_id.service": 1});
64
+ db.groups.createIndex({"_id.type": 1});' > /dev/null
65
+ echo -e " \033[1;32mdone\033[0m"
66
+ }
67
+
68
+ waitForOrion () {
69
+ echo -e " \n⏳ Waiting for \033[1;34mOrion\033[0m to be available\n"
70
+ while [ ` docker run --network fiware_default --rm appropriate/curl -s -o /dev/null -w %{http_code} ' http://orion:1026/version' ` -eq 000 ]
71
+ do
72
+ echo -e " Context Broker HTTP state: " ` curl -s -o /dev/null -w %{http_code} ' http://localhost:1026/version' ` " (waiting for 200)"
73
+ sleep 1
74
+ done
75
+ }
76
+
77
+
78
+ waitForIoTAgent () {
79
+ echo -e " \n⏳ Waiting for \033[1;36mIoT-Agent\033[0m to be available\n"
80
+ while [ ` docker run --network fiware_default --rm appropriate/curl -s -o /dev/null -w %{http_code} ' http://iot-agent:4041/version' ` -eq 000 ]
81
+ do
82
+ echo -e " IoT Agent HTTP state: " ` curl -s -o /dev/null -w %{http_code} ' http://localhost:4041/version' ` " (waiting for 200)"
83
+ sleep 1
84
+ done
85
+ }
33
86
34
87
command=" $1 "
35
88
case " ${command} " in
@@ -45,6 +98,8 @@ case "${command}" in
45
98
echo -e " - \033[1mMosquitto\033[0m acts as an MQTT Message Broker"
46
99
echo " "
47
100
docker-compose --log-level ERROR -p fiware up -d --remove-orphans
101
+ addDatabaseIndex
102
+ waitForOrion
48
103
loadData
49
104
displayServices
50
105
echo -e " Now open \033[4mhttp://localhost:3000/device/monitor\033[0m"
0 commit comments