blob: d5118736cd730bf7afbe8f3eb31853bb3e9eeef5 [file] [log] [blame]
gfrabonibe779fa2017-09-19 13:25:30 -04001#!/bin/sh
2
jasmineWen85d9d732018-03-06 16:13:35 +00003SEARCH_SERVICE_NAME="search-data-service.{{ .Values.nsPrefix }}"
gfrabonibe779fa2017-09-19 13:25:30 -04004SEARCH_SERVICE_PORT=9509
5HEALTH_CHECK_INDEX="healthcheck"
6
7# 'Document Index' REST Endpoint
8INDEX_URL="https://$SEARCH_SERVICE_NAME:$SEARCH_SERVICE_PORT/services/search-data-service/v1/search/indexes/$HEALTH_CHECK_INDEX"
9INDEX_SCHEMA="{\"fields\":[{\"name\": \"field1\", \"data-type\": \"string\"}]}"
10
jasmineWen85d9d732018-03-06 16:13:35 +000011SEARCH_CERT_FILE="/consul/certs/client-cert-onap.crt.pem"
12SEARCH_KEY_FILE="/consul/certs/client-cert-onap.key.pem"
gfrabonibe779fa2017-09-19 13:25:30 -040013
14## Try to create an index via the Search Data Service API.
jasmineWen85d9d732018-03-06 16:13:35 +000015CREATE_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)
gfrabonibe779fa2017-09-19 13:25:30 -040016
17RESULT_STRING=" "
18
19if [ $CREATE_INDEX_RESP -eq 201 ]; then
20 RESULT_STRING="Service Is Able To Communicate With Back End"
21elif [ $CREATE_INDEX_RESP -eq 400 ]; then
22 # A 400 response could mean that the index already exists (ie: we didn't
23 # clean up after ourselves on a previous check), so log the response but
24 # don't exit yet. If we fail on the delete then we can consider the
25 # check a failure, otherwise, we are good.
26 RESULT_STRING="$RESULT_STRING Create Index [FAIL - 400 (possible index already exists)] "
27else
28 RESULT_STRING="Service API Failure - $CREATE_INDEX_RESP"
29 echo $RESULT_STRING
30 exit 1
31fi
32
33## Now, clean up after ourselves.
jasmineWen85d9d732018-03-06 16:13:35 +000034DELETE_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)
gfrabonibe779fa2017-09-19 13:25:30 -040035
36if [ $DELETE_INDEX_RESP -eq 200 ]; then
37 RESULT_STRING="Service Is Able To Communicate With Back End"
jasmineWen85d9d732018-03-06 16:13:35 +000038else
gfrabonibe779fa2017-09-19 13:25:30 -040039 RESULT_STRING="Service API Failure - $DELETE_INDEX_RESP"
jasmineWen85d9d732018-03-06 16:13:35 +000040 echo $RESULT_STRING
gfrabonibe779fa2017-09-19 13:25:30 -040041 exit 1
42fi
43
44echo $RESULT_STRING
45return 0