CDH自动化部署--如何通过CM API创建一个集群

要想实现CDH自动化部署,第一步就是创建集群(Cluster),这篇文章讲的就是如何通过cm java api创建一个cluster。

第一步,先要配置好POM文件,引入CM API

   
        
            cdh.repo
            https://repository.cloudera.com/content/groups/cloudera-repos
            Cloudera Repository
            
                false
            
        
    

    
        
            cloudera-releases
            https://repository.cloudera.com/artifactory/libs-release-local
            Cloudera Releases Repository
        
        
            cloudera-snapshots
            https://repository.cloudera.com/artifactory/libs-snapshot-local
            Cloudera Snapshots Repository
        
    
我们的CDH版本是5.11.0,根据不同的CDH版本匹配CM API 的版本,这块一定要对应起来,避免后面出现不必要的错误


          com.cloudera.api
          cloudera-manager-api
          ${cm.version}
          
                
                    org.eclipse.jetty
                    jetty-continuation
                
                
                    org.eclipse.jetty
                    jetty-http
                
                
                    org.eclipse.jetty
                    jetty-io
                
                
                    org.eclipse.jetty
                    jetty-security
                
                
                    org.eclipse.jetty
                    jetty-server
                
                
                    org.eclipse.jetty
                    jetty-util
                
                
                    org.springframework
                    spring-aop
                
                
                    org.springframework
                    spring-asm
                
                
                    org.springframework
                    spring-beans
                
                
                    org.springframework
                    spring-context
                
                
                    org.springframework
                    spring-core
                
                
                    org.springframework
                    spring-expression
                
                
                    org.springframework
                    spring-web
                
                
                    com.google.guava
                    guava
                
                
                    com.sun.xml.bind
                    jaxb-impl
                
                
                    joda-time
                    joda-time
                
                
                    commons-logging
                    commons-logging
                
            

第二步,创建集群

        String host = "CDH MANAGER IP";
        int port = 7180;
        String user = "admin";
        String password = "admin";
        String clusterName = "automation-demo-cluster";
        //获得api
        ApiRootResource apiResource = new ClouderaManagerClientBuilder().withHost(host).withPort(port).withUsernamePassword(user, password).build();
        //根资源
        RootResourceV16 apiRoot = apiResource.getRootV16();
        //集群资源管理
        ClustersResourceV16 clustersResource = apiRoot.getClustersResource();
        ApiClusterList apiClusterList = new ApiClusterList();
        ApiCluster cluster = new ApiCluster();
        //设置集群的名称
        cluster.setName(clusterName);
        //设置集群的版本
        cluster.setVersion(ApiClusterVersion.CDH5);
        apiClusterList.add(cluster);
        //创建集群
        clustersResource.createClusters(apiClusterList);
  

登录CDH管理页面查看集群

1542961262(1).jpg

查看集群和删除集群

        //查看集群
        ApiCluster apiCluster = clustersResource.readCluster(clusterName);
        System.out.println("Cluster name is " + apiCluster.getName() + ", version is " + apiCluster.getVersion());
        //输出结果
        //Cluster name is automation-demo-cluster, version is CDH5

        //删除集群
        clustersResource.deleteCluster(clusterName);

至此,一个集群的基本操作我们就介绍完了,下一篇文章我会将如何创建HOST并把它添加进集群

你可能感兴趣的:(CDH自动化部署--如何通过CM API创建一个集群)