All Products
Search
Document Center

Realtime Compute for Apache Flink:Flink Java SDK

Last Updated:Jun 21, 2026

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

Usage notes

From September 19 to October 27, 2022, Alibaba Cloud rolled out an update to the SDK for Realtime Compute for Apache Flink across all regions. This new version is now the default.

Note
  • For information about the impact of the SDK update, see Service notices.

  • This document describes the new SDK version. To view the documentation for the previous version, click OpenAPI SDK (Deprecated).

Prerequisites

Realtime compute for Apache Flink Java SDKs

Selling console

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'

Development console

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'

Debug online and generate SDK examples

You can use OpenAPI Explorer to call API operations online, dynamically generate SDK sample code, and quickly search for API operations. You can view and download SDK sample code for API operations on the Realtime Compute for Apache Flink and Realtime Compute Selling Console pages. For more information, see Quick Start.

On the SDK Example tab, select a language, such as Java, click Run Example to run the code online, or click Download Complete Project to download the sample code.

Examples

Note
  • For the endpoints of the Realtime Compute for Apache Flink selling console, see Endpoints.

  • For the endpoints of the Realtime Compute for Apache Flink development console, see Endpoints.

Purchased workspaces

This example shows how to retrieve details about purchased Realtime Compute for Apache Flink workspaces in a specified region.

Region: The ID of the region. For more information, see Endpoints. For 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 {
        // Hard-coding the AccessKey pair in your code may cause the AccessKey pair to be leaked and threaten the security of all the resources in your account. The following sample code is 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 set in your runtime environment.
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set in your 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 an instance.
            System.out.println(response.getBody().getInstances().get(0).zoneId);
            // Query the ID of the resource group to which an instance belongs.
            System.out.println(response.getBody().getInstances().get(0).resourceGroupId);
            System.out.println(JSON.toJSON(response));
        } catch (TeaException error) {
            // In this example, the error message is printed for reference only. We recommend that you handle exceptions with caution in your project and do not ignore them.
            // Error message
            System.out.println(error.getMessage());
            // Diagnostic address
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // In this example, the error message is printed for reference only. We recommend that you handle exceptions with caution in your project and do not ignore them.
            // Error message
            System.out.println(error.getMessage());
            // Diagnostic address
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
    }
}

Create a deployment

SQL deployment

This example shows how to create an SQL deployment.

  • workspace: The ID of the workspace. You can obtain this ID from the ResourceId that is returned when you view purchased workspaces. For example, adf9e514****.

  • namespace: The name of the namespace. For example, test-default.

  • body.name: The name of the job. For example, mysql_data_holo_test.

  • body.engineVersion: The engine version. For example, vvr-8.0.7-flink-1.17. You can obtain the supported engine versions by listing the supported engine versions.

  • body.sqlArtifact.sqlScript: The content of the SQL script. 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 type of the job. For example, SQLSCRIPT.

  • body.deploymentTarget.mode: The deployment mode. Only the PER_JOB mode is supported.

  • body.deploymentTarget.name: The name of the deployment queue. For example, default-queue.

  • body.executionMode: execution mode. For example, STREAMING (streaming mode).

  • body.streamingResourceSetting.resourceSettingMode: The resource mode for the streaming mode. For example, BASIC.

  • body.streamingResourceSetting.basicResourceSetting.jobmanagerResourceSettingSpec.cpu: The number of CPU cores for the JobManager. For example, 2.

  • body.streamingResourceSetting.basicResourceSetting.jobmanagerResourceSettingSpec.memory: JobManager memory. For example, 4.0 GiB.

  • body.streamingResourceSetting.basicResourceSetting.taskmanagerResourceSettingSpec.cpu: The number of TaskManager CPU cores. For example, 2.

  • body.streamingResourceSetting.basicResourceSetting.taskmanagerResourceSettingSpec.memory: TaskManager memory. For 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 {
        // Hard-coding the AccessKey pair in your code may cause the AccessKey pair to be leaked and threaten the security of all the resources in your account. The following sample code is 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 set in your runtime environment.
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set in your 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>API 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 name of the API operation.
                .setAction("CreateDeployment")
                // The version of the API operation.
                .setVersion("2022-07-18")
                // The protocol of the API operation.
                .setProtocol("HTTPS")
                // The HTTP method of the API operation.
                .setMethod("POST")
                .setAuthType("AK")
                .setStyle("ROA")
                // The request path of the API 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 method returns a Map. You can obtain the response body, response headers, and HTTP status code from the map.
        client.callApi(params, request, runtime);
        java.util.Map<String, ?> response = client.callApi(params, request, runtime);
        System.out.println(response);
    }
}

