Tüm Ürünler
Search
Belge Merkezi

Realtime Compute for Apache Flink:Flink Java SDK

Son Güncelleme:Oct 04, 2026

Bu konu, Realtime Compute for Apache Flink Java SDK'nin nasıl kurulacağını ve kullanılacağını açıklar.

Kullanım notları

19 Eylül - 27 Ekim 2022 tarihleri arasında Alibaba Cloud, tüm bölgelerde Realtime Compute for Apache Flink SDK'si için bir güncelleme yayınladı. Bu yeni sürüm artık varsayılan sürümdür.

Not

Önkoşullar

  • Bir AccessKey oluşturulmuş olmalıdır. Daha fazla bilgi için bkz. AccessKey oluşturma.

    Not

    Alibaba Cloud hesabınızın AccessKey'i sızdırılırsa oluşabilecek güvenlik risklerini azaltmak için bir RAM kullanıcısı oluşturmanızı, bu kullanıcıya Flink ile ilgili izinler atamanızı ve ardından SDK'yı çağırmak için bu kullanıcının AccessKey'ini kullanmanızı öneririz. Daha fazla bilgi için aşağıdaki konulara bakın:

  • Java 8 veya sonraki bir sürüm yüklenmiş olmalıdır.

  • Hesabınızda gerekli izinler bulunmalıdır. Daha fazla bilgi için bkz. İzin Yönetimi.

Realtime Compute for Apache Flink Java SDK'leri

Selling console

Kurulum yöntemi

Kod

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

Kurulum yöntemi

Kod

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'

Çevrimiçi hata ayıklama ve SDK örnekleri oluşturma

API işlemlerini çevrimiçi olarak çağırmak, dinamik olarak SDK örnek kodu oluşturmak ve API işlemlerini hızlıca aramak için OpenAPI Explorer'ı kullanabilirsiniz. API işlemleri için SDK örnek kodlarını Realtime Compute for Apache Flink ve Realtime Compute Selling Console sayfalarında görüntüleyebilir ve indirebilirsiniz. Daha fazla bilgi için bkz. Hızlı Başlangıç.

SDK Örnek sekmesinde Java gibi bir dil seçin, kodu çevrimiçi çalıştırmak için Örneği Çalıştır öğesine tıklayın veya örnek kodu indirmek için Tam Projeyi İndir öğesine tıklayın.

Örnekler

Not
  • Realtime Compute for Apache Flink satış konsolu uç noktaları için bkz. Uç Noktalar.

  • Realtime Compute for Apache Flink geliştirme konsolu uç noktaları için bkz. Uç Noktalar.

Satın alınan çalışma alanları

Bu örnekte, belirtilen bir bölgedeki satın alınan Realtime Compute for Apache Flink çalışma alanlarının ayrıntılarının nasıl alınacağı gösterilmektedir.

Region: Bölgenin kimliği . Daha fazla bilgi için bkz. Uç Noktalar. Örneğin, 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);
        }
    }
}

Dağıtım oluşturma

SQL dağıtımı

Bu örnekte bir SQL dağıtımının nasıl oluşturulacağı gösterilmektedir.

  • workspace: Çalışma alanının kimliği. Bu kimliği, satın alınan çalışma alanlarını görüntülediğinizde döndürülen ResourceId değerinden alabilirsiniz. Örneğin, adf9e514****.

  • namespace: Ad alanının adı. Örneğin, test-default.

  • body.name: İşin adı. Örneğin, mysql_data_holo_test.

  • body.engineVersion: Motor sürümü. Örneğin, vvr-8.0.7-flink-1.17. Desteklenen motor sürümlerini desteklenen motor sürümlerini listeleyerek edinebilirsiniz.

  • body.sqlArtifact.sqlScript: SQL betiğinin içeriği. Örnek: 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: İşin türü. Örneğin, SQLSCRIPT.

  • body.deploymentTarget.mode: Dağıtım modu. Yalnızca PER_JOB modu desteklenir.

  • body.deploymentTarget.name: Dağıtım kuyruğunun adı. Örneğin, default-queue.

  • body.executionMode: yürütme modu. Örneğin, STREAMING (akış modu).

  • body.streamingResourceSetting.resourceSettingMode: Akış modu için kaynak modu. Örneğin, BASIC.

  • body.streamingResourceSetting.basicResourceSetting.jobmanagerResourceSettingSpec.cpu: JobManager için CPU çekirdek sayısı. Örneğin, 2.

  • body.streamingResourceSetting.basicResourceSetting.jobmanagerResourceSettingSpec.memory: JobManager belleği. Örneğin, 4,0 GiB.

  • body.streamingResourceSetting.basicResourceSetting.taskmanagerResourceSettingSpec.cpu: TaskManager CPU çekirdek sayısı. Örneğin, 2.

  • body.streamingResourceSetting.basicResourceSetting.taskmanagerResourceSettingSpec.memory: TaskManager belleği. Örneğin, 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 dağıtımı

Bu örnekte bir JAR dağıtımının nasıl oluşturulacağı gösterilmektedir.

