How-to: Automate Replications with Cloudera Manager API

Categories: CDH Cloud Cloudera Manager

Cloudera Enterprise Backup and Disaster Recovery (BDR) enables you to replicate data across data centers for disaster recovery scenarios. As a lower cost solution to geographical redundancy or as a means to perform an on-premises to cloud migration, BDR can also replicate HDFS and Hive data to and from Amazon S3 or a Microsoft Azure Data Lake Store.

Many customers may require an automated solution for creating, running, and managing replication schedules in order to minimize Recovery Point Objectives (RPOs) for late arriving data or to automate recovery after disaster recovery. This blog post walks through an example of automating HDFS replication by creating, running and managing BDR using the Cloudera Manager (CM) API.

Prerequisite

We strongly recommend you read the blog about How-to: Automate Your Cluster with Cloudera Manager API to learn the basics of the Cloudera Manager API.

Additionally, familiarize yourself with the Python client and the full API documentation.

Setting up a HDFS replication schedule

In this blog, we demonstrate use of the API via a Python script that creates, runs and manages an HDFS replication schedule. Cloudera BDR replications are pull-based replications, i.e. we need to create them in the target environment.

Step 1: Creating a peer

Before creating a replication schedule you need a peer, a source CM, from which data will be pulled. Please see the documentation for more information.

To create a peer:

The above sample creates an API root handle and gets a Cloudera Manager instance from it. We use the Cloudera Manager API to create a peer. For creating a peer, you need to provide the source CM URL and username/password of the admin user on the source CM.

Step 2: Creating an HDFS replication schedule

Now, you are ready to create an HDFS replication schedule.

To create an HDFS replication schedule:

We create an ApiHdfsReplicationArguments and populate important attributes, such as source path, destination name, mapreduce service to use, etc. For the source service, you will need to provide the HDFS service name and cluster name on the source CM. Please read the API documentation for the complete list of attributes for ApiHdfsReplicationArguments.

We then use hdfs_args to create an HDFS replication schedule.

Step 3: Running an HDFS replication schedule

The replication schedule created in step 2 has a frequency of 1 DAY, so the schedule will run at the initial start time every day. You can also manually run the schedule using the following:

Step 4: Monitoring the schedule

Once you get a command (cmd), you can wait for the command to finish and then get the results:

Managing the schedules

Once you get replication schedules setup, you can manage them with the Cloudera Manager API too.

Get all replication schedules for a given service:

Get a given replication schedule by schedule id for a given service:

Delete a given replication schedule by schedule id for a given service:

Update a given replication schedule by schedule id for a given service:

Setting up cloud replications

BDR also supports HDFS to/from S3 or ADLS replication using the Cloudera Manager API.

To use this functionality, you must first specify the AWS or Azure account. To add the account, do the following:

When creating a cloud (S3/ADLS) replication schedule, instead of a peer, you need to specify the cloud account that the replication schedule will use.

In this example, we create an ApiHdfsCloudReplicationArguments, populated it, and created an HDFS to S3 backup schedule. In addition to specifying important attributes such as source path, destination path, etc., we provided a destinationAccount as CLOUD_ACCOUNT and peerName as None in sourceService. The peerName is None since there is no peer for cloud replication schedules. We then use hdfs_cloud_args to create a HDFS-S3 replication schedule.  Note that the triggering and monitoring of the cloud replication schedule is the same as for an HDFS replication schedule described in the HDFS replication schedule from step 2. .

Debugging failures during replication

If a replication job fails, you can download replication diagnostic data for the replication command to troubleshoot and diagnose any issues.

The diagnostic data includes all the logs generated, including the MapReduce logs. You can also upload the logs to a support case for further analysis. Collecting a replication diagnostic bundle is available for API v11+ and Cloudera Manager version 5.5+.

To collect a replication diagnostic bundle:

Conclusion

Automating BDR replications using CM API is very powerful and especially useful if you have to manage a large number of replications. You can easily add this in your Oozie workflow and trigger/monitor replications. The BDR team’s internal testing framework uses this process, so it is a well tested one. Happy automation!

 

Facebooktwittergoogle_pluslinkedinmailFacebooktwittergoogle_pluslinkedinmail

One response on “How-to: Automate Replications with Cloudera Manager API

Leave a Reply

Your email address will not be published. Required fields are marked *

Prove you're human! *