Support Questions

Find answers, ask questions, and share your expertise

set Variable in ambari rest API

avatar

 

hi all

 

the following ambari API will stop only the data-nodes on workers machines

 

# curl -s -u admin:admin -H "X-Requested-By: ambari" -X PUT -d '{"RequestInfo":{"context":"Stop DataNodes","operation_level":{"level":"SERVICE","cluster_name":"$CLUSTER_NAME"},"query":"HostRoles/component_name=DATANODE&HostRoles/host_name.in(dn1.example.com,dn2.example.com,dn3.example.com)&HostRoles/maintenance_state=OFF"},"Body":{"HostRoles":{"state":"INSTALLED"}}}' "h ttp://$AMBARI_FQDN:8080/api/v1/clusters/$CLUSTER_NAME/host_components"

 

now we want to replace the list - n1.example.com,dn2.example.com,dn3.example.com

 

with variable - DATANODES=n1.example.com,dn2.example.com,dn3.example.com

 

so $DATANODES will replce the list in the API as the following

 

 

# curl -s -u admin:admin -H "X-Requested-By: ambari" -X PUT -d '{"RequestInfo":{"context":"Stop DataNodes","operation_level":{"level":"SERVICE","cluster_name":"$CLUSTER_NAME"},"query":"HostRoles/component_name=DATANODE&HostRoles/host_name.in($DATANODES)&HostRoles/maintenance_state=OFF"},"Body":{"HostRoles":{"state":"INSTALLED"}}}' "h ttp://$AMBARI_FQDN:8080/api/v1/clusters/$CLUSTER_NAME/host_components"

 

 

but this isn't working , any advice how to set it correctly ?

Michael-Bronson
1 ACCEPTED SOLUTION

avatar
Master Mentor

@mike_bronson7 

You can achieve it in a similar way described on the following thread:
https://community.cloudera.com/t5/Support-Questions/AMBARI-how-to-set-value-in-json-REST-API/td-p/29...

 

Example:

AMBARI_FQDN=newhwx1.example.com
CLUSTER_NAME=NewCluster
DATANODES=newhwx1.example.com,newhwx2.example.com,newhwx3.example.com,newhwx5.example.com


# curl -s -u admin:admin -H "X-Requested-By: ambari" -X PUT -d '{"RequestInfo":{"context":"Stop DataNodes","operation_level":{"level":"SERVICE","cluster_name":"'"$CLUSTER_NAME"'"},"query":"HostRoles/component_name=DATANODE&HostRoles/host_name.in('$DATANODES')&HostRoles/maintenance_state=OFF"},"Body":{"HostRoles":{"state":"INSTALLED"}}}' "http://$AMBARI_FQDN:8080/api/v1/clusters/$CLUSTER_NAME/host_components"

.

.

 

View solution in original post

1 REPLY 1

avatar
Master Mentor

@mike_bronson7 

You can achieve it in a similar way described on the following thread:
https://community.cloudera.com/t5/Support-Questions/AMBARI-how-to-set-value-in-json-REST-API/td-p/29...

 

Example:

AMBARI_FQDN=newhwx1.example.com
CLUSTER_NAME=NewCluster
DATANODES=newhwx1.example.com,newhwx2.example.com,newhwx3.example.com,newhwx5.example.com


# curl -s -u admin:admin -H "X-Requested-By: ambari" -X PUT -d '{"RequestInfo":{"context":"Stop DataNodes","operation_level":{"level":"SERVICE","cluster_name":"'"$CLUSTER_NAME"'"},"query":"HostRoles/component_name=DATANODE&HostRoles/host_name.in('$DATANODES')&HostRoles/maintenance_state=OFF"},"Body":{"HostRoles":{"state":"INSTALLED"}}}' "http://$AMBARI_FQDN:8080/api/v1/clusters/$CLUSTER_NAME/host_components"

.

.