summaryrefslogtreecommitdiffstats
path: root/dbc-client
diff options
context:
space:
mode:
authorajay_dp001 <ajay.deep.singh@est.tech>2021-11-01 14:50:02 +0530
committerajay_dp001 <ajay.deep.singh@est.tech>2022-01-25 17:58:08 +0000
commitdc8935a8db53e17108c847130f3f5e5b016a2891 (patch)
treedffd2eba4170ddf6bd62bd9fa8b6f92ca0959a05 /dbc-client
parent1dabd4722aab2a1ed32151e9d08e85d5b0ddb819 (diff)
[DMAAP-BC] Avoid Creating duplicate DR Publisher, Subscriber
Issue-ID: DCAEGEN2-2861 Signed-off-by: ajay_dp001 <ajay.deep.singh@est.tech> Change-Id: I3c17ce0bc2da1b4443e729c9888a23b503480ff8
Diffstat (limited to 'dbc-client')
-rw-r--r--dbc-client/misc/dbc-client51
-rw-r--r--dbc-client/src/main/resources/Dockerfile2
2 files changed, 52 insertions, 1 deletions
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/* && \