更新时间:2023-11-08 GMT+08:00
分享

参考样例

在准备好开发和运行环境后,用户可根据需求开发样例,例如参考代码如下:

package com.huawei.cloud.dalf.lakecat.examples;

import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ClientRequestException;
import com.huaweicloud.sdk.core.exception.ServerResponseException;
import com.huaweicloud.sdk.core.http.HttpConfig;
import com.huaweicloud.sdk.lakeformation.v1.LakeFormationClient;
import com.huaweicloud.sdk.lakeformation.v1.model.ListCatalogsRequest;
import com.huaweicloud.sdk.lakeformation.v1.model.ListCatalogsResponse;

import java.util.ArrayList;
import java.util.List;

public class LakeFormationExample {
    public static void main(String[] args) {
        // getAk(),getSk()方法需自行实现,可以从配置项或其他位置获取AK/SK
        // 请勿在代码中硬编码AK/SK
        String ak = getAk();
        String sk = getSk();

        // projectId: 项目ID
        String projectId = "{******your project id******}";

        // 1.初始化sdk
        HttpConfig config = HttpConfig.getDefaultHttpConfig();
        config.withIgnoreSSLVerification(true);
        List<String> endpoints = new ArrayList<>();
        endpoints.add("lakeformation.lakecat.com");
        BasicCredentials basicCredentials = new BasicCredentials().withAk(ak).withSk(sk).withProjectId(projectId);

        // 2.创建LakeFormationClient实例
        LakeFormationClient client = LakeFormationClient.newBuilder()
            .withHttpConfig(config)
            .withCredential(basicCredentials)
            .withEndpoints(endpoints)
            .build();

        // 3.创建请求,添加参数
        ListCatalogsRequest listCatalogsRequest =
            new ListCatalogsRequest().withInstanceId("{******your instance id******}");

        // 4.查询catalogs列表
        try {
            ListCatalogsResponse response = client.listCatalogs(listCatalogsRequest);
            System.out.println(response.getHttpStatusCode());
            System.out.println(response);
        } catch (ClientRequestException | ServerResponseException e) {
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getMessage());
        }
    }
}
分享:

    相关文档

    相关产品