All Products
Search
Document Center

Realtime Compute for Apache Flink:Flink SDK for Java (latest)

Last Updated:Mar 14, 2025

This topic describes how to install and use Realtime Compute for Apache Flink SDK for Java.

Usage notes

Alibaba Cloud updated its Realtime Compute for Apache Flink SDKs on September 19, 2022. The new SDK version is now the default version for users. This update was progressively rolled out across all regions from September 19, 2022 to October 27, 2022.

Note

Prerequisites

  • An AccessKey pair is created. For more information, see Obtain an AccessKey pair.

    Note

    To protect the AccessKey pair of your Alibaba Cloud account, we recommend that you create a Resource Access Management (RAM) user, grant the RAM user the permissions to access Realtime Compute for Apache Flink, and then use the AccessKey pair of the RAM user to call Realtime Compute for Apache Flink SDK. For more information, see the following topics:

  • Java 8 or later is installed.

  • The account that you want to use has the required access and operation permissions. For more information, see Permission management.

Install Realtime Compute for Apache Flink SDK for Java

SDK for Java for the selling console of Realtime Compute for Apache Flink

Installation method

Code

Apache Maven

<dependency>

<groupId>com.aliyun</groupId>

<artifactId>foasconsole20211028</artifactId>

<version>2.1.0</version>

</dependency>

Gradle Groovy DSL

implementation 'com.aliyun:foasconsole20211028:2.1.0'

Gradle Kotlin DSL

implementation("com.aliyun:foasconsole20211028:2.1.0")

Scala SBT

libraryDependencies += "com.aliyun" % "foasconsole20211028" % "2.1.0"

Apache Ivy

<dependency org="com.aliyun" name="foasconsole20211028" rev="2.1.0" />

Groovy Grape

@Grapes(

@Grab(group='com.aliyun', module='foasconsole20211028', version='2.1.0')

)

Leiningen

[com.aliyun/foasconsole20211028 "2.1.0"]

Apache Buildr

'com.aliyun:foasconsole20211028:jar:2.1.0'

SDK for Java for the development console of Realtime Compute for Apache Flink

Installation method

Code

Apache Maven

<dependency>

<groupId>com.aliyun</groupId>

<artifactId>ververica20220718</artifactId>

<version>1.7.0</version>

</dependency>

Gradle Groovy DSL

implementation 'com.aliyun:ververica20220718:1.7.0'

Gradle Kotlin DSL

implementation("com.aliyun:ververica20220718:1.7.0")

Scala SBT

libraryDependencies += "com.aliyun" % "ververica20220718" % "1.7.0"

Apache Ivy

<dependency org="com.aliyun" name="ververica20220718" rev="1.7.0" />

Groovy Grape

@Grapes(

@Grab(group='com.aliyun', module='ververica20220718', version='1.7.0')

)

Leiningen

[com.aliyun/ververica20220718 "1.7.0"]

Apache Buildr

'com.aliyun:ververica20220718:jar:1.7.0'

Perform online debugging and generate SDK sample code

You can use OpenAPI Explorer to call API operations online, search for API operations, and dynamically generate SDK sample code. This simplifies the use of the API operations. You can view and download the SDK sample code of the required API operations on the Realtime Compute for Apache Flink page and Realtime Compute Selling Console page of OpenAPI Explorer. For more information, see Get started with Alibaba Cloud Darabonba SDK for Java.

image

Examples

Note
  • For more information about the endpoints of the selling console of Realtime Compute for Apache Flink, visit OpenAPI Explorer.

  • For more information about the endpoints of the development console of Realtime Compute for Apache Flink, visit OpenAPI Explorer.

Query purchased workspaces

You can query the details of your purchased Realtime Compute for Apache Flink workspaces in a region. Required request parameter:

Region: the region ID. For more information, visit OpenAPI Explorer. Example: cn-hangzhou.

package com.aliyun.sample;
import com.aliyun.foasconsole20211028.models.DescribeInstancesResponse;
import com.aliyun.tea.*;
import com.alibaba.fastjson2.JSON;

