tencent cloud

使用指南

PDF
聚焦模式
字号
最后更新时间: 2024-01-13 11:19:28

开发准备

选择不同语言的 SDK,下载和安装 。
首次使用批量计算,参见 开始前的准备
了解更多接口参数,参见 API 文档

接入步骤

腾讯云提供了一个代码 在线生成工具,以交互式的体验,提供不同语言 SDK 代码示例。
1. 产品选择批量计算,找到对应的接口。
2. 根据帮助提示,填写个人密钥输入参数
3. (可选)勾选只看必选参数
4. 在右侧代码生成栏中,复制不同语言的代码到本地执行。
5. 在生产使用前,在“在线调用”栏中发起真实请求,验证结果是否符合预期。

代码示例

提交作业(Python 版本)

from tencentcloud.common import credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.batch.v20170312 import batch_client, models
try:
cred = credential.Credential("your secret id", "your secret key")
httpProfile = HttpProfile()
httpProfile.endpoint = "batch.tencentcloudapi.com"

clientProfile = ClientProfile()
clientProfile.httpProfile = httpProfile
client = batch_client.BatchClient(cred, "ap-guangzhou", clientProfile)

req = models.SubmitJobRequest()
params = '{"Placement":{"Zone":"ap-guangzhou-3"},"Job":{"JobName":"demo","JobDescription":"test job","Priority":1,"Tasks":[{"TaskName":"task","TaskInstanceNum":1,"Application":{"Command":"echo hello"},"ComputeEnv":{"EnvData":{"InstanceType":"S2.SMALL1","ImageId":"img-enf3kukl","SystemDisk":{"DiskType":"CLOUD_PREMIUM","DiskSize":50}}},"MaxRetryCount":1,"Timeout":3600}]}}'
req.from_json_string(params)

resp = client.SubmitJob(req)
print(resp.to_json_string())

except TencentCloudSDKException as err:
print(err)

查询作业(Python 版本)

from tencentcloud.common import credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.batch.v20170312 import batch_client, models
try:
cred = credential.Credential("your secret id", "your secret key")
httpProfile = HttpProfile()
httpProfile.endpoint = "batch.tencentcloudapi.com"

clientProfile = ClientProfile()
clientProfile.httpProfile = httpProfile
client = batch_client.BatchClient(cred, "ap-guangzhou", clientProfile)

req = models.DescribeJobRequest()
params = '{"JobId":"job-mhgy1dot"}'
req.from_json_string(params)

resp = client.DescribeJob(req)
print(resp.to_json_string())

except TencentCloudSDKException as err:
print(err)

提交作业(Java 版本)

import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;

import com.tencentcloudapi.batch.v20170312.BatchClient;

import com.tencentcloudapi.batch.v20170312.models.SubmitJobRequest;
import com.tencentcloudapi.batch.v20170312.models.SubmitJobResponse;

public class SubmitJob
{
public static void main(String [] args) {
try{

Credential cred = new Credential("your secret id", "your secret key");

HttpProfile httpProfile = new HttpProfile();
httpProfile.setEndpoint("batch.tencentcloudapi.com");

ClientProfile clientProfile = new ClientProfile();
clientProfile.setHttpProfile(httpProfile);

BatchClient client = new BatchClient(cred, "ap-guangzhou", clientProfile);

String params = "{\\"Placement\\":{\\"Zone\\":\\"ap-guangzhou-3\\"},\\"Job\\":{\\"JobName\\":\\"demo\\",\\"JobDescription\\":\\"test job\\",\\"Priority\\":1,\\"Tasks\\":[{\\"TaskName\\":\\"task\\",\\"TaskInstanceNum\\":1,\\"Application\\":{\\"Command\\":\\"echo hello\\"},\\"ComputeEnv\\":{\\"EnvData\\":{\\"InstanceType\\":\\"S2.SMALL1\\",\\"ImageId\\":\\"img-enf3kukl\\",\\"SystemDisk\\":{\\"DiskType\\":\\"CLOUD_PREMIUM\\",\\"DiskSize\\":50}}},\\"MaxRetryCount\\":1,\\"Timeout\\":3600}]}}";
SubmitJobRequest req = SubmitJobRequest.fromJsonString(params, SubmitJobRequest.class);

SubmitJobResponse resp = client.SubmitJob(req);

System.out.println(SubmitJobRequest.toJsonString(resp));
} catch (TencentCloudSDKException e) {
System.out.println(e.toString());
}

}

}

查询作业(Java 版本)

import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;

import com.tencentcloudapi.batch.v20170312.BatchClient;

import com.tencentcloudapi.batch.v20170312.models.DescribeJobRequest;
import com.tencentcloudapi.batch.v20170312.models.DescribeJobResponse;

public class DescribeJob
{
public static void main(String [] args) {
try{

Credential cred = new Credential("your secret id", "your secret key");

HttpProfile httpProfile = new HttpProfile();
httpProfile.setEndpoint("batch.tencentcloudapi.com");

ClientProfile clientProfile = new ClientProfile();
clientProfile.setHttpProfile(httpProfile);

BatchClient client = new BatchClient(cred, "ap-guangzhou", clientProfile);

String params = "{\\"JobId\\":\\"job-mhgy1dot\\"}";
DescribeJobRequest req = DescribeJobRequest.fromJsonString(params, DescribeJobRequest.class);

DescribeJobResponse resp = client.DescribeJob(req);

System.out.println(DescribeJobRequest.toJsonString(resp));
} catch (TencentCloudSDKException e) {
System.out.println(e.toString());
}

}

}


帮助和支持

本页内容是否解决了您的问题?

填写满意度调查问卷,共创更好文档体验。

文档反馈