Topik ini menjelaskan cara menginstal dan menggunakan Java SDK untuk Realtime Compute for Apache Flink.
Catatan
Alibaba Cloud memperbarui SDK untuk Realtime Compute for Apache Flink pada 19 September 2022. Versi SDK baru kini menjadi versi default dan telah diluncurkan di semua wilayah antara 19 September 2022 hingga 27 Oktober 2022.
Untuk informasi lebih lanjut mengenai dampak peningkatan SDK, lihat Pemberitahuan layanan.
Topik ini menjelaskan cara menggunakan versi baru SDK. Untuk dokumentasi versi lama SDK, unduh dokumen OpenAPI SDK (Tidak Dilanjutkan).
Prasyarat
Anda telah membuat Pasangan Kunci Akses (AccessKey pair). Untuk informasi lebih lanjut, lihat Buat Pasangan Kunci Akses.
CatatanUntuk mencegah risiko keamanan yang mungkin timbul akibat kebocoran Pasangan Kunci Akses, kami menyarankan Anda membuat pengguna Resource Access Management (RAM). Anda kemudian dapat memberikan izin yang diperlukan kepada pengguna RAM tersebut untuk mengakses Flink dan menggunakan Pasangan Kunci Akses pengguna RAM tersebut untuk memanggil SDK. Untuk informasi lebih lanjut, lihat topik berikut:
Untuk membuat pengguna RAM dan Pasangan Kunci Aksesnya, lihat Buat pengguna RAM atau Buat Pasangan Kunci Akses.
Untuk memberikan izin kepada pengguna RAM, lihat Otorisasi di konsol manajemen.
Anda memiliki lingkungan Java. Diperlukan Java 8 atau versi yang lebih baru.
Akun Anda memiliki akses dan izin operasi yang diperlukan. Untuk informasi lebih lanjut, lihat Manajemen izin.
Java SDK untuk Realtime Compute for Apache Flink
Java SDK untuk konsol pembelian Realtime Compute for Apache Flink
Metode instalasi | Kode |
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' |
Java SDK untuk konsol pengembangan Realtime Compute for Apache Flink
Metode instalasi | Kode |
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' |
Debugging online dan pembuatan contoh SDK
OpenAPI Explorer memungkinkan Anda memanggil Operasi API secara online, menghasilkan kode contoh SDK secara dinamis, dan dengan cepat mengambil Operasi API untuk menyederhanakan penggunaannya. Anda dapat melihat dan mengunduh contoh SDK untuk Operasi API di halaman API Konsol Pengembangan Realtime Compute for Apache Flink dan API Konsol Penjualan Realtime Compute for Apache Flink. Untuk informasi lebih lanjut, lihat Memulai dengan cepat.