public class Sample {
    /**
     * <b>description</b> :
     * <p>Use your AccessKey ID and AccessKey secret to initialize the client.</p>
     * @return Client
     *
     * @throws Exception
     */
    public static com.aliyun.foasconsole20211028.Client createClient() throws Exception {
        // If the project code is leaked, the AccessKey pair may be leaked and the security of all resources within your account may be compromised. The following sample code is provided for reference only. 
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured in the code runtime environment. 
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured in the code runtime environment. 
                .setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        config.endpoint = "foasconsole.aliyuncs.com";
        return new com.aliyun.foasconsole20211028.Client(config);
    }

    public static void main(String[] args_) throws Exception {
        com.aliyun.foasconsole20211028.Client client = Sample.createClient();
        com.aliyun.foasconsole20211028.models.DescribeInstancesRequest describeInstancesRequest = new com.aliyun.foasconsole20211028.models.DescribeInstancesRequest()
                .setRegion("cn-beijing");
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            DescribeInstancesResponse response = client.describeInstancesWithOptions(describeInstancesRequest, runtime);
            System.out.println(response.statusCode);
            // Query the region ID of a workspace.
            System.out.println(response.getBody().getInstances().get(0).zoneId);
            // Query the resource group ID of a workspace.
            System.out.println(response.getBody().getInstances().get(0).resourceGroupId);
            System.out.println(JSON.toJSON(response));

        } catch (TeaException error) {
            // Handle exceptions with caution in actual business scenarios and never ignore exceptions in your project. In this example, error messages are displayed for reference only. 
            // The error message.
            System.out.println(error.getMessage());
            // The URL of the corresponding error diagnostics page.
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // Handle exceptions with caution in actual business scenarios and never ignore exceptions in your project. In this example, error messages are displayed for reference only. 
            // The error message.
            System.out.println(error.getMessage());
            // The URL of the corresponding error diagnostics page.
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
    }
}

Create a deployment

SQL deployment

You can create an SQL deployment. Required request parameters:

  • workspace: the ID of the workspace. You can call the DescribeInstances operation and obtain the workspace ID from the ResourceId parameter in the response. Example: adf9e514****.

  • namespace: the name of the namespace. Example: test-default.

  • body.name: the name of the deployment. Example: mysql_data_holo_test.

  • body.engineVersion: the engine version. Example: vvr-8.0.7-flink-1.17. You can call the ListEngineVersionMetadata operation to query the supported engine versions.

  • body.sqlArtifact.sqlScript: the text content of the SQL deployment. Example: CREATE TEMPORARY TABLE datagen_source( name VARCHAR ) WITH ( 'connector' = 'datagen' ); CREATE TEMPORARY TABLE blackhole_sink( name VARCHAR ) with ( 'connector' = 'blackhole' ); INSERT INTO blackhole_sink SELECT name from datagen_source;.

  • body.sqlArtifact.kind: the deployment type. Example: SQLSCRIPT.

  • body.deploymentTarget.mode: the deployment mode. Set the value to PER_JOB.

  • body.deploymentTarget.name: the queue of the deployment. Example: default-queue.

  • body.executionMode: the execution mode. Example: STREAMING.

  • body.streamingResourceSetting.resourceSettingMode: the resource configuration mode used for the streaming mode. Example: BASIC.

  • body.streamingResourceSetting.basicResourceSetting.jobmanagerResourceSettingSpec.cpu: the number of CPU cores of the JobManager. Example: 2.

  • body.streamingResourceSetting.basicResourceSetting.jobmanagerResourceSettingSpec.memory: the memory of the JobManager. Example: 4.0 GiB.

  • body.streamingResourceSetting.basicResourceSetting.taskmanagerResourceSettingSpec.cpu: the number of CPU cores of the TaskManager. Example: 2.

  • body.streamingResourceSetting.basicResourceSetting.taskmanagerResourceSettingSpec.memory: the memory of the TaskManager. Example: 4.0 GiB.

package com.aliyun.sample;
import com.aliyun.tea.*;

public class Sample {

    /**
     * <b>description</b> :
     * <p>Use your AccessKey ID and AccessKey secret to initialize the client.</p>
     * @return Client
     *
     * @throws Exception
     */
    public static com.aliyun.teaopenapi.Client createClient() throws Exception {
        // If the project code is leaked, the AccessKey pair may be leaked and the security of all resources within your account may be compromised. The following sample code is provided for reference only. 
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured in the code runtime environment. 
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured in the code runtime environment. 
                .setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        config.endpoint = "ververica.cn-beijing.aliyuncs.com";
        return new com.aliyun.teaopenapi.Client(config);
    }

