Support Questions

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

how to know if API succeeded to restart all services

avatar

with the following API I restart all services in ambari that required restart

curl -sH "X-Requested-By: ambari" -u USER:$PASSWD -i http://$SERVER:8080/api/v1/clusters/$CLUSTER_NAME/requests?fields=Requests/request_status

how to know if API succeeded to restart all services ?

for example

we get true in case all services restart succsfuly

we get false when one or more services are failed

Michael-Bronson
1 ACCEPTED SOLUTION

avatar
Master Mentor

@Michael Bronson

You can make the following API call to check whether the "Restart all required services" got successfully COMPLETD or not? Or it got failed? By keep tracking the "request_status".

#  curl -sH "X-Requested-By: ambari" -u admin:admin -X GET http://hdfcluster1.example.com:8080/api/v1/clusters/TestCluster/requests?fields=Requests/id,Requests... | grep -A2 -B3 "Restart all required services"

.

Output Example:

      "Requests" : {
        "cluster_name" : "TestCluster",
        "id" : 789,
        "request_context" : "Restart all required services",
        "request_status" : "COMPLETED"
      }

.

If you want to know what got failed then you have the request id (789) to find out what went wrong:

#  curl -sH "X-Requested-By: ambari" -u admin:admin -X GET http://hdfcluster1.example.com:8080/api/v1/clusters/TestCluster/requests/789

.

In order to get more fine grained output like which Task got failed on which Host during "Restart all required services" operation, you can make the following kind of API call once you know the request id from above calls.

#  curl -sH "X-Requested-By: ambari" -u admin:admin -X GET http://hdfcluster1.example.com:8080/api/v1/clusters/TestCluster/requests/789/tasks?fields=Tasks/comm...

.

View solution in original post

8 REPLIES 8

avatar
Master Mentor

@Michael Bronson

You can make the following API call to check whether the "Restart all required services" got successfully COMPLETD or not? Or it got failed? By keep tracking the "request_status".

#  curl -sH "X-Requested-By: ambari" -u admin:admin -X GET http://hdfcluster1.example.com:8080/api/v1/clusters/TestCluster/requests?fields=Requests/id,Requests... | grep -A2 -B3 "Restart all required services"

.

Output Example:

      "Requests" : {
        "cluster_name" : "TestCluster",
        "id" : 789,
        "request_context" : "Restart all required services",
        "request_status" : "COMPLETED"
      }

.

If you want to know what got failed then you have the request id (789) to find out what went wrong:

#  curl -sH "X-Requested-By: ambari" -u admin:admin -X GET http://hdfcluster1.example.com:8080/api/v1/clusters/TestCluster/requests/789

.

In order to get more fine grained output like which Task got failed on which Host during "Restart all required services" operation, you can make the following kind of API call once you know the request id from above calls.

#  curl -sH "X-Requested-By: ambari" -u admin:admin -X GET http://hdfcluster1.example.com:8080/api/v1/clusters/TestCluster/requests/789/tasks?fields=Tasks/comm...

.

avatar

@Jay I think the following syntax is more fit for my case

 curl -sH "X-Requested-By: ambari" -u admin:admin -i http://$SERVER:8080/api/v1/clusters/$cluster_name/requests?fields=Requests/request_status |  awk '/request_status/' | tail -1  | egrep -iq "FAILED|ABORTED"

it will capture the last status , and if this fail or abort then the status is fail

what you think?

Michael-Bronson

avatar
Master Mentor

@Michael Bronson

If you simply wants to know if the "Restart all required services" was successfully completed or not then you can simply make the same old API call as following:

# curl -sH "X-Requested-By: ambari" -u admin:admin -X GET http://hdfcluster1.example.com:8080/api/v1/clusters/TestCluster/requests?fields=Requests/id,Requests... | grep -A2 -B3 "Restart all required services" | grep 'request_status'

.

Either the operation will be COMPLETED or FAILED|ABORTED.

# curl -sH "X-Requested-By: ambari" -u admin:admin -X GET http://hdfcluster1.example.com:8080/api/v1/clusters/TestCluster/requests?fields=Requests/id,Requests... | grep -A2 -B3 "Restart all required services" | grep 'request_status'
        "request_status" : "COMPLETED"

.

avatar

@Jay in my case we get the following

and the expected results should be only the last line ( last restart results )

curl -sH "X-Requested-By: ambari" -u admin:admin -X GET http://$server:8080/api/v1/clusters/$cluster/requests?fields=Requests/id,Requests/request_status,Req... | grep -A2 -B3 "Restart all required services" | grep 'request_status'
        "request_status" : "COMPLETED"
        "request_status" : "COMPLETED"
        "request_status" : "COMPLETED"
        "request_status" : "FAILED"
        "request_status" : "COMPLETED"
Michael-Bronson

avatar

@Jay see also what are the real latest restart status

      "href" : "http://master:8080/api/v1/clusters/HDP/requests/186",
      "Requests" : {
        "cluster_name" : "HDP",
        "id" : 186,
        "request_context" : "Restart all components for ZooKeeper",
        "request_status" : "ABORTED"
      }
    },
    {
      "href" : "http://master:8080/api/v1/clusters/HDP/requests/187",
      "Requests" : {
        "cluster_name" : "HDP",
        "id" : 187,
        "request_context" : "Restart all components for Kafka",
        "request_status" : "COMPLETED"
      }
    },
    {
      "href" : "http://master:8080/api/v1/clusters/HDP/requests/188",
      "Requests" : {
        "cluster_name" : "HDP",
        "id" : 188,
        "request_context" : "Restart all components for Kafka",
        "request_status" : "COMPLETED"
      }
    }
  ]
Michael-Bronson

avatar
Master Mentor

@Michael Bronson

By "latest restart status" do you mean a particular "Component" restart (like NameNode, DataNode..etc) Or a particular Service Restart ("HDFS" service / Yarn Service restart status?)

avatar

@Jay,

as you know we run the API that restart all req services,

and what we mean is that we want to capture only the last status from restart action , ( so the req ID should be only the last ) ,

for example , if now the last req id is 187 , then on the next restart it will be 188 , so we want to capture only the status of req id - 188 ( fail / ok )

but as I mentioned my syntax is give this

curl -sH "X-Requested-By: ambari" -u admin:admin -i http://$SERVER:8080/api/v1/clusters/$cluster_name/requests?fields=Requests/request_status | awk '/request_status/' | tail -1 | egrep -iq "FAILED|ABORTED"
[[ $? -eq 0 ]] && echo fail || echo ok
Michael-Bronson

avatar
Contributor

Is there any way to restart an ABORTED or FAILED request?