forked from hpcc-systems/h2h
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhdfspipe.in
178 lines (148 loc) · 4.87 KB
/
hdfspipe.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/bin/bash
#############################################
# Copyright (C) 2012 HPCC Systems.
#
# All rights reserved. This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with All rights reserved. This program is free software: you can redistribute program. If not, see <http://www.gnu.org/licenses/>.
#############################################
#DO NOT MODIFY THIS FILE!
#CONFIGURATION CHANGES CAN BE DONE HERE: /etc/HPCCSystems/@HDFSCONN_CONF_FILE@
source @HPCC_ETC_DIR@/init.d/hpcc_common
set_environmentvars
source $configs/@HDFSCONN_CONF_FILE@
CLASSPATH=$CLASSPATH:$HADOOP_CONF_DIR
###################################################
# CLASSPATH set up for libhdfs
###################################################
for f in $HADOOP_SHARE_DIR/*.jar ; do
CLASSPATH=$CLASSPATH:$f
done
for f in $HADOOP_SHARE_DIR/lib/*.jar ; do
CLASSPATH=$CLASSPATH:$f
done
if [ -n "$TARBALL_HADOOP_LOCATION" ]; then
CLASSPATH=$CLASSPATH:$TARBALL_HADOOP_LOCATION/conf
for f in $TARBALL_HADOOP_LOCATION/*.jar ; do
CLASSPATH=$CLASSPATH:$f
done
for f in $TARBALL_HADOOP_LOCATION/lib/*.jar ; do
CLASSPATH=$CLASSPATH:$f
done
fi
export CLASSPATH=$CLASSPATH
PID=$$
nodeid=0;
wuid=0;
for ((paramindex=1; paramindex <= $#; paramindex++ ));
do
if [ "${!paramindex}" = "-wuid" ];
then
((paramindex++));
wuid=${!paramindex};
echo "found wuid: $wuid";
elif [ "${!paramindex}" = "-nodeid" ];
then
((paramindex++));
nodeid=${!paramindex};
echo "found nodeid: $nodeid";
fi
done;
#the log variable is read from the HPCC Platform config
LOGS_LOCATION=$log
HDFSCONNLOGLOC=$LOGS_LOCATION/mydataconnectors
LOG=$HDFSCONNLOGLOC/@HDFS_CONNECTOR_TYPE@.$nodeid.$PID.$wuid.log
PIPERRLOG=$HDFSCONNLOGLOC/HPCC-FIFO.err.$PID
if [ -e $HDFSCONNLOGLOC ]
then
echo "log file found" >> $LOG
else
mkdir $HDFSCONNLOGLOC
fi
username=`id -nu`
echo "Script starting" >> $LOG
echo "PID: $PID" >> $LOG
echo "User: $username" >> $LOG
echo 'Incoming params: ' >> $LOG
echo $(printf '%q ' ${@}) >> $LOG
echo "NodeId: $nodeid" >> $LOG
echo "WUID: $wuid" >> $LOG
h2hpid=0;
h2hstatus=0;
TARGETCONNECTORNAME="@HDFSCONN_EXE_NAME@";
if [ "$1" = "" ];
then
echo "Error: No input params detected!" >> $LOG
exit 1;
elif [ $1 = "-mf" ];
then
$TARGETCONNECTORNAME ${@} 2>> $LOG;
h2hstatus=$?;
h2hpid=$!;
elif [ $1 = "-si" ];
then
$TARGETCONNECTORNAME ${@} 2>> $LOG;
h2hstatus=$?
h2hpid=$!;
elif [ $1 = "-so" ];
then
HPCCTMPFILE=/tmp/HPCCTMPFILE-$nodeid-$PID-$wuid;
if [ -f $HPCCTMPFILE ]
then
rm "$HPCCTMPFILE" 2>> $LOG
echo "deleted tmp file" >> $LOG
else
echo "$HPCCTMPFILE does not exist" >> $LOG
fi
echo "redirecting stdin to tmp file ... " >> $LOG
cat /dev/stdin > "$HPCCTMPFILE"
ls -l "$HPCCTMPFILE" >> $LOG
echo "calling hdfsconnector..." >> $LOG
$TARGETCONNECTORNAME ${@} -pipepath $HPCCTMPFILE 2>> $LOG
h2hpid=$!;
h2hstatus=$?;
elif [ $1 = "-sop" ];
then
pipepath=/tmp/HPCCPIPE-$nodeid-$PID-$wuid;
mkfifo $pipepath 2> $PIPERRLOG;
chmod 777 $pipepath 2> $PIPERRLOG;
echo "mkfifo $pipepath setup ..." >> $LOG
if test ! -s "$PIPERRLOG"
then
rm -f $PIPERRLOG 2> /dev/null
else
echo " WARNING (hdfsconnector mkfifo) error registered in file: $PIPERRLOG " >> $LOG
exit 1
fi
$TARGETCONNECTORNAME ${@} -pipepath $pipepath 2>> $LOG &
h2hpid=$!;
echo h2h pid: ${h2hpid} >> $LOG
echo "redirecting stdin to named pipe ... " >> $LOG
cat < /dev/stdin > "$pipepath" &
ls -l "$pipepath" >> $LOG
echo "Waiting on hdfsconnector PID ${h2hpid}" >> $LOG
wait ${h2hpid};
h2hstatus=$?;
echo "Finished waiting on hdfsconnector exit status: ${h2hstatus}" >> $LOG
if [ ${h2hstatus} -ne 0 ];
then
echo "Closing pipe due to hdfsconnector error" >> $LOG
exec <&- 2>> $LOG
exec $pipepath <&- 2>> $LOG
fi
rm -f $pipepath 2>> $LOG
else
echo "Error: check your params." >> $LOG;
h2hstatus=1;
fi
echo "$TARGETCONNECTORNAME exited with: ${h2hstatus}" >> $LOG
exit ${h2hstatus};