Contoh
Untuk titik akhir konsol penjualan Realtime Compute for Apache Flink, lihat OpenAPI Explorer.
Untuk titik akhir konsol pengembangan Realtime Compute for Apache Flink, lihat OpenAPI Explorer.
Lihat ruang kerja yang telah dibeli
Anda dapat mengkueri detail ruang kerja Realtime Compute for Apache Flink yang telah dibeli di wilayah tertentu. Parameter permintaan yang diperlukan adalah sebagai berikut:.
Region: ID wilayah. Untuk informasi lebih lanjut, lihat Titik akhir. Contohnya, `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>Gunakan ID AccessKey dan Rahasia AccessKey Anda untuk menginisialisasi client.</p>
* @return Client
*
* @throws Exception
*/
public static com.aliyun.foasconsole20211028.Client createClient() throws Exception {
// Kebocoran kode proyek dapat mengekspos Pasangan Kunci Akses Anda dan membahayakan keamanan semua sumber daya dalam akun Anda. Kode berikut hanya untuk referensi.
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
// Wajib. Pastikan variabel lingkungan ALIBABA_CLOUD_ACCESS_KEY_ID disetel di lingkungan eksekusi Anda.
.setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
// Wajib. Pastikan variabel lingkungan ALIBABA_CLOUD_ACCESS_KEY_SECRET disetel di lingkungan eksekusi Anda.
.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);
// Lihat ID wilayah instans.
System.out.println(response.getBody().getInstances().get(0).zoneId);
// Lihat ID kelompok sumber daya instans.
System.out.println(response.getBody().getInstances().get(0).resourceGroupId);
System.out.println(JSON.toJSON(response));
} catch (TeaException error) {
// Kode ini hanya untuk demonstrasi. Tangani exception dengan hati-hati. Jangan abaikan exception dalam proyek Anda.
// Pesan error
System.out.println(error.getMessage());
// Alamat diagnosis
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
} catch (Exception _error) {
TeaException error = new TeaException(_error.getMessage(), _error);
// Kode ini hanya untuk demonstrasi. Tangani exception dengan hati-hati. Jangan abaikan exception dalam proyek Anda.
// Pesan error
System.out.println(error.getMessage());
// Alamat diagnosis
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
}
}
}
Buat pekerjaan yang diterapkan
Pekerjaan SQL
Anda dapat membuat penerapan SQL. Parameter permintaan yang diperlukan adalah sebagai berikut.
workspace: ID ruang kerja. Anda dapat memperoleh ID dari ResourceId yang dikembalikan oleh operasi Lihat ruang kerja yang telah dibeli. Contohnya, `adf9e514****`.namespace: Menentukan nama proyek. Contohnya, `test-default`.body.name: Nama pekerjaan. Contohnya, `mysql_data_holo_test`.body.engineVersion: Versi engine. Contohnya, `vvr-8.0.7-flink-1.17`. Anda dapat memanggil operasi Daftar versi engine yang didukung untuk mengambil versi engine yang didukung.body.sqlArtifact.sqlScript: Skrip SQL pekerjaan. Contohnya: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: Jenis pekerjaan. Contohnya, `SQLSCRIPT`.body.deploymentTarget.mode: Mode penyebaran. Hanya mode `PER_JOB` yang didukung.body.deploymentTarget.name: Nama antrian penyebaran. Contohnya, `default-queue`.body.executionMode: Mode eksekusi. Contohnya, `STREAMING` (mode aliran).body.streamingResourceSetting.resourceSettingMode: Mode alokasi sumber daya untuk mode aliran. Contohnya, `BASIC`.body.streamingResourceSetting.basicResourceSetting.jobmanagerResourceSettingSpec.cpu: Jumlah core CPU JobManager (JM). Contohnya, `2`.body.streamingResourceSetting.basicResourceSetting.jobmanagerResourceSettingSpec.memory: Memori JM. Contohnya, `4.0 GiB`.body.streamingResourceSetting.basicResourceSetting.taskmanagerResourceSettingSpec.cpu: Jumlah core CPU TaskManager (TM). Contohnya, `2`.body.streamingResourceSetting.basicResourceSetting.taskmanagerResourceSettingSpec.memory: Memori TM. Contohnya, `4.0 GiB`.
package com.aliyun.sample;
import com.aliyun.tea.*;
public class Sample {
/**
* description :
* <p>Gunakan ID AccessKey dan Rahasia AccessKey Anda untuk menginisialisasi client.</p>
* @return Client
*
* @throws Exception
*/
public static com.aliyun.teaopenapi.Client createClient() throws Exception {
// Kebocoran kode proyek dapat mengekspos Pasangan Kunci Akses Anda dan membahayakan keamanan semua sumber daya dalam akun Anda. Kode berikut hanya untuk referensi.
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
// Wajib. Pastikan variabel lingkungan ALIBABA_CLOUD_ACCESS_KEY_ID disetel di lingkungan eksekusi Anda.
.setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
// Wajib. Pastikan variabel lingkungan ALIBABA_CLOUD_ACCESS_KEY_SECRET disetel di lingkungan eksekusi Anda.
.setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
config.endpoint = "ververica.cn-beijing.aliyuncs.com";
return new com.aliyun.teaopenapi.Client(config);
}
/**
* description :
* <p>Terkait API</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()
// Nama operasi API
.setAction("CreateDeployment")
// Versi operasi API
.setVersion("2022-07-18")
// Protokol operasi API
.setProtocol("HTTPS")
// Metode HTTP
.setMethod("POST")
.setAuthType("AK")
.setStyle("ROA")
// Jalur API
.setPathname("/api/v2/namespaces/" + namespace + "/deployments")
// Format badan permintaan
.setReqBodyType("json")
// Format badan respons
.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");
// parameter body
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")
))
))
))
);
// parameter header
java.util.Map<String, String> headers = new java.util.HashMap<>();
headers.put("workspace", "ab2*******884d");
// opsi waktu proses
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);
// Nilai kembali adalah Map. Anda dapat memperoleh tiga jenis data dari map tersebut: badan respons, header respons, dan kode status HTTP.
client.callApi(params, request, runtime);
java.util.Map<String, ?> response = client.callApi(params, request, runtime);
System.out.println(response);
}
}Pekerjaan JAR
Anda dapat membuat dan menerapkan penerapan JAR. Parameter permintaan yang diperlukan adalah sebagai berikut.
Pastikan paket JAR telah diunggah ke Bucket OSS dan ruang kerja Flink memiliki izin akses yang diperlukan. Untuk informasi lebih lanjut, lihat Unggahan sederhana ke OSS.
URL unduhan setelah pengunggahan adalah https://<Bucket>.oss-<Region>.aliyuncs.com/<FileName>.
workspace: ID ruang kerja. Anda dapat memperoleh ID dari ResourceId yang dikembalikan oleh operasi Lihat ruang kerja yang telah dibeli. Contohnya, `adf9e514****`.namespace: Nama proyek. Contohnya, `test-default`.body.name: Nama pekerjaan. Contohnya, `my-test-jar`.body.engineVersion: Versi engine. Contohnya, `vvr-8.0.7-flink-1.17`. Anda dapat memanggil operasi Daftar versi engine yang didukung untuk mengambil versi engine yang didukung.body.jarArtifact.kind: Jenis pekerjaan. Contohnya, `JAR`.body.jarArtifact.jarUri: URL lengkap pekerjaan JAR. Contohnya, `https://myBucket/oss-cn-hangzhou/test.jar`.body.jarArtifact.entryClass: Kelas entri. Tentukan nama lengkap kelas tersebut. Contohnya, `org.apache.flink.test`.body.deploymentTarget.mode: Mode penyebaran. Hanya mode `PER_JOB` yang didukung.body.deploymentTarget.name: Nama antrian penyebaran. Contohnya, `default-queue`.body.executionMode: Mode eksekusi. Contohnya, `STREAMING` (mode aliran).body.streamingResourceSetting.resourceSettingMode: Mode alokasi sumber daya untuk mode aliran. Contohnya, `BASIC`.body.streamingResourceSetting.basicResourceSetting.jobmanagerResourceSettingSpec.cpu: Jumlah core CPU JM. Contohnya, `2`.body.streamingResourceSetting.basicResourceSetting.jobmanagerResourceSettingSpec.memory: Memori JM. Contohnya, `4.0 GiB`.body.streamingResourceSetting.basicResourceSetting.taskmanagerResourceSettingSpec.cpu: Jumlah core CPU TM. Contohnya, `2`.body.streamingResourceSetting.basicResourceSetting.taskmanagerResourceSettingSpec.memory: Memori TM. Contohnya, `4.0 GiB`.
package com.aliyun.sample;
import com.aliyun.tea.*;
public class Sample {
/**
* description :
* <p>Gunakan ID AccessKey dan Rahasia AccessKey Anda untuk menginisialisasi client.</p>
* @return Client
*
* @throws Exception
*/
public static com.aliyun.teaopenapi.Client createClient() throws Exception {
// Kebocoran kode proyek dapat mengekspos Pasangan Kunci Akses Anda dan membahayakan keamanan semua sumber daya dalam akun Anda. Kode berikut hanya untuk referensi.
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
// Wajib. Pastikan variabel lingkungan ALIBABA_CLOUD_ACCESS_KEY_ID disetel di lingkungan eksekusi Anda.
.setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
// Wajib. Pastikan variabel lingkungan ALIBABA_CLOUD_ACCESS_KEY_SECRET disetel di lingkungan eksekusi Anda.
.setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
config.endpoint = "ververica.cn-hangzhou.aliyuncs.com";
return new com.aliyun.teaopenapi.Client(config);
}
/**
* description :
* <p>Terkait API</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()
// Nama operasi API
.setAction("CreateDeployment")
// Versi operasi API
.setVersion("2022-07-18")
// Protokol operasi API
.setProtocol("HTTPS")
// Metode HTTP
.setMethod("POST")
.setAuthType("AK")
.setStyle("ROA")
// Jalur API
.setPathname("/api/v2/namespaces/" + namespace + "/deployments")
// Format badan permintaan
.setReqBodyType("json")
// Format badan respons
.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");
// parameter body
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")
))
))
))
);
// parameter header
java.util.Map<String, String> headers = new java.util.HashMap<>();
headers.put("workspace", "d05a*****e44");
// opsi waktu proses
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);
// Nilai kembali adalah Map. Anda dapat memperoleh tiga jenis data dari map tersebut: badan respons, header respons, dan kode status HTTP.
java.util.Map<String, ?> response = client.callApi(params, request, runtime);
System.out.println(response);
}
}Dapatkan daftar penerapan
Anda dapat mengambil informasi tentang semua penerapan dalam sebuah namespace. Parameter permintaan yang diperlukan adalah sebagai berikut.
workspace: ID ruang kerja. Anda dapat memperoleh ID dari ResourceId yang dikembalikan oleh operasi Lihat ruang kerja yang telah dibeli. Contohnya, `adf9e514****`.namespace: Nama proyek. Contohnya, `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>Gunakan ID AccessKey dan Rahasia AccessKey Anda untuk menginisialisasi client.</p>
* @return Client
*
* @throws Exception
*/
public static com.aliyun.ververica20220718.Client createClient() throws Exception {
// Kebocoran kode proyek dapat mengekspos Pasangan Kunci Akses Anda dan membahayakan keamanan semua sumber daya dalam akun Anda. Kode berikut hanya untuk referensi.
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
// Wajib. Pastikan variabel lingkungan ALIBABA_CLOUD_ACCESS_KEY_ID disetel di lingkungan eksekusi Anda.
.setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
// Wajib. Pastikan variabel lingkungan ALIBABA_CLOUD_ACCESS_KEY_SECRET disetel di lingkungan eksekusi Anda.
.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) {
// Kode ini hanya untuk demonstrasi. Tangani exception dengan hati-hati. Jangan abaikan exception dalam proyek Anda.
// Pesan error
System.out.println(error.getMessage());
// Alamat diagnosis
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
} catch (Exception _error) {
TeaException error = new TeaException(_error.getMessage(), _error);
// Kode ini hanya untuk demonstrasi. Tangani exception dengan hati-hati. Jangan abaikan exception dalam proyek Anda.
// Pesan error
System.out.println(error.getMessage());
// Alamat diagnosis
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
}
}
}Jalankan pekerjaan
Anda dapat menjalankan pekerjaan yang telah diterapkan dalam sebuah proyek. Parameter permintaan yang diperlukan adalah sebagai berikut.
workspace: ID ruang kerja. Contohnya, `adf9e5147a****`.namespace: Nama proyek. Contohnya, `test-default`.deploymentId: ID penerapan pekerjaan. Anda dapat mengambil ID tersebut dengan memanggil operasi Ambil daftar penerapan. Contohnya, `10283a02-c6a6-4f3e-9f93-8dab****`.kind: Jenis offset awal. Nilai yang valid adalah `NONE` (start tanpa status), `LATEST_SAVEPOINT` (start dari snapshot pekerjaan terbaru), `FROM_SAVEPOINT` (start dari snapshot tertentu), dan `LATEST_STATE` (start dari status terbaru).
package com.aliyun.sample;
import com.aliyun.tea.*;
import com.aliyun.ververica20220718.models.StartJobWithParamsResponse;
import com.alibaba.fastjson2.JSON;
public class Sample {
/**
* description :
* <p>Gunakan ID AccessKey dan Rahasia AccessKey Anda untuk menginisialisasi client.</p>
* @return Client
*
* @throws Exception
*/
public static com.aliyun.ververica20220718.Client createClient() throws Exception {
// Kebocoran kode proyek dapat mengekspos Pasangan Kunci Akses Anda dan membahayakan keamanan semua sumber daya dalam akun Anda. Kode berikut hanya untuk referensi.
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
// Wajib. Pastikan variabel lingkungan ALIBABA_CLOUD_ACCESS_KEY_ID disetel di lingkungan eksekusi Anda.
.setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
// Wajib. Pastikan variabel lingkungan ALIBABA_CLOUD_ACCESS_KEY_SECRET disetel di lingkungan eksekusi Anda.
.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) {
// Kode ini hanya untuk demonstrasi. Tangani exception dengan hati-hati. Jangan abaikan exception dalam proyek Anda.
// Pesan error
System.out.println(error.getMessage());
// Alamat diagnosis
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
} catch (Exception _error) {
TeaException error = new TeaException(_error.getMessage(), _error);
// Kode ini hanya untuk demonstrasi. Tangani exception dengan hati-hati. Jangan abaikan exception dalam proyek Anda.
// Pesan error
System.out.println(error.getMessage());
// Alamat diagnosis
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
}
}
}Dapatkan informasi tentang pekerjaan yang diterapkan tertentu
Anda dapat mengambil informasi tentang semua instans pekerjaan dalam sebuah penerapan. Parameter permintaan yang diperlukan adalah sebagai berikut.
workspace: ID ruang kerja. Contohnya, `adf9e5147****`.namespace: Nama proyek. Contohnya, `test-default`.deploymentId: ID penerapan pekerjaan. Anda dapat mengambil ID tersebut dengan memanggil operasi Ambil daftar penerapan. Contohnya, `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>Gunakan ID AccessKey dan Rahasia AccessKey Anda untuk menginisialisasi client.</p>
* @return Client
*
* @throws Exception
*/
public static com.aliyun.ververica20220718.Client createClient() throws Exception {
// Kebocoran kode proyek dapat mengekspos Pasangan Kunci Akses Anda dan membahayakan keamanan semua sumber daya dalam akun Anda. Kode berikut hanya untuk referensi.
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
// Wajib. Pastikan variabel lingkungan ALIBABA_CLOUD_ACCESS_KEY_ID disetel di lingkungan eksekusi Anda.
.setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
// Wajib. Pastikan variabel lingkungan ALIBABA_CLOUD_ACCESS_KEY_SECRET disetel di lingkungan eksekusi Anda.
.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);
// Lihat hasil eksekusi pekerjaan.
System.out.println("Execution result is: "+response.body.success);
// Dapatkan ID pekerjaan. Parameter ini digunakan untuk menghentikan pekerjaan.
System.out.println(response.body.getData().get(0).jobId);
System.out.println(JSON.toJSON(response));
} catch (TeaException error) {
// Kode ini hanya untuk demonstrasi. Tangani exception dengan hati-hati. Jangan abaikan exception dalam proyek Anda.
// Pesan error
System.out.println(error.getMessage());
// Alamat diagnosis
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
} catch (Exception _error) {
TeaException error = new TeaException(_error.getMessage(), _error);
// Kode ini hanya untuk demonstrasi. Tangani exception dengan hati-hati. Jangan abaikan exception dalam proyek Anda.
// Pesan error
System.out.println(error.getMessage());
// Alamat diagnosis
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
}
}
}Hentikan instans pekerjaan
Anda dapat menghentikan instans pekerjaan. Parameter permintaan yang diperlukan adalah sebagai berikut.
workspace: ID ruang kerja. Contohnya, `adf9e5147****`.namespace: Nama proyek. Contohnya, `test-default`.jobId: ID instans pekerjaan. Anda dapat mengambil ID tersebut dengan memanggil operasi Ambil informasi tentang pekerjaan yang diterapkan tertentu. Contohnya, `3171d4d1-****-****-****-e762493b7765`.stopStrategy: Kebijakan untuk menghentikan pekerjaan. Nilai yang valid adalah `NONE` (hentikan segera), `STOP_WITH_SAVEPOINT` (hentikan setelah menghasilkan snapshot pekerjaan), dan `STOP_WITH_DRAIN` (hentikan dalam mode drain).
package com.aliyun.sample;
import com.alibaba.fastjson2.JSON;
import com.aliyun.tea.*;
import com.aliyun.ververica20220718.models.StopJobResponse;
public class Sample {
/**
* description :
* <p>Gunakan ID AccessKey dan Rahasia AccessKey Anda untuk menginisialisasi client.</p>
* @return Client
*
* @throws Exception
*/
public static com.aliyun.ververica20220718.Client createClient() throws Exception {
// Kebocoran kode proyek dapat mengekspos Pasangan Kunci Akses Anda dan membahayakan keamanan semua sumber daya dalam akun Anda. Kode berikut hanya untuk referensi.
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
// Wajib. Pastikan variabel lingkungan ALIBABA_CLOUD_ACCESS_KEY_ID disetel di lingkungan eksekusi Anda.
.setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
// Wajib. Pastikan variabel lingkungan ALIBABA_CLOUD_ACCESS_KEY_SECRET disetel di lingkungan eksekusi Anda.
.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) {
// Kode ini hanya untuk demonstrasi. Tangani exception dengan hati-hati. Jangan abaikan exception dalam proyek Anda.
// Pesan error
System.out.println(error.getMessage());
// Alamat diagnosis
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
} catch (Exception _error) {
TeaException error = new TeaException(_error.getMessage(), _error);
// Kode ini hanya untuk demonstrasi. Tangani exception dengan hati-hati. Jangan abaikan exception dalam proyek Anda.
// Pesan error
System.out.println(error.getMessage());
// Alamat diagnosis
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
}
}
}Referensi
Untuk informasi lebih lanjut mengenai Python SDK, lihat Python SDK.