Alibaba Cloud SDK for Java allows you to access ApsaraDB for HBase without the need to write complex code. This topic describes how to install and use Alibaba Cloud SDK for Java.

Debugging

Alibaba Cloud provides OpenAPI Explorer to greatly simplify API usage. For example, you can use OpenAPI Explorer to quickly search for API operations, call the API operations of cloud services online, and dynamically generate SDK sample code. We recommend that you use OpenAPI Explorer.

Prerequisites

  • An AccessKey pair is created. For more information, see Create an AccessKey pair.
    Note To protect the AccessKey pair of your Alibaba Cloud account, we recommend that you create a RAM user, grant the RAM user the permissions to access ApsaraDB for HBase, and then use the AccessKey pair of the RAM user to call Alibaba Cloud SDK for Java. For more information, see Performing access control by using RAM.
  • Java Development Kit (JDK) 1.6 or later is installed.

Install Alibaba Cloud SDK for Java

To install Alibaba Cloud SDK for Java, you can add dependencies by using Maven or importing JAR files. For more information, see Install Alibaba Cloud SDK for Java.
Note If you use Maven to add dependencies, enter the latest version number of the SDK.

Use Alibaba Cloud SDK for Java to call ApsaraDB for HBase API operations

  1. Create a DefaultAcsClient instance and initialize the instance.
    DefaultProfile profile = DefaultProfile.getProfile(
        "<regionId>",         // The region ID.
        "<accessKeyId>",      // The AccessKey ID of the RAM user.
        "<accessKeySecret>"); // The AccessKey secret of the RAM user.
    IAcsClient client = new DefaultAcsClient(profile);
  2. Optional. Specify the region and endpoint.
    DefaultProfile.addEndpoint(
        "<EndpointName>",  //The name of the endpoint. You can use a custom name.
        "<regionId>",      // The region ID.
        "r-kvstore",       // The service code. The service code of ApsaraDB for HBase is r-kvstore.
        "<Endpoint>");     // The endpoint of the API server.
    Note The API server address of an Alibaba Cloud service is an endpoint. The endpoint of each service varies based on the region. Alibaba Cloud SDK for Java has a built-in module that is used to search for endpoints. When you use the SDK to send an API request to a service, the SDK automatically obtains the endpoint based on the service ID and region ID that you specify when you create the SDK client. Therefore, this step is optional.
  3. Create an API request and configure the parameters.
    DescribeInstanceRequest request = new DescribeInstanceRequest();
            request.setClusterId("ap-*****************");
  4. Initiate the API request and process the response or exceptions.
    DescribeInstanceResponse response;
            try {
                response = client.getAcsResponse(request);
                System.out.println(new Gson().toJson(response));
            } catch (ClientException e) {
                e.printStackTrace();
            }

Sample requests

DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou",
                "ak******************", "akSecret********************");
        DefaultProfile.addEndpoint(
                "cn-hangzhou",    // The region ID.
                "hbase",    // The service code.
                "hbase.aliyuncs.com"    // The endpoint. The endpoint indicates the domain name.
        );
        IAcsClient client = new DefaultAcsClient(profile);
        DescribeInstanceRequest request = new DescribeInstanceRequest();
        request.setClusterId("ap-******************");
        DescribeInstanceResponse response;
        try {
            response = client.getAcsResponse(request);
            System.out.println(new Gson().toJson(response));
        } catch (ClientException e) {
            e.printStackTrace();
        }

Sample responses

{
    "requestId":"2817B189-6927-41E0-879F-*********",
    "instanceId":"ap-****************",
    "instanceName":"myInstanceName",
    "status":"ACTIVATION",
    "payType":"PayAsYouGo",
    "createdTime":"2019-10-31T21:50:14",
    "majorVersion":"2.0",
    "minorVersion":"2.4.3.1",
    "engine":"spark",
    "networkType":"VPC",
    "vpcId":"vpc-****************",
    "vswitchId":"vsw-****************",
    "masterInstanceType":"spark.sn1.medium",
    "masterNodeCount":2,
    "masterDiskType":"",
    "masterDiskSize":0,
    "coreInstanceType":"spark.sn1.large",
    "coreNodeCount":4,
    "coreDiskType":"cloud_efficiency",
    "coreDiskSize":100,
    "regionId":"cn-hangzhou",
    "zoneId":"cn-hangzhou-f",
    "coldStorageStatus":"close",
    "backupStatus":"close",
    "tags":[

    ]
}