Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

AMBARI + how to set value in json REST API

avatar
 

the following API example , will stop the kafka service in ambari

export service=kafka

curl -u admin:admin -i -H 'X-Requested-By: ambari' -X PUT -d '{"RequestInfo":{"context":"_PARSE_.STOP.$service","operation_level":{"level":"SERVICE","cluster_name":"$CLUSTER_NAME","service_name":"$service"}},"Body":{"ServiceInfo":{"state":"INSTALLED"}}}' http://$HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/$service 

the problem is about the syntax - _PARSE_.STOP.$service

and we see that actually service value - kafka not set in - PARSE.STOP.$service

so ambri saw the name as - PARSE.STOP.$service and not PARSE.STOP.kafka

any idea how we can set the value kafka inside the json syntax?

Michael-Bronson
1 ACCEPTED SOLUTION

avatar
Master Mentor

@mike_bronson7 

Thank you for sharing the screenshot .. it is very clean now.

Please replace the following:

"$CLUSTER_NAME" with "'"$CLUSTER_NAME"'"
"$service" with "'"$service"'"
"_PARSE_.STOP.$service" with "'"_PARSE_.STOP.$service"'"

 

In general, Replace any value which has    $ABCD with a single quote and then quote mark as  '"$ABCD"'

 

So the over all change will be "$ABCD" ----> "'"$ABCD"'"


Stop Kafka Service:

# curl -iLv -u "admin:admin" -i -H 'X-Requested-By: ambari' -X PUT -d '{"RequestInfo":{"context":"'"_PARSE_.STOP.$service"'","operation_level":{"level":"SERVICE","cluster_name":"'"$CLUSTER_NAME"'","service_name":"'"$service"'"}},"Body":{"ServiceInfo":{"state":"INSTALLED"}}}' http://$HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/$service

 

Start Kafka Service

# curl -iLv -u "admin:admin" -i -H 'X-Requested-By: ambari' -X PUT -d '{"RequestInfo":{"context":"'"_PARSE_.START.$service"'","operation_level":{"level":"SERVICE","cluster_name":"'"$CLUSTER_NAME"'","service_name":"'"$service"'"}},"Body":{"ServiceInfo":{"state":"STARTED"}}}' http://$HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/$service




 

 

View solution in original post

5 REPLIES 5

avatar
Master Mentor

@mike_bronson7 

I think the only change you will need to make is the "KAFKA" service in Uppercase because "kafka" in lowercase will not exist as a service.

Following is the example which i tested in my cluster and it works pretty fine.

# export service=kafka    (INCORRECT)

# export service=KAFKA

# curl -iLv -u "admin:admin" -i -H 'X-Requested-By: ambari' -X PUT -d '{"RequestInfo":{"context":"_PARSE_.STOP.$service","operation_level":{"level":"SERVICE","cluster_name":"$CLUSTER_NAME","service_name":"$service"}},"Body":{"ServiceInfo":{"state":"INSTALLED"}}}' http://$HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/$service

 

In order to start KAFKA service.

# curl -iLv -u "admin:admin" -i -H 'X-Requested-By: ambari' -X PUT -d '{"RequestInfo":{"context":"_PARSE_.START.$service","operation_level":{"level":"SERVICE","cluster_name":"$CLUSTER_NAME","service_name":"$service"}},"Body":{"ServiceInfo":{"state":"STARTED"}}}' http://$HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/$service

 

.

 

avatar

Dear Jay

 

yes I put KAFKA and not kafka , ( just I wrote by mistake in the post kafka instead KAFKA

but with the same problem

 

Michael-Bronson

avatar

also this is what we get from "ops" in ambari

 

you can see that ambari identify this as "$service" and not as KAFKA

 

Capture.PNG

Michael-Bronson

avatar
Master Mentor

@mike_bronson7 

Thank you for sharing the screenshot .. it is very clean now.

Please replace the following:

"$CLUSTER_NAME" with "'"$CLUSTER_NAME"'"
"$service" with "'"$service"'"
"_PARSE_.STOP.$service" with "'"_PARSE_.STOP.$service"'"

 

In general, Replace any value which has    $ABCD with a single quote and then quote mark as  '"$ABCD"'

 

So the over all change will be "$ABCD" ----> "'"$ABCD"'"


Stop Kafka Service:

# curl -iLv -u "admin:admin" -i -H 'X-Requested-By: ambari' -X PUT -d '{"RequestInfo":{"context":"'"_PARSE_.STOP.$service"'","operation_level":{"level":"SERVICE","cluster_name":"'"$CLUSTER_NAME"'","service_name":"'"$service"'"}},"Body":{"ServiceInfo":{"state":"INSTALLED"}}}' http://$HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/$service

 

Start Kafka Service

# curl -iLv -u "admin:admin" -i -H 'X-Requested-By: ambari' -X PUT -d '{"RequestInfo":{"context":"'"_PARSE_.START.$service"'","operation_level":{"level":"SERVICE","cluster_name":"'"$CLUSTER_NAME"'","service_name":"'"$service"'"}},"Body":{"ServiceInfo":{"state":"STARTED"}}}' http://$HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/$service




 

 

avatar

Dear Jay

 

what to say - you are the best , 

well done 

 

Michael-Bronson