如何在我的cloudera集群中找到KUDU数据库所在的KUDU主名称或端口?

时间:2018-09-13 21:19:36

标签: python-3.x pyspark cloudera impala apache-kudu

我正在尝试将Spark数据帧写入Kudu DB,但是我不知道Kudu主数据库。我正在使用的群集是Cloudera群集。

如何在群集中找到Kudu主站?

3 个答案:

答案 0 :(得分:0)

这是一个使用Cloudera Manager Java客户端(https://cloudera.github.io/cm_api/docs/java-client-swagger/)的非常基本的示例

package cloudera.kudu_example;

import java.io.IOException;

import com.cloudera.api.swagger.HostsResourceApi;
import com.cloudera.api.swagger.ServicesResourceApi;
import com.cloudera.api.swagger.client.ApiClient;
import com.cloudera.api.swagger.client.ApiException;
import com.cloudera.api.swagger.client.Configuration;
import com.cloudera.api.swagger.model.ApiHost;
import com.cloudera.api.swagger.model.ApiRole;
import com.cloudera.api.swagger.model.ApiRoleList;

public class App {
    public static void main( String[] args ) throws IOException {
        ApiClient cmClient = Configuration.getDefaultApiClient();

        cmClient.setBasePath(args[0]);
        cmClient.setUsername(args[1]);
        cmClient.setPassword(args[2]);

        cmClient.setVerifyingSsl(false);
        HostsResourceApi hostsApiInstance = new HostsResourceApi();
        ServicesResourceApi servicesApiInstance = new ServicesResourceApi();
        try {
            ApiRoleList apiRoles = servicesApiInstance.readRoles("Cluster 1", "KUDU-1");
            for(ApiRole role : apiRoles.getItems()) {
                if(role.getType().equalsIgnoreCase("KUDU_MASTER")) {
                    ApiHost host = hostsApiInstance.readHost(role.getHostRef().getHostId(), "full");
                    System.out.printf("Kudu master runs at %s. IP: %s, status %s", host.getHostname(), host.getIpAddress(), host.getEntityStatus());
                }
            }

        } catch (ApiException e) {
          System.err.println("Exception when calling ClustersResourceApi#readClusters");
          e.printStackTrace();
        }
    }
}

答案 1 :(得分:0)

以下是使用Python客户端v3(https://cloudera.github.io/cm_api/docs/python-client-swagger/)的python示例:

#!/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)

答案 2 :(得分:0)

我知道这不是最佳方法,但这是一种快速的方法。让我们假设我们已经有了一个kudu表(以防万一,即使您没有通过impala创建测试/临时表),也只需执行格式化到该表的描述即可。现在,您将获得一堆详细信息,包括kudu master详细信息(主机名),其中端口为8051。我相信一旦您知道主机和端口详细信息,便可以探索很多 用于您的Spark数据框。

临时表语法:

创建表kudu_no_partition_by_clause ( id bigint主键,s STRING,b BOOLEAN ) 存为KUDU;

describe的语法:描述格式化的table_name;

FYR:

Kudu网站管理详细信息:https://kudu.apache.org/releases/0.6.0/docs/administration.html

Kudu带有火花示例: https://kudu.apache.org/docs/developing.html

干杯!