Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]
Created 02-22-2018 10:30 AM
how to use API with variable inside the API
example , we replace the INSTALLED with ACTION=INSTALLED
and then we run the follwing
curl -u $USER:$PASSWD -i -H 'X-Requested-By: ambari' -X PUT -d '{"RequestInfo": {"context" :"Stop AMBARI_METRICS via REST"}, "Body": {"ServiceIfo": {"state": "$ACTION"}}}' http://$HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/AMBARI_METRICSbut the API not accepted the variable - $ACTION
please advice how to set the variable ACTION in the API so API will read this variable
example of API output when using the variable
HTTP/1.1 400 Bad Request X-Frame-Options: DENY X-XSS-Protection: 1; mode=block X-Content-Type-Options: nosniff Cache-Control: no-store Pragma: no-cache Set-Cookie: AMBARISESSIONID=1t1s2senrg3mtqgzda2qp8yv6;Path=/;HttpOnly Expires: Thu, 01 Jan 1970 00:00:00 GMT User: admin Content-Type: text/plain Content-Length: 313
Created 02-22-2018 11:04 AM
One solution can be as following:
# export HOST=amb25101.example.com
# export USER=admin
# export PASSWD=admin
# export ACTION=INSTALLED
# export CLUSTER_NAME=plain_ambari
# echo {"\"RequestInfo\": {\"context\" :\"Stop AMBARI_METRICS via REST\"}, \"Body\": {\"ServiceInfo\": {\"state\": \"$ACTION\"}}}" > /tmp/postData.txt
# curl -u $USER:$PASSWD -i -H 'X-Requested-By: ambari' -X PUT -d@/tmp/postData.txt http://$HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/AMBARI_METRICS.
So basically we are doing the following thing differently:
# echo {"\"RequestInfo\": {\"context\" :\"Stop AMBARI_METRICS via REST\"}, \"Body\": {\"ServiceInfo\": {\"state\": \"$ACTION\"}}}" > /tmp/postData.txt
# curl -u $USER:$PASSWD -i -H 'X-Requested-By: ambari' -X PUT -d@/tmp/postData.txt http://$HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/AMBARI_METRICS.
Created 02-22-2018 11:04 AM
One solution can be as following:
# export HOST=amb25101.example.com
# export USER=admin
# export PASSWD=admin
# export ACTION=INSTALLED
# export CLUSTER_NAME=plain_ambari
# echo {"\"RequestInfo\": {\"context\" :\"Stop AMBARI_METRICS via REST\"}, \"Body\": {\"ServiceInfo\": {\"state\": \"$ACTION\"}}}" > /tmp/postData.txt
# curl -u $USER:$PASSWD -i -H 'X-Requested-By: ambari' -X PUT -d@/tmp/postData.txt http://$HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/AMBARI_METRICS.
So basically we are doing the following thing differently:
# echo {"\"RequestInfo\": {\"context\" :\"Stop AMBARI_METRICS via REST\"}, \"Body\": {\"ServiceInfo\": {\"state\": \"$ACTION\"}}}" > /tmp/postData.txt
# curl -u $USER:$PASSWD -i -H 'X-Requested-By: ambari' -X PUT -d@/tmp/postData.txt http://$HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/AMBARI_METRICS.