implement dependency handling at the object level

Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
Steven Armstrong 2011-03-28 14:55:58 +02:00
parent cd1a1347c9
commit 4ee5d74c9f
5 changed files with 93 additions and 84 deletions

View file

@ -32,31 +32,16 @@ if [ ! -d "$(__cdist_object_dir "$object")" ]; then
__cdist_exit_err "Object $object is missing." __cdist_exit_err "Object $object is missing."
fi fi
finished="$(__cdist_object_code_finished "$object")"
require="$(__cdist_object_require "$object")"
code="$(__cdist_object_code "$object")-${__cdist_gencode_type}" code="$(__cdist_object_code "$object")-${__cdist_gencode_type}"
# Do nothing if our work has been done
if [ -f "$finished" ]; then
exit 0
fi
echo "Checking code-${__cdist_gencode_type} for $object ..." echo "Checking code-${__cdist_gencode_type} for $object ..."
if [ -f "$require" ]; then
while read requirement; do
echo "Requiring dependency $requirement for $object ..."
cdist-code-run "$requirement" "$__cdist_gencode_type"
done < "$require"
fi
if [ -e "$code" ]; then if [ -e "$code" ]; then
if [ -f "$code" ]; then if [ -f "$code" ]; then
if [ -x "$code" ]; then if [ -x "$code" ]; then
echo "Executing code-${__cdist_gencode_type} for $object ..." echo "Executing code-${__cdist_gencode_type} for $object ..."
"$code" "$code"
touch "$finished"
else else
__cdist_exit_err "$code exists, but is not executable." __cdist_exit_err "$code exists, but is not executable."
fi fi

View file

@ -42,7 +42,6 @@ __cdist_abs_myname="$__cdist_abs_mydir/$__cdist_myname"
: ${__cdist_name_bin:=bin} : ${__cdist_name_bin:=bin}
: ${__cdist_name_code:=code} : ${__cdist_name_code:=code}
: ${__cdist_name_code_finished:=codedone}
: ${__cdist_name_conf_dir:=conf} : ${__cdist_name_conf_dir:=conf}
: ${__cdist_name_dot_cdist:=.cdist} : ${__cdist_name_dot_cdist:=.cdist}
: ${__cdist_name_explorer:=explorer} : ${__cdist_name_explorer:=explorer}
@ -68,6 +67,7 @@ __cdist_abs_myname="$__cdist_abs_mydir/$__cdist_myname"
: ${__cdist_name_type:=type} : ${__cdist_name_type:=type}
: ${__cdist_name_type_bin:=type_bin} : ${__cdist_name_type_bin:=type_bin}
: ${__cdist_name_type_explorer:=type_explorer} : ${__cdist_name_type_explorer:=type_explorer}
: ${__cdist_name_objects_created:=objects_created}
# Used for IDs: Allow everything not starting with - and . # Used for IDs: Allow everything not starting with - and .
: ${__cdist_sane_regexp:=[^-\.].*} : ${__cdist_sane_regexp:=[^-\.].*}
@ -107,6 +107,7 @@ __cdist_tmp_file=$(mktemp "$__cdist_tmp_dir/cdist.XXXXXXXXXXXX")
: ${__cdist_manifest_dir:=$__cdist_conf_dir/$__cdist_name_manifest} : ${__cdist_manifest_dir:=$__cdist_conf_dir/$__cdist_name_manifest}
: ${__cdist_manifest_init:=$__cdist_manifest_dir/$__cdist_name_init} : ${__cdist_manifest_init:=$__cdist_manifest_dir/$__cdist_name_init}
: ${__cdist_type_dir:=$__cdist_conf_dir/$__cdist_name_type} : ${__cdist_type_dir:=$__cdist_conf_dir/$__cdist_name_type}
: ${__cdist_new_objects_created:=$__cdist_local_base_dir/$__cdist_name_objects_created}
################################################################################ ################################################################################
# Local output # Local output
@ -176,6 +177,14 @@ __cdist_init_deploy()
ln -sf "$__cdist_conf_dir" "$__cdist_local_base_dir/$__cdist_name_conf_dir" ln -sf "$__cdist_conf_dir" "$__cdist_local_base_dir/$__cdist_name_conf_dir"
} }
__cdist_new_objects_created() {
touch "$__cdist_tmp_dir/object_created"
}
__cdist_has_new_objects() {
touch "$__cdist_tmp_dir/object_created"
}
################################################################################ ################################################################################
# Object # Object
# #
@ -185,9 +194,9 @@ __cdist_object_code()
echo "$(__cdist_object_dir "$1")/${__cdist_name_code}" echo "$(__cdist_object_dir "$1")/${__cdist_name_code}"
} }
__cdist_object_code_finished() __cdist_object_finished()
{ {
echo "$(__cdist_object_dir "$1")/${__cdist_name_code_finished}" echo "$(__cdist_object_dir "$1")/${__cdist_name_object_finished}"
} }
__cdist_object_dir() __cdist_object_dir()
@ -250,6 +259,7 @@ __cdist_object_type_explorer_dir()
echo "$(__cdist_object_dir "$1")/${__cdist_name_explorer}" echo "$(__cdist_object_dir "$1")/${__cdist_name_explorer}"
} }
################################################################################ ################################################################################
# Remote # Remote
# #

