-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create spark job to get user file acc times using wmarchive lfnarray belonging crab jobs #113
Open
mrceyhun
wants to merge
3
commits into
dmwm:master
Choose a base branch
from
mrceyhun:f-wma-file-access
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
451fd5c
Create spark job to get user file acc times using wmarchive lfnarray …
mrceyhun d6d2c9c
Implement joint rucio and wmarchive data for user access time of data…
mrceyhun 4544fee
Implement user accessess monitoring to datasets using wmarchive rucio…
mrceyhun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
#!/bin/bash | ||
set -e | ||
# Author: Ceyhun Uzunoglu <ceyhunuzngl AT gmail [DOT] com> | ||
##H Cron job of wmarchive_crab_file_access.py which sends Spark agg results to MONIT via StompAMQ | ||
##H See PySpark job for detialed explanation. | ||
##H | ||
##H Usage: | ||
##H cron4wma_crab_ds_access.sh \ | ||
##H <keytab> value <amq> value <cmsmonitoring> value <stomp> value | ||
##H | ||
##H Example : | ||
##H cron4wma_crab_ds_access.sh \ | ||
##H --keytab ./keytab --amq ./amq-creds.json --cmsmonitoring ./CMSMonitoring.zip --stomp ./stomp-v700.zip \ | ||
##H --p1 32000 --p2 32001 --host $MY_NODE_NAME --wdir $WDIR | ||
##H Arguments with values: | ||
##H - keytab : Kerberos auth file: secrets/kerberos | ||
##H - amq : AMQ credentials and configurations json file for the used AMQ topic | ||
##H - cmsmonitoring : dmwm/CMSMonitoring/src/python/CMSMonitoring folder as zip to be sent to Spark nodes | ||
##H - stomp : stomp.py==7.0.0 module as zip to be sent to Spark nodes which has lower versions. | ||
##H - p1, p2, host, wdir : [ALL FOR K8S] p1 and p2 spark required ports(driver and blockManager), host is k8s node dns alias, wdir is working directory | ||
##H - test : will run only test job which will send only 10 documents to AMQ topic. Please give test/training AMQ credentials | ||
##H | ||
TZ=UTC | ||
START_TIME=$(date +%s) | ||
script_dir="$( | ||
cd -- "$(dirname "$0")" >/dev/null 2>&1 | ||
pwd -P | ||
)" | ||
# get common util functions | ||
. "$script_dir"/utils/common_utils.sh | ||
|
||
trap 'onFailExit' ERR | ||
onFailExit() { | ||
util4loge "finished with error!" || exit 1 | ||
} | ||
# ------------------------------------------------------------------------------------------------------- GET USER ARGS | ||
unset -v KEYTAB_SECRET AMQ_JSON_CREDS CMSMONITORING_ZIP STOMP_ZIP PORT1 PORT2 K8SHOST WDIR IS_TEST help | ||
[ "$#" -ne 0 ] || usage | ||
|
||
# --options (short options) is mandatory, and v is a dummy param. | ||
PARSED_ARGS=$(getopt --unquoted --options v,h --name "$(basename -- "$0")" --longoptions keytab:,amq:,cmsmonitoring:,stomp:,p1:,p2:,host:,wdir:,test,help -- "$@") | ||
VALID_ARGS=$? | ||
if [ "$VALID_ARGS" != "0" ]; then | ||
usage | ||
fi | ||
|
||
echo "$(date --rfc-3339=seconds)" "[INFO] Given arguments: $PARSED_ARGS" | ||
eval set -- "$PARSED_ARGS" | ||
|
||
while [[ $# -gt 0 ]]; do | ||
case "$1" in | ||
--keytab) KEYTAB_SECRET=$2 ; shift 2 ;; | ||
--amq) AMQ_JSON_CREDS=$2 ; shift 2 ;; | ||
--cmsmonitoring) CMSMONITORING_ZIP=$2 ; shift 2 ;; | ||
--stomp) STOMP_ZIP=$2 ; shift 2 ;; | ||
--p1) PORT1=$2 ; shift 2 ;; | ||
--p2) PORT2=$2 ; shift 2 ;; | ||
--host) K8SHOST=$2 ; shift 2 ;; | ||
--wdir) WDIR=$2 ; shift 2 ;; | ||
--test) IS_TEST=1 ; shift ;; | ||
-h | --help) help=1 ; shift ;; | ||
*) break ;; | ||
esac | ||
done | ||
|
||
if [[ "$help" == 1 ]]; then | ||
util_usage_help | ||
fi | ||
# ------------------------------------------------------------------------------------------------------------- PREPARE | ||
export PYTHONPATH=$script_dir/../src/python:$PYTHONPATH | ||
# run util to check PYTHONPATH | ||
util_check_pythonpath_for_cmsspark | ||
|
||
# Define logs path for Spark imports which produce lots of info logs | ||
LOG_DIR="$WDIR"/logs/$(date +%Y%m%d) | ||
mkdir -p "$LOG_DIR" | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The script should print all environment variable it uses, e.g.
This will help you later in debug process. |
||
# check files exist | ||
util_check_files "$KEYTAB_SECRET" "$AMQ_JSON_CREDS" "$CMSMONITORING_ZIP" "$STOMP_ZIP" | ||
# check variables set | ||
util_check_vars PORT1 PORT2 K8SHOST WDIR | ||
|
||
# INITIALIZE ANALYTIX SPARK3 | ||
util_setup_spark_k8s | ||
|
||
# Authenticate kerberos and get principle user name | ||
KERBEROS_USER=$(util_kerberos_auth_with_keytab "$KEYTAB_SECRET") | ||
util4logi "authenticated with ${KERBEROS_USER} user's keytab" | ||
|
||
# INFO LOGS | ||
util4logi "used variables ..." | ||
util4logi "KERBEROS_USER: ${KERBEROS_USER} , authenticated with user's keytab" | ||
util4logi "LOG_DIR: ${LOG_DIR}" | ||
|
||
# ------------------------------------------------------------------------------------------------------- RUN SPARK JOB | ||
# Required for Spark job in K8s | ||
util4logi "spark job starts" | ||
|
||
# Executor memory 16g is required because this spark job do heavy joins on 10 tables, half of them are big ones | ||
spark_submit_args=( | ||
--master yarn --conf spark.ui.showConsoleProgress=false --conf "spark.driver.bindAddress=0.0.0.0" | ||
--driver-memory=8g --executor-memory=16g | ||
--conf "spark.driver.host=${K8SHOST}" --conf "spark.driver.port=${PORT1}" --conf "spark.driver.blockManager.port=${PORT2}" | ||
--packages org.apache.spark:spark-avro_2.12:3.2.1 --py-files "${CMSMONITORING_ZIP},${STOMP_ZIP}" | ||
) | ||
py_input_args=(--creds "$AMQ_JSON_CREDS" --amq_batch_size 1000) | ||
|
||
function run_spark() { | ||
spark-submit "${spark_submit_args[@]}" "${script_dir}/../src/python/CMSSpark/wmarchive_crab_file_access.py" \ | ||
"${py_input_args[@]}" >>"${LOG_DIR}/spark-wma_crab_ds_access.log" 2>&1 | ||
} | ||
|
||
function run_test_spark() { | ||
# Test will send 10 documents to AMQ topic | ||
py_input_args+=(--test --start_date 2022-09-01 --end_date 2022-09-03) | ||
spark-submit "${spark_submit_args[@]}" "${script_dir}/../src/python/CMSSpark/wmarchive_crab_file_access.py" \ | ||
"${py_input_args[@]}" >>"${LOG_DIR}/spark-wma_crab_ds_access.log" 2>&1 | ||
} | ||
|
||
# RUN SPARK | ||
if [[ "$IS_TEST" == 1 ]]; then | ||
# will send only 10 documents, only to test/training AMQ topic. Please check python script for more details. | ||
run_test_spark 2>&1 | ||
else | ||
run_spark 2>&1 | ||
fi | ||
|
||
util4logi "last 10 lines of spark job log" | ||
tail -10 "${LOG_DIR}/spark-wma_crab_ds_access.log" | ||
|
||
duration=$(($(date +%s) - START_TIME)) | ||
util4logi "all finished, time spent: $(util_secs_to_human $duration)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add author part into the script.