-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
597 make sidecar and transformer containers communicate over socket (#…
…601) * Remove comented out code --------- Co-authored-by: Ben Galewsky <ben@peartreestudio.net>
- Loading branch information
1 parent
dedb7e7
commit 6b4235d
Showing
9 changed files
with
135 additions
and
331 deletions.
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
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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
rabbitmq | ||
pyarrow | ||
psutil | ||
watchdog | ||
pika>=1.1.0 | ||
minio>=7.1.0 | ||
retry | ||
|
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 |
---|---|---|
@@ -1,52 +1,78 @@ | ||
#!/usr/bin/env bash | ||
# This script is used in the science container to watch for new transform | ||
# requests in the form of JSON files. From this file, it extracts the source | ||
# input file URI, a scratch output filename and a final file path to write | ||
# requests in the form of JSON documents coming over the socket on port 8081. | ||
# From this doc, it extracts the source | ||
# input file URI, an output filename and a file path to write | ||
# the transformed file upon completion. | ||
# Signal to the sidecar that we are done by writing a file with the extension | ||
# .done to the directory. Also write the log files to the shared volume. | ||
# Finally, if there is an error then write a .failure file to signal to the | ||
# sidecar. | ||
# To signal to the sidecar that the transformation is done, we send result over | ||
# the socket. Also write the log files to the shared volume. | ||
# | ||
# Communication steps for each input file | ||
# watch sends "GeT" in order to ask for a json doc | ||
# watch runs transformation | ||
# writes to the socket "success." or "failure." | ||
# listens for the confirmation. | ||
|
||
# Arguments: | ||
# 1. A "language" used to execute the transform script. Usually bash or python | ||
# 2. The script to execute | ||
# 3. Path to the shared volume | ||
# | ||
lang=$1 | ||
cmd=$2 | ||
path=$3 | ||
|
||
while true; do | ||
if [ -f $path/*.json ]; then | ||
|
||
start=$(date +%s%N | cut -b1-13) | ||
|
||
for file in `ls $path/*.json`; do | ||
download_path=`grep -o '"downloadPath": "[^\"]*"' $file |tr -d '"' |tr -d ',' | awk '{print $2}' ` | ||
output_file=`grep -o '"safeOutputFileName": "[^\"]*"' $file |tr -d '"' |tr -d ',' | awk '{print $2}' ` | ||
completed_file=`grep -o 'completedFileName": "[^\"]*"' $file |tr -d '"' |tr -d ',' | awk '{print $2}' ` | ||
output_format=`grep -o '"result-format": "[^\"]*"' $file |tr -d '"' |tr -d ',' | awk '{print $2}' ` | ||
|
||
echo "Attempting $download_path -> $output_file -> $completed_file with $output_format format" | ||
$lang "$cmd" "$download_path" "$output_file" "$output_format" 2>&1 | tee $file.log | ||
|
||
if [ "${PIPESTATUS[0]}" == 0 ]; then | ||
echo "Success. skipping rest of input_files" | ||
mv "$output_file" "$completed_file" | ||
touch "$file".done | ||
rm "$file" | ||
else | ||
echo "Operation failed for $download_path" | ||
touch "$file".failed | ||
rm "$file" | ||
fi | ||
done; | ||
|
||
end=$(date +%s%N | cut -b1-13) | ||
echo "Elapsed Time: $(($end-$start)) ms" | ||
echo "connecting..." | ||
|
||
coproc nc { nc localhost 8081; } | ||
|
||
while [[ $nc_PID ]] ; do | ||
|
||
start=$(date +%s%N | cut -b1-13) | ||
echo "start: $start" | ||
# ask for a file to be processed | ||
printf >&${nc[1]} '%s\n' "GeT" | ||
read -r -u${nc[0]} line | ||
printf >&2 '%s\n' "Received request:" "$line" | ||
if [[ -z "$line" ]]; then | ||
echo "received an empty line" | ||
break | ||
fi | ||
download_path=$(echo $line | jq -r '.downloadPath') | ||
output_file=$(echo $line | jq -r '.safeOutputFileName') | ||
output_format=$(echo $line | jq -r '."result-format"') | ||
|
||
echo "Attempting $download_path -> $output_file with $output_format format" | ||
$lang "$cmd" "$download_path" "$output_file" "$output_format" 2>&1 | tee $path/abc.log | ||
|
||
# sending status back | ||
if [ "${PIPESTATUS[0]}" == 0 ]; then | ||
echo "Success. skipping rest of input_files" | ||
printf >&${nc[1]} '%s\n' "success." | ||
else | ||
echo 'SLEEPING in watch' | ||
sleep 0.1 | ||
echo "Operation failed for $download_path" | ||
printf >&${nc[1]} '%s\n' "failure." | ||
fi | ||
|
||
# get confirmation. | ||
read -r -u${nc[0]} line | ||
printf >&2 '%s\n' "Reply:" "$line" | ||
|
||
end=$(date +%s%N | cut -b1-13) | ||
echo "Elapsed Time: $(($end-$start)) ms" | ||
done | ||
|
||
|
||
# { | ||
# "request-id": "decfc25d-4b19-47c9-a742-6259450142c7", | ||
# "file-id": null, | ||
# "columns": null, | ||
# "paths": "root://lcg-lrz-rootd.grid.lrz.de:1094/pnfs/lrz-muenchen.de/data/atlas/dq2/atlaslocalgroupdisk/rucio/user/ivukotic/53/26/00284890-DCDB-E511-9F9D-02163E012FCA.root,root://eosatlas.cern.ch:1094//eos/atlas/atlasscratchdisk/rucio/user/ivukotic/53/26/00284890-DCDB-E511-9F9D-02163E012FCA.root", | ||
# "tree-name": null, | ||
# "service-endpoint": "http://servicex-release-testing-2-servicex-app:8000/servicex/internal/transformation/decfc25d-4b19-47c9-a742-6259450142c7", | ||
# "chunk-size": "1000", | ||
# "result-destination": "object-store", | ||
# "result-format": "parquet", | ||
# "downloadPath": "root://xcache.af.uchicago.edu:1094//root://lcg-lrz-rootd.grid.lrz.de:1094/pnfs/lrz-muenchen.de/data/atlas/dq2/atlaslocalgroupdisk/rucio/user/ivukotic/53/26/00284890-DCDB-E511-9F9D-02163E012FCA.root", | ||
# "safeOutputFileName": "/servicex/output/decfc25d-4b19-47c9-a742-6259450142c7/scratch/root:::xcache.af.uchicago.edu:1094::root:::lcg-lrz-rootd.grid.lrz.de:1094:pnfs:lrz-muenchen.de:data:atlas:dq2:atlaslocalgroupdisk:rucio:user:ivukotic:53:26:00284890-DCDB-E511-9F9D-02163E012FCA.root.parquet", | ||
# "completedFileName": "/servicex/output/decfc25d-4b19-47c9-a742-6259450142c7/root:::xcache.af.uchicago.edu:1094::root:::lcg-lrz-rootd.grid.lrz.de:1094:pnfs:lrz-muenchen.de:data:atlas:dq2:atlaslocalgroupdisk:rucio:user:ivukotic:53:26:00284890-DCDB-E511-9F9D-02163E012FCA.root.parquet" | ||
# } |
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
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
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.