本文介绍如何通过SMC Java SDK调用DescribeReplicationJobs查询一个或多个迁移源信息。

背景信息

您可以调用DescribeReplicationJobs接口批量查询迁移源信息,包括迁移时使用的网络类型、迁移任务总进度、迁移中转实例ID等详细信息,详情请参见DescribeReplicationJobs

代码示例

以下代码适用于查询迁移源信息:

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.smc.model.v20190601.DescribeReplicationJobsRequest;
import com.aliyuncs.smc.model.v20190601.DescribeReplicationJobsResponse;
import com.google.gson.Gson;
import java.util.ArrayList;
import java.util.List;

public class DescribeReplicationJobs {
    public static void main(String[] args) {
        //初始化AcsClient实例,设置地域ID及您的AccessKey信息
        DefaultProfile profile = DefaultProfile.getProfile("<region-Id>", "<accessKeyId>", "<accessSecret>");
        IAcsClient client = new DefaultAcsClient(profile);

        //创建API请求,并设置参数
        DescribeReplicationJobsRequest request = new DescribeReplicationJobsRequest();
        //设置迁移任务的页码
        request.setPageNumber(1);
        //设置每页行数
        request.setPageSize(10);
        //设置迁移源ID列表
        List<String> sourceIds = new ArrayList<>();
        sourceIds.add("s-bp152mkfswviw7sd****"); 
        request.setSourceIds(sourceIds);
        //设置迁移任务的名称
        //request.setName("MigrationTask");
        //设置迁移任务的业务状态
        //request.setBusinessStatus("Cleaning");
        //设置迁移任务ID列表
        //List<String> jobIds = new ArrayList<>();
        //jobIds.add("j-bp152mkfswviwbqj****");
        //request.setJobIds(jobIds);
        //设置迁移任务的主状态
        //request.setStatus("InError");

        //发送请求获取返回值或处理异常
        try {
            DescribeReplicationJobsResponse response = client.getAcsResponse(request);
            System.out.println(new Gson().toJson(response));
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}

执行结果

{
    "requestId": "55E622AC-8E2A-432A-93FB-ABA049CA3E9B",
    "totalCount": 1,
    "pageNumber": 1,
    "pageSize": 10,
    "replicationJobs": [{
        "jobId": "j-bp152mkfswviwbqj****",
        "sourceId": "s-bp152mkfswviw7sd****",
        "name": "MigrationTask",
        "description": "smcDescription",
        "regionId": "cn-hangzhou",
        "targetType": "Image",
        "imageId": "m-bp18h4rkl1g4as4d****",
        "status": "Finished",
        "businessStatus": "Cleaning",
        "errorCode": "",
        "progress": 100.0,
        "creationTime": "2020-01-08T06:44:04Z",
        "validTime": "2020-02-07T06:44:05Z",
        "startTime": "2020-01-08T06:44:05Z",
        "endTime": "2020-01-08T08:33:54Z",
        "netMode": 0,
        "systemDiskSize": 80,
        "vpcId": "vpc-bp1vwnn14rqpyiczj****",
        "vSwitchId": "vsw-bp1ddbrxdlrcbim46****",
        "transitionInstanceId": "i-bp1a1ww07yiz0vzn****",
        "runOnce": true,
        "dataDisks": [],
        "replicationJobRuns": [{
            "imageId": "m-bp18h4rkl1g4as4d****",
            "type": "Manual",
            "startTime": "2020-01-08T06:44:05Z",
            "endTime": "2020-01-08T08:32:25Z"
        }]
    }]
}