Created
March 13, 2013 14:39
-
-
Save andry1/5152739 to your computer and use it in GitHub Desktop.
Example HTTPFS communication using curl+kerberos
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
#!/bin/bash | |
# | |
# Uses a keytab to auth to kerberos and then creates an empty file/directory | |
# to notify oozie that data is ready. | |
# Specify the name of the dataset to notify for as the first argument, | |
# and optionally the day in UTC during which the data is intended to be loaded | |
# (defaults to the current day in UTC) | |
# e.g. : | |
# | |
# /path/to/datasci_notify.sh audopt_us | |
# OR | |
# /path/to/datasci_notify.sh audopt_us 2013-03-23 | |
# | |
KEYTAB=`dirname $0`/datasci.keytab | |
PRINCIPAL=datasci@COLLECTIVE-MEDIA.NET | |
KINIT=/usr/bin/kinit | |
CURL=/usr/bin/curl | |
NOTIFY_PATH=/datasciences/batchimport | |
READY_FILE=_READY | |
HTTPFS="http://nn01-301.ny7.collective-media.net:14000/webhdfs/v1" | |
function die { | |
echo "ERROR: $1" | |
exit 1 | |
} | |
DATASET_NAME=$1 | |
[ -z "$DATASET_NAME" ] && die "Please specify name of dataset to notify for as the first argument!" | |
UTC_DAY="$2" | |
if [ -z "$UTC_DAY" ]; then | |
TZ=UTC | |
UTC_DAY=`date +'%Y-%m-%d'` | |
echo "Using default date of $UTC_DAY UTC" | |
fi | |
[ -f "$KEYTAB" ] || die "keytab file $KEYTAB does not exist!" | |
[ -x "$KINIT" ] || die "kinit binary $KINIT does not exist or is not executable!" | |
[ -x "$CURL" ] || die "curl command $CURL does not exist or is not executable!" | |
$KINIT -k -t "$KEYTAB" "$PRINCIPAL" || die "Failed to authenticate to kerberos using keytab $KEYTAB as $PRINCIPAL" | |
TARGET_DIR="${NOTIFY_PATH}/${DATASET_NAME}/${UTC_DAY}" | |
$CURL -f -X PUT -i --negotiate -u : "${HTTPFS}${TARGET_DIR}?op=MKDIRS&permission=1775" || die "Failed to create target dir ${TARGET_DIR} in HDFS" | |
$CURL -f -X PUT -i --negotiate -u : "${HTTPFS}${TARGET_DIR}/${READY_FILE}?op=CREATE&overwrite=true" && \ | |
$CURL -f -H "Content-Type: application/octet-stream" -X PUT -i --negotiate -u : "${HTTPFS}${TARGET_DIR}/${READY_FILE}?op=CREATE&overwrite=true&data=true" || die "Failed to create ${TARGET_DIR}/${READY_FILE}" || \ | |
die "Failed to create ${TARGET_DIR}/${READY_FILE}" | |
echo "${TARGET_DIR}/${READY_FILE} created" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks. We need to transfer the file with .tmp extention while the file is in transit and will have to remove the .tmp extention once transfer is complete. Can you please suggest how can we achive it using curl