View file

@ -35,30 +35,27 @@ __cdist_cur_object_dir="$(__cdist_object_dir "$__cdist_object")"
# Only the id # Only the id
__cdist_object_id="$(__cdist_object_id_from_object "$__cdist_object")" __cdist_object_id="$(__cdist_object_id_from_object "$__cdist_object")"
if [ ! -f "${__cdist_cur_object_dir}/$__cdist_name_object_finished" ]; then echo "Checking manifest for $__cdist_object ..."
echo "Checking manifest for $__cdist_object ..."
__cdist_type="$(__cdist_type_from_object "$__cdist_object")" __cdist_type="$(__cdist_type_from_object "$__cdist_object")"
__cdist_manifest="$(__cdist_type_manifest "$__cdist_type")" __cdist_manifest="$(__cdist_type_manifest "$__cdist_type")"
if [ -f "$__cdist_manifest" ]; then if [ -f "$__cdist_manifest" ]; then
if [ -x "$__cdist_manifest" ]; then if [ -x "$__cdist_manifest" ]; then
# Make __cdist_manifest available for cdist-type-emulator # Make __cdist_manifest available for cdist-type-emulator
export __cdist_manifest export __cdist_manifest
echo "Executing manifest ${__cdist_manifest} ..." echo "Executing manifest ${__cdist_manifest} ..."
# Make variables available to non-core - FIXME: beatify # Make variables available to non-core - FIXME: beatify
export $__cdist_name_var_object="$__cdist_cur_object_dir" export $__cdist_name_var_object="$__cdist_cur_object_dir"
export $__cdist_name_var_object_id="$__cdist_object_id" export $__cdist_name_var_object_id="$__cdist_object_id"
export $__cdist_name_var_type="$(__cdist_type_dir "$__cdist_type")" export $__cdist_name_var_type="$(__cdist_type_dir "$__cdist_type")"
cdist-manifest-run "$__cdist_target_host" "$__cdist_manifest" cdist-manifest-run "$__cdist_target_host" "$__cdist_manifest"
else # Tell cdist that there may be new objects
__cdist_exit_err "${__cdist_manifest} needs to be executable." touch "$__cdist_new_objects_created"
fi else
__cdist_exit_err "${__cdist_manifest} needs to be executable."
fi fi
fi fi
# done with this object
touch "$__cdist_cur_object_dir/$__cdist_name_object_finished"

View file

