/cloudera-manager-api

Open Source Java Client for Cloudera Manager API

Primary LanguageJavaOtherNOASSERTION

Cloudera Manager API client

Java client for Cloudera Manager Rest interface

Things to consider

We designed the API to work with CM 4.0+ (v1 of the API) and we used it to deploy a cluster with Cloudera Manager 4.0.4 via API.

Features

  • the interface is very close to the original API
  • very good JavaDoc documentation
  • all created objects are immutable => thread safe
  • fluent API

How to use

Create a client instance:

    private final URI ENDPOINT = URI.create("http://<cloudera-manager-service>:7180"));
    
    ClouderaManagerClient CLIENT = ClouderaManagerClient.withConnectionURI(ENDPOINT)
                                                        .withAuth("admin", "admin").build();

and use it to issue requests to the server:

    // add a host to the pool
    HostList hosts = null;
    try {
      hosts = CLIENT.hosts().createHosts(Sets.newHashSet(
          new Host(CM_SERVICE_IP, TARGET_HOST_NAME)));
    } catch (UniformInterfaceException e) {
      LOGGER.info(e.getResponse().getEntity(ErrorMessage.class).toString());
    }
    
    // create a cluster
    Cluster cluster = new Cluster(CLUSTER_NAME, ClusterVersion.CDH3);
    ClusterList created = CLIENT.clusters().createClusters(Sets.newHashSet(cluster));

Calls will return immediatly and you will have to interrogate Cloudera Manaer for the result of the call as it might take some time before the commands issued will finish.

Fortunatelly it's easy, all you have to do is use waitFor( ) method:

    // issue an expensive command that will take some time to finish
    
    BulkCommandList commands = CLIENT.clusters().getCluster(CLUSTER_NAME)
        .getService(HDFS_SERVICE_NAME).hdfsFormat(new RoleNameList("hdfs-nn"));
    LOGGER.info("Commands for formatting HDFS: " + commands.toString());
    
    // wait for them to finish and get the results
    List<Command> result = CLIENT.commands().waitFor(commands);

See ClouderaManagerClientLiveTest.java for examples on how to create a cluster and add services to it via Java Client API calls.

Testing with Vagrant

Integration tests can be don using Vagrant. Vagrant is a VirtualBox driver written in Ruby. You will need to install VirtualBox and Ruby, before Vagrant. The process is explained in an article on our blog.

Resources