Updated on 2024-08-10 GMT+08:00

FlinkServer REST API Sample Program (Java)

Description

Call the FlinkServer RESTful API to create tenants.

Sample Code

For the complete code, see com.huawei.bigdata.flink.examples.TestCreateTenants.

public class TestCreateTenants {
    public static void main(String[] args) {
        ParameterTool paraTool = ParameterTool.fromArgs(args);
        final String hostName = paraTool.get("hostName");    // Replace hostName in the hosts file with the actual host name.
        final String keytab = paraTool.get("keytab file path");        // user.keytab file path
        final String krb5 = paraTool.get("krb5 file path");            // krb5.conf file path
        final String principal = paraTool.get("Authentication username");  // Authentication user

        System.setProperty("java.security.krb5.conf", krb5);
        String url = "https://"+hostName+":28943/flink/v1/tenants";
        String jsonstr = "{" +
                "\n\t \"tenantId\":\"92\"," +
                "\n\t \"tenantName\":\"test92\"," +
                "\n\t \"remark\":\"test tenant remark1\"," +
                "\n\t \"updateUser\":\"test_updateUser1\"," +
                "\n\t \"createUser\":\"test_createUser1\"" +
                "\n}";

        try {
            LoginClient.getInstance().setConfigure(url, principal, keytab, "");
            LoginClient.getInstance().login();
            System.out.println(HttpClientUtil.doPost(url, jsonstr, "utf-8", true));
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}