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
In normal mode, users can connect to the RestServer service without logging in. Therefore, comment out the following code statements related to login in the main method of the HBaseRestTest class in the hbase-rest-example\src\main\java\com\huawei\hadoop\hbase\examples package:
//In Windows environment //String userdir = HBaseRestTest.class.getClassLoader().getResource("conf").getPath() + File.separator; //In Linux environment //String userdir = System.getProperty("user.dir") + File.separator + "conf" + File.separator; //userKeytabFile = userdir + "user.keytab"; //krb5File = userdir + "krb5.conf"; //String principal = "hbaseuser1"; //login(principal, userKeytabFile, krb5File);
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); }
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot