Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions clusterize/clusterize.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type DataProtectionParams struct {

type ClusterParams struct {
VMNames []string
VMNamesToDevicePaths []string
IPs []string
ClusterName string
Prefix string
Expand Down Expand Up @@ -51,6 +52,7 @@ func (c *ClusterizeScriptGenerator) GetClusterizeScript() string {
#!/bin/bash
set -ex
VMS=(%s)
VMS_TO_DEVICE_PATHS=(%s)
IPS=(%s)
CLUSTER_NAME=%s
HOSTS_NUM=%d
Expand Down Expand Up @@ -78,9 +80,7 @@ func (c *ClusterizeScriptGenerator) GetClusterizeScript() string {
export WEKA_DEPLOYMENT_PASSWORD="$(echo $fetch_result | jq -r .password)"
export WEKA_ADMIN_PASSWORD="$(echo $fetch_result | jq -r .admin_password)"
export WEKA_RUN_CREDS="-e WEKA_USERNAME=admin -e WEKA_PASSWORD=$WEKA_ADMIN_PASSWORD"
devices=$(weka local run --container compute0 $WEKA_RUN_CREDS bash -ce 'wapi machine-query-info --info-types=DISKS -J | python3 /opt/weka/tmp/find_drives.py')
set -x
devices=($devices)

CONTAINER_NAMES=(drives0 compute0)
PORTS=(14000 15000)
Expand Down Expand Up @@ -138,16 +138,29 @@ func (c *ClusterizeScriptGenerator) GetClusterizeScript() string {
report "{\"hostname\": \"$HOSTNAME\", \"type\": \"progress\", \"message\": \"Adding drives\"}"

DRIVE_NUMS=( $(weka cluster container | grep drives | awk '{print $1;}') )
for drive_num in "${DRIVE_NUMS[@]}"; do
for drive_container_id in "${DRIVE_NUMS[@]}"; do
drive_container_hostname=( $(weka cluster container $drive_container_id | grep drives | awk '{print $2;}') )
echo "Processing container $drive_container_id with hostname $drive_container_hostname"

devices=()
# ------- VMS_TO_DEVICE_PATHS has the format: "drive_container_hostname:dev1,dev2,dev3" -------
for v in "${VMS_TO_DEVICE_PATHS[@]}"; do
# ------- if v contains 'drive_container_hostname', then get the devices------
if [[ $v == *"$drive_container_hostname"* ]]; then
devices=( $(echo $v | cut -d':' -f2 | tr ',' ' ') )
fi
done
echo "Adding drives ${devices[*]} to container $drive_container_id"

bad_drives=false
devices_str=$(IFS=' ' ;echo "${devices[*]}")
if ! weka cluster drive add $drive_num $devices_str; then
report "{\"hostname\": \"$HOSTNAME\", \"type\": \"error\", \"message\": \"Failed adding drives: $drive_num: $devices_str\"}"
if ! weka cluster drive add $drive_container_id $devices_str; then
report "{\"hostname\": \"$HOSTNAME\", \"type\": \"error\", \"message\": \"Failed adding drives: $drive_container_id: $devices_str\"}"
bad_drives=true
fi

if [ $bad_drives = true ]; then
weka_hostname=$(weka cluster container -c $drive_num | tail -n +2 | awk '{print $2}')
weka_hostname=$(weka cluster container -c $drive_container_id | tail -n +2 | awk '{print $2}')
containers=($(weka cluster container | grep $weka_hostname | awk '{print $1}'))
for c in "${containers[@]}"
do
Expand All @@ -170,7 +183,7 @@ func (c *ClusterizeScriptGenerator) GetClusterizeScript() string {
done
done

report "{\"hostname\": \"$HOSTNAME\", \"type\": \"debug\", \"message\": \"Removing drives: $drive_num\"}"
report "{\"hostname\": \"$HOSTNAME\", \"type\": \"debug\", \"message\": \"Removing drives: $drive_container_id\"}"
drives=($(weka cluster drive | grep $weka_hostname | awk '{print $2}'))
for d in "${drives[@]}"
do
Expand Down Expand Up @@ -246,6 +259,7 @@ func (c *ClusterizeScriptGenerator) GetClusterizeScript() string {
script := fmt.Sprintf(
dedent.Dedent(clusterizeScriptTemplate),
strings.Join(params.VMNames, " "),
strings.Join(params.VMNamesToDevicePaths, " "),
strings.Join(params.IPs, " "),
params.ClusterName,
params.ClusterizationTarget,
Expand Down
4 changes: 3 additions & 1 deletion deploy/deploy_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ func (d *DeployScriptGenerator) GetBackendDeployScript() string {
done
done

clusterize "{\"name\": \"$VM\"}" > /tmp/clusterize.sh
devices_str=$(printf "\\\"%%s\\\"," "${devices[@]}" | sed 's/,$//')

clusterize "{\"name\": \"$VM\", \"device_paths\": [$devices_str]}" > /tmp/clusterize.sh
chmod +x /tmp/clusterize.sh
/tmp/clusterize.sh 2>&1 | tee /tmp/weka_clusterization.log
`
Expand Down
1 change: 1 addition & 0 deletions protocol/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ type Vm struct {
Protocol ProtocolGW `json:"protocol"`
ContainerUid string `json:"container_uid"` // protocol frontend container uid
NicName string `json:"nic_name"` // protocol management nic name
DevicePaths []string `json:"device_paths"` // drives to be added to weka on clusterization
}

type FetchRequest struct {
Expand Down