This topic describes how to use the SMC Java SDK to call the CreateReplicationJob operation to create a migration task for a migration source.

Background information

You can create a migration task for a migration source by calling the CreateReplicationJob operation. For more information, see CreateReplicationJob.

  • Migration tasks can only be created for migration sources that are in the Available state.
  • Each migration source can only be associated with a single unfinished migration task. Unfinished statuses include Ready, Running, Stopped, Waiting, InError, and Expired.
  • Each Alibaba Cloud account can create up to 100 migration tasks.
  • When the type of the migration destination is image, you must specify the parameters ImageName, SystemDiskSize, and DataDisk.
  • When you perform a migration within a VPC, the VSwitchId parameter is required and the VpcId parameter is optional.

Sample code

The following code can be used to create a migration task and bind it with the usage:production tag. In the migration task, you must specify the VPC and set the system disk size of the target ECS instance to 80 GiB.

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.CreateReplicationJobRequest;
import com.aliyuncs.smc.model.v20190601.CreateReplicationJobResponse;
import java.util.ArrayList;
import java.util.List;

public class CreateReplicationJob {
    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.
        CreateReplicationJobRequest request = new CreateReplicationJobRequest();
        // The ID of the migration source.
        request.setSourceId("s-bp152mkfswviw7sd****");// The ID of VPC.
        // The ID of the VSwitch in the VPC.
        // The system disk size of the target Alibaba Cloud ECS instance. Unit: GiB.
        // Specify whether to create a one-time migration task or an incremental migration task.
        // The tag key-value pair of the migration task.
        List<CreateReplicationJobRequest.Tag> tags = new ArrayList<>();
        CreateReplicationJobRequest.Tag tag = new CreateReplicationJobRequest.Tag();
        // The name of the migration task.
        // The description of the migration task.
        // The time when the migration task will be executed.
        // The time when the migration task will expire.
        // The ID of the target instance.
        // The name of the target Alibaba Cloud image to be delivered in the migration task.
        // To ensure the idempotence of the request, you can use the client to generate a value of up to 64 ASCII characters, and assign the value to ClientToken.
        // The interval of running an incremental migration task.
        // The index number and size of the data disk of the target Alibaba Cloud ECS instance.
        //List<CreateReplicationJobRequest.DataDisk> datadisks = new ArrayList<>();
        //CreateReplicationJobRequest.DataDisk datadisk = new CreateReplicationJobRequest.DataDisk();
        // The index number of the data disk of the target Alibaba Cloud ECS instance.
        // The size of the data disk of the target Alibaba Cloud ECS instance.
        // The maximum number of images to be retained by the incremental migration task by default.
        // The mode of data transmission network.
        // Copy the parameter information of the driver.
        // The type of the target that will be delivered in the migration task.

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