Support Questions

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

BDR usinf CM API

avatar
Contributor

I'm new to cloudera and am trying to automatically start and stop replication jobs. We're replicating from prod to our DR site.

 

Can someone share examples of python or java code that shows how to call the cm api to start and stop replication jobs?

 

Any help is appreciated.

1 ACCEPTED SOLUTION

avatar
Contributor
10 REPLIES 10

avatar
Contributor
 

avatar
Community Manager

Thank you for marking your issue as solved @DanielWhite. Can you advise what the solution was?


Cy Jervis, Manager, Community Program
Was your question answered? Make sure to mark the answer as the accepted solution.
If you find a reply useful, say thanks by clicking on the thumbs up button.

avatar
Contributor

I've solved half of the question. I can start bdr jobs but haven't figured out how to stop them yet.

I'm using the cloudera api and curl to start the jobs via a bash script. I have a python script I'm developing for use in the future.

 

Like -

curl -X POST -u user:password \
'http://server:7180/api/v9/clusters/Cluster%201/services/hive/replications/jobnumber/run'

 

I tried using the hadoop and mapred commands to kill a job but this made the job lose it's mind and didn't kill it gracefully. This caused an error in the cloudera manager and I had to set null in the jobs log to get it to die.

 

Like -

hadoop job -kill "$mapred_jobid"

avatar
Contributor

I solved the stop bdr jobs. This is done with the command api. Once a bdr job is started it gets a unique command id. Its runs using this id rather then the job number that we see in CM. The following is how I'm stopping the jobs

 

Firstly, get the command id by using the status api -

 

command_id=`curl -u admin:password "http://servername:7180/api/v9/clusters/C
luster%201/services/"$i"/replications" | grep -A 1 '"active" : true' | awk '{print $3}' | aw
k -F '/' '{print $4}' | sed '/^\s*$/d'`

 

Second, stop the job using the command abort api -

 

curl -X POST -u admin:password \
                "http://servername:7180/api/v9/commands/"$command_id"/abort"

 

Thanks,

Daniel

avatar
New Contributor

Hi ,

i am trying in the same way but its not showing any replication schedules .

hostname:/$ curl -su <user> https://hostname:7183/api/v1/clusters/cluster%20/services/hdfs/replications/
Enter host password for user 'user':
hostname:/$

Please advise .

avatar
Master Guru

@sorabhj412,

 

As described here, the "replications" api call is only available starting with API v11:

 

https://cloudera.github.io/cm_api/apidocs/v19/path__clusters_-clusterName-_services_-serviceName-_re...

 

You should be able to get this to work if you change your URL to v11 or as high as your CM supports:

 

https://hostname:7183/api/v11/clusters/cluster/services/hdfs/replications/

 

To see what the max version of the API your Cloudera Manager supports, run:

 

curl -su <user> https://hostname:7183/api/version

 

NOTE: you also seem to have a space character after your "cluster" cluster name:  "clusters/cluster%20/"  I believe that may also cause you problems.  To see what cluster name you have, check with:

 

curl -su <user> https://hostname:7183/api/v11/clusters

avatar
Contributor

Try the following -

 

$i = hive or hdfs

 

curl -u username:password "http://hostname:7180/api/v13/clusters/Cluster%201/services/"$i"/replications"

avatar
New Contributor

Hi Daniel,

Thanks , I tried your suggestion and the commands looks working . but it’s not showing any output even after 60mins .

Below command just keep running .

I am looking for a way to get BDR Job history from command line . please help.

cloudera-scm@gbrpsr000004835 PROD $ curl -su <user> -X GET  'https://<localhost>:7183/api/v15/clusters/Cluster%DR'/services/hdfs/replications

avatar
New Contributor

I've same the issue, but i got the BDR job history back after waited for 4 hours. The BDR job history file is very large. Is anyway to filter out only extract the job from yesterday?

Thanks,

Scott