@ -21,6 +21,7 @@
# #
# For the given object: # For the given object:
# - run type explorers # - run type explorers
# - run type manifest
# - generate code # - generate code
# - copy object to target # - copy object to target
# - execute code on target # - execute code on target
@ -35,24 +36,41 @@ __cdist_object="$1"; shift
__cdist_type="$(__cdist_type_from_object "$__cdist_object")" __cdist_type="$(__cdist_type_from_object "$__cdist_object")"
__cdist_types_pushed="$__cdist_tmp_dir/types_pushed"
touch "$__cdist_types_pushed"
# Check if type of object has >= 1 explorer __cdist_object_finished="$(__cdist_object_finished "$__cdist_object")"
__cdist_has_explorer="$(__cdist_type_has_explorer "$__cdist_type")" if [ ! -f "$__cdist_object_finished" ]; then
echo
echo "Running object $__cdist_object"
# Check if type of object has >= 1 explorer
__cdist_has_explorer="$(__cdist_type_has_explorer "$__cdist_type")"
# Run the type explorers for the current object if any
if [ "$__cdist_has_explorer" ]; then
if ! grep -q "$__cdist_type" "$__cdist_types_pushed"; then
cdist-type-explorer-push "$__cdist_target_host" "$__cdist_type"
echo "$__cdist_type" >> "$__cdist_types_pushed"
fi
cdist-object-explorer-run "$__cdist_target_host" "$__cdist_object"
fi
# Run the manifest for the current object
cdist-object-manifest-run "$__cdist_target_host" "$__cdist_object"
# Run the gencode scripts for the current object
cdist-object-gencode-run "$__cdist_target_host" "$__cdist_object"
# Transfer the current object to the target
cdist-object-push "$__cdist_target_host" "$__cdist_object"
# Run the code for the current object
cdist-object-code-run "$__cdist_target_host" "$__cdist_object"
# Mark this object as done
touch "$__cdist_object_finished"
# Run the type explorers for the current object if any
if [ "$__cdist_has_explorer" ]; then
cdist-object-explorer-run "$__cdist_target_host" "$__cdist_object"
fi fi
# Run the manifest for the current object
cdist-object-manifest-run "$__cdist_target_host" "$__cdist_object"
# Run the gencode scripts for the current object
cdist-object-gencode-run "$__cdist_target_host" "$__cdist_object"
# Transfer the current object to the target
cdist-object-push "$__cdist_target_host" "$__cdist_object"
# Run the code for the current object
cdist-object-code-run "$__cdist_target_host" "$__cdist_object"

View file

@ -29,39 +29,38 @@ set -eu
__cdist_target_host="$1"; shift __cdist_target_host="$1"; shift
__cdist_objects="$__cdist_tmp_dir/objects" __cdist_objects="$__cdist_tmp_dir/objects"
__cdist_types_pushed="$__cdist_tmp_dir/types_pushed"
touch "$__cdist_types_pushed" # Loop until we do not create new objects anymore
# which is equal to all objects have been run
touch "$__cdist_new_objects_created"
while [ -f "$__cdist_new_objects_created" ]; do
# Assume we're done after this run
rm "$__cdist_new_objects_created"
# Get listing of objects
__cdist_object_list "$__cdist_out_object_dir" > "$__cdist_objects"
# Get listing of objects # NEED TO CREATE ARRAY, SSH DESTROYS WHILE READ LOOP
__cdist_object_list "$__cdist_out_object_dir" > "$__cdist_objects" while read __cdist_object; do
set -- "$@" "$__cdist_object"
done < "$__cdist_objects"
while [ $# -gt 0 ]; do
__cdist_object="$1"; shift
# NEED TO CREATE ARRAY, SSH DESTROYS WHILE READ LOOP __cdist_object_require="$(__cdist_object_require "$__cdist_object")"
while read __cdist_object; do if [ -f "$__cdist_object_require" ]; then
set -- "$@" "$__cdist_object" echo
done < "$__cdist_objects" while read __cdist_requirement; do
echo "Resolving dependency $__cdist_object -> $__cdist_requirement ..."
cdist-object-run "$__cdist_target_host" "$__cdist_requirement"
done < "$__cdist_object_require"
fi
while [ $# -gt 0 ]; do # Process the object
__cdist_object="$1"; shift cdist-object-run "$__cdist_target_host" "$__cdist_object"
echo
echo "Running object $__cdist_object"
__cdist_type="$(__cdist_type_from_object "$__cdist_object")"
# Check if type of object has >= 1 explorer
__cdist_has_explorer="$(__cdist_type_has_explorer "$__cdist_type")"
# Transfer the type explorers if any
if [ "$__cdist_has_explorer" ]; then
if ! grep -q "$__cdist_type" "$__cdist_types_pushed"; then
cdist-type-explorer-push "$__cdist_target_host" "$__cdist_type"
echo "$__cdist_type" >> "$__cdist_types_pushed"
fi
fi
# Process the given object
cdist-object-run "$__cdist_target_host" "$__cdist_object"
done
done done