summaryrefslogtreecommitdiffstats
path: root/kubernetes/consul/resources/config/consul-agent-config/scripts/search-data-service-availability.sh
diff options
context:
space:
mode:
authorjasmineWen <jasmine.wen@amdocs.com>2018-03-06 16:13:35 +0000
committerjasmineWen <jasmine.wen@amdocs.com>2018-03-19 15:42:08 +0000
commit85d9d73270f01d0770c29e8516dd0154669e9cf5 (patch)
tree8f135e6dbdc2359f9329352aa7bda94c2e40be76 /kubernetes/consul/resources/config/consul-agent-config/scripts/search-data-service-availability.sh
parent0947cdf7e780641e1604ef3752483fa4d29efb3e (diff)
Move consul config from shared NFS to configmap
Issue-ID: OOM-597 Change-Id: I708c3e9df16003a54462f76c6ffe513b270faae8 Signed-off-by: jasmineWen <jasmine.wen@amdocs.com>
Diffstat (limited to 'kubernetes/consul/resources/config/consul-agent-config/scripts/search-data-service-availability.sh')
-rw-r--r--kubernetes/consul/resources/config/consul-agent-config/scripts/search-data-service-availability.sh45
1 files changed, 45 insertions, 0 deletions
diff --git a/kubernetes/consul/resources/config/consul-agent-config/scripts/search-data-service-availability.sh b/kubernetes/consul/resources/config/consul-agent-config/scripts/search-data-service-availability.sh
new file mode 100644
index 0000000000..d5118736cd
--- /dev/null
+++ b/kubernetes/consul/resources/config/consul-agent-config/scripts/search-data-service-availability.sh
@@ -0,0 +1,45 @@
+#!/bin/sh
+
+SEARCH_SERVICE_NAME="search-data-service.{{ .Values.nsPrefix }}"
+SEARCH_SERVICE_PORT=9509
+HEALTH_CHECK_INDEX="healthcheck"
+
+# 'Document Index' REST Endpoint
+INDEX_URL="https://$SEARCH_SERVICE_NAME:$SEARCH_SERVICE_PORT/services/search-data-service/v1/search/indexes/$HEALTH_CHECK_INDEX"
+INDEX_SCHEMA="{\"fields\":[{\"name\": \"field1\", \"data-type\": \"string\"}]}"
+
+SEARCH_CERT_FILE="/consul/certs/client-cert-onap.crt.pem"
+SEARCH_KEY_FILE="/consul/certs/client-cert-onap.key.pem"
+
+## Try to create an index via the Search Data Service API.
+CREATE_INDEX_RESP=$(curl -s -o /dev/null -w "%{http_code}" -k --cert $SEARCH_CERT_FILE --cert-type PEM --key $SEARCH_KEY_FILE --key-type PEM -d "$INDEX_SCHEMA" --header "Content-Type: application/json" --header "X-TransactionId: ConsulHealthCheck" -X PUT $INDEX_URL)
+
+RESULT_STRING=" "
+
+if [ $CREATE_INDEX_RESP -eq 201 ]; then
+ RESULT_STRING="Service Is Able To Communicate With Back End"
+elif [ $CREATE_INDEX_RESP -eq 400 ]; then
+ # A 400 response could mean that the index already exists (ie: we didn't
+ # clean up after ourselves on a previous check), so log the response but
+ # don't exit yet. If we fail on the delete then we can consider the
+ # check a failure, otherwise, we are good.
+ RESULT_STRING="$RESULT_STRING Create Index [FAIL - 400 (possible index already exists)] "
+else
+ RESULT_STRING="Service API Failure - $CREATE_INDEX_RESP"
+ echo $RESULT_STRING
+ exit 1
+fi
+
+## Now, clean up after ourselves.
+DELETE_INDEX_RESP=$(curl -s -o /dev/null -w "%{http_code}" -k --cert $SEARCH_CERT_FILE --cert-type PEM --key $SEARCH_KEY_FILE --key-type PEM -d "{ }" --header "Content-Type: application/json" --header "X-TransactionId: ConsulHealthCheck" -X DELETE $INDEX_URL)
+
+if [ $DELETE_INDEX_RESP -eq 200 ]; then
+ RESULT_STRING="Service Is Able To Communicate With Back End"
+else
+ RESULT_STRING="Service API Failure - $DELETE_INDEX_RESP"
+ echo $RESULT_STRING
+ exit 1
+fi
+
+echo $RESULT_STRING
+return 0