JAR deployment

This example shows how to create a JAR deployment.

Note
  • Upload the JAR package to an OSS bucket and ensure that your Realtime Compute for Apache Flink workspace has permission to access it. For more information, see Simple upload.

  • After the file is uploaded, the download URL is in the format of https://<Bucket>.oss-<Region>.aliyuncs.com/<FileName>.

  • workspace: The ID of the workspace. You can obtain this ID from the ResourceId that is returned when you view purchased workspaces. For example, adf9e514****.

  • namespace: The name of the namespace. For example, test-default.

  • body.name: The job name. For example, my-test-jar.

  • body.engineVersion: The engine version. For example, vvr-8.0.7-flink-1.17. You can obtain a list of supported engine versions.

  • body.jarArtifact.kind: The type of the job artifact. For example, JAR.

  • body.jarArtifact.jarUri: The full URL path of the JAR deployment. For example, https://myBucket/oss-cn-hangzhou/test.jar.

  • body.jarArtifact.entryClass: The entry point class. You must specify the fully qualified class name. For example, org.apache.flink.test.

  • body.deploymentTarget.mode: Deployment mode. Only the PER_JOB mode is supported.

  • body.deploymentTarget.name: The name of the deployment queue. For example, default-queue.

  • body.executionMode: Execution mode. For example, STREAMING (streaming mode).

  • body.streamingResourceSetting.resourceSettingMode: The resource mode for the streaming mode. For example, BASIC.

  • body.streamingResourceSetting.basicResourceSetting.jobmanagerResourceSettingSpec.cpu: The number of CPU cores for the JobManager. For example, 2.

  • body.streamingResourceSetting.basicResourceSetting.jobmanagerResourceSettingSpec.memory: JobManager memory. For example, 4.0 GiB.

  • body.streamingResourceSetting.basicResourceSetting.taskmanagerResourceSettingSpec.cpu: The number of CPU cores for the TM. For example, 2.

  • body.streamingResourceSetting.basicResourceSetting.taskmanagerResourceSettingSpec.memory: The memory of the TaskManager. For 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 {
        // Hard-coding the AccessKey pair in your code may cause the AccessKey pair to be leaked and threaten the security of all the resources in your account. The following sample code is 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 set in your runtime environment.
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set in your 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>API 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 name of the API operation.
                .setAction("CreateDeployment")
                // The version of the API operation.
                .setVersion("2022-07-18")
                // The protocol of the API operation.
                .setProtocol("HTTPS")
                // The HTTP method of the API operation.
                .setMethod("POST")
                .setAuthType("AK")
                .setStyle("ROA")
                // The request path of the API 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 method returns a Map. You can obtain the response body, response headers, and HTTP status code from the map.
        java.util.Map<String, ?> response = client.callApi(params, request, runtime);
        System.out.println(response);
    }
}

List deployments

