-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcfm_deployment.sh
More file actions
188 lines (154 loc) · 6.55 KB
/
Copy pathcfm_deployment.sh
File metadata and controls
188 lines (154 loc) · 6.55 KB
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
#!/bin/bash
###########################################################################
# Cloudera CFM (NIFI) Parcel & CSD install
# CFM DOCS:https://docs.cloudera.com/cfm/2.1.7/index.html
# CFM DOWNLOAD LOCATIONS: https://docs.cloudera.com/cfm/2.1.7/release-notes/topics/cfm-download-locations.html
# Description:
# Make sure CM server is healthy and running and run this script on CM server .
# This script automates the process of:
# - Downloading Cloudera CFM parcels and CSD jars using credentials
# - Setting appropriate permissions for those files
# - Restarting the Cloudera SCM server to process the new parcel
# - Waiting for the .torrent file to generated by by Cloudera Manager
# - Distributing and activating the parcel using CM REST API
#
###########################################################################
# Function to download files and set ownership and permissions for CFM Parcel and CSD
download_and_set_permissions() {
local url=$1
local destination=$2
local username=$3
local password=$4
echo "Downloading $destination ..."
wget --user="$username" --password="$password" -O "$destination" "$url"
if [ -f "$destination" ]; then
echo " Downloaded $destination successfully."
chown cloudera-scm:cloudera-scm "$destination"
chmod 644 "$destination"
echo "🔧 Ownership and permissions set for $destination"
else
echo " Failed to download $destination"
exit 1
fi
}
# Function to wait for .parcel.torrent file generation
wait_for_torrent_file() {
local parcel_path=$1
local timeout=$2 # seconds
local waited=0
local interval=60
local torrent_file="${parcel_path}.torrent"
echo "⏳ Waiting for torrent file $torrent_file to be generated..."
while [ ! -f "$torrent_file" ]; do
if [ $waited -ge $timeout ]; then
echo "Timeout reached waiting for torrent file $torrent_file"
exit 1
fi
echo "... still waiting ($waited / $timeout seconds)"
sleep $interval
waited=$((waited + interval))
done
echo "Torrent file detected: $torrent_file"
}
# Function to call CM API (POST)
cm_api_post() {
local url=$1
local user=$2
local pass=$3
curl -s -u "$user:$pass" -X POST -H "accept: application/json" "$url"
}
# Function to get parcel state from CM API
get_parcel_state() {
local api_base=$1
local cluster=$2
local product=$3
local version=$4
local user=$5
local pass=$6
curl -s -u "$user:$pass" -H "accept: application/json" \
"$api_base/api/v54/clusters/$cluster/parcels/products/$product/versions/$version" | \
grep -oP '"stage"\s*:\s*"\K[^"]+'
}
# -------------------------
# Prompt for all inputs including credentials to download CFM parcels and jars and credentials to run Cloudera API
# -------------------------
echo " Enter Cloudera SCM parcel download credentials:"
read -p "Download Username: " download_user
read -sp "Download Password: " download_pass
echo
echo "🔧 Enter Cloudera Manager API details:"
read -p "CM Host (e.g. 0.0.0.0): " cm_host
read -p "CM Port (e.g. 7180): " cm_port
read -p "Cluster Name: " cluster_name
read -p "Parcel Product Name (e.g. CFM): " parcel_product
read -p "Parcel Version (e.g. 2.1.7.2003-5): " parcel_version
read -p "CM API Username: " cm_user
read -sp "CM API Password: " cm_pass
echo
# Construct URLs
CFM_URL="https://archive.cloudera.com/p/cfm2/2.1.7.2003/redhat8/yum/tars/parcel/CFM-${parcel_version}-el8.parcel"
CFM_SHA_URL="https://archive.cloudera.com/p/cfm2/2.1.7.2003/redhat8/yum/tars/parcel/CFM-${parcel_version}-el8.parcel.sha"
NIFI_CSD_URL="https://archive.cloudera.com/p/cfm2/2.1.7.2003/redhat8/yum/tars/parcel/NIFI-1.28.1.2.1.7.2003-5.jar"
# Dynamically extract JAR name from URL
nifi_jar_name=$(basename "$NIFI_CSD_URL")
# Destination directories
CFM_DIR="/opt/cloudera/parcel-repo"
CSD_DIR="/opt/cloudera/csd"
mkdir -p "$CFM_DIR"
mkdir -p "$CSD_DIR"
# Download parcels and jars
download_and_set_permissions "$CFM_URL" "$CFM_DIR/CFM-${parcel_version}-el8.parcel" "$download_user" "$download_pass"
download_and_set_permissions "$CFM_SHA_URL" "$CFM_DIR/CFM-${parcel_version}-el8.parcel.sha" "$download_user" "$download_pass"
download_and_set_permissions "$NIFI_CSD_URL" "$CSD_DIR/${nifi_jar_name}" "$download_user" "$download_pass"
# Restart Cloudera SCM Server
echo " Restarting Cloudera SCM Server..."
sudo systemctl restart cloudera-scm-server
if [ $? -ne 0 ]; then
echo " Failed to restart Cloudera SCM server."
exit 1
fi
echo " Cloudera SCM server restarted successfully."
# Wait for .parcel.torrent file creation
parcel_path="${CFM_DIR}/CFM-${parcel_version}-el8.parcel"
wait_for_torrent_file "$parcel_path" 600 # 600 seconds = 10 minutes timeout
# Prepare CM API base URL
API_BASE="http://${cm_host}:${cm_port}"
# Start parcel distribution
# Please change the API Version accordingly as per CM version , You can also access the Cloudera Manager Swagger API user interface from the Cloudera Manager Admin Console. Go to Support > API Explorer to open Swagger.
# https://docs.cloudera.com/cdp-private-cloud-base/7.1.9/concepts/topics/cm-api-overview.html
echo " Starting parcel distribution..."
distribute_url="${API_BASE}/api/v54/clusters/${cluster_name}/parcels/products/${parcel_product}/versions/${parcel_version}/commands/startDistribution"
distribute_response=$(cm_api_post "$distribute_url" "$cm_user" "$cm_pass")
if [[ "$distribute_response" == *"error"* ]]; then
echo "Failed to initiate parcel distribution."
echo "Response: $distribute_response"
exit 1
fi
echo " Parcel distribution started."
# Poll parcel distribution status
echo " Checking parcel distribution status..."
while true; do
state=$(get_parcel_state "$API_BASE" "$cluster_name" "$parcel_product" "$parcel_version" "$cm_user" "$cm_pass")
echo "Current parcel stage: $state"
if [[ "$state" == "DISTRIBUTED" ]]; then
echo " Parcel distributed successfully."
break
elif [[ "$state" == "FAILED" ]]; then
echo "Parcel distribution failed."
exit 1
else
echo "Waiting 60 seconds before next status check..."
sleep 60
fi
done
# Activate the parcel
echo "Activating the parcel..."
activate_url="${API_BASE}/api/v54/clusters/${cluster_name}/parcels/products/${parcel_product}/versions/${parcel_version}/commands/activate"
activate_response=$(cm_api_post "$activate_url" "$cm_user" "$cm_pass")
if [[ "$activate_response" == *"error"* ]]; then
echo "Failed to activate parcel."
echo "Response: $activate_response"
exit 1
fi
echo " Parcel activated successfully."
exit 0