This repository has been archived by the owner on Sep 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathpreprocess.sh
executable file
·67 lines (59 loc) · 2.17 KB
/
preprocess.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
# Copyright 2013 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
declare -r LOCAL_TMP_DIR=$1 ; shift
declare -r PROJECT=$1 ; shift
declare -r TMP_CLOUD_STORAGE=$1 ; shift
declare -r HADOOP=hadoop-1.2.1
declare -r KEY_DIR=$LOCAL_TMP_DIR/ssh-key
declare -r DEB_PACKAGE_DIR=$LOCAL_TMP_DIR/deb_packages
function die() {
echo 1>&2
echo "########## ERROR ##########" 1>&2
echo $@ 1>&2
echo "###########################" 1>&2
echo 1>&2
exit 1
}
# Generate key pair for SSH for hadoop user.
if [ -d $KEY_DIR ] ; then
rm -rf $KEY_DIR
fi
mkdir -p $KEY_DIR
ssh-keygen -t rsa -P '' -f $KEY_DIR/id_rsa || die "Failed to create SSH key."
# Upload Hadoop package and JRE package to Google Cloud Storage
gsutil -m cp -R $LOCAL_TMP_DIR/$HADOOP.tar.gz $DEB_PACKAGE_DIR \
$TMP_CLOUD_STORAGE/ || \
die "Failed to copy Hadoop and Java packages to " \
"Cloud Storage $TMP_CLOUD_STORAGE/"
# Set up firewalls to allow Hadoop monitor ports
function set_firewall() {
local -r name=$1 ; shift
local -r description=$1 ; shift
local -r port=$1 ; shift
if gcutil --project=$PROJECT getfirewall $name > /dev/null 2>&1 ; then
:
else
gcutil --project=$PROJECT addfirewall $name \
--description="$description" --allowed="tcp:$port" || \
die "Failed to create firewall rule $name for port $port " \
"\($description\)"
fi
}
set_firewall hdfs-namenode "HDFS NameNode Web console" 50070
set_firewall hdfs-datanode "HDFS DataNode Web console" 50075
set_firewall hadoop-mr-jobtracker "Hadoop MapReduce JobTracker Web console" \
50030
set_firewall hadoop-mr-tasktracker "Hadoop MapReduce TaskTracker Web console" \
50060