Skip to content

Commit 3978b25

Browse files
Scott Shambargermarkgoddard
authored andcommitted
monasca-thresh: Allow topology check and removal in storm
Patch adds a script in the monasca-thresh image that can be used to check if a topology exists in Storm, and optionally kill it. This is part of a bug in kolla-ansible where topologies were not submitted to Storm, but run locally. This patch includes a topology check script enabled by KOLLA_BOOTSTRAP which will exit kolla_start if the topology exists, and optionally enables topology removal (to allow replacement) enabled by TOPOLOGY_REPLACE. Topology names and various timeouts may be customized. If the new env variables are not set, existing behavior is unchanged. Partial-Bug: #1808805 Change-Id: If8f0730031435dda4235b7f2d2c23e5f5f767f87
1 parent 99e4849 commit 3978b25

File tree

4 files changed

+111
-1
lines changed

4 files changed

+111
-1
lines changed

docker/monasca/monasca-thresh/Dockerfile.j2

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,14 @@ RUN cd /monasca-common-source/java \
6666

6767
# Overwrite the script inherited from Storm
6868
COPY extend_start.sh /usr/local/bin/kolla_extend_start
69+
70+
# Add bootstrap script
71+
COPY topology_bootstrap.sh /usr/local/bin/topology_bootstrap
72+
6973
RUN touch /usr/local/bin/kolla_monasca_extend_start \
70-
&& chmod 755 /usr/local/bin/kolla_extend_start /usr/local/bin/kolla_monasca_extend_start
74+
&& chmod 755 /usr/local/bin/kolla_extend_start \
75+
/usr/local/bin/kolla_monasca_extend_start \
76+
/usr/local/bin/topology_bootstrap
7177

7278
{% block monasca_thresh_footer %}{% endblock %}
7379
{% block footer %}{% endblock %}

docker/monasca/monasca-thresh/extend_start.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,9 @@ if [[ $(ls -Ab ${MONASCA_WORKER_DIR}) != "" ]]; then
4242
fi
4343

4444
. /usr/local/bin/kolla_monasca_extend_start
45+
46+
# Bootstrap and exit if KOLLA_BOOTSTRAP variable is set. This catches all cases
47+
# of the KOLLA_BOOTSTRAP variable being set, including empty.
48+
if [[ "${!KOLLA_BOOTSTRAP[@]}" ]]; then
49+
. /usr/local/bin/topology_bootstrap
50+
fi
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/bin/sh
2+
3+
# This script should be sourced by kolla_extend_start when bootstrapping
4+
#
5+
# Optional env(<default>):
6+
# TOPOLOGY_NAME("monasca-thresh") - topology name to check
7+
# TOPOLOGY_KILL_TIMEOUT(5) - secs to wait for topology kill
8+
# STORM_WAIT_RETRIES(24) - retries to check for storm
9+
# STORM_WAIT_TIMEOUT(20) - secs to wait for storm list
10+
# STORM_WAIT_DELAY(5) - secs between storm list attempts
11+
12+
# - If topology exists, then:
13+
# a) if TOPOLOGY_REPLACE is set, the existing topology is killed
14+
# and script falls through (topology may be added)
15+
# b) otherwise script exits with 0 (topology already exists)
16+
# - If topology doesn't exist, script falls through (topology may be added)
17+
# - If storm cannot be reached, or kill fails, script exits with 1
18+
19+
TOPOLOGY_NAME=${TOPOLOGY_NAME:-monasca-thresh}
20+
TOPOLOGY_KILL_TIMEOUT=${TOPOLOGY_KILL_TIMEOUT:-5}
21+
22+
# defaults from monasca-thresh
23+
STORM_WAIT_RETRIES=${STORM_WAIT_RETRIES:-24}
24+
STORM_WAIT_TIMEOUT=${STORM_WAIT_TIMEOUT:-20}
25+
STORM_WAIT_DELAY=${STORM_WAIT_DELAY:-5}
26+
27+
STORM="/opt/storm/bin/storm"
28+
29+
echo "Waiting for storm to become available..."
30+
success="false"
31+
for i in $(seq "$STORM_WAIT_RETRIES"); do
32+
if timeout "$STORM_WAIT_TIMEOUT" "$STORM" list; then
33+
echo "Storm is available, continuing..."
34+
success="true"
35+
break
36+
else
37+
echo "Connection attempt $i of $STORM_WAIT_RETRIES failed"
38+
sleep "$STORM_WAIT_DELAY"
39+
fi
40+
done
41+
42+
if [ "$success" != "true" ]; then
43+
echo "Unable to connect to Storm! Exiting..."
44+
sleep 1
45+
exit 1
46+
fi
47+
48+
locate_topology() { # <topology>
49+
echo "Searching for topology $1 in the storm"
50+
topologies=$("$STORM" list | awk '/-----/,0{if (!/-----/)print $1}')
51+
found="false"
52+
for topology in $topologies; do
53+
if [ "$topology" = "$1" ]; then
54+
echo "Found storm topology with name: $topology"
55+
found="true"
56+
break
57+
fi
58+
done
59+
}
60+
61+
# search for existing topology
62+
locate_topology "$TOPOLOGY_NAME"
63+
64+
if [ "$found" = "true" ]; then
65+
66+
if [[ ! "${!TOPOLOGY_REPLACE[@]}" ]]; then
67+
echo "Topology $TOPOLOGY_NAME found, submission not necessary"
68+
exit 0
69+
fi
70+
71+
echo "Topology replacement requested, killing old one..."
72+
"$STORM" kill "$TOPOLOGY_NAME" -w "$TOPOLOGY_KILL_TIMEOUT"
73+
74+
echo "Wait $TOPOLOGY_KILL_TIMEOUT secs for topology to reap its artifacts..."
75+
sleep "$TOPOLOGY_KILL_TIMEOUT"
76+
77+
for i in $(seq "$STORM_WAIT_RETRIES"); do
78+
locate_topology "$TOPOLOGY_NAME"
79+
[ "$found" != "true" ] && break
80+
echo "... wait some more..."
81+
sleep "$STORM_WAIT_DELAY"
82+
done
83+
if [ "$found" = "true" ]; then
84+
echo "Unable to kill existing topology, giving up..."
85+
exit 1
86+
fi
87+
echo "Topology successfully killed, continuing..."
88+
else
89+
echo "Topology not found, continuing..."
90+
fi
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
fixes:
3+
- |
4+
Adds an option to the monasca-thresh container which checks
5+
if the topology is currently submitted (KOLLA_BOOTSTRAP), with
6+
an option to kill it (TOPOLOGY_REPLACE). Topology names
7+
and various timeouts may be customized.
8+
`LP#1808805 <https://launchpad.net/bugs/1808805>`__

0 commit comments

Comments
 (0)