Fix poll policy error 13/41213/1
authorLusheng Ji <lji@research.att.com>
Thu, 5 Apr 2018 16:02:52 +0000 (12:02 -0400)
committerLusheng Ji <lji@research.att.com>
Thu, 5 Apr 2018 16:03:01 +0000 (12:03 -0400)
Issue-ID: DCAEGEN2-206
Change-Id: I728d00bd74a6cdc5b1aca520efe77f686ef9aae0
Signed-off-by: Lusheng Ji <lji@research.att.com>
tca-cdap-container/restart.sh

index bc15cac..95a41d2 100755 (executable)
@@ -147,9 +147,24 @@ function tca_poll_policy {
     URL2="$URL1:preferences"
 
     echo "tca_poll_policy: Retrieving configuration file at ${URL1}"
-    curl -s "$URL1" | jq . --sort-keys > "${TCA_CONF_TEMP}"
-    echo "Retrieving preferences file at ${URL1}"
-    curl -s "$URL2" | jq . --sort-keys > "${TCA_PREF_TEMP}"
+    HTTP_RESPONSE=$(curl --silent --write-out "HTTPSTATUS:%{http_code}" "$URL1")
+    HTTP_BODY=$(echo $HTTP_RESPONSE | sed -e 's/HTTPSTATUS\:.*//g')
+    HTTP_STATUS=$(echo $HTTP_RESPONSE | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')
+    if [ "$HTTP_STATUS" != "200" ]; then
+      echo "receiving $HTTP_RESPONSE from CBS"
+      return
+    fi
+    echo $HTTP_BODY | jq . --sort-keys > "${TCA_CONF_TEMP}"
+
+    echo "tca_poll_policy: Retrieving preferences file at ${URL1}"
+    HTTP_RESPONSE=$(curl --silent --write-out "HTTPSTATUS:%{http_code}" "$URL2")
+    HTTP_BODY=$(echo $HTTP_RESPONSE | sed -e 's/HTTPSTATUS\:.*//g')
+    HTTP_STATUS=$(echo $HTTP_RESPONSE | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')
+    if [ "$HTTP_STATUS" != "200" ]; then
+      echo "receiving $HTTP_RESPONSE from CBS"
+      return
+    fi
+    echo $HTTP_BODY | jq . --sort-keys > "${TCA_PREF_TEMP}"
 
     if [ ! -e "${TCA_CONF_TEMP}" ] || [ "$(ls -sh ${TCA_CONF_TEMP} |cut -f1 -d' ' |sed -e 's/[^0-9]//g')"  -lt "1" ]; then
        echo "Fail to receive configuration"