    /**
     * <b>description</b> :
     * <p>Operation-specific parameters</p>
     *
     * @param path params
     * @return OpenApi.Params
     */
    public static com.aliyun.teaopenapi.models.Params createApiInfo(String namespace) throws Exception {
        com.aliyun.teaopenapi.models.Params params = new com.aliyun.teaopenapi.models.Params()
                // The operation that you want to perform.
                .setAction("CreateDeployment")
                // The version number of the operation.
                .setVersion("2022-07-18")
                // The protocol of the operation.
                .setProtocol("HTTPS")
                // The HTTP method of the operation.
                .setMethod("POST")
                .setAuthType("AK")
                .setStyle("ROA")
                // The URL of the operation.
                .setPathname("/api/v2/namespaces/" + namespace + "/deployments")
                // The format of the request body.
                .setReqBodyType("json")
                // The format of the response body.
                .setBodyType("json");
        return params;
    }

    public static void main(String[] args_) throws Exception {
        java.util.List<String> args = java.util.Arrays.asList(args_);
        com.aliyun.teaopenapi.Client client = Sample.createClient();
        com.aliyun.teaopenapi.models.Params params = Sample.createApiInfo("test-default");
        // body params
        java.util.Map<String, Object> body = TeaConverter.buildMap(
                new TeaPair("name", "mysql_data_holo_test"),
                new TeaPair("engineVersion", "vvr-8.0.7-flink-1.17"),
                new TeaPair("artifact", TeaConverter.buildMap(
                        new TeaPair("sqlArtifact", TeaConverter.buildMap(
                                new TeaPair("sqlScript", "CREATE TEMPORARY TABLE datagen_source(   name VARCHAR ) WITH (   'connector' = 'datagen' ); CREATE TEMPORARY TABLE blackhole_sink(   name  VARCHAR ) with (   'connector' = 'blackhole' ); INSERT INTO blackhole_sink SELECT name from datagen_source;")
                        )),
                        new TeaPair("kind", "SQLSCRIPT")
                )),
                new TeaPair("deploymentTarget", TeaConverter.buildMap(
                        new TeaPair("mode", "PER_JOB"),
                        new TeaPair("name", "default-queue")
                )),
                new TeaPair("executionMode", "STREAMING"),
                new TeaPair("streamingResourceSetting", TeaConverter.buildMap(
                        new TeaPair("resourceSettingMode", "BASIC"),
                        new TeaPair("basicResourceSetting", TeaConverter.buildMap(
                                new TeaPair("jobmanagerResourceSettingSpec", TeaConverter.buildMap(
                                        new TeaPair("cpu", 2),
                                        new TeaPair("memory", "4")
                                )),
                                new TeaPair("taskmanagerResourceSettingSpec", TeaConverter.buildMap(
                                        new TeaPair("cpu", 2),
                                        new TeaPair("memory", "4")
                                ))
                        ))
                ))
        );
        // header params
        java.util.Map<String, String> headers = new java.util.HashMap<>();
        headers.put("workspace", "ab2*******884d");
        // runtime options
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        com.aliyun.teaopenapi.models.OpenApiRequest request = new com.aliyun.teaopenapi.models.OpenApiRequest()
                .setHeaders(headers)
                .setBody(body);
        // The return value is of the Map type. The return value contains the following types of data: response body, response headers, and HTTP status code. 
        client.callApi(params, request, runtime);
        java.util.Map<String, ?> response = client.callApi(params, request, runtime);
        System.out.println(response);
    }
}

JAR deployment

You can create a JAR deployment. Required request parameters:

