gfraboni | be779fa | 2017-09-19 13:25:30 -0400 | [diff] [blame] | 1 | #!/bin/sh |
Jakub Latusek | d4e96f4 | 2020-10-21 13:36:29 +0200 | [diff] [blame] | 2 | {{/* |
gfraboni | be779fa | 2017-09-19 13:25:30 -0400 | [diff] [blame] | 3 | |
Mukul | 2b4e753 | 2018-08-03 10:41:29 +0000 | [diff] [blame] | 4 | # Copyright © 2018 AT&T, Amdocs, Bell Canada Intellectual Property. All rights reserved. |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | # you may not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
Jakub Latusek | d4e96f4 | 2020-10-21 13:36:29 +0200 | [diff] [blame] | 17 | */}} |
Mukul | 2b4e753 | 2018-08-03 10:41:29 +0000 | [diff] [blame] | 18 | |
Priyanka Jain | c07e1d1 | 2018-05-03 12:52:04 +0000 | [diff] [blame] | 19 | SEARCH_SERVICE_NAME="search-data-service.{{ include "common.namespace" . }}" |
gfraboni | be779fa | 2017-09-19 13:25:30 -0400 | [diff] [blame] | 20 | SEARCH_SERVICE_PORT=9509 |
| 21 | HEALTH_CHECK_INDEX="healthcheck" |
| 22 | |
| 23 | # 'Document Index' REST Endpoint |
| 24 | INDEX_URL="https://$SEARCH_SERVICE_NAME:$SEARCH_SERVICE_PORT/services/search-data-service/v1/search/indexes/$HEALTH_CHECK_INDEX" |
| 25 | INDEX_SCHEMA="{\"fields\":[{\"name\": \"field1\", \"data-type\": \"string\"}]}" |
| 26 | |
jasmineWen | 85d9d73 | 2018-03-06 16:13:35 +0000 | [diff] [blame] | 27 | SEARCH_CERT_FILE="/consul/certs/client-cert-onap.crt.pem" |
| 28 | SEARCH_KEY_FILE="/consul/certs/client-cert-onap.key.pem" |
gfraboni | be779fa | 2017-09-19 13:25:30 -0400 | [diff] [blame] | 29 | |
| 30 | ## Try to create an index via the Search Data Service API. |
jasmineWen | 85d9d73 | 2018-03-06 16:13:35 +0000 | [diff] [blame] | 31 | 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) |
gfraboni | be779fa | 2017-09-19 13:25:30 -0400 | [diff] [blame] | 32 | |
| 33 | RESULT_STRING=" " |
| 34 | |
| 35 | if [ $CREATE_INDEX_RESP -eq 201 ]; then |
| 36 | RESULT_STRING="Service Is Able To Communicate With Back End" |
| 37 | elif [ $CREATE_INDEX_RESP -eq 400 ]; then |
| 38 | # A 400 response could mean that the index already exists (ie: we didn't |
| 39 | # clean up after ourselves on a previous check), so log the response but |
| 40 | # don't exit yet. If we fail on the delete then we can consider the |
| 41 | # check a failure, otherwise, we are good. |
| 42 | RESULT_STRING="$RESULT_STRING Create Index [FAIL - 400 (possible index already exists)] " |
| 43 | else |
| 44 | RESULT_STRING="Service API Failure - $CREATE_INDEX_RESP" |
| 45 | echo $RESULT_STRING |
| 46 | exit 1 |
| 47 | fi |
| 48 | |
| 49 | ## Now, clean up after ourselves. |
jasmineWen | 85d9d73 | 2018-03-06 16:13:35 +0000 | [diff] [blame] | 50 | 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) |
gfraboni | be779fa | 2017-09-19 13:25:30 -0400 | [diff] [blame] | 51 | |
| 52 | if [ $DELETE_INDEX_RESP -eq 200 ]; then |
| 53 | RESULT_STRING="Service Is Able To Communicate With Back End" |
jasmineWen | 85d9d73 | 2018-03-06 16:13:35 +0000 | [diff] [blame] | 54 | else |
gfraboni | be779fa | 2017-09-19 13:25:30 -0400 | [diff] [blame] | 55 | RESULT_STRING="Service API Failure - $DELETE_INDEX_RESP" |
jasmineWen | 85d9d73 | 2018-03-06 16:13:35 +0000 | [diff] [blame] | 56 | echo $RESULT_STRING |
gfraboni | be779fa | 2017-09-19 13:25:30 -0400 | [diff] [blame] | 57 | exit 1 |
| 58 | fi |
| 59 | |
| 60 | echo $RESULT_STRING |
| 61 | return 0 |