|
| 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 |
0 commit comments