Skip to content

Commit

Permalink
Adding init_tier0 function (#1466)
Browse files Browse the repository at this point in the history
* Adding init_tier0

* Fix parsing bugs for commented lines && semicolons in values

* Do not copy the manage script to WMA_CONFIG_DIR

* Temporarily stop modifying agent configuration with tier0-mod-config

* Fix few forgotten Tier0 related vars && reenable all steps for tier0-mod-config

* Add _proxy_renew for T0 && avoid _check_mounts  for T0 && Skip Add resource  control for T0 && Fix variables in tier0_init

* Move init_agent echo line

* Fix indentation in init_tier0

* Fix indentation in init_wmagent

* Rename resRecord variables

* Avoid copying the run time scripts if not running from inside a Docker container

* Dynamically build resource  options

Fix resRecord array name substitution

* Add a check for docker container during initialization

* Fix allways nonError return values for init_tier0 step

* Avoid checking for mounts when not running from docker

* Move _copy_runtime as a separate  function && Fix ambiguos comments, variable names and printouts

* Rename dockerBuildId to wmaBuildId && add Vir env agent start message

* Follow up on review comments

* Remove no longer needed export for WMAGENT_CONFIG

* Follow up on review comments
  • Loading branch information
todor-ivanov authored May 23, 2024
1 parent 874876a commit b0a54f3
Show file tree
Hide file tree
Showing 6 changed files with 252 additions and 109 deletions.
2 changes: 1 addition & 1 deletion docker/pypi/wmagent/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ ENV WMA_INSTALL_DIR=$WMA_CURRENT_DIR/install
ENV WMA_STATE_DIR=$WMA_CURRENT_DIR/state
ENV WMA_CONFIG_DIR=$WMA_CURRENT_DIR/config
ENV WMA_CONFIG_FILE=$WMA_CONFIG_DIR/config.py
ENV WMA_MANAGE_DIR=$WMA_CONFIG_DIR
ENV WMA_LOG_DIR=$WMA_CURRENT_DIR/logs
ENV WMA_DEPLOY_DIR=/usr/local
ENV WMA_MANAGE_DIR=$WMA_DEPLOY_DIR/bin
ENV WMA_ENV_FILE=$WMA_DEPLOY_DIR/deploy/env.sh
ENV WMA_SECRETS_FILE=$WMA_ADMIN_DIR/WMAgent.secrets
ENV ORACLE_PATH=$WMA_DEPLOY_DIR/etc/oracle
Expand Down
2 changes: 1 addition & 1 deletion docker/pypi/wmagent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ They are set at different moments along the process: i.e. at `buildtime` - when
* config=$WMA_CONFIG_DIR
* manage=$WMA_MANAGE_DIR/manage
* RUCIO_HOME=$WMA_CONFIG_DIR
* WMA_BUILD_ID=$(cat $WMA_ROOT_DIR/.dockerBuildId)
* WMA_BUILD_ID=$(cat $WMA_ROOT_DIR/.wmaBuildId)
* WMCORE_ROOT=$WMA_DEPLOY_DIR
* WMAGENTPY3_ROOT=$WMA_INSTALL_DIR
* WMAGENTPY3_VERSION=$WMA_TAG
Expand Down
98 changes: 82 additions & 16 deletions docker/pypi/wmagent/bin/manage
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ activate_agent(){
# The very first step of activating the WMAgent upon all needed checks and
# validations performed during the initialization process.
# No .init* flags are checked at this stage.
cp -vf $WMA_DEPLOY_DIR/etc/WMAgentConfig.py $WMA_CONFIG_DIR/config-template.py
if [[ "$TEAMNAME" == Tier0* ]]; then
cat $WMA_DEPLOY_DIR/etc/WMAgentConfig.py $WMA_DEPLOY_DIR/etc/Tier0Config.py > $WMA_CONFIG_DIR/config-template.py
else
cp -vf $WMA_DEPLOY_DIR/etc/WMAgentConfig.py $WMA_CONFIG_DIR/config-template.py
fi

}

#
Expand Down Expand Up @@ -103,7 +108,7 @@ db_prompt(){
# Agent stuff #
##############################

# generate the agent config from the basic template
# generate the WMAgent config from the basic template
init_wmagent(){

case $AGENT_FLAVOR in
Expand All @@ -124,7 +129,7 @@ init_wmagent(){

local errVal=0
wmagent-mod-config $database_options \
--input=$WMA_CONFIG_DIR/config-template.py \
--input=$WMA_CONFIG_DIR/config-template.py \
--output=$WMA_CONFIG_DIR/config.py \
--working_dir=$WMA_INSTALL_DIR \
--couch_url=http://$COUCH_USER:$COUCH_PASS@$COUCH_HOST:$COUCH_PORT \
Expand All @@ -134,17 +139,17 @@ init_wmagent(){
--grafana_token=$GRAFANA_TOKEN \
--wmstats_url=$WMSTATS_URL \
--reqmgr2_url=$REQMGR2_URL \
--acdc_url=$ACDC_URL \
--dbs3_url=$DBS3_URL \
--dbs3_reader_url=$DBS3_READER_URL \
--dqm_url=$DQM_URL \
--requestcouch_url=$REQUESTCOUCH_URL \
--central_logdb_url=$CENTRAL_LOGDB_URL \
--wmarchive_url=$WMARCHIVE_URL \
--amq_credentials=$AMQ_CREDENTIALS \
--rucio_account=$RUCIO_ACCOUNT \
--rucio_host=$RUCIO_HOST \
--rucio_auth=$RUCIO_AUTH
--acdc_url=$ACDC_URL \
--dbs3_url=$DBS3_URL \
--dbs3_reader_url=$DBS3_READER_URL \
--dqm_url=$DQM_URL \
--requestcouch_url=$REQUESTCOUCH_URL \
--central_logdb_url=$CENTRAL_LOGDB_URL \
--wmarchive_url=$WMARCHIVE_URL \
--amq_credentials=$AMQ_CREDENTIALS \
--rucio_account=$RUCIO_ACCOUNT \
--rucio_host=$RUCIO_HOST \
--rucio_auth=$RUCIO_AUTH
let errVal+=$?

wmcore-db-init --config $WMA_CONFIG_DIR/config.py --create --modules=WMCore.WMBS,WMCore.Agent.Database,WMComponent.DBS3Buffer,WMCore.BossAir,WMCore.ResourceControl;
Expand All @@ -157,10 +162,71 @@ init_wmagent(){
}


##############################
# Tier0 stuff #
##############################


# generate the tier0 config from the basic template
init_tier0(){
local errVal=0
wmagent-mod-config --input=$WMA_CONFIG_DIR/config-template.py \
--output=$WMA_CONFIG_DIR/config-agent.py \
--coredb_url=oracle://$ORACLE_USER:$ORACLE_PASS@$ORACLE_TNS \
--working_dir=$WMA_INSTALL_DIR \
--couch_url=http://$COUCH_USER:$COUCH_PASS@$COUCH_HOST:$COUCH_PORT \
--workqueue_db_name=$LOCAL_WORKQUEUE_DBNAME \
--workload_summary_url=$WORKLOAD_SUMMARY_URL \
--grafana_token=$GRAFANA_TOKEN \
--wmstats_url=$WMSTATS_URL \
--dbs3_url=$DBS3_URL \
--dqm_url=$DQM_URL \
--requestcouch_url=$REQUESTCOUCH_URL \
--central_logdb_url=$CENTRAL_LOGDB_URL \
--wmarchive_url=$WMARCHIVE_URL \
--amq_credentials=$AMQ_CREDENTIALS \
--rucio_account=$RUCIO_ACCOUNT \
--rucio_host=$RUCIO_HOST \
--rucio_auth=$RUCIO_AUTH
let errVal+=$?

# NOTE: For the next step relates to modifying the originally generated WMAgent config file
# from $WMA_CONFIG_DIR/config-agent.py
# to $WMA_CONFIG_DIR/config.py
# It removes the components not relevant for T0 and adds the additional DB credentials
# used at Tier0Feeder. In order for it to be executed properly we need to download the
# tier0-mod-config script from https://github.com/dmwm/T0/blob/master/bin/tier0-mod-config
optargs=""
[[ -n $CONFDB_URL ]] && optargs="$optargs --confdb_url=$CONFDB_URL"
[[ -n $SMDB_URL ]] && optargs="$optargs --smdb_url=$SMDB_URL"
[[ -n $POPCONLOGDB_URL ]] && optargs="$optargs --popconlogdb_url=$POPCONLOGDB_URL"
[[ -n $T0DATASVCDB_URL ]] && optargs="$optargs --t0datasvcdb_url=$T0DATASVCDB_URL"
[[ -n $SMNOTIFYDB_URL ]] && optargs="$optargs --smnotifydb_url=$SMNOTIFYDB_URL"

tier0-mod-config --input=$WMA_CONFIG_DIR/config-agent.py \
--output=$WMA_CONFIG_DIR/config.py \
$optargs
let errVal+=$?

wmcore-db-init --config $WMA_CONFIG_DIR/config.py --create --modules=WMCore.WMBS,WMCore.Agent.Database,WMComponent.DBS3Buffer,WMCore.BossAir,WMCore.ResourceControl,T0.WMBS;
let errVal+=$?

wmagent-couchapp-init;
let errVal+=$?

return $errVal
}


init_agent(){
if _init_valid $wmaInitActive ; then
echo "Initialising Agent..."
init_wmagent
if [[ "$TEAMNAME" == Tier0* ]]; then
echo "Initializing Tier0 Agent..."
init_tier0
else
echo "Initializing WMAgent..."
init_wmagent
fi
else
echo "ERROR: This agent has not been activated yet. Cannot proceed."
return $(false)
Expand Down
49 changes: 43 additions & 6 deletions docker/pypi/wmagent/bin/manage-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ wmaSchemaFile=$WMA_CONFIG_DIR/.wmaSchemaFile.sql
wmaDBName=wmagent
#-------------------------------------------------------------------------------

_is_venv() {
# Auxiliary function to determine if we are running within a shell with active python virtual env
$(python3 -c 'import sys; isVenv = sys.prefix == sys.base_prefix;sys.exit(isVenv)')
}

_is_docker() {
# Auxiliary function to determine if we are running within a docker env
[[ -f /.dockerenv ]] && grep -q docker /proc/1/cgroup
}

_exec_mysql() {
# Auxiliary function to avoid repetitive and long calls to the mysql command
# :param $1: SQL command to be executed passed a s single string
Expand Down Expand Up @@ -252,7 +262,7 @@ _status_of_oracle(){
# Auxiliary function to check if the oracle database configured for the current agent is empty
echo "$FUNCNAME:"
_exec_oracle "select 1 from dual;"
# sqlplus $ORACLE_USER/$ORACLE_PASS@$ORACLE_TNS <<EOF
# sqlplus $ORACLE_USER/$ORACLE_PASS@$ORACLE_TNS <<EOF
# whenever sqlerror exit sql.sqlcode;
# select 1 from dual;
# exit;
Expand All @@ -265,8 +275,22 @@ _status_of_oracle(){
_renew_proxy(){
# Auxiliary function to renew agent proxy
local hostName=`hostname -f`
_load_wmasecrets

# Here to find out if the agent is CERN or FNAL and use the proper credentials name for _renew_proxy
[[ "$TEAMNAME" == Tier0* ]] && {
echo "$FUNCNAME: This is a Tier0 agent"
local vomsproxyCmd="voms-proxy-init -rfc \
-voms cms:/cms/Role=production -valid 168:00 -bits 2048 \
-cert $X509_USER_CERT -key $X509_USER_KEY \
-out $X509_USER_PROXY"
$vomsproxyCmd || {
echo "$FUNCNAME: ERROR: Failed to renew invalid myproxy"
return $(false)
}
return
}

if [[ "$hostName" == *cern.ch ]]; then
local myproxyCredName="amaltaroCERN"
elif [[ "$hostName" == *fnal.gov ]]; then
Expand Down Expand Up @@ -306,7 +330,7 @@ _parse_wmasecrets(){

# Building the list by parsing the secrets file itself.
[[ -n $varsToCheck ]] || {
varsToCheck=`grep -v "^[[:blank:]]#" $secretsFile |grep \= | awk -F\= '{print $1}'`
varsToCheck=`grep -v "^[[:blank:]]*#" $secretsFile |grep \= | awk -F\= '{print $1}'`
}

for var in $varsToCheck
Expand Down Expand Up @@ -342,7 +366,7 @@ _load_wmasecrets(){
# If no list of variables to be loaded was given assume all of them.
# Building the list by parsing the secrets file itself.
[[ -n $varsToLoad ]] || {
varsToLoad=`grep -v "^[[:blank:]]#" $secretsFile |grep \= | awk -F\= '{print $1}'`
varsToLoad=`grep -v "^[[:blank:]]*#" $secretsFile |grep \= | awk -F\= '{print $1}'`
}

# Here we validate every variable for itself before loading it
Expand All @@ -359,8 +383,21 @@ _load_wmasecrets(){
for varName in $varsToLoad
do
value=`grep -E "^[[:blank:]]*$varName=" $secretsFile | sed "s/ *$varName=//"`
[[ $varName =~ ^RESOURCE_ ]] && declare -g -A $varName
eval $varName=$value
if [[ $varName =~ ^RESOURCE_ ]]; then
declare -g -A $varName
eval $varName=$value || {
let errVal+=$?
echo "$FUNCNAME: ERROR: Could not evaluate: ${varName}=${!varName}"
return $errVal
}
else
eval $varName='$value' || {
let errVal+=$?
echo "$FUNCNAME: ERROR: Could not evaluate: ${varName}=${!varName}"
return $errVal
}
fi
# echo ${varName}=${!varName}
[[ -n $varName ]] || { echo "$FUNCNAME: ERROR: Empty value for: $varName=$value"; let errVal+=1 ;}
done

Expand Down Expand Up @@ -401,7 +438,7 @@ _print_settings(){
env |grep ^WMA| sort

echo "-------------- WMA_SECRETS_FILE variables: --------------"
varsToPrint=`grep -v "^[[:blank:]]#" $WMA_SECRETS_FILE |grep \= | awk -F\= '{print $1}'`
varsToPrint=`grep -v "^[[:blank:]]*#" $WMA_SECRETS_FILE |grep \= | awk -F\= '{print $1}'`

for varName in $varsToPrint
do
Expand Down
Loading

0 comments on commit b0a54f3

Please sign in to comment.