-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy-csd.sh
executable file
·130 lines (114 loc) · 3.11 KB
/
deploy-csd.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
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
#!/bin/bash
# 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.
# Deploy CSD to CM
# Working properties
target_dir='/opt/cloudera/csd/'
host=''
username='root'
password='cloudera'
workdir='target/'
cm_login="admin:admin"
pwd=`pwd`
# Argument parsing
while getopts "t:u:w:h:c:i:" optname ; do
case "$optname" in
"t")
target=$OPTARG
;;
"u")
username=$OPTARG
;;
"w")
password=$OPTARG
;;
"h")
host=$OPTARG
;;
"c")
cm_login=$OPTARG
;;
"i")
identity_file=$OPTARG
;;
"?")
echo "Unknown option $OPTARG"
exit 1
;;
*)
# Should not occur
echo "Unknown error while processing options"
exit 1
;;
esac
done
# Parameter checking
if [[ -z $host ]]; then
echo "Missing argument -h with CM host"
exit 1
fi
if [[ -z $identity_file ]]; then
echo "Missing argument -i with ssh identity file"
exit 1
fi
# Work itself
echo "Target directory: $target_dir"
echo "Host: $host"
echo "Username: $username"
echo "Password: $password"
echo "CM Login: $cm_login"
# Execute $1 on remote server
function remote_exec() {
echo "Executing command: $1"
ssh -oUserKnownHostsFile=/dev/null -i ${identity_file} -o 'StrictHostKeyChecking no' ${username}@${host} $1
}
# Copy $1 to $2 on remote server (e.g. upload)
function remote_copy() {
echo "Executing command: scp $1 ${username}@${host}:$2"
scp -oUserKnownHostsFile=/dev/null -i ${identity_file} -o 'StrictHostKeyChecking no' $1 ${username}@${host}:$2
}
# Execute givem CM REST API call
function cm_api() {
echo "Calling CM API $1: $2"
curl -sS -X $1 -u $cm_login -i "http://${host}:7180/api/v8/$2" 2>&1
}
function cm_get() {
cm_api "GET" "$1"
}
function cm_post() {
cm_api "POST" "$1" > /dev/null
}
# Wait until parcel will get to given state
function cm_wait_for_load () {
while [ 1 ]
do
# Call echo service (should return back what we send there)
output=$(cm_get /tools/echo?message=Started)
# Ignore any "connection refused" commit from curl though
message=`echo $output | grep -v "Connection refused" | grep message | sed -re "s/^.* \"message\" : \"([A-Z]+)\".*\$/\1/"`
# Breaking condition
echo $message | grep "Started" > /dev/null && break
# To keep us informed
echo "Waiting on CM server to start up"
sleep 5
done
}
# Build local CSD (stored in csd folder)
cd csd
echo "Building CSD archive"
mvn clean package -DskipTests
cd $pwd
echo "Uploading CSD to CM server"
remote_copy csd/target/SQOOP2_BETA*.jar $target_dir
echo "Restartin CM server to load new CSD version"
remote_exec "/etc/init.d/cloudera-scm-server restart"
cm_wait_for_load