3 #============LICENSE_START==================================================
5 #===========================================================================
6 # Copyright (C) 2017-2018 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
12 # http://www.apache.org/licenses/LICENSE-2.0
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==================================================
23 ELK_MAP_SUCCESS_RE="\"acknowledged\": *true"
26 echo -n "syntax: $(basename $0) "
28 echo -n "([--audit] |"
32 echo "$(date +"%Y-%m-%d_%H-%M-%S") $1" >> ${POLICY_LOGS}/policy/elk.log
36 function delete_index() {
37 if [[ $DEBUG == y ]]; then
38 echo "-- ${FUNCNAME[0]} $@ --"
42 COMMAND="curl --silent -X DELETE http://localhost:9200/policy"
43 OUTPUT="$(${COMMAND} 2>&1)"
46 log "${RC}: ${COMMAND}"
49 if [[ ${RC} != 0 ]] || [[ ! ${OUTPUT} =~ ${ELK_MAP_SUCCESS_RE} ]]; then
50 log "WARNING: curl: delete /policy: ${RC}"
54 log "OK: curl: delete /policy: ${OUTPUT}"
58 function create_index() {
59 if [[ $DEBUG == y ]]; then
60 echo "-- ${FUNCNAME[0]} $@ --"
64 COMMAND="curl --silent -X PUT http://localhost:9200/policy"
65 OUTPUT="$(${COMMAND} 2>&1)"
68 log "${RC}: ${COMMAND}"
71 if [[ ${RC} != 0 ]] || [[ ! ${OUTPUT} =~ ${ELK_MAP_SUCCESS_RE} ]]; then
72 log "ERROR: curl: put /policy: ${RC}"
76 log "OK: curl: put /policy."
80 function check_elk_status() {
81 if [[ $DEBUG == y ]]; then
82 echo "-- ${FUNCNAME[0]} $@ --"
86 ${POLICY_HOME}/etc/init.d/elk status
87 if [[ $? != 0 ]]; then
88 log "ERROR: elk is down. Aborting .."
93 function check_elk_policy_index() {
94 if [[ $DEBUG == y ]]; then
95 echo "-- ${FUNCNAME[0]} $@ --"
99 COMMAND="curl --silent -X GET http://localhost:9200/policy"
100 OUTPUT="$(${COMMAND} 2>&1)"
103 log "${RC}: ${COMMAND}"
105 if [[ ${RC} != 0 ]] || [[ ! ${OUTPUT} =~ policy ]]; then
106 log "ERROR: curl: get /policy: ${RC}"
110 log "OK: curl: get /policy."
114 #The Script will update the policy data on querying from database as a bulk to Elastic Database
116 if [[ $DEBUG == y ]]; then
117 echo "-- ${FUNCNAME[0]} $@ --"
123 if ! check_elk_policy_index; then
124 echo "policy index does not exist. So, Policy Index is created."
125 if ! create_index; then
126 echo "abort: policy index creation failed."
131 $JAVA_HOME/bin/java -cp $POLICY_HOME/servers/pap/webapps/pap/WEB-INF/lib/ONAP-PAP-REST-*.jar:$POLICY_HOME/servers/pap/webapps/pap/WEB-INF/lib/*: -DPOLICY_LOGS=$POLICY_LOGS -DPROPERTY_FILE=$POLICY_HOME/servers/pap/bin/policyelk.properties org.onap.policy.pap.xacml.rest.elk.client.ElasticSearchPolicyUpdate
134 #########################################################################
136 ## script execution body
138 #########################################################################
143 until [[ -z "$1" ]]; do
145 -d|--debug|debug) DEBUG=y
148 -a|--audit|audit) OPERATION=audit
157 # operation validation
160 *) echo "invalid operation (${OPERATION}).";
166 if [[ -z ${POLICY_HOME} ]]; then
167 echo "error: POLICY_HOME is unset."
171 log "**** $OPERATION ****"
173 if pidof -o %PPID -x $(basename $0) > /dev/null 2>&1; then
174 echo "WARNING: an $(basename $0) process is already running. Exiting."
178 . ${POLICY_HOME}/etc/profile.d/env.sh
184 *) echo "invalid operation (${OPERATION}).";