Note
  • Make sure that a JAR package is uploaded to an Object Storage Service (OSS) bucket and you have the permissions to access the Realtime Compute for Apache Flink workspace. For more information, see Simple upload.

  • The OSS URL of the JAR package is https://<Bucket>.oss-<Region>.aliyuncs.com/<FileName>.

  • workspace: the ID of the workspace. You can call the DescribeInstances operation and obtain the workspace ID from the ResourceId parameter in the response. Example: adf9e514****.

  • namespace: the name of the namespace. Example: test-default.

  • body.name: the name of the deployment. Example: my-test-jar.

  • body.engineVersion: the engine version. Example: vvr-8.0.7-flink-1.17. You can call the ListEngineVersionMetadata operation to query the supported engine versions.

  • body.jarArtifact.kind: the deployment type. Example: JAR.

  • body.jarArtifact.jarUri: the OSS URL of the JAR package. Example: https://myBucket/oss-cn-hangzhou/test.jar.

  • body.jarArtifact.entryClass: the full name of the entry point class. Example: org.apache.flink.test.

  • body.deploymentTarget.mode: the deployment mode. Set the value to PER_JOB.

  • body.deploymentTarget.name: the queue of the deployment. Example: default-queue.

  • body.executionMode: the execution mode. Example: STREAMING.

  • body.streamingResourceSetting.resourceSettingMode: the resource configuration mode used for the streaming mode. Example: BASIC.

  • body.streamingResourceSetting.basicResourceSetting.jobmanagerResourceSettingSpec.cpu: the number of CPU cores of the JobManager. Example: 2.

  • body.streamingResourceSetting.basicResourceSetting.jobmanagerResourceSettingSpec.memory: the memory of the JobManager. Example: 4.0 GiB.

  • body.streamingResourceSetting.basicResourceSetting.taskmanagerResourceSettingSpec.cpu: the number of CPU cores of the TaskManager. Example: 2.

  • body.streamingResourceSetting.basicResourceSetting.taskmanagerResourceSettingSpec.memory: the memory of the TaskManager. Example: 4.0 GiB.

package com.aliyun.sample;
import com.aliyun.tea.*;

public class Sample {

    /**
     * <b>description</b> :
     * <p>Use your AccessKey ID and AccessKey secret to initialize the client.</p>
     * @return Client
     *
     * @throws Exception
     */
    public static com.aliyun.teaopenapi.Client createClient() throws Exception {
        // If the project code is leaked, the AccessKey pair may be leaked and the security of all resources within your account may be compromised. The following sample code is provided for reference only. 
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured in the code runtime environment. 
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured in the code runtime environment. 
                .setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        config.endpoint = "ververica.cn-hangzhou.aliyuncs.com";
        return new com.aliyun.teaopenapi.Client(config);
    }

    /**
     * <b>description</b> :
     * <p>Operation-specific parameters</p>
     *
     * @param path params
     * @return OpenApi.Params
     */
    public static com.aliyun.teaopenapi.models.Params createApiInfo(String namespace) throws Exception {
        com.aliyun.teaopenapi.models.Params params = new com.aliyun.teaopenapi.models.Params()
                // The operation that you want to perform.
                .setAction("CreateDeployment")
                // The version number of the operation.
                .setVersion("2022-07-18")
                // The protocol of the operation.
                .setProtocol("HTTPS")
                // The HTTP method of the operation.
                .setMethod("POST")
                .setAuthType("AK")
                .setStyle("ROA")
                // The URL of the operation.
                .setPathname("/api/v2/namespaces/" + namespace + "/deployments")
                // The format of the request body.
                .setReqBodyType("json")
                // The format of the response body.
                .setBodyType("json");
        return params;
    }

