Repository: ambari Updated Branches: refs/heads/trunk 7db1f10c7 -> a1488cec7
AMBARI-13256 configs.sh cannot add name-value pair to an empty config (dsen) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/a1488cec Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/a1488cec Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/a1488cec Branch: refs/heads/trunk Commit: a1488cec7378b29bf04be08b901d6a210cfa9269 Parents: 7db1f10 Author: Dmytro Sen <d...@apache.org> Authored: Tue Sep 29 16:21:03 2015 +0300 Committer: Dmytro Sen <d...@apache.org> Committed: Tue Sep 29 16:21:03 2015 +0300 ---------------------------------------------------------------------- .../src/main/resources/scripts/configs.sh | 21 ++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/a1488cec/ambari-server/src/main/resources/scripts/configs.sh ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/scripts/configs.sh b/ambari-server/src/main/resources/scripts/configs.sh index a32ff42..ba02d2d 100755 --- a/ambari-server/src/main/resources/scripts/configs.sh +++ b/ambari-server/src/main/resources/scripts/configs.sh @@ -130,14 +130,19 @@ doConfigUpdate () { if [ "`echo $line | grep -E "},?$"`" ]; then ## Properties ended ## Add property - # Remove the last , propLen=${#newProperties} lastChar=${newProperties:$propLen-1:1} - if [ "$lastChar" == "," ]; then - newProperties=${newProperties:0:$propLen-1} - fi - if [ "$MODE" == "set" ]; then - newProperties="$newProperties, \"$CONFIGKEY\" : \"$CONFIGVALUE\" " + if [ "$MODE" == "delete" ]; then + # Remove the last , + if [ "$lastChar" == "," ]; then + newProperties=${newProperties:0:$propLen-1} + fi + elif [ "$MODE" == "set" ]; then + # Add comma if required + if [ "$lastChar" != "," -a "$lastChar" != "{" ]; then + newProperties="$newProperties," + fi + newProperties="$newProperties \"$CONFIGKEY\" : \"$CONFIGVALUE\"" fi newProperties=$newProperties$line propertiesStarted=0 @@ -154,6 +159,10 @@ doConfigUpdate () { elif [ "`echo $line | grep -E "},?$"`" ]; then currentLevel=$((currentLevel-1)) if [ "$currentLevel" == 1 ]; then + # if no properties in current config + if [ "$MODE" == "set" -a -z "$newProperties" ]; then + newProperties="\"properties\" : { \"$CONFIGKEY\" : \"$CONFIGVALUE\"}" + fi newTag=`date "+%s%N"` newTag="version${newTag}" finalJson="{ \"Clusters\": { \"desired_config\": {\"type\": \"$SITE\", \"tag\":\"$newTag\", $newProperties}}}"