This topic describes how to use the SMC Java SDK to call the DescribeReplicationJobs operation to query the information about migration sources.

Background information

You can call the DescribeReplicationJobs operation to query the information of multiple migration sources in batches, including the network type used for migration, the overall progress of the migration task, and the ID of the intermediate instance. For more information, see DescribeReplicationJobs.

Sample code

The following code can be used to query the information of migration sources:

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) {
        // Initialize the AcsClient instance, and set the region ID and your AccessKey pair.
        DefaultProfile profile = DefaultProfile.getProfile("<region-Id>", "<accessKeyId>", "<accessSecret>");
        IAcsClient client = new DefaultAcsClient(profile);

        // Create an API request and configure its parameters.
        DescribeReplicationJobsRequest request = new DescribeReplicationJobsRequest();
        // Set the page number of the migration task.
        request.setPageNumber(1);
        // Set the number of entries to return on each page.
        request.setPageSize(10);
        // Set the list of migration source IDs.
        List<String> sourceIds = new ArrayList<>();
        sourceIds.add("s-bp152mkfswviw7sd****"); 
        request.setSourceIds(sourceIds);
        // Set the name of the migration task.
        //request.setName("MigrationTask");
        // Set the business status of the migration task.
        //request.setBusinessStatus("Cleaning");
        // Set the list of migration task IDs.
        //List<String> jobIds = new ArrayList<>();
        //jobIds.add("j-bp152mkfswviwbqj****");
        //request.setJobIds(jobIds);
        // Set the primary status of the migration task.
        //request.setStatus("InError");

        // Send the request to obtain the return value or handle the exception.
        try {
            DescribeReplicationJobsResponse response = client.getAcsResponse(request);
            System.out.println(new Gson().toJson(response));
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}

Result

{
    "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"
        }]
    }]
}