@ -107,36 +107,44 @@ apply_revision() {
}
}
# execute the rev script iff there's no entry for *any* host yet
# execute the rev script iff there's no entry for *any* host yet
apply_revs() {
apply_generic_ revs() {
[ -n "$1" ] || return 1
[ -n "$1" ] || return 1
revs="$1"
revs="$1"
for missing_revision in $(ngcp-check-rev-applied --schema db_schema --revision $revs | awk '/^No match for revision/ {print $5}') ; do
for missing_revision in $(ngcp-check-rev-applied --schema db_schema --revision $revs | awk '/^No match for revision/ {print $5}') ; do
revision_file="$(find /usr/share/ngcp-db-schema/ -name "$missing_revision")"
revision_file="$(find /usr/share/ngcp-db-schema/ -name "$missing_revision")"
if [ -r "$revision_file" ] ; then
apply_revision "$revision_file"
else
echo "Warning: missing revision $missing_revision identified but could not find according db-schema file."
fi
done
}
# execute the rev script iff there's no entry for the *current* host yet
# execute the rev script iff there's no entry for the *current* host yet
case "$revision_file" in
apply_host_specific_revs() {
*_not_replicated.up)
[ -n "$1" ] || return 1
if ngcp-check-rev-applied --schema db_schema --revision $revs --node "$hostname" | grep 'already executed' ; then
continue
revs="$1"
fi
;;
for missing_revision in $(ngcp-check-rev-applied --schema db_schema --revision $revs --node "$hostname" | awk '/^No match for revision/ {print $5}') ; do
esac
r evi sion_file="$(find /usr/sh are/ng cp-db-schema/ -name "$missing_revision")"
if [ -r "$revision_file" ] ; then
if [ -r "$revision_file" ] ; then
apply_revision "$revision_file"
apply_revision "$revision_file"
else
else
echo "Warning: missing revision $missing_revision identified but could not find according db-schema file."
echo "Warning: missing revision $missing_revision identified but could not find according file."
fi
fi
done
done
}
}
revision_wrapper() {
revision_wrapper() {
[ -n "$1" ] || return 1
[ -n "$1" ] || return 1
local revlist
local host_specific_revs;
local generic_revs;
for rev in $* ; do
for rev in $* ; do
@ -152,23 +160,22 @@ revision_wrapper() {
case "$revname" in
case "$revname" in
# the scripts that should be executed on *all* hosts, no matter whether
# the scripts that should be executed on *all* hosts, no matter whether
# they are active or inactive, since the script's content doesn't get replicated
# they are active or inactive, since the script's content doesn't get replicated
# NOTE: the actual logic is inside the apply_revs to avoid *_not_replicated.up
# scripts being executed independent from the other ones
*_not_replicated.up)
*_not_replicated.up)
revli st ="$revli st $(basename $rev)"
host_specific_revs="$host_specific_revs $(basename $rev)"
;;
;;
*)
*)
if running_on_active_node ; then
if running_on_active_node ; then
echo "Replication script ${revname} noted, nothing to do on active node"
echo "Replication script ${revname} noted, nothing to do on active node"
else
else
revli st ="$revli st $(basename $rev)"
generic_ revs="$generic_ revs $(basename $rev)"
fi
fi
;;
;;
esac
esac
done
done
apply_revs "$revlist"
apply_generic_revs "$generic_revs"
apply_host_specific_revs "$host_specific_revs"
}
}
# make sure we get sorted 10XXX after 9XXX
# make sure we get sorted 10XXX after 9XXX