Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

BDR usinf CM API

SOLVED Go to solution

BDR usinf CM API

Explorer

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

Accepted Solutions

Re: BDR using CM API

Explorer
 
8 REPLIES 8

Re: BDR using CM API

Explorer
 

Re: BDR using CM API

Community Manager

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



Cy Jervis, Community Manager

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.

Learn more about the Cloudera Community:
Community Guidelines
How to use the forum

Re: BDR using CM API

Explorer

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"

Re: BDR using CM API

Explorer

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

Re: BDR using CM API

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 .

Re: BDR using CM API

Super 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

Re: BDR using CM API

Explorer

Try the following -

 

$i = hive or hdfs

 

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

Re: BDR using CM API

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