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

Background information

You can call the DescribeSourceServers operation to query the information about multiple migration sources in batches, including the migration task ID, kernel version level, and the system disk size of the migration sources. For more information, see DescribeSourceServers.

Sample code

The following code can be used to query the information of migration sources that are in the InUse state:

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.DescribeSourceServersRequest;
import com.aliyuncs.smc.model.v20190601.DescribeSourceServersResponse;
import com.google.gson.Gson;
import java.util.ArrayList;
import java.util.List;

public class DescribeSourceServers {
    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.
        DescribeSourceServersRequest request = new DescribeSourceServersRequest();
        // The ID of the migration source.
        List<String> sourceIds = new ArrayList<>();
        sourceIds.add("s-bp152mkfswviw7sd****");
        //sourceIds.add("s-bp152mkfswviw7sd****");
        request.setSourceIds(sourceIds);         
        // The number of the migration source list page to return.
        request.setPageNumber(1);
        // The number of entries to return on each page.
        request.setPageSize(10);
        // The status of the migration source.
        request.setState("InUse");
        // The name of the migration source.
        //request.setName("smcName");
        // The ID of the migration task.
        //request.setJobId("j-bp152mkfswviwbqj****");

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

Result

{
    "requestId": "766829A6-BC4D-47D2-A0C6-08870FEA785B",
    "totalCount": 1,
    "pageNumber": 1,
    "pageSize": 10,
    "sourceServers": [{
        "sourceId": "s-bp152mkfswviw7sd****",
        "jobId": "j-bp152mkfswviwbqj****",
        "agentVersion": "2.0.5",
        "name": "smcName",
        "description": "Server Source Imported By GotoAliyun. Hostname: smcName IP Address: 192.***.***.29",
        "kernelLevel": 0,
        "platform": "CentOS",
        "architecture": "x86_64",
        "systemDiskSize": 40,
        "replicationDriver": "SMT",
        "systemInfo": "{\"agent_mode\":\"daemon\",\"agent_type\":\"aliyun\",\"client_type\":\"\",\"cores\":\"2\",\"cpu_info\":\"\",\"cpu_usage\":\"1.99\",\"hostname\":\"smcName\",\"ipv4\":\"192. ***. ***.29\",\"memory\":\"1.00\",\"memory_usage\":\"0.38\"}",
        "creationTime": "2020-01-08T06:38:20Z",
        "state": "InUse",
        "errorCode": "SourceServer.Offline",
        "heartbeatRate": 30,
        "dataDisks": []
    }]
}