SQL deployment
This example shows how to create an SQL deployment.
-
workspace: The ID of the workspace. You can obtain this ID from the ResourceId that is returned when you view purchased workspaces. For example, adf9e514****.
-
namespace: The name of the namespace. For example, test-default.
-
body.name: The name of the job. For example, mysql_data_holo_test.
-
body.engineVersion: The engine version. For example, vvr-8.0.7-flink-1.17. You can obtain the supported engine versions by listing the supported engine versions.
-
body.sqlArtifact.sqlScript: The content of the SQL script. Example: CREATE TEMPORARY TABLE datagen_source( name VARCHAR ) WITH ( 'connector' = 'datagen' ); CREATE TEMPORARY TABLE blackhole_sink( name VARCHAR ) with ( 'connector' = 'blackhole' ); INSERT INTO blackhole_sink SELECT name from datagen_source;.
-
body.sqlArtifact.kind: The type of the job. For example, SQLSCRIPT.
-
body.deploymentTarget.mode: The deployment mode. Only the PER_JOB mode is supported.
-
body.deploymentTarget.name: The name of the deployment queue. For example, default-queue.
-
body.executionMode: execution mode. For example, STREAMING (streaming mode).
-
body.streamingResourceSetting.resourceSettingMode: The resource mode for the streaming mode. For example, BASIC.
-
body.streamingResourceSetting.basicResourceSetting.jobmanagerResourceSettingSpec.cpu: The number of CPU cores for the JobManager. For example, 2.
-
body.streamingResourceSetting.basicResourceSetting.jobmanagerResourceSettingSpec.memory: JobManager memory. For example, 4.0 GiB.
-
body.streamingResourceSetting.basicResourceSetting.taskmanagerResourceSettingSpec.cpu: The number of TaskManager CPU cores. For example, 2.
-
body.streamingResourceSetting.basicResourceSetting.taskmanagerResourceSettingSpec.memory: TaskManager memory. For example, 4.0 GiB.
package com.aliyun.sample;
import com.aliyun.tea.*;
public class Sample {
/**
* <b>description</b> :
* <p>Use your AccessKey ID and AccessKey secret to initialize the client.</p>
* @return Client
*
* @throws Exception
*/
public static com.aliyun.teaopenapi.Client createClient() throws Exception {
// Hard-coding the AccessKey pair in your code may cause the AccessKey pair to be leaked and threaten the security of all the resources in your account. The following sample code is for reference only.
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set in your runtime environment.
.setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set in your runtime environment.
.setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
config.endpoint = "ververica.cn-beijing.aliyuncs.com";
return new com.aliyun.teaopenapi.Client(config);
}
/**
* <b>description</b> :
* <p>API parameters</p>
*
* @param path params
* @return OpenApi.Params
*/
public static com.aliyun.teaopenapi.models.Params createApiInfo(String namespace) throws Exception {
com.aliyun.teaopenapi.models.Params params = new com.aliyun.teaopenapi.models.Params()
// The name of the API operation.
.setAction("CreateDeployment")
// The version of the API operation.
.setVersion("2022-07-18")
// The protocol of the API operation.
.setProtocol("HTTPS")
// The HTTP method of the API operation.
.setMethod("POST")
.setAuthType("AK")
.setStyle("ROA")
// The request path of the API operation.
.setPathname("/api/v2/namespaces/" + namespace + "/deployments")
// The format of the request body.
.setReqBodyType("json")
// The format of the response body.
.setBodyType("json");
return params;
}
public static void main(String[] args_) throws Exception {
java.util.List<String> args = java.util.Arrays.asList(args_);
com.aliyun.teaopenapi.Client client = Sample.createClient();
com.aliyun.teaopenapi.models.Params params = Sample.createApiInfo("test-default");
// body params
java.util.Map<String, Object> body = TeaConverter.buildMap(
new TeaPair("name", "mysql_data_holo_test"),
new TeaPair("engineVersion", "vvr-8.0.7-flink-1.17"),
new TeaPair("artifact", TeaConverter.buildMap(
new TeaPair("sqlArtifact", TeaConverter.buildMap(
new TeaPair("sqlScript", "CREATE TEMPORARY TABLE datagen_source( name VARCHAR ) WITH ( 'connector' = 'datagen' ); CREATE TEMPORARY TABLE blackhole_sink( name VARCHAR ) with ( 'connector' = 'blackhole' ); INSERT INTO blackhole_sink SELECT name from datagen_source;")
)),
new TeaPair("kind", "SQLSCRIPT")
)),
new TeaPair("deploymentTarget", TeaConverter.buildMap(
new TeaPair("mode", "PER_JOB"),
new TeaPair("name", "default-queue")
)),
new TeaPair("executionMode", "STREAMING"),
new TeaPair("streamingResourceSetting", TeaConverter.buildMap(
new TeaPair("resourceSettingMode", "BASIC"),
new TeaPair("basicResourceSetting", TeaConverter.buildMap(
new TeaPair("jobmanagerResourceSettingSpec", TeaConverter.buildMap(
new TeaPair("cpu", 2),
new TeaPair("memory", "4")
)),
new TeaPair("taskmanagerResourceSettingSpec", TeaConverter.buildMap(
new TeaPair("cpu", 2),
new TeaPair("memory", "4")
))
))
))
);
// header params
java.util.Map<String, String> headers = new java.util.HashMap<>();
headers.put("workspace", "ab2*******884d");
// runtime options
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
com.aliyun.teaopenapi.models.OpenApiRequest request = new com.aliyun.teaopenapi.models.OpenApiRequest()
.setHeaders(headers)
.setBody(body);
// The method returns a Map. You can obtain the response body, response headers, and HTTP status code from the map.
client.callApi(params, request, runtime);
java.util.Map<String, ?> response = client.callApi(params, request, runtime);
System.out.println(response);
}
}
JAR deployment
This example shows how to create a JAR deployment.
Note
-
Upload the JAR package to an OSS bucket and ensure that your Realtime Compute for Apache Flink workspace has permission to access it. For more information, see Simple upload.
-
After the file is uploaded, the download URL is in the format of https://<Bucket>.oss-<Region>.aliyuncs.com/<FileName>.
-
workspace: The ID of the workspace. You can obtain this ID from the ResourceId that is returned when you view purchased workspaces. For example, adf9e514****.
-
namespace: The name of the namespace. For example, test-default.
-
body.name: The job name. For example, my-test-jar.
-
body.engineVersion: The engine version. For example, vvr-8.0.7-flink-1.17. You can obtain a list of supported engine versions.
-
body.jarArtifact.kind: The type of the job artifact. For example, JAR.
-
body.jarArtifact.jarUri: The full URL path of the JAR deployment. For example, https://myBucket/oss-cn-hangzhou/test.jar.
-
body.jarArtifact.entryClass: The entry point class. You must specify the fully qualified class name. For example, org.apache.flink.test.
-
body.deploymentTarget.mode: Deployment mode. Only the PER_JOB mode is supported.
-
body.deploymentTarget.name: The name of the deployment queue. For example, default-queue.
-
body.executionMode: Execution mode. For example, STREAMING (streaming mode).
-
body.streamingResourceSetting.resourceSettingMode: The resource mode for the streaming mode. For example, BASIC.
-
body.streamingResourceSetting.basicResourceSetting.jobmanagerResourceSettingSpec.cpu: The number of CPU cores for the JobManager. For example, 2.
-
body.streamingResourceSetting.basicResourceSetting.jobmanagerResourceSettingSpec.memory: JobManager memory. For example, 4.0 GiB.
-
body.streamingResourceSetting.basicResourceSetting.taskmanagerResourceSettingSpec.cpu: The number of CPU cores for the TM. For example, 2.
-
body.streamingResourceSetting.basicResourceSetting.taskmanagerResourceSettingSpec.memory: The memory of the TaskManager. For example, 4.0 GiB.
package com.aliyun.sample;
import com.aliyun.tea.*;
public class Sample {
/**
* <b>description</b> :
* <p>Use your AccessKey ID and AccessKey secret to initialize the client.</p>
* @return Client
*
* @throws Exception
*/
public static com.aliyun.teaopenapi.Client createClient() throws Exception {
// Hard-coding the AccessKey pair in your code may cause the AccessKey pair to be leaked and threaten the security of all the resources in your account. The following sample code is for reference only.
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set in your runtime environment.
.setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set in your runtime environment.
.setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
config.endpoint = "ververica.cn-hangzhou.aliyuncs.com";
return new com.aliyun.teaopenapi.Client(config);
}
/**
* <b>description</b> :
* <p>API parameters</p>
*
* @param path params
* @return OpenApi.Params
*/
public static com.aliyun.teaopenapi.models.Params createApiInfo(String namespace) throws Exception {
com.aliyun.teaopenapi.models.Params params = new com.aliyun.teaopenapi.models.Params()
// The name of the API operation.
.setAction("CreateDeployment")
// The version of the API operation.
.setVersion("2022-07-18")
// The protocol of the API operation.
.setProtocol("HTTPS")
// The HTTP method of the API operation.
.setMethod("POST")
.setAuthType("AK")
.setStyle("ROA")
// The request path of the API operation.
.setPathname("/api/v2/namespaces/" + namespace + "/deployments")
// The format of the request body.
.setReqBodyType("json")
// The format of the response body.
.setBodyType("json");
return params;
}
public static void main(String[] args_) throws Exception {
java.util.List<String> args = java.util.Arrays.asList(args_);
com.aliyun.teaopenapi.Client client = Sample.createClient();
com.aliyun.teaopenapi.models.Params params = Sample.createApiInfo("flink-default");
// body params
java.util.Map<String, Object> body = TeaConverter.buildMap(
new TeaPair("name", "my-test-jar"),
new TeaPair("engineVersion", "vvr-8.0.7-flink-1.17"),
new TeaPair("artifact", TeaConverter.buildMap(
new TeaPair("kind", "JAR"),
new TeaPair("jarArtifact", TeaConverter.buildMap(
new TeaPair("jarUri", "https://flink-test.oss-cn-hangzhou.aliyuncs.com/flinkDemo.jar?*****"),
new TeaPair("entryClass", "com.aliyun.FlinkDemo")
))
)),
new TeaPair("deploymentTarget", TeaConverter.buildMap(
new TeaPair("mode", "PER_JOB"),
new TeaPair("name", "default-queue")
)),
new TeaPair("executionMode", "STREAMING"),
new TeaPair("streamingResourceSetting", TeaConverter.buildMap(
new TeaPair("resourceSettingMode", "BASIC"),
new TeaPair("basicResourceSetting", TeaConverter.buildMap(
new TeaPair("jobmanagerResourceSettingSpec", TeaConverter.buildMap(
new TeaPair("cpu", 2),
new TeaPair("memory", "4")
)),
new TeaPair("taskmanagerResourceSettingSpec", TeaConverter.buildMap(
new TeaPair("cpu", 2),
new TeaPair("memory", "4")
))
))
))
);
// header params
java.util.Map<String, String> headers = new java.util.HashMap<>();
headers.put("workspace", "d05a*****e44");
// runtime options
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
com.aliyun.teaopenapi.models.OpenApiRequest request = new com.aliyun.teaopenapi.models.OpenApiRequest()
.setHeaders(headers)
.setBody(body);
// The method returns a Map. You can obtain the response body, response headers, and HTTP status code from the map.
java.util.Map<String, ?> response = client.callApi(params, request, runtime);
System.out.println(response);
}
}