tencent cloud

批量计算

产品简介
什么是批量计算?
应用场景
产品优势
名词解释
配额限制
数据安全
购买指南
快速入门
开始前的准备
命令行快速开始
命令行快速开始-计算环境
作业配置说明
控制台快速开始
控制台使用指南
任务模板管理
作业管理
用户指南
如何制作批量计算可用的镜像
Windows 自定义镜像
环境变量
COS、CFS 路径填写
事件通知和回调
访问管理
命令行工具
前置准备
简单开始
执行远程代码包
远程存储映射
实践教程
使用计算环境搭建集群
3ds Max 2018 渲染示例
深度学习示例
API 文档
History
Introduction
API Category
Making API Requests
Compute Environment APIs
Configuration Viewing-related APIs
Task Template-related APIs
Job-related APIs
Data Types
Error Codes
SDK文档
使用指南
常见问题
联系我们
词汇表

使用指南

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

}

}


帮助和支持

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

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

文档反馈