Not
  • JAR paketini bir OSS paketine yükleyin ve Realtime Compute for Apache Flink çalışma alanınızın buna erişim iznine sahip olduğundan emin olun. Daha fazla bilgi için bkz. Basit yükleme.

  • Dosya yüklendikten sonra indirme URL'si https://<Bucket>.oss-<Region>.aliyuncs.com/<FileName> biçimindedir.

  • workspace: Çalışma alanının kimliği. Bu kimliği, satın alınan çalışma alanlarını görüntülediğinizde döndürülen ResourceId değerinden alabilirsiniz. Örneğin, adf9e514****.

  • namespace: Ad alanının adı. Örneğin, test-default.

  • body.name: İş adı. Örneğin, my-test-jar.

  • body.engineVersion: Motor sürümü. Örneğin, vvr-8.0.7-flink-1.17. Desteklenen motor sürümlerinin listesini edinebilirsiniz.

  • body.jarArtifact.kind: İş yapıtı türü. Örneğin, JAR.

  • body.jarArtifact.jarUri: JAR dağıtımının tam URL yolu. Örneğin, https://myBucket/oss-cn-hangzhou/test.jar.

  • body.jarArtifact.entryClass: Giriş noktası sınıfı. Tam nitelikli sınıf adını belirtmeniz gerekir. Örneğin, org.apache.flink.test.

  • body.deploymentTarget.mode: Dağıtım modu. Yalnızca PER_JOB modu desteklenir.

  • body.deploymentTarget.name: Dağıtım kuyruğunun adı. Örneğin, default-queue.

  • body.executionMode: Yürütme modu. Örneğin, STREAMING (akış modu).

  • body.streamingResourceSetting.resourceSettingMode: Akış modu için kaynak modu. Örneğin, BASIC.

  • body.streamingResourceSetting.basicResourceSetting.jobmanagerResourceSettingSpec.cpu: JobManager için CPU çekirdek sayısı. Örneğin, 2.

  • body.streamingResourceSetting.basicResourceSetting.jobmanagerResourceSettingSpec.memory: JobManager belleği. Örneğin, 4,0 GiB.

  • body.streamingResourceSetting.basicResourceSetting.taskmanagerResourceSettingSpec.cpu: TM için CPU çekirdek sayısı. Örneğin, 2.

  • body.streamingResourceSetting.basicResourceSetting.taskmanagerResourceSettingSpec.memory: TaskManager belleği. Örneğin, 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);
    }
}

Dağıtımları listeleme

Bu örnekte bir ad alanındaki tüm dağıtımların nasıl listeleneceği gösterilmektedir.

  • workspace: Çalışma alanının kimliği. Kimliği, Satın alınan çalışma alanlarını görüntüleme bölümündeki işlem tarafından döndürülen ResourceId değerinden alabilirsiniz. Örneğin, adf9e514****.

  • namespace: Ad alanının adı. Örneğin, 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);
        }
    }
}

İşi başlatma

Bu örnekte bir ad alanındaki bir dağıtımdan işin nasıl başlatılacağı gösterilmektedir.

  • workspace: Çalışma alanı kimliği. Örneğin, adf9e5147a****.

  • namespace: Ad alanının adı, örneğin test-default.

  • deploymentId: Dağıtımın kimliği. Bu kimliği Dağıtımları listele işlemini çağırarak alabilirsiniz. Örneğin, 10283a02-c6a6-4f3e-9f93-8dab****.

  • kind: Geri yükleme stratejisinin türü. Desteklenen değerler NONE (durumsuz başlatma), LATEST_SAVEPOINT (en son savepoint'ten başlatma), FROM_SAVEPOINT (belirtilen bir savepoint'ten başlatma) ve LATEST_STATE (en son durumdan başlatma)'dır.

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);
        }
    }
}

İşleri listeleme

Bu örnekte belirli bir dağıtım için tüm işlerin nasıl sorgulanacağı gösterilmektedir.

  • workspace: Çalışma alanı kimliği. Örneğin, adf9e5147****.

  • namespace: Ad alanının adı, örneğin test-default.

  • deploymentId: Dağıtım kimliği. Bu kimliği almak için bkz. Dağıtımların listesini alma. Örneğin, 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);
        }
    }
}

İşi durdurma

Bu örnekte bir işin nasıl durdurulacağı gösterilmektedir.

  • workspace: Çalışma alanı kimliği. Örneğin, adf9e5147****.

  • namespace: Ad alanının adı, örneğin test-default.

  • jobId: İşin kimliği. Daha fazla bilgi için bkz. Belirli bir dağıtım hakkında bilgi alma. Örneğin, 3171d4d1-**--**-e762493b7765.

  • stopStrategy: İş durdurma stratejisi. Desteklenen değerler NONE (işi doğrudan durdurur), STOP_WITH_SAVEPOINT (savepoint oluşturulduktan sonra işi durdurur) ve STOP_WITH_DRAIN (işi drain modunda durdurur)'dır.

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);
        }
    }
}

Başvurular

Python SDK hakkında daha fazla bilgi için bkz. Python SDK referansı.