|
@ -1982,7 +1982,7 @@ _get_provides_provides() { |
|
|
service rn rd |
|
|
service rn rd |
|
|
|
|
|
|
|
|
if [ -e "$cache_file" ]; then |
|
|
if [ -e "$cache_file" ]; then |
|
|
debug "$FUNCNAME: CACHEDIR cache hit $1" |
|
|
|
|
|
|
|
|
# debug "$FUNCNAME: CACHEDIR cache hit $1" |
|
|
cat "$cache_file" |
|
|
cat "$cache_file" |
|
|
return 0 |
|
|
return 0 |
|
|
fi |
|
|
fi |
|
@ -2013,7 +2013,7 @@ _get_metadata_provides() { |
|
|
service rn rd |
|
|
service rn rd |
|
|
|
|
|
|
|
|
if [ -e "$cache_file" ]; then |
|
|
if [ -e "$cache_file" ]; then |
|
|
debug "$FUNCNAME: CACHEDIR cache hit" |
|
|
|
|
|
|
|
|
#debug "$FUNCNAME: CACHEDIR cache hit" |
|
|
cat "$cache_file" |
|
|
cat "$cache_file" |
|
|
return 0 |
|
|
return 0 |
|
|
fi |
|
|
fi |
|
@ -2052,6 +2052,50 @@ _get_services_provides() { |
|
|
export -f _get_services_provides |
|
|
export -f _get_services_provides |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_get_charm_provides() { |
|
|
|
|
|
local cache_file="$CACHEDIR/$FUNCNAME.cache.$(charm.store_metadata_hash)" |
|
|
|
|
|
if [ -e "$cache_file" ]; then |
|
|
|
|
|
#debug "$FUNCNAME: SESSION cache hit" |
|
|
|
|
|
cat "$cache_file" |
|
|
|
|
|
return 0 |
|
|
|
|
|
fi |
|
|
|
|
|
start="$SECONDS" |
|
|
|
|
|
debug "Getting charm provider list..." |
|
|
|
|
|
while read-0 charm _ realpath metadata; do |
|
|
|
|
|
metadata="$(charm.metadata "$charm")" || continue |
|
|
|
|
|
# echo "reading $charm" >&2 |
|
|
|
|
|
while read-0 rn rd; do |
|
|
|
|
|
printf "%s\0" "$charm" "$rn" "$rd" |
|
|
|
|
|
done < <(_get_metadata_provides "$metadata") |
|
|
|
|
|
done < <(charm.ls) | tee "$cache_file" |
|
|
|
|
|
errlvl="${PIPESTATUS[0]}" |
|
|
|
|
|
debug " ..charm provider list done $GRAY(in $((SECONDS - start))s)$NORMAL" |
|
|
|
|
|
return "$errlvl" |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_get_charm_providing() { |
|
|
|
|
|
local cache_file="$state_tmpdir/$FUNCNAME.cache.$(printf "%s\0" "$@" | md5_compat)" \ |
|
|
|
|
|
relation="$1" |
|
|
|
|
|
if [ -e "$cache_file" ]; then |
|
|
|
|
|
#debug "$FUNCNAME: SESSION cache hit $1" |
|
|
|
|
|
cat "$cache_file" |
|
|
|
|
|
return 0 |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
while read-0 charm relation_name relation_def; do |
|
|
|
|
|
[ "$relation_name" == "$relation" ] || continue |
|
|
|
|
|
printf "%s\0" "$charm" "$relation_def" |
|
|
|
|
|
done < <(_get_charm_provides) > "$cache_file" |
|
|
|
|
|
|
|
|
|
|
|
if [ "$?" != 0 ]; then |
|
|
|
|
|
rm -f "$cache_file" ## no cache |
|
|
|
|
|
return 1 |
|
|
|
|
|
fi |
|
|
|
|
|
cat "$cache_file" |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_get_services_providing() { |
|
|
_get_services_providing() { |
|
|
local cache_file="$state_tmpdir/$FUNCNAME.cache.$(printf "%s\0" "$@" | md5_compat)" \ |
|
|
local cache_file="$state_tmpdir/$FUNCNAME.cache.$(printf "%s\0" "$@" | md5_compat)" \ |
|
|
relation="$1" |
|
|
relation="$1" |
|
@ -2076,6 +2120,22 @@ _get_services_providing() { |
|
|
export -f _get_services_provides |
|
|
export -f _get_services_provides |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_out_new_relation_from_defs() { |
|
|
|
|
|
local service="$1" rn="$2" ts="$3" prov_def="$4" rel_def="$5" rc td rc_prov |
|
|
|
|
|
|
|
|
|
|
|
rc_prov=$(printf "%s" "$prov_def" | shyaml -y get-value "default-options" 2>/dev/null) |
|
|
|
|
|
## YYYvlab: should be seen even in no debug mode no ? |
|
|
|
|
|
rc=$(printf "%s" "$rel_def" | shyaml -y get-value "default-options" 2>/dev/null) |
|
|
|
|
|
|
|
|
|
|
|
td=$(echo "$prov_def" | shyaml get-value 'tech-dep' 2>/dev/null) |
|
|
|
|
|
td=${td:-True} |
|
|
|
|
|
rc=$(merge_yaml_str "$rc_prov" "$rc") || return 1 |
|
|
|
|
|
|
|
|
|
|
|
printf "%s\0" "$service" "$relation_name" "$ts" "$rc" "$td" |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get_all_relations () { |
|
|
get_all_relations () { |
|
|
local cache_file="$state_tmpdir/$FUNCNAME.cache.$(printf "%s\0" "$@" | md5_compat)" \ |
|
|
local cache_file="$state_tmpdir/$FUNCNAME.cache.$(printf "%s\0" "$@" | md5_compat)" \ |
|
|
services |
|
|
services |
|
@ -2155,16 +2215,12 @@ get_all_relations () { |
|
|
array_read-0 providers providers_def < <(_get_services_providing "$relation_name" "${service_list[@]}") |
|
|
array_read-0 providers providers_def < <(_get_services_providing "$relation_name" "${service_list[@]}") |
|
|
if [ "${#providers[@]}" == 1 ]; then |
|
|
if [ "${#providers[@]}" == 1 ]; then |
|
|
ts="${providers[0]}" |
|
|
ts="${providers[0]}" |
|
|
rd_provider="${providers_def[0]}" |
|
|
|
|
|
rc_provider=$(printf "%s" "$rd_provider" | shyaml -y get-value "default-options" 2>/dev/null) |
|
|
|
|
|
## YYYvlab: should be seen even in no debug mode no ? |
|
|
|
|
|
debug "Auto-pairs ${DARKYELLOW}$service${NORMAL}" \ |
|
|
debug "Auto-pairs ${DARKYELLOW}$service${NORMAL}" \ |
|
|
"--${DARKBLUE}$relation_name${NORMAL}--> ${DARKYELLOW}$ts${NORMAL}" |
|
|
"--${DARKBLUE}$relation_name${NORMAL}--> ${DARKYELLOW}$ts${NORMAL}" |
|
|
rc=$(printf "%s" "$relation_def" | shyaml -y get-value "default-options" 2>/dev/null) |
|
|
|
|
|
td=$(echo "$rd_provider" | shyaml get-value 'tech-dep' 2>/dev/null) |
|
|
|
|
|
td=${td:-True} |
|
|
|
|
|
rc=$(merge_yaml_str "$rc_provider" "$rc") || return 1 |
|
|
|
|
|
printf "%s\0" "$service" "$relation_name" "$ts" "$rc" "$td" >> "${cache_file}.wip" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_out_new_relation_from_defs "$service" "$relation_name" "$ts" \ |
|
|
|
|
|
"${providers_def[0]}" "$relation_def" \ |
|
|
|
|
|
>> "${cache_file}.wip" |
|
|
|
|
|
|
|
|
## Adding service |
|
|
## Adding service |
|
|
[ "${services[$ts]}" ] && continue |
|
|
[ "${services[$ts]}" ] && continue |
|
@ -2219,7 +2275,39 @@ get_all_relations () { |
|
|
## situation is stable |
|
|
## situation is stable |
|
|
|
|
|
|
|
|
if [ "${#summon[@]}" != 0 ]; then |
|
|
if [ "${#summon[@]}" != 0 ]; then |
|
|
die "Summon code not implemented yet" |
|
|
|
|
|
|
|
|
while [ "${#summon[@]}" != 0 ]; do |
|
|
|
|
|
service="${summon[0]}" |
|
|
|
|
|
relation_name="${summon[1]}" |
|
|
|
|
|
relation_def="${summon[2]}" |
|
|
|
|
|
summon=("${summon[@]:3}") |
|
|
|
|
|
providers=() |
|
|
|
|
|
providers_def=() |
|
|
|
|
|
array_read-0 providers providers_def < <(_get_charm_providing "$relation_name" "${service_list[@]}") |
|
|
|
|
|
if [ "${#providers[@]}" == 0 ]; then |
|
|
|
|
|
die "Summoning a ${DARKBLUE}$relation_name${NORMAL} provider failed: none were found in charm store." |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
if [ "${#providers[@]}" -gt 1 ]; then |
|
|
|
|
|
warn "Auto-summon ${DARKYELLOW}$service${NORMAL}" \ |
|
|
|
|
|
"--${DARKBLUE}$relation_name${NORMAL}--> ($DARKYELLOW""${providers[@]}""$NORMAL)"\ |
|
|
|
|
|
"(> 1 provider). Choosing first." |
|
|
|
|
|
fi |
|
|
|
|
|
ts="${providers[0]}" |
|
|
|
|
|
|
|
|
|
|
|
## YYYvlab: should be seen even in no debug mode no ? |
|
|
|
|
|
debug "Auto-summon ${DARKYELLOW}$service${NORMAL}" \ |
|
|
|
|
|
"--${DARKBLUE}$relation_name${NORMAL}--> ${DARKYELLOW}$ts${NORMAL}" |
|
|
|
|
|
|
|
|
|
|
|
_out_new_relation_from_defs "$service" "$relation_name" "$ts" \ |
|
|
|
|
|
"${providers_def[0]}" "$relation_def" \ |
|
|
|
|
|
>> "${cache_file}.wip" |
|
|
|
|
|
|
|
|
|
|
|
## Adding service |
|
|
|
|
|
[ "${services[$ts]}" ] && continue |
|
|
|
|
|
array_read-0 new_services_uses < <(_get_services_uses "$ts") |
|
|
|
|
|
services[$ts]=1 |
|
|
|
|
|
changed=1 |
|
|
|
|
|
done |
|
|
continue |
|
|
continue |
|
|
fi |
|
|
fi |
|
|
[ "$NO_CONSTRAINT_CHECK" ] && break |
|
|
[ "$NO_CONSTRAINT_CHECK" ] && break |
|
@ -3759,15 +3847,10 @@ else |
|
|
fi |
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NO_CONSTRAINT_CHECK= |
|
|
|
|
|
|
|
|
NO_CONSTRAINT_CHECK=True |
|
|
case "$action" in |
|
|
case "$action" in |
|
|
""|down|restart|logs|config|ps) |
|
|
|
|
|
NO_CONSTRAINT_CHECK=True |
|
|
|
|
|
;; |
|
|
|
|
|
*) |
|
|
|
|
|
if [ "$is_service_action" ]; then |
|
|
|
|
|
NO_CONSTRAINT_CHECK=True |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
up) |
|
|
|
|
|
NO_CONSTRAINT_CHECK= |
|
|
;; |
|
|
;; |
|
|
esac |
|
|
esac |
|
|
|
|
|
|
|
|