IDC

批量计算 使用指南 - SDK 文档

作者:admin 2021-09-13 我要评论

您可通过以下视频了解并开始使用批量计算 SDK: 开发准备 选择不同语言的 SDK,下载和安装 。 首次使用批量计算,参考 开始前的准备。 了解更多接口参数,参考 A...

在说正事之前,我要推荐一个福利:你还在原价购买阿里云、腾讯云、华为云服务器吗?那太亏啦!来这里,新购、升级、续费都打折,能够为您省60%的钱呢!2核4G企业级云服务器低至69元/年,点击进去看看吧>>>)

您可通过以下视频了解并开始使用批量计算 SDK:

开发准备

  • 选择不同语言的 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());
        }

    }

}

版权声明:本文转载自网络,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。本站转载出于传播更多优秀技术知识之目的,如有侵权请联系QQ/微信:153890879删除

相关文章
腾讯云代理商
精彩导读
海外云服务器
热门资讯
腾讯云代理商