Finish up basic functionality
This commit is contained in:
parent
f5326d38df
commit
efc05f6ce1
|
@ -77,6 +77,32 @@ function initialize_ring {
|
|||
create $PARTITION_POWER $REPLICAS $MIN_HOURS
|
||||
}
|
||||
|
||||
function get_zone {
|
||||
# a hack to assign units to zones until config is taken care of
|
||||
# in ensemble
|
||||
zone_file="/var/run/ensemble/swift-zone"
|
||||
checked_in="/var/run/ensemble/checked-in"
|
||||
if [[ -e $checked_in ]] ; then
|
||||
# changed relation seems to run twice? dont get new zone if
|
||||
# we just got one
|
||||
cat $checked_in | grep $ENSEMBLE_REMOTE_UNIT >/dev/null
|
||||
if [[ $? == 0 ]] ; then
|
||||
ZONE=$(cat $checked_in | grep $ENSEMBLE_REMOTE_UNIT | cut -d, -f2)
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
if [[ ! -e $zone_file ]] ; then
|
||||
echo 1 > $zone_file
|
||||
fi
|
||||
ZONE=$(cat $zone_file)
|
||||
echo "$ENSEMBLE_REMOTE_UNIT,$ZONE" >>$checked_in
|
||||
if [[ $ZONE == $REPLICAS ]] ; then
|
||||
echo 1 >$zone_file
|
||||
return 0
|
||||
fi
|
||||
echo $[$ZONE+1] >$zone_file
|
||||
}
|
||||
|
||||
function add_to_ring {
|
||||
# swift-ring-builder returns 1 for success, 2 for zero.
|
||||
# TODO: File bug for return codes
|
||||
|
@ -93,10 +119,16 @@ function add_to_ring {
|
|||
fi
|
||||
}
|
||||
|
||||
function rebalance_ring {
|
||||
# This exists to make up for non-standard return codes
|
||||
ensemble-log "Rebalancing ring $1"
|
||||
swift-ring-builder /etc/swift/$i.builder rebalance
|
||||
function exists_in_ring {
|
||||
swift-ring-builder /etc/swift/$i.builder \
|
||||
search z$ZONE-$IP:$PORT/$DEVICE
|
||||
[[ $? == "1" ]] && return 0
|
||||
return 1
|
||||
}
|
||||
|
||||
function rebalance_ring {
|
||||
# rebalance returns 0 on success, go figure
|
||||
ensemble-log "Rebalancing ring $1"
|
||||
swift-ring-builder /etc/swift/$i.builder rebalance
|
||||
return $?
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ function install_hook {
|
|||
service memcached restart
|
||||
echo "swift-proxy-node - install: Initializing rings"
|
||||
for i in account container object ; do initialize_ring $i ; done
|
||||
mkdir -p $WWW_DIR
|
||||
mkdir -p $WWW_DIR && chown -R www-data $WWW_DIR
|
||||
}
|
||||
|
||||
function proxy_joined {
|
||||
|
@ -37,11 +37,12 @@ function proxy_joined {
|
|||
}
|
||||
|
||||
function proxy_changed {
|
||||
ZONE=`relation-get zone`
|
||||
IP=`relation-get ip`
|
||||
HOST=`relation-get hostname`
|
||||
DEVICE=`relation-get device`
|
||||
[[ -z $ZONE ]] || [[ -z $IP ]] || [[ -z $DEVICE ]] && \
|
||||
echo "ZONE|IP|DEVICE not set. Peer not ready? Exit 0 and wait." && exit 0
|
||||
#ZONE=`relation-get zone`
|
||||
get_zone
|
||||
[[ -z $ZONE ]] || [[ -z $HOST ]] || [[ -z $DEVICE ]] && \
|
||||
echo "ZONE|HOST|DEVICE not set. Peer not ready? Exit 0 and wait." && exit 0
|
||||
|
||||
if [[ $ZONE -gt $REPLICAS ]] ; then
|
||||
echo "ERROR: Peer $ENSEMBLE_REMOTE_UNIT attempting to join a non-existent zone!"
|
||||
|
@ -49,7 +50,7 @@ function proxy_changed {
|
|||
fi
|
||||
PORT=6000
|
||||
RINGS="object container account"
|
||||
|
||||
IP=$(dig +short $HOST)
|
||||
for i in $RINGS ; do
|
||||
if [[ ! -e /etc/swift/$i.builder ]] ; then
|
||||
echo "Ring $i missing, initializing"
|
||||
|
@ -58,29 +59,73 @@ function proxy_changed {
|
|||
done
|
||||
|
||||
for i in $RINGS ; do
|
||||
add_to_ring $i $ZONE $IP $PORT $DEVICE || exit 1
|
||||
if ! exists_in_ring ; then
|
||||
add_to_ring $i $ZONE $IP $PORT $DEVICE || exit 1
|
||||
else
|
||||
ensemble-log "swift-proxy: $IP:$PORT/$DEVICE already exists in $ZONE"
|
||||
fi
|
||||
PORT=$[$PORT+1]
|
||||
done
|
||||
echo "Current peers:"
|
||||
relation-list
|
||||
current_peers=$(relation-list | wc -l)
|
||||
|
||||
if [[ $(relation-get | wc -l) -lt $REPLICAS ]] ; then
|
||||
echo "Not enough peers, will not balance rings yet."
|
||||
# checks to find out if we should rebalance rings
|
||||
balance_file="/var/run/ensemble/swift-balanced"
|
||||
|
||||
if [[ $current_peers -lt $REPLICAS ]] ; then
|
||||
echo "Not enough peers to maitain minimum $REPLICAS replicas ($current_peers/$REPLICAS), skipping rebalance."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# for i in $RINGS ; do
|
||||
# rebalance_ring $i || exit 1
|
||||
# done
|
||||
# stamp=`date +%Y%M%d-%H%M%S`
|
||||
# export_dir="$WWW_DIR/$stamp"
|
||||
# mkdir $export_dir
|
||||
# echo "Copying rings to $export_dir for client consumption"
|
||||
# relation-set update_url="http://$IP/$stamp"
|
||||
if [[ -e $balance_file ]] ; then
|
||||
[[ $(cat $balance_file | cut -d, -f1) == $current_peers ]] && \
|
||||
echo "Ring already balanced since $current_peers present."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Balancing rings"
|
||||
for i in $RINGS ; do
|
||||
rebalance_ring $i || exit 1
|
||||
done
|
||||
|
||||
chown -R swift /etc/swift
|
||||
|
||||
stamp=`date +%Y%M%d-%H%M%S`
|
||||
export_dir="$WWW_DIR/$stamp"
|
||||
echo "$current_peers,$stamp" > $balance_file
|
||||
|
||||
# rings have been balanced, push out new rings to nodes via webserver
|
||||
mkdir -p $export_dir
|
||||
echo "Copying rings to $export_dir for client consumption"
|
||||
for i in $RINGS ; do
|
||||
cp /etc/swift/$i.ring.gz $export_dir
|
||||
done
|
||||
chown -R swift:swift /etc/swift
|
||||
chown -R www-data $export_dir
|
||||
relation-set update_url="http://$(hostname -f)/swift-rings/$stamp"
|
||||
swift-init proxy status || swift-init proxy start
|
||||
}
|
||||
|
||||
function proxy_broken {
|
||||
# remove all ring configuration on broken
|
||||
rm -rf /etc/swift/*.ring.gz
|
||||
rm -rf /etc/swift/*.builder
|
||||
rm -rf /etc/swift/backups
|
||||
rm -rf /var/run/ensemble/swift-balanced
|
||||
rm -rf /var/run/ensemble/checked-in
|
||||
rm -rf /var/run/ensemble/swift-zone
|
||||
rm -rf /var/www/swift-rings
|
||||
}
|
||||
|
||||
[[ -d /etc/swift ]] && chown -R swift /etc/swift
|
||||
|
||||
ensemble-log "swift-proxy: Firing hook $ARG0"
|
||||
case $ARG0 in
|
||||
"install") install_hook ;;
|
||||
"start"|"stop") exit 0 ;;
|
||||
"swift-proxy-relation-joined") proxy_joined ;;
|
||||
"swift-proxy-relation-changed") proxy_changed ;;
|
||||
"swift-proxy-relation-broken") proxy_broken ;;
|
||||
esac
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
ensemble: formula
|
||||
name: swift-proxy
|
||||
revision: 26
|
||||
revision: 51
|
||||
summary: "Swift proxy node"
|
||||
description: |
|
||||
Swift is a distributed virtual object store. This formula deploys the proxy node
|
||||
|
|
Loading…
Reference in New Issue