Run all components in one namespace
[oom.git] / kubernetes / config / docker / init / src / config / consul / consul-agent-config / scripts / search-data-service-availability.sh
1 #!/bin/sh
2
3 SEARCH_SERVICE_NAME="search-data-service.namespace-placeholder"
4 SEARCH_SERVICE_PORT=9509
5 HEALTH_CHECK_INDEX="healthcheck"
6
7 # 'Document Index' REST Endpoint
8 INDEX_URL="https://$SEARCH_SERVICE_NAME:$SEARCH_SERVICE_PORT/services/search-data-service/v1/search/indexes/$HEALTH_CHECK_INDEX"
9 INDEX_SCHEMA="{\"fields\":[{\"name\": \"field1\", \"data-type\": \"string\"}]}"
10
11
12 SEARCH_CERT_FILE="/consul/config/certs/client-cert-onap.crt.pem"
13 SEARCH_KEY_FILE="/consul/config/certs/client-cert-onap.key.pem"
14
15
16 ## Try to create an index via the Search Data Service API.
17 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) 
18
19 RESULT_STRING=" "
20
21 if [ $CREATE_INDEX_RESP -eq 201 ]; then
22    RESULT_STRING="Service Is Able To Communicate With Back End"
23 elif [ $CREATE_INDEX_RESP -eq 400 ]; then
24    # A 400 response could mean that the index already exists (ie: we didn't
25    # clean up after ourselves on a previous check), so log the response but
26    # don't exit yet.  If we fail on the delete then we can consider the
27    # check a failure, otherwise, we are good.
28    RESULT_STRING="$RESULT_STRING Create Index [FAIL - 400 (possible index already exists)] "
29 else
30    RESULT_STRING="Service API Failure - $CREATE_INDEX_RESP"
31    echo $RESULT_STRING
32    exit 1
33 fi
34
35 ## Now, clean up after ourselves.
36 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) 
37
38 if [ $DELETE_INDEX_RESP -eq 200 ]; then
39    RESULT_STRING="Service Is Able To Communicate With Back End"
40 else 
41    RESULT_STRING="Service API Failure - $DELETE_INDEX_RESP"
42    echo $RESULT_STRING 
43    exit 1
44 fi
45
46 echo $RESULT_STRING
47 return 0