    public static void main(String[] args_) throws Exception {
        java.util.List<String> args = java.util.Arrays.asList(args_);
        com.aliyun.teaopenapi.Client client = Sample.createClient();
        com.aliyun.teaopenapi.models.Params params = Sample.createApiInfo("flink-default");
        // body params
        java.util.Map<String, Object> body = TeaConverter.buildMap(
                new TeaPair("name", "my-test-jar"),
                new TeaPair("engineVersion", "vvr-8.0.7-flink-1.17"),
                new TeaPair("artifact", TeaConverter.buildMap(
                        new TeaPair("kind", "JAR"),
                        new TeaPair("jarArtifact", TeaConverter.buildMap(
                                new TeaPair("jarUri", "https://flink-test.oss-cn-hangzhou.aliyuncs.com/flinkDemo.jar?*****"),
                                new TeaPair("entryClass", "com.aliyun.FlinkDemo")
                        ))
                )),
                new TeaPair("deploymentTarget", TeaConverter.buildMap(
                        new TeaPair("mode", "PER_JOB"),
                        new TeaPair("name", "default-queue")
                )),
                new TeaPair("executionMode", "STREAMING"),
                new TeaPair("streamingResourceSetting", TeaConverter.buildMap(
                        new TeaPair("resourceSettingMode", "BASIC"),
                        new TeaPair("basicResourceSetting", TeaConverter.buildMap(
                                new TeaPair("jobmanagerResourceSettingSpec", TeaConverter.buildMap(
                                        new TeaPair("cpu", 2),
                                        new TeaPair("memory", "4")
                                )),
                                new TeaPair("taskmanagerResourceSettingSpec", TeaConverter.buildMap(
                                        new TeaPair("cpu", 2),
                                        new TeaPair("memory", "4")
                                ))
                        ))
                ))
        );
        // header params
        java.util.Map<String, String> headers = new java.util.HashMap<>();
        headers.put("workspace", "d05a*****e44");
        // runtime options
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        com.aliyun.teaopenapi.models.OpenApiRequest request = new com.aliyun.teaopenapi.models.OpenApiRequest()
                .setHeaders(headers)
                .setBody(body);
        // The return value is of the Map type. The return value contains the following types of data: response body, response headers, and HTTP status code. 
        java.util.Map<String, ?> response = client.callApi(params, request, runtime);
        System.out.println(response);
    }
}

Query a list of deployments

You can query the information about all deployments in a namespace. Required request parameters:

  • workspace: the ID of the workspace. You can call the DescribeInstances operation and obtain the workspace ID from the ResourceId parameter in the response. Example: adf9e514****.

  • namespace: the name of the namespace. Example: test-default.

package com.sample;
import com.aliyun.tea.*;
import com.alibaba.fastjson2.JSON;
import com.aliyun.ververica20220718.models.ListDeploymentsResponse;

public class Sample {
    /**
     * <b>description</b> :
     * <p>Use your AccessKey ID and AccessKey secret to initialize the client.</p>
     * @return Client
     *
     * @throws Exception
     */
    public static com.aliyun.ververica20220718.Client createClient() throws Exception {
        // If the project code is leaked, the AccessKey pair may be leaked and the security of all resources within your account may be compromised. The following sample code is provided for reference only. 
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured in the code runtime environment. 
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured in the code runtime environment. 
                .setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        config.endpoint = "ververica.cn-hangzhou.aliyuncs.com";
        return new com.aliyun.ververica20220718.Client(config);
    }

    public static void main(String[] args_) throws Exception {
        com.aliyun.ververica20220718.Client client = Sample.createClient();
        com.aliyun.ververica20220718.models.ListDeploymentsHeaders listDeploymentsHeaders = new com.aliyun.ververica20220718.models.ListDeploymentsHeaders()
                .setWorkspace("ab2a******884d");
        com.aliyun.ververica20220718.models.ListDeploymentsRequest listDeploymentsRequest = new com.aliyun.ververica20220718.models.ListDeploymentsRequest();
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            ListDeploymentsResponse response=client.listDeploymentsWithOptions("test-default", listDeploymentsRequest, listDeploymentsHeaders, runtime);
            System.out.println(response.body.data.get(0).name);
            System.out.println(response.body.data.get(0).deploymentId);
            System.out.println(JSON.toJSON(response));
        } catch (TeaException error) {
            // Handle exceptions with caution in actual business scenarios and never ignore exceptions in your project. In this example, error messages are displayed for reference only. 
            // The error message.
            System.out.println(error.getMessage());
            // The URL of the corresponding error diagnostics page.
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // Handle exceptions with caution in actual business scenarios and never ignore exceptions in your project. In this example, error messages are displayed for reference only. 
            // The error message.
            System.out.println(error.getMessage());
            // The URL of the corresponding error diagnostics page.
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
    }
}

Start a deployment

You can start a deployment in a namespace. Required request parameters:

  • workspace: the ID of the workspace. Example: adf9e5147a****.

  • namespace: the name of the namespace. Example: test-default.

  • deploymentId: the ID of the deployment. You can call the ListDeployments operation to query the deployment ID. Example: 10283a02-c6a6-4f3e-9f93-8dab****.

  • kind: the type of the start offset. Valid values: NONE, LATEST_SAVEPOINT, FROM_SAVEPOINT, and LATEST_STATE.

