Removing Drools-pdp swagger annotations
[policy/drools-pdp.git] / policy-management / src / main / server-gen / bin / telemetry
1 #!/usr/bin/env sh
2
3 # ============LICENSE_START=======================================================
4 # ONAP
5 # ================================================================================
6 # Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
7 # ================================================================================
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 #      http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 # ============LICENSE_END=========================================================
20
21 source ${POLICY_HOME}/etc/profile.d/env.sh
22
23 REST_TOOL="http-prompt"
24 TELEMETRY_SPEC="${POLICY_HOME}/config/telemetry-spec.json"
25
26 if ! type -p "${REST_TOOL}" >/dev/null 2>&1; then
27     echo "error: prerequisite software not found: http-prompt"
28     exit 1
29 fi
30
31 if ! "${POLICY_HOME}"/bin/policy-management-controller status >/dev/null 2>&1; then
32     echo "error: pdp-d is not running"
33     exit 2
34 fi
35
36 CREDENTIALS=
37 if [ -n "${TELEMETRY_USER}" ]; then
38     CREDENTIALS="--auth ${TELEMETRY_USER}:${TELEMETRY_PASSWORD}"
39 fi
40
41 PROTOCOL="http"
42
43 # use environment flag if set
44 if [ $HTTP_SERVER_HTTPS == "true" ]; then
45     PROTOCOL="https"
46 fi
47
48 # it takes precedence to have https explicitly set over the environment variable
49 if egrep "^http\.server\.services\..*CONFIG\.https.*=.*true" ${POLICY_HOME}/config/engine.properties; then
50     PROTOCOL="https"
51 fi
52
53 if [ ! -r "${TELEMETRY_SPEC}" ]; then
54     echo "generating new spec .."
55     if ! http --verify=no ${CREDENTIALS} "${PROTOCOL}"://localhost:9696/policy/pdp/engine/swagger >${TELEMETRY_SPEC} 2>/dev/null; then
56         echo "error: cannot generate telemetry spec"
57         rm -f ${TELEMETRY_SPEC} 2>/dev/null
58         exit 3
59     fi
60 fi
61
62 exec http-prompt "${PROTOCOL}"://localhost:9696/policy/pdp/engine --verify=no ${CREDENTIALS} --spec ${TELEMETRY_SPEC}
63