This example shows how to list all deployments in a namespace.

  • workspace: The ID of the workspace. You can obtain the ID from the ResourceId that is returned by the operation in View purchased workspaces. For example, adf9e514****.

  • namespace: The name of the namespace. For 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 {
        // Hard-coding the AccessKey pair in your code may cause the AccessKey pair to be leaked and threaten the security of all the resources in your account. The following sample code is 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 set in your runtime environment.
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set in your 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) {
            // In this example, the error message is printed for reference only. We recommend that you handle exceptions with caution in your project and do not ignore them.
            // Error message
            System.out.println(error.getMessage());
            // Diagnostic address
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // In this example, the error message is printed for reference only. We recommend that you handle exceptions with caution in your project and do not ignore them.
            // Error message
            System.out.println(error.getMessage());
            // Diagnostic address
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
    }
}

Start a job

This example shows how to start a job from a deployment in a namespace.

  • workspace: The workspace ID. For example, adf9e5147a****.

  • namespace: The name of the namespace, such as test-default.

  • deploymentId: The ID of the deployment. You can obtain this ID by calling the List deployments operation. For example, 10283a02-c6a6-4f3e-9f93-8dab****.

  • kind: The type of the restore strategy. Supported values are NONE (stateless start), LATEST_SAVEPOINT (start from the latest savepoint), FROM_SAVEPOINT (start from a specified savepoint), and LATEST_STATE (start from the 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 {
        // Hard-coding the AccessKey pair in your code may cause the AccessKey pair to be leaked and threaten the security of all the resources in your account. The following sample code is 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 set in your runtime environment.
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set in your 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) {
            // In this example, the error message is printed for reference only. We recommend that you handle exceptions with caution in your project and do not ignore them.
            // Error message
            System.out.println(error.getMessage());
            // Diagnostic address
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // In this example, the error message is printed for reference only. We recommend that you handle exceptions with caution in your project and do not ignore them.
            // Error message
            System.out.println(error.getMessage());
            // Diagnostic address
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
    }
}

List jobs

This example shows how to query all jobs for a specific deployment.

  • workspace: The workspace ID. For example, adf9e5147****.

  • namespace: The name of the namespace, for example, test-default.

  • deploymentId: The deployment ID. To obtain this ID, see Get the list of deployments. For 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 {
        // Hard-coding the AccessKey pair in your code may cause the AccessKey pair to be leaked and threaten the security of all the resources in your account. The following sample code is 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 set in your runtime environment.
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set in your 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 result of the job.
            System.out.println("Execution result is: "+response.body.success);
            // Obtain the job ID. This ID is used to cancel the job.
            System.out.println(response.body.getData().get(0).jobId);
            System.out.println(JSON.toJSON(response));
        } catch (TeaException error) {
            // In this example, the error message is printed for reference only. We recommend that you handle exceptions with caution in your project and do not ignore them.
            // Error message
            System.out.println(error.getMessage());
            // Diagnostic address
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // In this example, the error message is printed for reference only. We recommend that you handle exceptions with caution in your project and do not ignore them.
            // Error message
            System.out.println(error.getMessage());
            // Diagnostic address
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
    }
}

Stop a job

This example shows how to stop a job.

  • workspace: The workspace ID. For example, adf9e5147****.

  • namespace: The name of the namespace, for example, test-default.

  • jobId: The ID of the job. For more information, see Obtain information about a specific deployment. For example, 3171d4d1-****-****-****-e762493b7765.

  • stopStrategy: The job stop strategy. The supported values are NONE (stops the job directly), STOP_WITH_SAVEPOINT (stops the job after a savepoint is created), and STOP_WITH_DRAIN (stops the job in drain mode).

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 {
        // Hard-coding the AccessKey pair in your code may cause the AccessKey pair to be leaked and threaten the security of all the resources in your account. The following sample code is 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 set in your runtime environment.
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set in your 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) {
            // In this example, the error message is printed for reference only. We recommend that you handle exceptions with caution in your project and do not ignore them.
            // Error message
            System.out.println(error.getMessage());
            // Diagnostic address
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // In this example, the error message is printed for reference only. We recommend that you handle exceptions with caution in your project and do not ignore them.
            // Error message
            System.out.println(error.getMessage());
            // Diagnostic address
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
    }
}

References

For more information about the Python SDK, see the Python SDK reference.