Files
secondo/Algebras/Hadoop/clusterManagement/ps-secondo-buildMini
2026-01-23 17:03:45 +08:00

214 lines
6.6 KiB
Bash

#!/bin/bash
bin=`dirname "$0"`
bin=`cd "$bin"; pwd`
source $bin/ps-functions
DISCL=false
DISLC=false
# Process the parameters
declare -i numOfArgs=$#
let numOfArgs++
while [ $# -eq 0 -o $numOfArgs -ne $OPTIND ]; do
getopts "hlco" optKey
if [ "$optKey" == "?" ]; then
optKey="h"
fi
case $optKey in
h) echo -en "\nUsage of ${0##*/}:\n\n"
echo -en " -h Print this message and exit.\n\n"
echo -en " -l Distribute the packed mini Secondo to the Local node.\n\n"
echo -en " -c Distribute the packed mini Secondo to the Cluster nodes,\n"
echo -en " according to the PARALLEL_SECONDO_SLAVES list.\n\n"
echo -en " -o Pack and distribute the mini Secondo based on Own configuration \n"
echo -en " $HOME/.parasecrc \n\n"
exit 0;;
l) DISLC=true;;
c) DISCL=true;;
o) if [ ! -f "$HOME/.parasecrc" ]; then
echo -e "The local parallel secondo configuration $HOME/.parasecrc doesn't exist."
exit -1;
else
source $HOME/.parasecrc
fi
esac
done
# Find the actual secondo path
SECPATH="$PARALLEL_SECONDO_BUILD_DIR"
while [ -h "$SECPATH" ]; do
#-h file True if file exists and is a symbolic link.
ls=`ls -ld "$SECPATH"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '.*/.*' > /dev/null; then
SECPATH="$link"
else
SECPATH=`dirname "$SECPATH"`/"$link"
fi
done
if [ ! -d "$SECPATH" ]; then
echo "Cannot access \$SECPATH: No such directory"
echo "The value of \$SECPATH is: ${SECPATH}"
fi
# If multiple mini secondos are defined
ARVNAME="secondo.tar.gz"
MSARV="${PARALLEL_SECONDO_MAINDS}/${ARVNAME}"
echo "=============== Build Mini Secondo ================"
echo "The mini Secondo is built based on: $SECPATH"
if [ -f "${MSARV}" ]; then
rm "${MSARV}"
echo "Delete the exist mini secondo archive: ${MSARV}"
fi
echo -e "\n---- The Mini Secondo contains ----"
cat "${bin}/miniSec_list"
echo -e "---- End Mini Secondo File List ---\n"
#Provides wildcards in mini-secondo list
while read file; do
if [ "$(trim $file)" != "" ]; then
echo ${PARALLEL_SECONDO_BUILD_DIR}/$file
fi
done < "${bin}/miniSec_list" | tr ' ' '\n' | xargs tar czf "${MSARV}" -C "$SECPATH" 2>/dev/null
declare -i SLEVEL=$(echo $SECPATH | tr '/' '\n' | sed '/^$/d' | wc -l)
echo "The mini secondo archive is built in ${MSARV}"
echo -e "============= End Building Mini Secondo ===========\n"
declare -r CONFNAME="SecondoConfig.ini"
# Deploy the mini Secondo to local node
if [ $DISLC = true ]; then
echo "===== Start Deploy mini Secondo Local ====="
IFS=':'
declare -a MINISECS=(${PARALLEL_SECONDO})
declare -a MINISECONS=(${PARALLEL_SECONDO_DBCONFIG})
if [ ${#MINISECS[*]} -ne ${#MINISECONS[*]} ]; then
echo "Error! The configuration of mini Secondo and the configuration doesn't match"
echo "PARALLEL_SECONDO is : ${#MINISECS[*]}"
echo "PARALLEL_SECONDO_DBCONFIG is : ${#MINISECONS[*]}"
exit -1
fi
declare -i CNT=0
while [ ${CNT} -lt ${#MINISECS[*]} ]; do
MINISEC="${MINISECS[$CNT]}/${PARALLEL_SECONDO_DATASERVER_NAME}/${PARALLEL_SECONDO_MINI_NAME}"
SECCONF="${MINISECONS[$CNT]}"
let CNT++
if [ -L "${MINISEC}" ]; then
echo -e "${MINISEC} is a link pointing to $(readlink ${MINISEC})."
echo -e "Hence the MiniSecondo distribution passes over this data server. \n"
continue
elif [ -d "${MINISEC}" ]; then
echo "Delete the exist mini secondo: ${MINISEC}"
if [ -w "${MINISEC}" ]; then
rm -rf "${MINISEC}"
else
echo "You don't have the authority to delete the path ${MINISEC}"
exit -1;
fi
else
if [ -f "${MINISEC}" ]; then
echo "The ${MINISEC} should be a directory, not a file."
exit -1;
fi
fi
mkdir "$MINISEC"
tar -xzf "${MSARV}" -C "${MINISEC}" --strip=$SLEVEL
cp -v "${SECCONF}" "${MINISEC}/bin/${CONFNAME}"
chmod -R 775 ${MINISEC}/bin
echo -e "The mini secondo is deployed in local: ${MINISEC}\n"
done
echo "===== End Deploy mini Secondo Local ====="
fi
# Deploy the mini Secondo to cluster nodes in pipeline
# Also the master and slave lists
RARVNAME="DTR_secondo.tar.gz"
aJobs=()
Status="/tmp/.${USER}_ps-secondo-buildMini.data"
cat /dev/null > $Status
function buildNodeMiniSec
{
NODE=$1 #IP Address
RSEC=$(ssh $NODE "echo \$PARALLEL_SECONDO" 2>/dev/null) # Remote mini Secondo
RSECON=$(ssh $NODE "echo \$PARALLEL_SECONDO_DBCONFIG" 2>/dev/null) # Use nodes' local description
RSECDSNAME=$(ssh $NODE "echo \$PARALLEL_SECONDO_DATASERVER_NAME" 2>/dev/null)
RSECMNNAME=$(ssh $NODE "echo \$PARALLEL_SECONDO_MINI_NAME" 2>/dev/null)
declare -a RSA=($(echo $RSEC | tr ':' ' '))
declare -a RSCA=($(echo $RSECON | tr ':' ' '))
if [ ${#RSA[@]} -ne ${#RSCA[@]} ]; then
echo "In node $NODE, the PARALLEL_SECONDO doesn't match with its PARALLEL_SECONDO_DBCONFIG, \
PARALLEL_SECONDO is: $RSEC , PARALLEL_SECONDO_DBCONFIG is: $RSECON " >> $Status
else
declare -i CNT=0
while [ $CNT -lt ${#RSA[@]} ]; do
fLoc="${RSA[$CNT]}/${RSECDSNAME}"
rsLoc="${fLoc}/${RSECMNNAME}"
LPOS=$(ssh "$NODE" "readlink ${rsLoc}" 2>/dev/null)
if [ "$LPOS" != "" ]; then
echo -e "${NODE}:$(($CNT + 1))\t${rsLoc}\t\tOmit as it is a link to ${LPOS}" >> $Status
else
scp "$MSARV" "$NODE:${fLoc}/${RARVNAME}" 2>/dev/null
ssh "$NODE" "rm -rf ${rsLoc}" 2>/dev/null
ssh "$NODE" "mkdir ${rsLoc}" 2>/dev/null
ssh "$NODE" "tar -xzf ${fLoc}/${RARVNAME} -C ${rsLoc} --strip=${SLEVEL}" 2>/dev/null
# Changed the access mode after distribute the data
ssh "$NODE" "chmod -R 775 ${rsLoc}/bin" 2>/dev/null
ssh "$NODE" "cp ${RSCA[$CNT]} ${rsLoc}/bin/${CONFNAME}" 2>/dev/null
echo -e "${NODE}:$(($CNT + 1))\t${rsLoc}\tDone with ${RSCA[$CNT]}" >> $Status
fi
let CNT++
done
fi
}
if [ $DISCL = true ]; then
echo "===== Deploy mini Secondo Cluster ====="
echo -e "Distribute the mini secondo to every node inside the cluster, \nincluding the master node. ... \n\n"
IPLIST=($(get_slaveIPs -m))
NDNUM=${#IPLIST[*]}
for((NDIDX=0;NDIDX<$NDNUM;))do
node=${IPLIST[$NDIDX]}
for((token=1;token<$PS_PIPE_Width;token++));do
if [ $NDIDX -gt $NDNUM ];then
break
fi
if [ ! "${aJobs[$token]}" ] || ! kill -0 ${aJobs[$token]} 2>/dev/null; then
buildNodeMiniSec $node &
aJobs[$token]=$!
let NDIDX++
break
fi
done
done
for ((token=1;token<$PS_PIPE_Width;)); do
if ! kill -0 ${aJobs[$token]} 2>/dev/null; then
let token++
fi
done
echo -e "\tDataServer\t\tMiniSec\t\t\t\tStatus"
cat $Status | sort | cat -n
fi
exit 0