Get started with the Java SDK for Realtime Compute for Apache Flink to install the SDK, initialize a client, and manage Flink job deployments programmatically.
Alibaba Cloud updated the SDKs for Realtime Compute for Apache Flink on September 19, 2022. The new SDK is now the default across all regions. This update was rolled out across all regions from September 19, 2022, to October 27, 2022. For the impact of this update, see Service notices. For the old SDK documentation, download the OpenAPI SDK (Discontinued).
Prerequisites
Before you begin, make sure you have:
-
An AccessKey pair. For more information, see Create an AccessKey pair. To avoid exposing your primary account credentials, create a Resource Access Management (RAM) user, grant it the required Flink permissions, and use its AccessKey pair instead. See Create a RAM user and Authorize in the management console.
-
Java 8 or later.
-
The required access permissions. See Permission management.
Set the following environment variables before running any code examples:
| Variable | Description |
|---|---|
ALIBABA_CLOUD_ACCESS_KEY_ID |
Your AccessKey ID |
ALIBABA_CLOUD_ACCESS_KEY_SECRET |
Your AccessKey secret |
Install the SDK
Realtime Compute for Apache Flink provides two Java SDKs. Install the one that matches your use case.OpenAPI Explorer
Selling console SDK (for workspace purchase and management)
Use this SDK to manage purchased workspaces (list instances, check quotas, etc.).
| Build tool | Dependency declaration |
|---|---|
| Apache Maven | <dependency><br> <groupId>com.aliyun</groupId><br> <artifactId>foasconsole20211028</artifactId><br> <version>2.1.0</version><br></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(<br> @Grab(group='com.aliyun', module='foasconsole20211028', version='2.1.0')<br>) |
| Leiningen | [com.aliyun/foasconsole20211028 "2.1.0"] |
| Apache Buildr | 'com.aliyun:foasconsole20211028:jar:2.1.0' |
Development console SDK (for job deployment and lifecycle management)
Use this SDK to create deployments, start and stop jobs, list deployments, and query job status.
| Build tool | Dependency declaration |
|---|---|
| Apache Maven | <dependency><br> <groupId>com.aliyun</groupId><br> <artifactId>ververica20220718</artifactId><br> <version>1.7.0</version><br></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(<br> @Grab(group='com.aliyun', module='ververica20220718', version='1.7.0')<br>) |
| Leiningen | [com.aliyun/ververica20220718 "1.7.0"] |
| Apache Buildr | 'com.aliyun:ververica20220718:jar:1.7.0' |
Try it in OpenAPI Explorer
OpenAPI Explorer lets you call API operations online and generate SDK sample code interactively. To browse and test API operations, see Realtime Compute for Apache Flink Development Console API and Realtime Compute for Apache Flink Selling Console API. For a quick walkthrough, see Quick start.
Examples
All examples read credentials from environment variables and call the SDK with explicit runtime options. For selling console endpoints, see OpenAPI Explorer (foasconsole). For development console endpoints, see OpenAPI Explorer (ververica).
List purchased workspaces
Query workspaces purchased in a specified region using the DescribeInstances operation.
Required parameters:
| Parameter | Description | Example |
|---|---|---|
Region. For more information, see Endpoints |
The region ID. See Endpoints. | cn-hangzhou |
package com.aliyun.sample;
import com.aliyun.foasconsole20211028.models.DescribeInstancesResponse;
import com.aliyun.tea.*;
import com.alibaba.fastjson2.JSON;
public class Sample {
/**
* description :
* <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 {
// Leaking project code can expose your AccessKey pair and compromise the security of all resources in your account. The following 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 execution 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 execution 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);
// View the region ID of an instance.
System.out.println(response.getBody().getInstances().get(0).zoneId);
// View the resource group ID of an instance.
System.out.println(response.getBody().getInstances().get(0).resourceGroupId);
System.out.println(JSON.toJSON(response));
} catch (TeaException error) {
// This code is for demonstration only. Handle exceptions with care. Do not ignore exceptions in your project.
// Error message
System.out.println(error.getMessage());
// Diagnosis 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);
// This code is for demonstration only. Handle exceptions with care. Do not ignore exceptions in your project.
// Error message
System.out.println(error.getMessage());
// Diagnosis address
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
}
}
}
Create a deployment
Use the CreateDeployment operation to create a deployment. The workspace header value comes from the ResourceId field in the response from List purchased workspaces.
SQL job
Required parameters:
| Parameter | Description | Example |
|---|---|---|
workspace (header) |
Workspace ID, from ResourceId in the list workspaces response |
adf9e514**** |
namespace |
Project name | test-default |
body.name |
Job name | mysql_data_holo_test |
body.engineVersion |
Engine version. To get valid values, call ListEngineVersionMetadata. | vvr-8.0.7-flink-1.17 |
body.sqlArtifact.sqlScript |
SQL script for the job | CREATE TEMPORARY TABLE datagen_source... |
body.sqlArtifact.kind |
Job type | SQLSCRIPT |
body.deploymentTarget.mode |
Deployment mode. Only PER_JOB is supported. |
PER_JOB |
body.deploymentTarget.name |
Deployment queue name | default-queue |
body.executionMode |
Execution mode | STREAMING |
body.streamingResourceSetting.resourceSettingMode |
Resource allocation mode | BASIC |
body.streamingResourceSetting.basicResourceSetting.jobmanagerResourceSettingSpec.cpu |
JobManager (JM) CPU cores | 2 |
body.streamingResourceSetting.basicResourceSetting.jobmanagerResourceSettingSpec.memory |
JM memory | 4.0 GiB |
body.streamingResourceSetting.basicResourceSetting.taskmanagerResourceSettingSpec.cpu |
TaskManager (TM) CPU cores | 2 |
body.streamingResourceSetting.basicResourceSetting.taskmanagerResourceSettingSpec.memory |
TM memory | 4.0 GiB |
package com.aliyun.sample;
import com.aliyun.tea.*;
public class Sample {
/**
* description :
* <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 {
// Leaking project code can expose your AccessKey pair and compromise the security of all resources in your account. The following 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 execution 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 execution environment.
.setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
config.endpoint = "ververica.cn-beijing.aliyuncs.com";
return new com.aliyun.teaopenapi.Client(config);
}
/**
* description :
* <p>API-related</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()
// API operation name
.setAction("CreateDeployment")
// API operation version
.setVersion("2022-07-18")
// API operation protocol
.setProtocol("HTTPS")
// HTTP method
.setMethod("POST")
.setAuthType("AK")
.setStyle("ROA")
// API path
.setPathname("/api/v2/namespaces/" + namespace + "/deployments")
// Request body format
.setReqBodyType("json")
// Response body format
.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 a Map. You can get three types of data from the map: the response body, response headers, and the HTTP status code.
client.callApi(params, request, runtime);
java.util.Map<String, ?> response = client.callApi(params, request, runtime);
System.out.println(response);
}
}
JAR job
You can create and deploy a JAR deployment. The required request parameters are as follows.
Before creating a JAR deployment, upload the JAR package to an OSS bucket and grant the Flink workspace access to it. See Simple upload to OSS. The download URL follows the format https://<Bucket>.oss-<Region>.aliyuncs.com/<FileName>.
Required parameters:
| Parameter | Description | Example |
|---|---|---|
workspace (header) |
Workspace ID, from ResourceId in the list workspaces response |
adf9e514**** |
namespace |
Project name | test-default |
body.name |
Job name | my-test-jar |
body.engineVersion |
Engine version. To get valid values, call ListEngineVersionMetadata. | vvr-8.0.7-flink-1.17 |
body.jarArtifact.kind |
Job type | JAR |
body.jarArtifact.jarUri |
Full URL of the JAR file in OSS | https://myBucket/oss-cn-hangzhou/test.jar |
body.jarArtifact.entryClass |
Fully qualified entry class name | org.apache.flink.test |
body.deploymentTarget.mode |
Deployment mode. Only PER_JOB is supported. |
PER_JOB |
body.deploymentTarget.name |
Deployment queue name | default-queue |
body.executionMode |
Execution mode | STREAMING |
body.streamingResourceSetting.resourceSettingMode |
Resource allocation mode | BASIC |
body.streamingResourceSetting.basicResourceSetting.jobmanagerResourceSettingSpec.cpu |
JM CPU cores | 2 |
body.streamingResourceSetting.basicResourceSetting.jobmanagerResourceSettingSpec.memory |
JM memory | 4.0 GiB |
body.streamingResourceSetting.basicResourceSetting.taskmanagerResourceSettingSpec.cpu |
TM CPU cores | 2 |
body.streamingResourceSetting.basicResourceSetting.taskmanagerResourceSettingSpec.memory |
TM memory | 4.0 GiB |
package com.aliyun.sample;
import com.aliyun.tea.*;
public class Sample {
/**
* description :
* <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 {
// Leaking project code can expose your AccessKey pair and compromise the security of all resources in your account. The following 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 execution 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 execution environment.
.setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
config.endpoint = "ververica.cn-hangzhou.aliyuncs.com";
return new com.aliyun.teaopenapi.Client(config);
}
/**
* description :
* <p>API-related</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()
// API operation name
.setAction("CreateDeployment")
// API operation version
.setVersion("2022-07-18")
// API operation protocol
.setProtocol("HTTPS")
// HTTP method
.setMethod("POST")
.setAuthType("AK")
.setStyle("ROA")
// API path
.setPathname("/api/v2/namespaces/" + namespace + "/deployments")
// Request body format
.setReqBodyType("json")
// Response body format
.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 a Map. You can get three types of data from the map: the response body, response headers, and the HTTP status code.
java.util.Map<String, ?> response = client.callApi(params, request, runtime);
System.out.println(response);
}
}
List deployments
Retrieve all deployments in a namespace using the ListDeployments operation.
Required parameters:
| Parameter | Description | Example |
|---|---|---|
workspace (header) |
Workspace ID, from ResourceId in the list workspaces response |
adf9e514**** |
namespace |
Project name | test-default |
package com.sample;
import com.aliyun.tea.*;
import com.alibaba.fastjson2.JSON;
import com.aliyun.ververica20220718.models.ListDeploymentsResponse;
public class Sample {
/**
* description :
* <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 {
// Leaking project code can expose your AccessKey pair and compromise the security of all resources in your account. The following 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 execution 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 execution 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) {
// This code is for demonstration only. Handle exceptions with care. Do not ignore exceptions in your project.
// Error message
System.out.println(error.getMessage());
// Diagnosis 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);
// This code is for demonstration only. Handle exceptions with care. Do not ignore exceptions in your project.
// Error message
System.out.println(error.getMessage());
// Diagnosis address
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
}
}
}
Start a job
Start a deployed job using the StartJobWithParams operation. To get the deploymentId, call the ListDeployments operation.
Required parameters:
| Parameter | Description | Example |
|---|---|---|
workspace (header) |
Workspace ID | adf9e5147a**** |
namespace |
Project name | test-default |
deploymentId |
Deployment ID, from the list deployments response | 10283a02-c6a6-4f3e-9f93-8dab**** |
kind |
Start offset type. Valid values: NONE (stateless start), LATEST_SAVEPOINT (start from the latest job snapshot), FROM_SAVEPOINT (start from a specified snapshot), LATEST_STATE (start from the latest state) |
NONE |
package com.aliyun.sample;
import com.aliyun.tea.*;
import com.aliyun.ververica20220718.models.StartJobWithParamsResponse;
import com.alibaba.fastjson2.JSON;
public class Sample {
/**
* description :
* <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 {
// Leaking project code can expose your AccessKey pair and compromise the security of all resources in your account. The following 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 execution 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 execution 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) {
// This code is for demonstration only. Handle exceptions with care. Do not ignore exceptions in your project.
// Error message
System.out.println(error.getMessage());
// Diagnosis 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);
// This code is for demonstration only. Handle exceptions with care. Do not ignore exceptions in your project.
// Error message
System.out.println(error.getMessage());
// Diagnosis address
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
}
}
}
Get job instances
List all job instances in a deployment using the ListJobs operation. To get the deploymentId, call the ListDeployments operation. The response includes the jobId needed to stop a specific job instance.
Required parameters:
| Parameter | Description | Example |
|---|---|---|
workspace (header) |
Workspace ID | adf9e5147**** |
namespace |
Project name | test-default |
deploymentId |
Deployment ID, from the list deployments response | 8489b7ec-**--**-cc4c17fa12b0 |
package com.aliyun.sample;
import com.aliyun.tea.*;
import com.aliyun.ververica20220718.models.ListJobsResponse;
import com.alibaba.fastjson2.JSON;
public class Sample {
/**
* description :
* <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 {
// Leaking project code can expose your AccessKey pair and compromise the security of all resources in your account. The following 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 execution 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 execution 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 job execution result.
System.out.println("Execution result is: "+response.body.success);
// Get the job ID. This parameter is used to stop the job.
System.out.println(response.body.getData().get(0).jobId);
System.out.println(JSON.toJSON(response));
} catch (TeaException error) {
// This code is for demonstration only. Handle exceptions with care. Do not ignore exceptions in your project.
// Error message
System.out.println(error.getMessage());
// Diagnosis 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);
// This code is for demonstration only. Handle exceptions with care. Do not ignore exceptions in your project.
// Error message
System.out.println(error.getMessage());
// Diagnosis address
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
}
}
}
Stop a job instance
Stop a running job instance using the StopJob operation. To get the jobId, call the ListJobs operation.
Required parameters:
| Parameter | Description | Example |
|---|---|---|
workspace (header) |
Workspace ID | adf9e5147**** |
namespace |
Project name | test-default |
jobId |
Job instance ID, from the get job instances response | 3171d4d1-**--**-e762493b7765 |
stopStrategy |
Stop policy. Valid values: NONE (stop immediately), STOP_WITH_SAVEPOINT (stop after generating a job snapshot), STOP_WITH_DRAIN (stop in drain mode) |
NONE |
package com.aliyun.sample;
import com.alibaba.fastjson2.JSON;
import com.aliyun.tea.*;
import com.aliyun.ververica20220718.models.StopJobResponse;
public class Sample {
/**
* description :
* <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 {
// Leaking project code can expose your AccessKey pair and compromise the security of all resources in your account. The following 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 execution 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 execution 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) {
// This code is for demonstration only. Handle exceptions with care. Do not ignore exceptions in your project.
// Error message
System.out.println(error.getMessage());
// Diagnosis 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);
// This code is for demonstration only. Handle exceptions with care. Do not ignore exceptions in your project.
// Error message
System.out.println(error.getMessage());
// Diagnosis address
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
}
}
}
What's next
For more information about the Python SDK, see Python SDK.