package com.aliyun.sample;
import com.aliyun.tea.*;
import com.aliyun.ververica20220718.models.StartJobWithParamsResponse;
import com.alibaba.fastjson2.JSON;

public class Sample {

    /**
     * <b>description</b> :
     * <p>Use your AccessKey ID and AccessKey secret to initialize the client.</p>
     * @return Client
     *
     * @throws Exception
     */
    public static com.aliyun.ververica20220718.Client createClient() throws Exception {
        // If the project code is leaked, the AccessKey pair may be leaked and the security of all resources within your account may be compromised. The following sample code is provided for reference only. 
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured in the code runtime environment. 
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured in the code runtime environment. 
                .setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        config.endpoint = "ververica.cn-hangzhou.aliyuncs.com";
        return new com.aliyun.ververica20220718.Client(config);
    }

    public static void main(String[] args_) throws Exception {
        com.aliyun.ververica20220718.Client client = Sample.createClient();
        com.aliyun.ververica20220718.models.StartJobWithParamsHeaders startJobWithParamsHeaders = new com.aliyun.ververica20220718.models.StartJobWithParamsHeaders()
                .setWorkspace("ab2a******884d");
        com.aliyun.ververica20220718.models.DeploymentRestoreStrategy jobStartParametersDeploymentRestoreStrategy = new com.aliyun.ververica20220718.models.DeploymentRestoreStrategy()
                .setKind("NONE");
        com.aliyun.ververica20220718.models.JobStartParameters jobStartParameters = new com.aliyun.ververica20220718.models.JobStartParameters()
                .setRestoreStrategy(jobStartParametersDeploymentRestoreStrategy)
                .setDeploymentId("10283a02-****-****-****-8dabf617d52f");
        com.aliyun.ververica20220718.models.StartJobWithParamsRequest startJobWithParamsRequest = new com.aliyun.ververica20220718.models.StartJobWithParamsRequest()
                .setBody(jobStartParameters);
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            StartJobWithParamsResponse response = client.startJobWithParamsWithOptions("test-default", startJobWithParamsRequest, startJobWithParamsHeaders, runtime);
            System.out.println(JSON.toJSON(response.body));
        } catch (TeaException error) {
            // Handle exceptions with caution in actual business scenarios and never ignore exceptions in your project. In this example, error messages are displayed for reference only. 
            // The error message.
            System.out.println(error.getMessage());
            // The URL of the corresponding error diagnostics page.
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // Handle exceptions with caution in actual business scenarios and never ignore exceptions in your project. In this example, error messages are displayed for reference only. 
            // The error message.
            System.out.println(error.getMessage());
            // The URL of the corresponding error diagnostics page.
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
    }
}

Query the information about a deployment

You can query the information about all jobs in a deployment. Required request parameters:

  • workspace: the ID of the workspace. Example: adf9e5147****.

  • namespace: the name of the namespace. Example: test-default.

  • deploymentId: the ID of the deployment. You can call the ListDeployments operation to query the deployment ID. Example: 8489b7ec-****-****-****-cc4c17fa12b0.

package com.aliyun.sample;
import com.aliyun.tea.*;
import com.aliyun.ververica20220718.models.ListJobsResponse;
import com.alibaba.fastjson2.JSON;

public class Sample {

    /**
     * <b>description</b> :
     * <p>Use your AccessKey ID and AccessKey secret to initialize the client.</p>
     * @return Client
     *
     * @throws Exception
     */
    public static com.aliyun.ververica20220718.Client createClient() throws Exception {
        // If the project code is leaked, the AccessKey pair may be leaked and the security of all resources within your account may be compromised. The following sample code is provided for reference only. 
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured in the code runtime environment. 
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured in the code runtime environment. 
                .setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        config.endpoint = "ververica.cn-beijing.aliyuncs.com";
        return new com.aliyun.ververica20220718.Client(config);
    }

