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

Background information

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

  • You can create migration tasks for source servers that are in the Available state.
  • Each source server can be associated with only one migration task that is in the Ready, Running, Stopped, Waiting, InError, or Expired state.
  • You can create a maximum of 100 migration tasks for each Alibaba Cloud account.
  • If you migrate a source server to a destination image, you must specify the ImageName, SystemDiskSize, and DataDisk parameters.
  • If you use a virtual private cloud (VPC) to migrate data, the VSwitchId parameter is required but the VpcId parameter is optional.

Sample code

Use the following sample code to create a migration task, attach the usage:production tag to the migration task, specify the VPC, and set the system disk size of the destination Elastic Compute Service (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 the VPC.
        // The ID of the VSwitch in the VPC.
        // The system disk size of the destination 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 is executed.
        // The time when the migration task expires.
        // The ID of the destination instance.
        // The name of the destination image to be delivered in the migration task.
        // To ensure the request is idempotent, you can use the client to generate a value of up to 64 ASCII characters, and assign the value to ClientToken.
        // The interval between two incremental migration tasks.
        // The index number and size of the data disk of the destination ECS instance.
        //List<CreateReplicationJobRequest.DataDisk> datadisks = new ArrayList<>();
        //CreateReplicationJobRequest.DataDisk datadisk = new CreateReplicationJobRequest.DataDisk();
        // The index number of the data disk of the destination ECS instance.
        // The size of the data disk of the destination ECS instance.
        // The maximum number of images to be retained by the incremental migration task by default.
        // The mode of the data transmission network.
        // Copy the parameter settings of the driver.
        // The type of the destination image.

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