Skip to content

Commit

Permalink
Merge pull request #1561 from mapellidario/20241104_wma_checklocalcouch
Browse files Browse the repository at this point in the history
wmagent - do not init if couch is not empty
  • Loading branch information
mapellidario authored Nov 8, 2024
2 parents e1106b4 + 77c3214 commit c835caa
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docker/pypi/wmagent-base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RUN apt-get update
RUN apt-get install -y libmariadb-dev-compat libmariadb-dev apache2-utils cron mariadb-server myproxy voms-clients voms-clients-java rlwrap libaio1 && apt-get clean

# Install some debugging tools
RUN apt-get install -y hostname net-tools iputils-ping procps && apt-get clean
RUN apt-get install -y hostname net-tools iputils-ping procps jq && apt-get clean

# Install recursive ps utility tool
RUN apt-get install -y pslist && apt-get clean
Expand Down
2 changes: 1 addition & 1 deletion docker/pypi/wmagent/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# syntax=docker/dockerfile-upstream:master
FROM registry.cern.ch/cmsweb/wmagent-base:pypi-20240923-stable
FROM registry.cern.ch/cmsweb/wmagent-base:pypi-20241107-stable
MAINTAINER Valentin Kuznetsov vkuznet@gmail.com

# TAG to be passed at build time through `--build-arg TAG=<WMA_TAG>`. Default: None
Expand Down
4 changes: 4 additions & 0 deletions docker/pypi/wmagent/bin/manage
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,10 @@ clean_oracle(){
return $errVal
}

clean_couch(){
echo "$FUNCNAME: automatic cleaning of local CouchDB is not implemented, yet"
}

status(){
echo "----------------------------------------------------------------------"
echo "Status of services:"
Expand Down
25 changes: 25 additions & 0 deletions docker/pypi/wmagent/bin/manage-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,31 @@ _sql_db_isclean(){
esac
}

_couch_db_isclean(){
# assume that we can connect to local CouchDB
# assume that env contains local couch user and password.
echo "$FUNCNAME: Checking if local CouchDB is empty (curl to wmagent_summary db name)"
agent_summary=$(curl -s -u "$COUCH_USER:$COUCH_PASS" http://$COUCH_HOST:$COUCH_PORT/wmagent_summary)

if ! type jq > /dev/null ; then
echo "$FUNCNAME: jq is not installed, we cannot check if CouchDB is empty. Skipping this step."
return $(true)
fi
agent_summary_notclean=$(jq "select(.doc_count > 1 or .doc_del_count > 0)" <<< $agent_summary)

if [ -n "${agent_summary_notclean}" ]; then
# the variable is not empty -> means that couch is not empty
echo "$FUNCNAME: local CouchDB is not empty. We cannot init WMAgent"
doc_count=$(jq ".doc_count" <<< $agent_summary)
doc_del_count=$(jq ".doc_del_count" <<< $agent_summary)
echo "$FUNCNAME: it contains $doc_count docs, $doc_del_count deleted docs"
return $(false)
else
# the variable is empty -> means that couch is empty
echo "$FUNCNAME: local CouchDB is empty. We can init WMAgent"
fi
}

_sql_write_agentid(){
# Auxiliary function to write the current agent build id into the sql database
echo "$FUNCNAME: Preserving the current WMA_BUILD_ID and HostName at database: $wmaDBName."
Expand Down
9 changes: 7 additions & 2 deletions docker/pypi/wmagent/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,10 @@ _check_couch() {
echo "$FUNCNAME: Checking whether the CouchDB database is reachable..."
_status_of_couch || return $(false)

# echo "$FUNCNAME: Additional checks for CouchDB:"
echo "$FUNCNAME: Additional checks for CouchDB:"
local cleanMessage="You may consider cleaning local couchdb with 'rm -rf /data/dockerMount/srv/couchdb/'"
# NOTE: To implement any additional check to the CouchDB similar to the relational databases
_couch_db_isclean || { echo "$FUNCNAME: Error: non empty local CouchDB. $cleanMessage"; return $(false); }
}

check_databases() {
Expand Down Expand Up @@ -313,7 +315,10 @@ check_databases() {
esac

# Checking CouchDB:
_check_couch
[[ -n $COUCH_HOST ]] && [[ -n $COUCH_PORT ]] && [[ -n $COUCH_USER ]] && [[ -n $COUCH_PASS ]] &&
couchdbCred=true
$couchdbCred || { echo "$FUNCNAME: ERROR: No local CouchDB credentials provided at $WMA_SECRETS_FILE" ; return $(false); }
_check_couch
echo "-----------------------------------------------------------------------"
}

Expand Down

0 comments on commit c835caa

Please sign in to comment.