-
Notifications
You must be signed in to change notification settings - Fork 5
/
hdfspipe.in
289 lines (238 loc) · 9.17 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#!/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@
#Since batch doesn't allow simple decimal algebra, we have to parse
#the target hadoop version
OLDIFS=$IFS;
IFS='.';
VER_TOKS=( $HADOOP_VERSION )
IFS=$OLDIFS;
CLASSPATH=$CLASSPATH:$HADOOP_CONF_DIR
###################################################
# CLASSPATH set up for libhdfs
# One of the most common problems with libhdfs is the CLASSPATH is not set properly when calling a program that uses libhdfs.
# per Hadoop: http://hadoop.apache.org/docs/r2.3.0/hadoop-project-dist/hadoop-hdfs/LibHdfs.html
# Make sure you set it to all the Hadoop jars needed to run Hadoop itself.
# Currently, there is no way to programmatically generate the classpath, but a good bet is to include all the jar files in
# $HADOOP_PREFIX and $HADOOP_PREFIX/lib as well as the right configuration directory containing hdfs-site.xml
# However as it turns out, the jars are in different subfolders under the share directory
#
###################################################
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
if [ ${VER_TOKS[0]} -ge "2" ] && [ ${VER_TOKS[1]} -ge 5 ]; then
for f in $TARBALL_HADOOP_LOCATION/share/hadoop/common/*.jar ; do
CLASSPATH=$CLASSPATH:$f;
done
for f in $TARBALL_HADOOP_LOCATION/share/hadoop/common/lib/*.jar ; do
CLASSPATH=$CLASSPATH:$f;
done
for f in $TARBALL_HADOOP_LOCATION/share/hadoop/hdfs/*.jar ; do
CLASSPATH=$CLASSPATH:$f;
done
for f in $TARBALL_HADOOP_LOCATION/share/hadoop/hdfs/lib/*.jar ; do
CLASSPATH=$CLASSPATH:$f;
done
for f in $TARBALL_HADOOP_LOCATION/share/hadoop/yarn/*.jar ; do
CLASSPATH=$CLASSPATH:$f;
done
for f in $TARBALL_HADOOP_LOCATION/share/hadoop/yarn/lib/*.jar ; do
CLASSPATH=$CLASSPATH:$f;
done
for f in $TARBALL_HADOOP_LOCATION/share/hadoop/mapreduce/*.jar ; do
CLASSPATH=$CLASSPATH:$f;
done
for f in $TARBALL_HADOOP_LOCATION/share/hadoop/mapreduce/lib/*.jar ; do
CLASSPATH=$CLASSPATH:$f;
done
fi
else
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
for f in $HADOOP_SHARE_DIR/hadoop/hdfs/*.jar ; do
CLASSPATH=$CLASSPATH:$f
done
for f in $HADOOP_SHARE_DIR/hadoop/hdfs/lib/*.jar ; do
CLASSPATH=$CLASSPATH:$f
done
for f in $HADOOP_SHARE_DIR/hadoop/common/*.jar ; do
CLASSPATH=$CLASSPATH:$f
done
for f in $HADOOP_SHARE_DIR/hadoop/common/lib/*.jar ; do
CLASSPATH=$CLASSPATH:$f
done
for f in $HADOOP_SHARE_DIR/hadoop/tools/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};
elif [ "${!paramindex}" = "-nodeid" ];
then
((paramindex++));
nodeid=${!paramindex};
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
if [ ${h2hstatus} -ne 0 ]
then
if [ "$TARGETCONNECTORNAME" = "libhdfsconnector" ]
then
echo "" >> $LOG
if [ -z "$TARBALL_HADOOP_LOCATION" ] && [ -z "$HADOOP_SHARE_DIR" ]
then
echo "WARNING: both TARBALL_HADOOP_LOCATION and HADOOP_SHARE_DIR are empty" >> $LOG
echo "This could cause incomplete classpath setup which is necessary to use" >> $LOG
fi
if [ -n "$TARBALL_HADOOP_LOCATION" ] && [ ! -d "$TARBALL_HADOOP_LOCATION" ]
then
echo "WARNING: The specified TARBALL_HADOOP_LOCATION value is invalid: $TARBALL_HADOOP_LOCATION" >> $LOG
echo "This value might be necessary for running libhdfs." >> $LOG
fi
if [ -n "$HADOOP_SHARE_DIR" ] && [ ! -d "$HADOOP_SHARE_DIR" ]
then
echo "WARNING: The specified HADOOP_SHARE_DIR value is invalid: $HADOOP_SHARE_DIR" >> $LOG
echo "This value might be necessary for running libhdfs." >> $LOG
fi
echo "" >> $LOG
echo "A common error running h2h, is inaccesible pre-requisites." >> $LOG
PATHSEP=":";
arr=$(echo $LD_LIBRARY_PATH | tr "$PATHSEP" "\n")
for v in $arr
do
if [ -n "$v" ] && [ ! -d "$v" ]
then
echo "WARNING: detected an invalid entry in LD_LIBRARY_PATH: $v" >> $LOG
echo "Is this entry necessary to run H2H?" >> $LOG
fi
done
echo "" >> $LOG
echo "Please verify all configuration entries in $configs/@HDFSCONN_CONF_FILE@" >> $LOG
echo "" >> $LOG
fi
fi
echo "$TARGETCONNECTORNAME exited with: ${h2hstatus}" >> $LOG
exit ${h2hstatus};