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