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