Lusheng Ji | d6d409f | 2018-03-22 23:25:45 -0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # ================================================================================ |
| 3 | # Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. |
| 4 | # ================================================================================ |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # ============LICENSE_END========================================================= |
| 17 | |
| 18 | set -e |
| 19 | |
| 20 | CDAP_HOST='localhost' |
| 21 | CDAP_PORT='11015' |
| 22 | TCA_NAMESPACE='cdap_tca_hi_lo' |
| 23 | TCA_APPNAME='dcae-tca' |
| 24 | |
| 25 | TCA_ARTIFACT='dcae-analytics-cdap-tca' |
Lusheng Ji | d6d409f | 2018-03-22 23:25:45 -0400 | [diff] [blame] | 26 | TCA_FILE_PATH='/opt/tca' |
Lusheng Ji | 1dd7a99 | 2018-05-10 23:54:18 -0400 | [diff] [blame^] | 27 | TCA_JAR="$(ls -1r ${TCA_FILE_PATH}/${TCA_ARTIFACT}*.jar | head -1)" |
| 28 | TCA_ARTIFACT_VERSION=$(echo "$TCA_JAR" |rev |cut -f 2-4 -d '.' |rev) |
Lusheng Ji | d6d409f | 2018-03-22 23:25:45 -0400 | [diff] [blame] | 29 | TCA_APP_CONF="${TCA_FILE_PATH}/tca_app_config.json" |
| 30 | TCA_CONF="${TCA_FILE_PATH}/tca_config.json" |
| 31 | TCA_PREF="${TCA_FILE_PATH}/tca_app_preferences.json" |
| 32 | TCA_CONF_TEMP='/tmp/tca_config.json' |
| 33 | TCA_APP_CONF_TEMP='/tmp/tca_app_config.json' |
| 34 | TCA_PREF_TEMP='/tmp/tca_preferences.json' |
| 35 | |
| 36 | TCA_PATH_APP="${CDAP_HOST}:${CDAP_PORT}/v3/namespaces/${TCA_NAMESPACE}/apps/${TCA_APPNAME}" |
| 37 | TCA_PATH_ARTIFACT="${CDAP_HOST}:${CDAP_PORT}/v3/namespaces/${TCA_NAMESPACE}/artifacts" |
| 38 | |
Lusheng Ji | d6d409f | 2018-03-22 23:25:45 -0400 | [diff] [blame] | 39 | |
Lusheng Ji | 1dd7a99 | 2018-05-10 23:54:18 -0400 | [diff] [blame^] | 40 | CONSUL_HOST=${CONSUL_HOST:-consul} |
| 41 | CONSUL_PORT=${CONSUL_PORT:-8500} |
Lusheng Ji | 3622f7a | 2018-04-04 21:51:34 -0400 | [diff] [blame] | 42 | CONFIG_BINDING_SERVICE=${CONFIG_BINDING_SERVICE:-config_binding_service} |
| 43 | |
| 44 | CBS_SERVICE_NAME=${CONFIG_BINDING_SERVICE} |
| 45 | |
vagrant | 61c202d | 2018-04-05 20:34:40 +0000 | [diff] [blame] | 46 | #Changing to HOSTNAME parameter for consistency with k8s deploy |
| 47 | MY_NAME=${HOSTNAME:-tca} |
Lusheng Ji | 3622f7a | 2018-04-04 21:51:34 -0400 | [diff] [blame] | 48 | |
Lusheng Ji | 3622f7a | 2018-04-04 21:51:34 -0400 | [diff] [blame] | 49 | |
| 50 | echo "Generting preference file" |
| 51 | sed -i 's/{{DMAAPHOST}}/'"${DMAAPHOST}"'/g' ${TCA_PREF} |
| 52 | sed -i 's/{{DMAAPPORT}}/'"${DMAAPPORT}"'/g' ${TCA_PREF} |
| 53 | sed -i 's/{{DMAAPPUBTOPIC}}/'"${DMAAPPUBTOPIC}"'/g' ${TCA_PREF} |
| 54 | sed -i 's/{{DMAAPSUBTOPIC}}/'"${DMAAPSUBTOPIC}"'/g' ${TCA_PREF} |
| 55 | sed -i 's/{{DMAAPSUBGROUP}}/OpenDCAEc12/g' ${TCA_PREF} |
| 56 | sed -i 's/{{DMAAPSUBID}}/c12/g' ${TCA_PREF} |
| 57 | sed -i 's/{{AAIHOST}}/'"${AAIHOST}"'/g' ${TCA_PREF} |
| 58 | sed -i 's/{{AAIPORT}}/'"${AAIPORT}"'/g' ${TCA_PREF} |
Lusheng Ji | 1dd7a99 | 2018-05-10 23:54:18 -0400 | [diff] [blame^] | 59 | if [ -z "$REDISHOSTPORT" ]; then |
Lusheng Ji | 3622f7a | 2018-04-04 21:51:34 -0400 | [diff] [blame] | 60 | sed -i 's/{{REDISHOSTPORT}}/NONE/g' ${TCA_PREF} |
| 61 | sed -i 's/{{REDISCACHING}}/false/g' ${TCA_PREF} |
| 62 | else |
| 63 | sed -i 's/{{REDISHOSTPORT}}/'"${REDISHOSTPORT}"'/g' ${TCA_PREF} |
| 64 | sed -i 's/{{REDISCACHING}}/true/g' ${TCA_PREF} |
| 65 | fi |
Lusheng Ji | d6d409f | 2018-03-22 23:25:45 -0400 | [diff] [blame] | 66 | |
| 67 | function tca_stop { |
| 68 | # stop programs |
| 69 | echo |
| 70 | echo "Stopping TCADMaaPMRPublisherWorker, TCADMaaPMRSubscriberWorker, and TCAVESCollectorFlow ..." |
| 71 | echo |
| 72 | curl -s -X POST "http://${TCA_PATH_APP}/workers/TCADMaaPMRPublisherWorker/stop" |
| 73 | curl -s -X POST "http://${TCA_PATH_APP}/workers/TCADMaaPMRSubscriberWorker/stop" |
| 74 | curl -s -X POST "http://${TCA_PATH_APP}/flows/TCAVESCollectorFlow/stop" |
| 75 | echo "done" |
| 76 | echo |
| 77 | } |
| 78 | |
| 79 | function tca_load_artifact { |
| 80 | echo |
Lusheng Ji | 3622f7a | 2018-04-04 21:51:34 -0400 | [diff] [blame] | 81 | echo "Loading artifact ${TCA_JAR} to http://${TCA_PATH_ARTIFACT}/${TCA_ARTIFACT}..." |
Lusheng Ji | d6d409f | 2018-03-22 23:25:45 -0400 | [diff] [blame] | 82 | curl -s -X POST --data-binary @"${TCA_JAR}" "http://${TCA_PATH_ARTIFACT}/${TCA_ARTIFACT}" |
| 83 | echo |
| 84 | } |
| 85 | |
| 86 | function tca_load_conf { |
| 87 | echo |
Lusheng Ji | 3622f7a | 2018-04-04 21:51:34 -0400 | [diff] [blame] | 88 | echo "Loading configuration ${TCA_APP_CONF} to http://${TCA_PATH_APP}" |
Lusheng Ji | d6d409f | 2018-03-22 23:25:45 -0400 | [diff] [blame] | 89 | curl -s -X PUT -d @${TCA_APP_CONF} http://${TCA_PATH_APP} |
| 90 | echo |
| 91 | |
| 92 | # load preferences |
| 93 | echo |
Lusheng Ji | 3622f7a | 2018-04-04 21:51:34 -0400 | [diff] [blame] | 94 | echo "Loading preferences ${TCA_PREF} to http://${TCA_PATH_APP}/preferences" |
Lusheng Ji | d6d409f | 2018-03-22 23:25:45 -0400 | [diff] [blame] | 95 | curl -s -X PUT -d @${TCA_PREF} http://${TCA_PATH_APP}/preferences |
| 96 | echo |
| 97 | } |
| 98 | |
| 99 | |
| 100 | function tca_delete { |
| 101 | echo |
Lusheng Ji | 3622f7a | 2018-04-04 21:51:34 -0400 | [diff] [blame] | 102 | echo "Deleting application dcae-tca http://${TCA_PATH_APP}" |
Lusheng Ji | d6d409f | 2018-03-22 23:25:45 -0400 | [diff] [blame] | 103 | curl -s -X DELETE http://${TCA_PATH_APP} |
| 104 | echo |
| 105 | |
| 106 | # delete artifact |
| 107 | echo |
Lusheng Ji | 3622f7a | 2018-04-04 21:51:34 -0400 | [diff] [blame] | 108 | echo "Deleting artifact http://${TCA_PATH_ARTIFACT}/${TCA_ARTIFACT}/versions/${TCA_ARTIFACT_VERSION} ..." |
Lusheng Ji | d6d409f | 2018-03-22 23:25:45 -0400 | [diff] [blame] | 109 | curl -s -X DELETE "http://${TCA_PATH_ARTIFACT}/${TCA_ARTIFACT}/versions/${TCA_ARTIFACT_VERSION}" |
| 110 | echo |
| 111 | } |
| 112 | |
| 113 | function tca_start { |
| 114 | echo |
| 115 | echo "Starting TCADMaaPMRPublisherWorker, TCADMaaPMRSubscriberWorker, and TCAVESCollectorFlow ..." |
| 116 | curl -s -X POST "http://${TCA_PATH_APP}/workers/TCADMaaPMRPublisherWorker/start" |
| 117 | curl -s -X POST "http://${TCA_PATH_APP}/workers/TCADMaaPMRSubscriberWorker/start" |
| 118 | curl -s -X POST "http://${TCA_PATH_APP}/flows/TCAVESCollectorFlow/start" |
| 119 | echo |
| 120 | } |
| 121 | |
| 122 | |
| 123 | function tca_status { |
| 124 | echo |
| 125 | echo "TCADMaaPMRPublisherWorker status: " |
| 126 | curl -s "http://${TCA_PATH_APP}/workers/TCADMaaPMRPublisherWorker/status" |
| 127 | echo |
| 128 | echo "TCADMaaPMRSubscriberWorker status: " |
| 129 | curl -s "http://${TCA_PATH_APP}/workers/TCADMaaPMRSubscriberWorker/status" |
| 130 | echo |
| 131 | echo "TCAVESCollectorFlow status" |
| 132 | curl -s "http://${TCA_PATH_APP}/flows/TCAVESCollectorFlow/status" |
| 133 | echo; echo |
| 134 | } |
| 135 | |
| 136 | |
| 137 | function tca_poll_policy { |
Lusheng Ji | e134c82 | 2018-04-23 23:16:32 -0400 | [diff] [blame] | 138 | URL0="${CBS_HOST}:${CBS_PORT}/service_component_all/${MY_NAME}" |
Lusheng Ji | 1dd7a99 | 2018-05-10 23:54:18 -0400 | [diff] [blame^] | 139 | echo "tca_poll_policy: Retrieving all-in-one config at ${URL0}" |
Lusheng Ji | e134c82 | 2018-04-23 23:16:32 -0400 | [diff] [blame] | 140 | HTTP_RESPONSE=$(curl --silent --write-out "HTTPSTATUS:%{http_code}" "$URL0") |
Lusheng Ji | 1dd7a99 | 2018-05-10 23:54:18 -0400 | [diff] [blame^] | 141 | HTTP_BODY=$(echo "$HTTP_RESPONSE" | sed -e 's/HTTPSTATUS\:.*//g') |
| 142 | HTTP_STATUS=$(echo "$HTTP_RESPONSE" | tr -d '\n' | sed -e 's/.*HTTPSTATUS://') |
Lusheng Ji | ac864ce | 2018-04-05 12:02:52 -0400 | [diff] [blame] | 143 | |
Lusheng Ji | ac864ce | 2018-04-05 12:02:52 -0400 | [diff] [blame] | 144 | if [ "$HTTP_STATUS" != "200" ]; then |
Lusheng Ji | 1dd7a99 | 2018-05-10 23:54:18 -0400 | [diff] [blame^] | 145 | echo "tca_poll_policy: Retrieving all-in-one config failed with status $HTTP_STATUS" |
Lusheng Ji | e134c82 | 2018-04-23 23:16:32 -0400 | [diff] [blame] | 146 | URL1="${CBS_HOST}:${CBS_PORT}/service_component/${MY_NAME}" |
Lusheng Ji | 1dd7a99 | 2018-05-10 23:54:18 -0400 | [diff] [blame^] | 147 | echo "tca_poll_policy: Retrieving app config only at ${URL1}" |
Lusheng Ji | e134c82 | 2018-04-23 23:16:32 -0400 | [diff] [blame] | 148 | HTTP_RESPONSE1=$(curl --silent --write-out "HTTPSTATUS:%{http_code}" "$URL1") |
Lusheng Ji | 1dd7a99 | 2018-05-10 23:54:18 -0400 | [diff] [blame^] | 149 | HTTP_BODY1=$(echo "$HTTP_RESPONSE1" | sed -e 's/HTTPSTATUS\:.*//g') |
| 150 | HTTP_STATUS1=$(echo "$HTTP_RESPONSE1" | tr -d '\n' | sed -e 's/.*HTTPSTATUS://') |
Lusheng Ji | e134c82 | 2018-04-23 23:16:32 -0400 | [diff] [blame] | 151 | if [ "$HTTP_STATUS1" != "200" ]; then |
Lusheng Ji | 1dd7a99 | 2018-05-10 23:54:18 -0400 | [diff] [blame^] | 152 | echo "tca_poll_policy: Retrieving app config only failed with status $HTTP_STATUS1" |
Lusheng Ji | e134c82 | 2018-04-23 23:16:32 -0400 | [diff] [blame] | 153 | return |
| 154 | fi |
| 155 | |
| 156 | URL2="$URL1:preferences" |
Lusheng Ji | 1dd7a99 | 2018-05-10 23:54:18 -0400 | [diff] [blame^] | 157 | echo "tca_poll_policy: Retrieving app preferences only at ${URL2}" |
Lusheng Ji | e134c82 | 2018-04-23 23:16:32 -0400 | [diff] [blame] | 158 | HTTP_RESPONSE2=$(curl --silent --write-out "HTTPSTATUS:%{http_code}" "$URL2") |
Lusheng Ji | 1dd7a99 | 2018-05-10 23:54:18 -0400 | [diff] [blame^] | 159 | HTTP_BODY2=$(echo "$HTTP_RESPONSE2" | sed -e 's/HTTPSTATUS\:.*//g') |
| 160 | HTTP_STATUS2=$(echo "$HTTP_RESPONSE2" | tr -d '\n' | sed -e 's/.*HTTPSTATUS://') |
Lusheng Ji | e134c82 | 2018-04-23 23:16:32 -0400 | [diff] [blame] | 161 | if [ "$HTTP_STATUS2" != "200" ]; then |
Lusheng Ji | 1dd7a99 | 2018-05-10 23:54:18 -0400 | [diff] [blame^] | 162 | echo "tca_poll_policy: Retrieving app preferences only failed with status $HTTP_STATUS2" |
| 163 | return |
| 164 | fi |
| 165 | |
| 166 | if [[ "$CONFIG" == "null" || "$PREF" == "null" ]]; then |
| 167 | echo "tca_poll_policy: either app config or app preferences being empty, config not applicable" |
Lusheng Ji | e134c82 | 2018-04-23 23:16:32 -0400 | [diff] [blame] | 168 | return |
| 169 | fi |
| 170 | |
Lusheng Ji | 1dd7a99 | 2018-05-10 23:54:18 -0400 | [diff] [blame^] | 171 | echo "$HTTP_BODY1" | jq . --sort-keys > "${TCA_CONF_TEMP}" |
| 172 | echo "$HTTP_BODY2" | jq . --sort-keys > "${TCA_PREF_TEMP}" |
Lusheng Ji | e134c82 | 2018-04-23 23:16:32 -0400 | [diff] [blame] | 173 | else |
Lusheng Ji | 1dd7a99 | 2018-05-10 23:54:18 -0400 | [diff] [blame^] | 174 | CONFIG=$(echo "$HTTP_BODY" | jq .config.app_config) |
| 175 | PREF=$(echo "$HTTP_BODY" | jq .config.app_preferences) |
| 176 | POLICY=$(echo "$HTTP_BODY" | jq .policies.items[0].config.content.tca_policy) |
vagrant | b51fd79 | 2018-05-01 08:21:11 +0000 | [diff] [blame] | 177 | |
vagrant | b51fd79 | 2018-05-01 08:21:11 +0000 | [diff] [blame] | 178 | |
Lusheng Ji | 1dd7a99 | 2018-05-10 23:54:18 -0400 | [diff] [blame^] | 179 | if [[ "$CONFIG" == "null" || "$PREF" == "null" ]]; then |
| 180 | echo "tca_poll_policy: CONFIG received is parsed to be empty, trying to parse using R1 format" |
| 181 | CONFIG=$(echo "$HTTP_BODY" | jq .config) |
| 182 | NEWPREF=$(echo "$HTTP_BODY" | jq .preferences) |
| 183 | |
| 184 | #echo "CONFIG is [$CONFIG]" |
| 185 | #echo "NEWPREF is [$NEWPREF]" |
vagrant | b51fd79 | 2018-05-01 08:21:11 +0000 | [diff] [blame] | 186 | else |
Lusheng Ji | 1dd7a99 | 2018-05-10 23:54:18 -0400 | [diff] [blame^] | 187 | echo "tca_poll_policy: CONFIG is [${CONFIG}], PREF is [${PREF}], POLICY is [${POLICY}]" |
| 188 | ## Check if policy content under tca_policy is returned null |
| 189 | ## null indicates no active policy flow; hence use configuration loaded |
| 190 | ## from blueprint |
| 191 | if [ "$POLICY" == "null" ]; then |
| 192 | # tca_policy through blueprint |
| 193 | NEWPREF=${PREF} |
| 194 | else |
| 195 | # tca_policy through active policy flow through PH |
| 196 | NEWPREF=$(echo "$PREF" | jq --arg tca_policy "$POLICY" '. + {$tca_policy}') |
| 197 | fi |
| 198 | NEWPREF=$(echo "$NEWPREF" | sed 's/\\n//g') |
vagrant | b51fd79 | 2018-05-01 08:21:11 +0000 | [diff] [blame] | 199 | fi |
Lusheng Ji | 1dd7a99 | 2018-05-10 23:54:18 -0400 | [diff] [blame^] | 200 | |
| 201 | if [[ "$CONFIG" == "null" || "$NEWPREF" == "null" ]]; then |
| 202 | echo "tca_poll_policy: either app config or app preferences being empty, config not applicable" |
| 203 | return |
| 204 | fi |
| 205 | |
| 206 | echo "$CONFIG" | jq . --sort-keys > "${TCA_CONF_TEMP}" |
| 207 | echo "$NEWPREF" | jq . --sort-keys > "${TCA_PREF_TEMP}" |
Lusheng Ji | ac864ce | 2018-04-05 12:02:52 -0400 | [diff] [blame] | 208 | fi |
Lusheng Ji | d6d409f | 2018-03-22 23:25:45 -0400 | [diff] [blame] | 209 | |
| 210 | if [ ! -e "${TCA_CONF_TEMP}" ] || [ "$(ls -sh ${TCA_CONF_TEMP} |cut -f1 -d' ' |sed -e 's/[^0-9]//g')" -lt "1" ]; then |
| 211 | echo "Fail to receive configuration" |
| 212 | return |
| 213 | fi |
| 214 | if [ ! -e "${TCA_PREF_TEMP}" ] || [ "$(ls -sh ${TCA_PREF_TEMP} |cut -f1 -d' ' |sed -e 's/[^0-9]//g')" -lt "1" ]; then |
| 215 | echo "Fail to receive preferences" |
| 216 | return |
| 217 | fi |
| 218 | |
| 219 | CONF_CHANGED="" |
| 220 | # extract only the config section from APP CONF (which has both artifact and config sections) |
| 221 | jq .config --sort-keys ${TCA_APP_CONF} > ${TCA_CONF} |
| 222 | if ! diff ${TCA_CONF} ${TCA_CONF_TEMP} ; then |
| 223 | echo "TCA config changed" |
| 224 | # generating the new app conf using current app conf's artifact section and the new downloaded config |
| 225 | jq --argfile CONFVALUE ${TCA_CONF_TEMP} '.config = $CONFVALUE' <${TCA_APP_CONF} > ${TCA_APP_CONF_TEMP} |
| 226 | |
| 227 | mv ${TCA_APP_CONF_TEMP} ${TCA_APP_CONF} |
| 228 | CONF_CHANGED=1 |
| 229 | fi |
| 230 | |
| 231 | PERF_CHANGED="" |
| 232 | # update the subscriber ConsumerID, if not already unique, |
| 233 | # so replicas appear as different consumers in the consumer group |
| 234 | HOSTID=$(head -1 /etc/hostname | rev |cut -f1-2 -d'-' |rev) |
| 235 | CONSUMERID=$(jq .subscriberConsumerId ${TCA_PREF_TEMP} |sed -e 's/\"//g') |
| 236 | if ! (echo "$CONSUMERID" |grep "$HOSTID"); then |
| 237 | CONSUMERID="${CONSUMERID}-${HOSTID}" |
Lusheng Ji | 1dd7a99 | 2018-05-10 23:54:18 -0400 | [diff] [blame^] | 238 | jq --arg CID "${CONSUMERID}" '.subscriberConsumerId = $CID' < "${TCA_PREF_TEMP}" > "${TCA_PREF_TEMP}2" |
Lusheng Ji | d6d409f | 2018-03-22 23:25:45 -0400 | [diff] [blame] | 239 | mv "${TCA_PREF_TEMP}2" "${TCA_PREF_TEMP}" |
| 240 | fi |
| 241 | if ! diff ${TCA_PREF} ${TCA_PREF_TEMP} ; then |
| 242 | echo "TCA preference updated" |
| 243 | mv ${TCA_PREF_TEMP} ${TCA_PREF} |
| 244 | PERF_CHANGED=1 |
| 245 | fi |
| 246 | |
Lusheng Ji | 1dd7a99 | 2018-05-10 23:54:18 -0400 | [diff] [blame^] | 247 | if [[ "$PERF_CHANGED" == "1" || "$CONF_CHANGED" == "1" ]]; then |
| 248 | echo "Newly received configuration/preference differ from the running instance's. reload confg" |
Lusheng Ji | d6d409f | 2018-03-22 23:25:45 -0400 | [diff] [blame] | 249 | tca_stop |
| 250 | tca_delete |
| 251 | tca_load_artifact |
| 252 | tca_load_conf |
| 253 | tca_start |
| 254 | tca_status |
| 255 | fi |
| 256 | } |
| 257 | |
| 258 | |
| 259 | export PATH=${PATH}:/opt/cdap/sdk/bin |
| 260 | |
Lusheng Ji | 1dd7a99 | 2018-05-10 23:54:18 -0400 | [diff] [blame^] | 261 | |
| 262 | echo "Starting TCA-CDAP in standalone mode" |
| 263 | |
Lusheng Ji | d6d409f | 2018-03-22 23:25:45 -0400 | [diff] [blame] | 264 | # starting CDAP SDK in background |
| 265 | cdap sdk start |
| 266 | |
Lusheng Ji | 1dd7a99 | 2018-05-10 23:54:18 -0400 | [diff] [blame^] | 267 | echo "Started, waiting CDAP ready on port 11015 ..." |
Lusheng Ji | d6d409f | 2018-03-22 23:25:45 -0400 | [diff] [blame] | 268 | while ! nc -z ${CDAP_HOST} ${CDAP_PORT}; do |
| 269 | sleep 0.1 # wait for 1/10 of the second before check again |
| 270 | done |
Lusheng Ji | d6d409f | 2018-03-22 23:25:45 -0400 | [diff] [blame] | 271 | |
| 272 | echo "Creating namespace cdap_tca_hi_lo ..." |
| 273 | curl -s -X PUT "http://${CDAP_HOST}:${CDAP_PORT}/v3/namespaces/cdap_tca_hi_lo" |
| 274 | |
Lusheng Ji | d6d409f | 2018-03-22 23:25:45 -0400 | [diff] [blame] | 275 | # stop programs |
| 276 | tca_stop |
| 277 | |
Lusheng Ji | d6d409f | 2018-03-22 23:25:45 -0400 | [diff] [blame] | 278 | # delete application |
| 279 | tca_delete |
| 280 | |
Lusheng Ji | d6d409f | 2018-03-22 23:25:45 -0400 | [diff] [blame] | 281 | # load artifact |
| 282 | tca_load_artifact |
| 283 | tca_load_conf |
| 284 | |
Lusheng Ji | d6d409f | 2018-03-22 23:25:45 -0400 | [diff] [blame] | 285 | # start programs |
| 286 | tca_start |
| 287 | |
Lusheng Ji | d6d409f | 2018-03-22 23:25:45 -0400 | [diff] [blame] | 288 | # get status of programs |
| 289 | tca_status |
| 290 | |
Lusheng Ji | 1dd7a99 | 2018-05-10 23:54:18 -0400 | [diff] [blame^] | 291 | echo "TCA-CDAP standalone mode initialization completed" |
Lusheng Ji | d6d409f | 2018-03-22 23:25:45 -0400 | [diff] [blame] | 292 | |
| 293 | |
Lusheng Ji | 1dd7a99 | 2018-05-10 23:54:18 -0400 | [diff] [blame^] | 294 | |
| 295 | #Changing to HOSTNAME parameter for consistency with k8s deploy |
| 296 | MY_NAME=${HOSTNAME:-tca} |
| 297 | |
| 298 | unset CBS_HOST |
| 299 | unset CBS_PORT |
| 300 | echo "TCA environment: I am ${MY_NAME}, consul at ${CONSUL_HOST}:${CONSUL_PORT}, CBS service name ${CBS_SERVICE_NAME}" |
| 301 | |
| 302 | while echo |
Lusheng Ji | d6d409f | 2018-03-22 23:25:45 -0400 | [diff] [blame] | 303 | do |
Lusheng Ji | 1dd7a99 | 2018-05-10 23:54:18 -0400 | [diff] [blame^] | 304 | echo "$(date): ======================================================" |
| 305 | if [[ -z "$CBS_HOST" || -z "$CBS_PORT" ]]; then |
| 306 | echo "Retrieving host and port for ${CBS_SERVICE_NAME} from ${CONSUL_HOST}:${CONSUL_PORT}" |
| 307 | sleep 2 |
| 308 | CBS_HOST=$(curl -s "${CONSUL_HOST}:${CONSUL_PORT}/v1/catalog/service/${CBS_SERVICE_NAME}" |jq .[0].ServiceAddress |sed -e 's/\"//g') |
| 309 | CBS_PORT=$(curl -s "${CONSUL_HOST}:${CONSUL_PORT}/v1/catalog/service/${CBS_SERVICE_NAME}" |jq .[0].ServicePort |sed -e 's/\"//g') |
| 310 | echo "CBS discovered to be at ${CBS_HOST}:${CBS_PORT}" |
| 311 | fi |
| 312 | |
| 313 | if [ ! -z "$CBS_HOST" ] && [ ! -z "$CBS_PORT" ]; then |
| 314 | tca_poll_policy |
| 315 | fi |
Lusheng Ji | d6d409f | 2018-03-22 23:25:45 -0400 | [diff] [blame] | 316 | sleep 30 |
| 317 | done |