You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sr...@apache.org on 2013/10/01 22:01:29 UTC

git commit: AMBARI-3404. Add userId password options to configs script. (srimanth)

Updated Branches:
  refs/heads/trunk c11eea175 -> eca0b5ead


AMBARI-3404. Add userId password options to configs script. (srimanth)


Project: http://git-wip-us.apache.org/repos/asf/incubator-ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ambari/commit/eca0b5ea
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/eca0b5ea
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/eca0b5ea

Branch: refs/heads/trunk
Commit: eca0b5ead835af3d77dc6d1397f982c2dc2302c4
Parents: c11eea1
Author: Srimanth Gunturi <sg...@hortonworks.com>
Authored: Tue Oct 1 11:02:19 2013 -0700
Committer: Srimanth Gunturi <sg...@hortonworks.com>
Committed: Tue Oct 1 12:59:56 2013 -0700

----------------------------------------------------------------------
 .../src/main/resources/scripts/configs.sh       | 44 +++++++++++++++++---
 1 file changed, 38 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/eca0b5ea/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 2aa5250..983fc59 100755
--- a/ambari-server/src/main/resources/scripts/configs.sh
+++ b/ambari-server/src/main/resources/scripts/configs.sh
@@ -19,20 +19,47 @@
 #
 
 usage () {
-  echo "Usage: configs.sh <ACTION> <AMBARI_HOST> <CLUSTER_NAME> <SITE_NAME> [CONFIG_KEY] [CONFIG_VALUE]";
+  echo "Usage: configs.sh [-u userId] [-p password] [-port port] <ACTION> <AMBARI_HOST> <CLUSTER_NAME> <CONFIG_TYPE> [CONFIG_KEY] [CONFIG_VALUE]";
   echo "";
+  echo "       [-u userId]: Optional user ID to use for authentication. Default is 'admin'.";
+  echo "       [-p password]: Optional password to use for authentication. Default is 'admin'.";
+  echo "       [-port port]: Optional port number for Ambari server. Default is '8080'. Provide empty string to not use port.";
   echo "       <ACTION>: One of 'get', 'set', 'delete'. 'Set' adds/updates as necessary.";
   echo "       <AMBARI_HOST>: Server external host name";
   echo "       <CLUSTER_NAME>: Name given to cluster. Ex: 'c1'"
-  echo "       <SITE_NAME>: One of the various configuration sites in Ambari. Ex:global, core-site, hdfs-site, etc.";
+  echo "       <CONFIG_TYPE>: One of the various configuration types in Ambari. Ex:global, core-site, hdfs-site, mapred-queue-acls, etc.";
   echo "       [CONFIG_KEY]: Key that has to be set or deleted. Not necessary for 'get' action.";
   echo "       [CONFIG_VALUE]: Optional value to be set. Not necessary for 'get' or 'delete' actions.";
   exit 1;
 }
 
-AMBARIURL="http://$2:8080"
 USERID="admin"
 PASSWD="admin"
+PORT=":8080"
+
+if [ "$1" == "-u" ] ; then
+	USERID=$2;
+	shift 2;
+	echo "USERID=$USERID";
+fi
+
+if [ "$1" == "-p" ] ; then
+	PASSWD=$2;
+	shift 2;
+	echo "PASSWORD=$PASSWD";
+fi
+
+if [ "$1" == "-port" ] ; then
+	if [ -z $2 ]; then
+		PORT="";
+	else
+		PORT=":$2";
+	fi
+	shift 2;
+	echo "PORT=$PORT";
+fi
+
+AMBARIURL="http://$2$PORT"
 CLUSTER=$3
 SITE=$4
 SITETAG=''
@@ -58,7 +85,12 @@ currentSiteTag () {
     fi
   done;
   if [ -z $currentSiteTag ]; then
-    echo "Tag unknown for site $SITE";
+    errOutput=`curl -s -u $USERID:$PASSWD "$AMBARIURL/api/v1/clusters/$CLUSTER?fields=Clusters/desired_configs"`;
+    echo "[ERROR] \"$SITE\" not found in server response.";
+    echo "[ERROR] Output of \`curl -s -u $USERID:$PASSWD \"$AMBARIURL/api/v1/clusters/$CLUSTER?fields=Clusters/desired_configs\"\` is:";
+    echo $errOutput | while read -r line; do
+      echo "[ERROR] $line";
+    done;
     exit 1;
   fi
   currentSiteTag=`echo $currentSiteTag|cut -d \" -f 2`
@@ -95,7 +127,7 @@ doConfigUpdate () {
         newProperties=$newProperties$line
         propertiesStarted=0;
         
-        newTag=`date "+%Y%m%d%H%M%S"`
+        newTag=`date "+%s"`
         newTag="version$newTag"
         finalJson="{ \"Clusters\": { \"desired_config\": {\"type\": \"$SITE\", \"tag\":\"$newTag\", $newProperties}}}"
         newFile="doSet_$newTag.json"
@@ -157,4 +189,4 @@ case "$1" in
   *) 
     usage
     ;;
-esac
\ No newline at end of file
+esac