Browse Source

new: support "--without-relation" to remove a relation if needed.

checking
Valentin Lab 5 years ago
parent
commit
c6feae7ef7
  1. 26
      bin/compose-core

26
bin/compose-core

@ -1399,7 +1399,7 @@ export -f get_service_relation_tech_dep
## Use compose file to get deps, and relation definition in metadata.yml ## Use compose file to get deps, and relation definition in metadata.yml
## for tech-dep attribute. ## for tech-dep attribute.
get_service_deps() { get_service_deps() {
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$1"
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$(H "$@" "$ALL_RELATIONS")"
if [ -e "$cache_file" ]; then if [ -e "$cache_file" ]; then
# debug "$FUNCNAME: cache hit ($*)" # debug "$FUNCNAME: cache hit ($*)"
cat "$cache_file" cat "$cache_file"
@ -1420,7 +1420,7 @@ export -f get_service_deps
_rec_get_depth() { _rec_get_depth() {
local elt=$1 dep deps max local elt=$1 dep deps max
[ "${depths[$elt]}" ] && return 0 [ "${depths[$elt]}" ] && return 0
local cache_file="$state_tmpdir/$FUNCNAME.cache.$1.$(declare -pA depths | md5_compat)"
local cache_file="$state_tmpdir/$FUNCNAME.cache.$(H "$@" "$(declare -pA depths)" "$ALL_RELATIONS")"
if [ -e "$cache_file.depths" ]; then if [ -e "$cache_file.depths" ]; then
#debug "$FUNCNAME: cache hit ($*) - $cache_file.depths" #debug "$FUNCNAME: cache hit ($*) - $cache_file.depths"
while read-0 k v; do while read-0 k v; do
@ -1463,7 +1463,7 @@ export -f _rec_get_depth
get_ordered_service_dependencies() { get_ordered_service_dependencies() {
local services=("$@") cache_file="$state_tmpdir/$FUNCNAME.cache.$(H "$@")" \
local services=("$@") cache_file="$state_tmpdir/$FUNCNAME.cache.$(H "$@" "$ALL_RELATIONS")" \
i value key heads depths visited i value key heads depths visited
if [ -e "$cache_file" ]; then if [ -e "$cache_file" ]; then
# debug "$FUNCNAME: cache hit ($*)" # debug "$FUNCNAME: cache hit ($*)"
@ -2013,7 +2013,7 @@ export -f get_compose_relations
get_service_relations () { get_service_relations () {
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$1" \
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$(H "$@" "$ALL_RELATIONS")" \
s rn ts rc td s rn ts rc td
if [ -e "$cache_file" ]; then if [ -e "$cache_file" ]; then
#debug "$FUNCNAME: SESSION cache hit $1" #debug "$FUNCNAME: SESSION cache hit $1"
@ -2303,7 +2303,7 @@ _out_new_relation_from_defs() {
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.$(H "$@" "$(declare -p without_relations)")" \
services services
if [ -e "${cache_file}" ]; then if [ -e "${cache_file}" ]; then
@ -2330,6 +2330,10 @@ get_all_relations () {
while [ "${#all_services[@]}" != 0 ]; do while [ "${#all_services[@]}" != 0 ]; do
array_pop all_services service array_pop all_services service
while read-0 relation_name ts relation_config tech_dep; do while read-0 relation_name ts relation_config tech_dep; do
[ "${without_relations[$service:$relation_name]}" ] && {
debug "Ignoring compose $DARKYELLOW$service$NORMAL --$DARKBLUE$relation_name$NORMAL--> ${DARKYELLOW}$ts$NORMAL"
continue
}
printf "%s\0" "$service" "$relation_name" "$ts" "$relation_config" "$tech_dep" printf "%s\0" "$service" "$relation_name" "$ts" "$relation_config" "$tech_dep"
## adding target services ? ## adding target services ?
@ -2353,6 +2357,11 @@ get_all_relations () {
relation_def="${services_uses[2]}" relation_def="${services_uses[2]}"
services_uses=("${services_uses[@]:3}") services_uses=("${services_uses[@]:3}")
[ "${without_relations[$service:$relation_name]}" ] && {
debug "Skipping $DARKYELLOW$service$NORMAL --$DARKBLUE$relation_name$NORMAL--> $DARKYELLOW*$NORMAL"
continue
}
default_options=$(printf "%s" "$relation_def" | shyaml -y get-value "default-options" 2>/dev/null) default_options=$(printf "%s" "$relation_def" | shyaml -y get-value "default-options" 2>/dev/null)
## is this "use" declaration satisfied ? ## is this "use" declaration satisfied ?
found= found=
@ -2577,7 +2586,6 @@ run_service_relations () {
# debug " Relations of ${DARKYELLOW}$subservice${NORMAL}:" # debug " Relations of ${DARKYELLOW}$subservice${NORMAL}:"
while read-0 relation_name target_service relation_config tech_dep; do while read-0 relation_name target_service relation_config tech_dep; do
export relation_config export relation_config
export TARGET_SERVICE_NAME=$target_service export TARGET_SERVICE_NAME=$target_service
MASTER_TARGET_SERVICE_NAME=$(get_top_master_service_for_service "$target_service") || return 1 MASTER_TARGET_SERVICE_NAME=$(get_top_master_service_for_service "$target_service") || return 1
MASTER_TARGET_CHARM_NAME=$(get_service_charm "$MASTER_TARGET_SERVICE_NAME") || return 1 MASTER_TARGET_CHARM_NAME=$(get_service_charm "$MASTER_TARGET_SERVICE_NAME") || return 1
@ -3798,6 +3806,7 @@ action=
stage="main" ## switches from 'main', to 'action', 'remainder' stage="main" ## switches from 'main', to 'action', 'remainder'
is_docker_compose_action= is_docker_compose_action=
rebuild_relations_to_service=() rebuild_relations_to_service=()
declare -A without_relations
DC_MATCH_MULTI=$(get_docker_compose_multi_opts_list) && DC_MATCH_MULTI=$(get_docker_compose_multi_opts_list) &&
DC_MATCH_SINGLE=$(get_docker_compose_single_opts_list) || return 1 DC_MATCH_SINGLE=$(get_docker_compose_single_opts_list) || return 1
while read-0 arg; do while read-0 arg; do
@ -3838,6 +3847,11 @@ while read-0 arg; do
--no-relations) --no-relations)
export no_relations=true export no_relations=true
;; ;;
--without-relation)
read-0 value
without_relations["$value"]=1
shift
;;
--no-hooks) --no-hooks)
export no_hooks=true export no_hooks=true
;; ;;

Loading…
Cancel
Save