62805c679a35fba6466c72e51e0ee491ead13793
[demos/kafka/wordcount] / README.sh
1 #!/bin/bash
2
3 FORTUNE=juplo/wordcount--fortune:1.0.1
4 RECORDER=juplo/wordcount--recorder:1.2.2
5 USERS=juplo/wordcount--users:1.0.7
6 SPLITTER=juplo/wordcount--splitter:1.2.2
7 COUNTER=juplo/wordcount--counter:1.4.2
8 TOP10=juplo/wordcount--top10:1.4.2
9 QUERY=juplo/wordcount--query:2.1.2
10 POPULAR=juplo/wordcount--popular:1.3.2
11
12 if [ "$1" = "cleanup" ]
13 then
14   docker compose down -v --remove-orphans
15   docker image rm $FORTUNE
16   docker image rm $RECORDER
17   docker image rm $USERS
18   docker image rm $SPLITTER
19   docker image rm $COUNTER
20   docker image rm $TOP10
21   docker image rm $QUERY
22   docker image rm $POPULAR
23   exit
24 fi
25
26 if [[
27   $(docker image ls -q $FORTUNE) == "" ||
28   $(docker image ls -q $RECORDER) == "" ||
29   $(docker image ls -q $USERS) == "" ||
30   $(docker image ls -q $SPLITTER) == "" ||
31   $(docker image ls -q $COUNTER) == "" ||
32   $(docker image ls -q $TOP10) == "" ||
33   $(docker image ls -q $QUERY) == "" ||
34   $(docker image ls -q $POPULAR) == "" ||
35   "$1" = "build"
36 ]]
37 then
38   docker compose rm -svf bart riddler nerd recorder users splitter counter top10 query popular
39 fi
40
41 if [[ $(docker image ls -q $FORTUNE) == "" || "$1" = "build" ]]
42 then
43   echo "Building image $FORTUNE"
44   ( cd fortune; ./README.sh $FORTUNE; )
45 else
46   echo -n "Using existing image for $FORTUNE: "
47   docker image ls --format json $FORTUNE | jq -r '(.ID + " - " + .CreatedSince)'
48 fi
49
50 if [[ $(docker image ls -q $RECORDER) == "" || "$1" = "build" ]]
51 then
52   echo "Building image $RECORDER"
53   mvn -f recorder/pom.xml clean package docker:build
54 else
55   echo -n "Using existing image for $RECORDER: "
56   docker image ls --format json $RECORDER | jq -r '(.ID + " - " + .CreatedSince)'
57 fi
58
59 if [[ $(docker image ls -q $USERS) == "" || "$1" = "build" ]]
60 then
61   echo "Building image $USERS"
62   mvn -f users/pom.xml clean package docker:build
63 else
64   echo -n "Using existing image for $USERS: "
65   docker image ls --format json $USERS | jq -r '(.ID + " - " + .CreatedSince)'
66 fi
67
68 if [[ $(docker image ls -q $SPLITTER) == "" || "$1" = "build" ]]
69 then
70   echo "Building image $SPLITTER"
71   mvn -f splitter/pom.xml clean package docker:build
72 else
73   echo -n "Using existing image for $SPLITTER: "
74   docker image ls --format json $SPLITTER | jq -r '(.ID + " - " + .CreatedSince)'
75 fi
76
77 if [[ $(docker image ls -q $COUNTER) == "" || "$1" = "build" ]]
78 then
79   echo "Building image $COUNTER"
80   mvn -f counter/pom.xml clean package docker:build
81 else
82   echo -n "Using existing image for $COUNTER: "
83   docker image ls --format json $COUNTER | jq -r '(.ID + " - " + .CreatedSince)'
84 fi
85
86 if [[ $(docker image ls -q $TOP10) == "" || "$1" = "build" ]]
87 then
88   echo "Building image $TOP10"
89   mvn -f top10/pom.xml clean package docker:build
90 else
91   echo -n "Using existing image for $TOP10: "
92   docker image ls --format json $TOP10 | jq -r '(.ID + " - " + .CreatedSince)'
93 fi
94
95 if [[ $(docker image ls -q $QUERY) == "" || "$1" = "build" ]]
96 then
97   echo "Building image $QUERY"
98   mvn -f query/pom.xml clean package docker:build
99 else
100   echo -n "Using existing image for $QUERY: "
101   docker image ls --format json $QUERY | jq -r '(.ID + " - " + .CreatedSince)'
102 fi
103
104 if [[ $(docker image ls -q $POPULAR) == "" || "$1" = "build" ]]
105 then
106   echo "Building image $POPULAR"
107   mvn -f popular/pom.xml clean package docker:build
108 else
109   echo -n "Using existing image for $POPULAR: "
110   docker image ls --format json $POPULAR | jq -r '(.ID + " - " + .CreatedSince)'
111 fi
112
113
114 docker compose up setup
115
116 echo "Starting the service 'users'..."
117 docker compose up -d users
118 while [ "$(http users.localhost/actuator/health 2> /dev/null | jq -r .status 2> /dev/null)" != "UP" ]; do echo "Waiting for service users..."; sleep 1; done
119 http -v post users.localhost username=bart firstName=Bart lastName=Simpson sex=MALE
120 http -v post users.localhost username=nerd firstName=Jane lastName=Doe sex=FEMALE
121 http -v post users.localhost username=riddler firstName=Rumpel lastName=Stilzchen sex=MALE
122
123 echo "Starting the other instances..."
124 docker compose up -d recorder
125 docker compose up -d splitter
126 docker compose up -d counter
127 docker compose up -d top10
128 docker compose up -d query
129
130 echo "Starting the simulated users..."
131 docker compose up -d bart nerd riddler
132
133 while [ "$(http query.localhost/actuator/health 2>/dev/null | jq -r .status 2> /dev/null)" != "UP" ]; do echo "Waiting for service query..."; sleep 1; done
134 http -v query.localhost/bart
135 sleep 1
136 http -v query.localhost/bart
137 sleep 1
138 http -v query.localhost/bart
139 sleep 1
140 http -v query.localhost/bart
141 sleep 1
142 http -v query.localhost/bart
143 sleep 1
144 http -v query.localhost/bart
145 sleep 1
146 http -v query.localhost/bart
147 http -v query.localhost/nerd
148 http -v query.localhost/riddler
149
150 # docker compose up -d --scale query=5 query
151 http -v --follow query.localhost/bart
152 sleep 1
153 http -v --follow query.localhost/bart
154 sleep 1
155 http -v --follow query.localhost/bart
156 sleep 1
157 http -v --follow query.localhost/bart
158 sleep 1
159 http -v --follow query.localhost/bart
160 sleep 1
161 http -v --follow query.localhost/bart
162 sleep 1
163 http -v --follow query.localhost/bart
164
165 http -v --follow query.localhost/nerd
166 http -v --follow query.localhost/nerd
167 http -v --follow query.localhost/nerd
168 http -v --follow query.localhost/nerd
169 http -v --follow query.localhost/nerd
170
171 http -v --follow query.localhost/riddler
172 http -v --follow query.localhost/riddler
173 http -v --follow query.localhost/riddler
174 http -v --follow query.localhost/riddler
175 http -v --follow query.localhost/riddler