From: ajay_dp001 Date: Mon, 1 Nov 2021 09:20:02 +0000 (+0530) Subject: [DMAAP-BC] Avoid Creating duplicate DR Publisher, Subscriber X-Git-Tag: 2.0.9~1^2 X-Git-Url: https://gerrit.onap.org/r/gitweb?p=dmaap%2Fbuscontroller.git;a=commitdiff_plain;h=dc8935a8db53e17108c847130f3f5e5b016a2891 [DMAAP-BC] Avoid Creating duplicate DR Publisher, Subscriber Issue-ID: DCAEGEN2-2861 Signed-off-by: ajay_dp001 Change-Id: I3c17ce0bc2da1b4443e729c9888a23b503480ff8 --- diff --git a/dbc-client/misc/dbc-client b/dbc-client/misc/dbc-client index 7247e01..2436e9a 100644 --- a/dbc-client/misc/dbc-client +++ b/dbc-client/misc/dbc-client @@ -28,6 +28,7 @@ export PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin RESP_CACHE=${RESP_CACHE:-''} RESP=${RESP:-'/dev/null'} APP_ROOT=${APP_ROOT:-/opt/app/dbc-client} +IF_PUB_SUB_EXIST=${IF_PUB_SUB_EXIST:-false} CONFIGMAP_ROOT=${CONFIGMAP_ROOT:-/opt/app/config} PORT=${PORT:-8443} @@ -91,6 +92,14 @@ function do_http_post() { while true; do if [ "$2" != "feeds" -a "$2" != "topics" ]; then req_body=$(cat "${1}" | envsubst) + if [ -n "$RESP_CACHE" ] && [ "${2}" = "dr_pubs" -o "${2}" = "dr_subs" ]; then + IF_PUB_SUB_EXIST=false + check_pub_sub "${2}" "${req_body}" "${RESP}" + if [ "${IF_PUB_SUB_EXIST}" = true ]; then + echo "DR Publisher or Subscriber already exist.." + break + fi + fi rc=$(xcurl -o "$RESP" -d "$req_body" "${URL}${2}") if [ "$rc" = "200" -o "$rc" = "201" -o "$rc" = "409" ]; then echo "Http Post request is successful with response code=$rc" @@ -108,5 +117,47 @@ function do_http_post() { done } +function check_pub_sub() { + #Parameters: + #${1} Param - String representing dir either dr_pubs or dr_subs + #${2} Param - Request details (Dr Publisher/Subscriber creation input details) containing feedName, dr-userName, dr-Password, dr-LocationName + #${3} Param - String representing RESP_CACHE Env to '/opt/app/config/cache' or '/dev/null' + feed_config_resp="$RESP_CACHE"/"feedConfig-$(echo "${3//[!0-9]/}")-resp.json" + if [ -f "${feed_config_resp}" ]; then + echo "Checking if pub or sub exist.." + val=${1#*_} + dr_usr=$(echo "${2}" | jq -r '.username') + dr_pwd=$(echo "${2}" | jq -r '.userpwd') + pub_sub_cnt=$(jq ".${val} | length" "${feed_config_resp}") + local i=0 + while [ "$i" -lt "$pub_sub_cnt" ]; do + _dr_usr=$(jq -r ".${val}[$i].username" "${feed_config_resp}") + _dr_pwd=$(jq -r ".${val}[$i].userpwd" "${feed_config_resp}") + if [ "${dr_usr}" = "${_dr_usr}" -a "${dr_pwd}" = "${_dr_pwd}" ]; then + if [ "${1}" = "dr_pubs" ]; then + echo "Publisher exist with username: ${dr_usr}, password: ${dr_pwd}" + echo "$(jq -c ".${val}[$i]" "${feed_config_resp}")" >"${3}" + IF_PUB_SUB_EXIST=true + break + elif [ "${1}" = "dr_subs" ]; then + dr_loc=$(echo "${2}" | jq -r '.dcaeLocationName') + _dr_loc=$(jq -r ".${val}[$i].dcaeLocationName" "${feed_config_resp}") + dr_deliveryURL=$(echo "${2}" | jq -r '.deliveryURL') + _dr_deliveryURL=$(jq -r ".${val}[$i].deliveryURL" "${feed_config_resp}") + if [ "${dr_loc}" = "${_dr_loc}" -a "${dr_deliveryURL}" = "${_dr_deliveryURL}" ]; then + echo "Subscriber exist with username: ${dr_usr}, password: ${dr_pwd}, dcaeLocationName: ${dr_loc}, deliveryURL: ${dr_deliveryURL}" + echo "$(jq -c ".${val}[$i]" "${feed_config_resp}")" >"${3}" + IF_PUB_SUB_EXIST=true + break + fi + fi + fi + i=$((i + 1)) + done + else + echo "Feed configuration doesn't exist." + fi +} + init_config init_dbc_provisioning diff --git a/dbc-client/src/main/resources/Dockerfile b/dbc-client/src/main/resources/Dockerfile index 831d4f2..e63ce9d 100644 --- a/dbc-client/src/main/resources/Dockerfile +++ b/dbc-client/src/main/resources/Dockerfile @@ -34,7 +34,7 @@ RUN mkdir -p /usr/local/share/ca-certificates && \ RUN update-ca-certificates # Install curl & openssl -RUN apk add --no-cache curl openssl gettext +RUN apk add --no-cache curl openssl gettext jq RUN mkdir -p /opt/app/osaaf/local && \ chmod +x /opt/app/dbc-client/bin/* && \