    public static void main(String[] args_) throws Exception {
        com.aliyun.ververica20220718.Client client = Sample.createClient();
        com.aliyun.ververica20220718.models.ListJobsHeaders listJobsHeaders = new com.aliyun.ververica20220718.models.ListJobsHeaders()
                .setWorkspace("ab2a******884d");
        com.aliyun.ververica20220718.models.ListJobsRequest listJobsRequest = new com.aliyun.ververica20220718.models.ListJobsRequest()
                .setDeploymentId("8489b7ec-****-****-****-cc4c17fa12b0");
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            ListJobsResponse response =  client.listJobsWithOptions("test-default", listJobsRequest, listJobsHeaders, runtime);
            // View the execution results of the deployment.
            System.out.println("Execution result is:"+ response.body.success);
            // Obtain the job ID. This parameter is used to cancel a job.
            System.out.println(response.body.getData().get(0).jobId);
            System.out.println(JSON.toJSON(response));
        } catch (TeaException error) {
            // Handle exceptions with caution in actual business scenarios and never ignore exceptions in your project. In this example, error messages are displayed for reference only. 
            // The error message.
            System.out.println(error.getMessage());
            // The URL of the corresponding error diagnostics page.
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // Handle exceptions with caution in actual business scenarios and never ignore exceptions in your project. In this example, error messages are displayed for reference only. 
            // The error message.
            System.out.println(error.getMessage());
            // The URL of the corresponding error diagnostics page.
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
    }
}

Cancel a job

You can cancel a job in a deployment. Required request parameters:

  • workspace: the ID of the workspace. Example: adf9e5147****.

  • namespace: the name of the namespace. Example: test-default.

  • jobId: the job ID. You can call the ListJobs operation to query the job ID. Example: 3171d4d1-****-****-****-e762493b7765.

  • stopStrategy: the strategy that is used to cancel the job. Valid values: NONE, STOP_WITH_SAVEPOINT, and STOP_WITH_DRAIN.

package com.aliyun.sample;
import com.alibaba.fastjson2.JSON;
import com.aliyun.tea.*;
import com.aliyun.ververica20220718.models.StopJobResponse;

public class Sample {

    /**
     * <b>description</b> :
     * <p>Use your AccessKey ID and AccessKey secret to initialize the client.</p>
     * @return Client
     *
     * @throws Exception
     */
    public static com.aliyun.ververica20220718.Client createClient() throws Exception {
        // If the project code is leaked, the AccessKey pair may be leaked and the security of all resources within your account may be compromised. The following sample code is provided for reference only. 
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured in the code runtime environment. 
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured in the code runtime environment. 
                .setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        config.endpoint = "ververica.cn-hangzhou.aliyuncs.com";
        return new com.aliyun.ververica20220718.Client(config);
    }

    public static void main(String[] args_) throws Exception {
        java.util.List<String> args = java.util.Arrays.asList(args_);
        com.aliyun.ververica20220718.Client client = Sample.createClient();
        com.aliyun.ververica20220718.models.StopJobHeaders stopJobHeaders = new com.aliyun.ververica20220718.models.StopJobHeaders()
                .setWorkspace("ab2a******884d");
        com.aliyun.ververica20220718.models.StopJobRequestBody stopJobRequestBody = new com.aliyun.ververica20220718.models.StopJobRequestBody()
                .setStopStrategy("NONE");
        com.aliyun.ververica20220718.models.StopJobRequest stopJobRequest = new com.aliyun.ververica20220718.models.StopJobRequest()
                .setBody(stopJobRequestBody);
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            StopJobResponse response = client.stopJobWithOptions("test-default", "7970e881-****-****-****-1a3746710878", stopJobRequest, stopJobHeaders, runtime);
            System.out.println(JSON.toJSON(response.getBody().getData()));
        } catch (TeaException error) {
            // Handle exceptions with caution in actual business scenarios and never ignore exceptions in your project. In this example, error messages are displayed for reference only. 
            // The error message.
            System.out.println(error.getMessage());
            // The URL of the corresponding error diagnostics page.
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // Handle exceptions with caution in actual business scenarios and never ignore exceptions in your project. In this example, error messages are displayed for reference only. 
            // The error message.
            System.out.println(error.getMessage());
            // The URL of the corresponding error diagnostics page.
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
    }
}

References

For more information about Realtime Compute for Apache Flink SDK for Python, see Flink SDK for Python.