Help Center> Data Lake Insight> SDK Reference> Java SDK> Initializing the DLI Client
Updated on 2023-07-19 GMT+08:00

Initializing the DLI Client

To use DLI SDK to access DLI, you need to initialize the DLI client. During DLI client initialization, you can perform authentication using the Access Key ID/Secret Access Key (AK/SK) or token. The sample code is as follows:

Prerequisites

  • You have configured the Java SDK environment by following the instructions provided Instructions.
  • You have initialized the DLI Client by following the instructions provided in Initializing the DLI Client.

Sample code for AK/SK authentication

1
2
3
4
5
6
  String ak = "ak";
  String sk = "sk";
  String regionName = "regionname";
  String projectId = "project_id";
  DLIInfo dliInfo = new DLIInfo(regionName, ak, sk, projectId);
  DLIClient client = new DLIClient(AuthenticationMode.AKSK, dliInfo);

You can perform the following operations to obtain the Access Keys, project ID, and Region:

  1. Log in to the management console.
  2. Hover the cursor on the username in the upper right corner and select My Credentials from the drop-down list.
  3. In the navigation pane on the left, choose Access Keys and click Create Access Key. Confirm that you want to proceed with the operation and click OK.
  4. On the displayed page, click Download. Open the credential file to obtain the AK/SK information.
  5. In the navigation pane on the left, choose API Credentials. In the Projects pane, locate project_id and obtain the region information.

Sample code for token-based authentication

1
2
3
4
5
6
7
  String domainName = "domainname";
  String userName = "username";
  String password = "password";
  String regionName = "regionname";
  String projectId = "project_id";
  DLIInfo dliInfo = new DLIInfo(regionName, domainName, userName, password, projectId);
  DLIClient client = new DLIClient(AuthenticationMode.TOKEN, dliInfo);

You can change the endpoint in set mode. Run the following statement: dliInfo.setServerEndpoint(endpoint).