Search code examples
python-3.xpysparkclouderaimpalaapache-kudu

How to find KUDU master name or port in which KUDU DB in my cloudera cluster?


I am trying to write a Spark dataframe to Kudu DB, but I do not know the Kudu master. The cluster I am using is a Cloudera cluster.

How do I find Kudu master in the cluster?


Solution

  • Here is python example using Python client v3 (https://cloudera.github.io/cm_api/docs/python-client-swagger/):

    #!/usr/local/bin/python
    import cm_client
    
    # Configure HTTP basic authorization: basic
    #configuration = cm_client.Configuration()
    cm_client.configuration.username = 'admin'
    cm_client.configuration.password = 'admin'
    
    # Create an instance of the API class
    api_client = cm_client.ApiClient("http://your-cdh-cluster-cm-host:7180/api/v30")
    
    # create an instance of the ServicesResourceApi class
    service_api_instance = cm_client.ServicesResourceApi(api_client)
    
    # create an instance of the HostsResourceApi class
    host_api_instance = cm_client.HostsResourceApi(api_client)
    
    # find KUDU_MASTER roles in the CDH cluster
    cluster_roles = service_api_instance.read_roles("Cluster 1", "KUDU-1")
    for role in cluster_roles.items:
      if role.type == "KUDU_MASTER":
        role_host = host_api_instance.read_host(role.host_ref.host_id, view="full")
        print("Kudu master is located on %s\n" % role_host.hostname)