forked from sudar/Yahoo_LDA
-
Notifications
You must be signed in to change notification settings - Fork 31
/
functions.sh
45 lines (40 loc) · 1.28 KB
/
functions.sh
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
#input: number of seconds to sleep
wait_for_all(){
HADOOP_CMD="${HADOOP_HOME+${HADOOP_HOME}/bin/}hadoop";
echo "Synch directory: " $2 1>&2;
#Write that I am done
echo ${mapred_task_partition} " done." | ${HADOOP_CMD} dfs -put - $2/${mapred_task_partition};
#Find how many are done
echo "Num of map tasks: " ${mapred_map_tasks} 1>&2;
num_clients_done=`${HADOOP_CMD} dfs -ls $2 | wc -l`;
num_clients_done=`expr ${num_clients_done} - 1`;
${HADOOP_CMD} dfs -ls $2 1>&2;
echo "Num of clients done: " ${num_clients_done} 1>&2;
#Sleep till all are done
while [ ${num_clients_done} -lt ${mapred_map_tasks} ]; do
echo "Sleeping" 1>&2;
sleep $1;
num_clients_done=`${HADOOP_CMD} dfs -ls $2 | wc -l`;
num_clients_done=`expr ${num_clients_done} - 1`;
echo "Num of clients done: " ${num_clients_done} 1>&2;
done;
echo "All clients done!" 1>&2;
}
#inp1: Exit code
#inp2: Identifier
check_exit_status(){
if [ "$1" -ne "0" ]; then
echo "$2 returned an error code of $1" 1>&2;
exit $1;
else
echo "$2 done" 1>&2;
fi
}
get_num_mappers(){
name=`expr $1 : "\(.*\)\..*"`;
ext=`expr $1 : "$name\.\(.*\)"`;
#echo $name $ext 1>&2;
if [ $ext ] && [ $ext == "gz" ]; then echo 1; return 1;
else num=`echo "($2 / $3) + 1" | bc`; echo $num; return $num;
fi;
}