|
| 1 | +#! /usr/bin/env bash |
| 2 | + |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | + |
| 6 | +BULLET_EXAMPLES_VERSION=0.1.1 |
| 7 | +BULLET_UI_VERSION=0.1.0 |
| 8 | +BULLET_WS_VERSION=0.0.1 |
| 9 | +JETTY_VERSION=9.3.16.v20170120 |
| 10 | +STORM_VERSION=1.0.3 |
| 11 | +NVM_VERSION=0.33.1 |
| 12 | +NODE_VERSION=6.9.4 |
| 13 | + |
| 14 | +println() { |
| 15 | + local DATE="$(date)" |
| 16 | + local FORMAT=$1 |
| 17 | + shift |
| 18 | + printf "\n${DATE} [BULLET-QUICKSTART]: " |
| 19 | + printf "${FORMAT}\n" $* |
| 20 | +} |
| 21 | + |
| 22 | +export_vars() { |
| 23 | + local PWD="$(pwd)" |
| 24 | + |
| 25 | + println "Exporting some variables..." |
| 26 | + export BULLET_HOME="${PWD}/bullet-quickstart" |
| 27 | + export BULLET_EXAMPLES=$BULLET_HOME/bullet-examples |
| 28 | + println "Done!" |
| 29 | + |
| 30 | + println "Using the following artifacts..." |
| 31 | + println "Bullet Examples: ${BULLET_EXAMPLES_VERSION}" |
| 32 | + println "Bullet Web Service: ${BULLET_WS_VERSION}" |
| 33 | + println "Bullet UI: ${BULLET_UI_VERSION}" |
| 34 | + println "Jetty: ${JETTY_VERSION}" |
| 35 | + println "Storm: ${STORM_VERSION}" |
| 36 | + println "NVM: ${NVM_VERSION}" |
| 37 | + println "Node.js: ${NODE_VERSION}" |
| 38 | + println "Done!" |
| 39 | +} |
| 40 | + |
| 41 | +setup() { |
| 42 | + println "Setting up directories..." |
| 43 | + mkdir -p $BULLET_HOME/backend/storm |
| 44 | + mkdir -p $BULLET_HOME/service |
| 45 | + mkdir -p $BULLET_HOME/ui |
| 46 | + println "Done!" |
| 47 | +} |
| 48 | + |
| 49 | +install_bullet_examples() { |
| 50 | + cd "${BULLET_HOME}" |
| 51 | + println "Downloading Bullet Examples ${BULLET_EXAMPLES_VERSION}..." |
| 52 | + curl -#LO "https://github.com/yahoo/bullet-docs/releases/download/v${BULLET_EXAMPLES_VERSION}/examples_artifacts.tar.gz" |
| 53 | + println "Installing Bullet Examples..." |
| 54 | + tar -xzf examples_artifacts.tar.gz |
| 55 | + println "Done!" |
| 56 | +} |
| 57 | + |
| 58 | +install_storm() { |
| 59 | + local STORM="apache-storm-${STORM_VERSION}" |
| 60 | + |
| 61 | + cd "${BULLET_HOME}/backend" |
| 62 | + |
| 63 | + println "Downloading Storm ${STORM_VERSION}..." |
| 64 | + curl -#O "http://apache.org/dist/storm/${STORM}/${STORM}.zip" |
| 65 | + |
| 66 | + println "Installing Storm ..." |
| 67 | + unzip -qq "${STORM}.zip" |
| 68 | + |
| 69 | + println "Configuring Storm ..." |
| 70 | + export PATH="$BULLET_HOME/backend/${STORM}/bin/:${PATH}" |
| 71 | + echo 'drpc.servers: ["127.0.0.1"]' >> "${STORM}/conf/storm.yaml" |
| 72 | + println "Done!" |
| 73 | +} |
| 74 | + |
| 75 | +launch_storm() { |
| 76 | + println "Launching Storm Dev Zookeeper..." |
| 77 | + storm dev-zookeeper & |
| 78 | + |
| 79 | + println "Launching Storm Nimbus..." |
| 80 | + storm nimbus & |
| 81 | + |
| 82 | + println "Launching Storm DRPC..." |
| 83 | + storm drpc & |
| 84 | + |
| 85 | + println "Launching Storm UI..." |
| 86 | + storm ui & |
| 87 | + |
| 88 | + println "Launching Storm LogViewer..." |
| 89 | + storm logviewer & |
| 90 | + |
| 91 | + println "Launching a Storm Supervisor..." |
| 92 | + storm supervisor & |
| 93 | + |
| 94 | + println "Sleeping for 60 s to ensure all components are up..." |
| 95 | + println "=====================================================================================================" |
| 96 | + sleep 60 |
| 97 | + println "=====================================================================================================" |
| 98 | + println "Done!" |
| 99 | +} |
| 100 | + |
| 101 | +launch_bullet_storm() { |
| 102 | + println "Copying Bullet topology configuration and artifacts..." |
| 103 | + cp "${BULLET_EXAMPLES}/storm"/* "${BULLET_HOME}/backend/storm" |
| 104 | + |
| 105 | + println "Launching the Bullet topology..." |
| 106 | + cd "${BULLET_HOME}/backend/storm" && ./launch.sh |
| 107 | + |
| 108 | + println "Sleeping for 30 s to ensure all Bullet Storm components are up..." |
| 109 | + sleep 30 |
| 110 | + |
| 111 | + println "Getting one random record from the Bullet topology..." |
| 112 | + curl -s -X POST -d '{}' http://localhost:3774/drpc/bullet |
| 113 | + println "Done!" |
| 114 | +} |
| 115 | + |
| 116 | +install_jetty() { |
| 117 | + cd "${BULLET_HOME}/service" |
| 118 | + |
| 119 | + println "Downloading Jetty ${JETTY_VERSION}..." |
| 120 | + curl -#O "http://central.maven.org/maven2/org/eclipse/jetty/jetty-distribution/${JETTY_VERSION}/jetty-distribution-${JETTY_VERSION}.zip" |
| 121 | + |
| 122 | + println "Installing Jetty..." |
| 123 | + unzip -qq "jetty-distribution-${JETTY_VERSION}.zip" |
| 124 | + println "Done!" |
| 125 | +} |
| 126 | + |
| 127 | +launch_bullet_web_service() { |
| 128 | + cd "${BULLET_HOME}/service/jetty-distribution-${JETTY_VERSION}" |
| 129 | + |
| 130 | + println "Downloading Bullet Web Service ${BULLET_WS_VERSION}..." |
| 131 | + curl -#Lo webapps/bullet-service.war \ |
| 132 | + "http://jcenter.bintray.com/com/yahoo/bullet/bullet-service/${BULLET_WS_VERSION}/bullet-service-${BULLET_WS_VERSION}.war" |
| 133 | + |
| 134 | + println "Configuring Bullet Web Service..." |
| 135 | + cp "${BULLET_EXAMPLES}/web-service"/example_* "${BULLET_HOME}/service/jetty-distribution-${JETTY_VERSION}" |
| 136 | + |
| 137 | + println "Launching Bullet Web Service..." |
| 138 | + cd "${BULLET_HOME}/service/jetty-distribution-${JETTY_VERSION}" |
| 139 | + java -jar -Dbullet.service.configuration.file="example_context.properties" -Djetty.http.port=9999 start.jar > logs/out 2>&1 & |
| 140 | + |
| 141 | + println "Sleeping for 30 s to ensure Bullet Web Service is up..." |
| 142 | + sleep 30 |
| 143 | + |
| 144 | + println "Getting one random record from Bullet through the Web Service..." |
| 145 | + curl -s -X POST -d '{}' http://localhost:9999/bullet-service/api/drpc |
| 146 | + println "Getting column schema from the Web Service..." |
| 147 | + curl -s http://localhost:9999/bullet-service/api/columns |
| 148 | + println "Finished Bullet Web Service test" |
| 149 | +} |
| 150 | + |
| 151 | +install_node() { |
| 152 | + println "Downloading and installing NVM ${NVM_VERSION}..." |
| 153 | + curl -s "https://raw.githubusercontent.com/creationix/nvm/v${NVM_VERSION}/install.sh" | bash |
| 154 | + |
| 155 | + source ~/.bashrc |
| 156 | + println "Installing Node ${NODE_VERSION}..." |
| 157 | + |
| 158 | + # NVM unset var bug |
| 159 | + set +u |
| 160 | + nvm install "v${NODE_VERSION}" |
| 161 | + nvm use "v${NODE_VERSION}" |
| 162 | + set -u |
| 163 | + |
| 164 | + println "Done!" |
| 165 | +} |
| 166 | + |
| 167 | +launch_bullet_ui() { |
| 168 | + cd "${BULLET_HOME}/ui" |
| 169 | + |
| 170 | + println "Downloading Bullet UI ${BULLET_UI_VERSION}..." |
| 171 | + curl -#LO "https://github.com/yahoo/bullet-ui/releases/download/v${BULLET_UI_VERSION}/bullet-ui-v${BULLET_UI_VERSION}.tar.gz" |
| 172 | + |
| 173 | + println "Installing Bullet UI..." |
| 174 | + tar -xzf "bullet-ui-v${BULLET_UI_VERSION}.tar.gz" |
| 175 | + |
| 176 | + println "Configuring Bullet UI..." |
| 177 | + cp "${BULLET_EXAMPLES}/ui/env-settings.json" config/ |
| 178 | + |
| 179 | + println "Launching Bullet UI..." |
| 180 | + PORT=8800 node express-server.js & |
| 181 | + |
| 182 | + println "Sleeping for 5 s to ensure Bullet UI is up..." |
| 183 | + sleep 5 |
| 184 | + println "Done!" |
| 185 | +} |
| 186 | + |
| 187 | +cleanup() { |
| 188 | + set +eo pipefail |
| 189 | + |
| 190 | + storm kill bullet && sleep 30 |
| 191 | + |
| 192 | + ps aux | grep "[e]xpress-server.js" | awk '{print $2}' | xargs kill |
| 193 | + |
| 194 | + ps aux | grep "[e]xample_context.properties" | awk '{print $2}' | xargs kill |
| 195 | + |
| 196 | + ps aux | grep "[a]pache-storm-${STORM_VERSION}" | awk '{print $2}' | xargs kill |
| 197 | + |
| 198 | + rm -rf "${BULLET_HOME}" /tmp/dev-storm-zookeeper /tmp/jetty-* |
| 199 | + |
| 200 | + set -eo pipefail |
| 201 | +} |
| 202 | + |
| 203 | +teardown() { |
| 204 | + println "Killing all Bullet components. This may take a while if the topology is up..." |
| 205 | + cleanup &> /dev/null |
| 206 | + println "Done!" |
| 207 | +} |
| 208 | + |
| 209 | +unset_all() { |
| 210 | + unset -f println export_vars setup install_bullet_examples \ |
| 211 | + install_storm launch_storm launch_bullet_storm \ |
| 212 | + install_jetty launch_bullet_web_service \ |
| 213 | + install_node launch_bullet_ui \ |
| 214 | + cleanup teardown unset_all launch |
| 215 | +} |
| 216 | + |
| 217 | +launch() { |
| 218 | + export_vars |
| 219 | + |
| 220 | + teardown |
| 221 | + |
| 222 | + setup |
| 223 | + install_bullet_examples |
| 224 | + |
| 225 | + install_storm |
| 226 | + launch_storm |
| 227 | + launch_bullet_storm |
| 228 | + |
| 229 | + install_jetty |
| 230 | + launch_bullet_web_service |
| 231 | + |
| 232 | + install_node |
| 233 | + launch_bullet_ui |
| 234 | + |
| 235 | + println "All components launched! Visit localhost:8800 (default) for the UI" |
| 236 | + unset_all |
| 237 | +} |
| 238 | + |
| 239 | +launch |
| 240 | + |
0 commit comments