Querying Cluster Information Using REST

Function

Use the REST service to transfer the URL consisting of the host and port to obtain the cluster version and status information through HTTP.

Example Code

  • Connecting to the RestServer Service

    The following code snippets are in the main method in the HBaseRestTest class of the hbase-rest-example\src\main\java\com\huawei\hadoop\hbase\examples packet.

     // RESTServer's hostname.
            String restHostName = "100.120.16.170";[1]
            String securityModeUrl = new StringBuilder("https://").append(restHostName).append(":21309").toString();
            String nonSecurityModeUrl = new StringBuilder("http://").append(restHostName).append(":21309").toString();
            HBaseRestTest test = new HBaseRestTest();
    
            //If cluster is non-security mode,use nonSecurityModeUrl as  parameter.
            test.test(nonSecurityModeUrl);[2]

    [1] Change the value of restHostName to the IP address of the node where the RestServer instance to be accessed is located, and configure the node IP address in the hosts file on the local host where the sample code is run.

    [2] In non-security mode, access the HBase REST service in HTTP mode and use nonSecurityModeUrl as the test.test() parameter.

  • Obtaining the cluster version information

    The following code snippets are in the getClusterVersion method in the HBaseRestTest class of the hbase-rest-example\src\main\java\com\huawei\hadoop\hbase\examples packet.

    private void getClusterVersion(String url) {
         String endpoint = "/version/cluster";
         Optional<ResultModel> result = sendAction(url + endpoint, MethodType.GET, null);
         handleNormalResult((Optional<ResultModel>) result);
     }
  • Obtaining the cluster status information

    The following code snippets are in the getClusterStatus method in the HBaseRestTest class of the hbase-rest-example\src\main\java\com\huawei\hadoop\hbase\examples packet.

    private void getClusterStatus(String url) {
         String endpoint = "/status/cluster";
         Optional<ResultModel> result = sendAction(url + endpoint, MethodType.GET, null);
         handleNormalResult(result);
     }