This topic describes how to use the SMC Java SDK to call the ModifyReplicationJobAttribute operation to modify the attributes of a migration task.

Background information

You can call the ModifyReplicationJobAttribute operation to modify the attributes of a migration task, including the name of the target image to be delivered in the migration task, the ID of the target instance, and the maximum number of images to be retained by the incremental migration task by default. For more information, see ModifyReplicationJobAttribute.

Note
  • The Name and Description parameters can be modified throughout the lifecycle of a migration task.
  • The Frequency and MaxNumberOfImageToKeep parameters can be modified only before the migration task is executed or when the migration task is in the Waiting state.
  • Other parameters can be modified only before the migration task is executed.

Sample code

The following code can be used to modify the name and description of the migration task and the system disk size of the target ECS instance:

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.ModifyReplicationJobAttributeRequest;
import com.aliyuncs.smc.model.v20190601.ModifyReplicationJobAttributeResponse;
import com.google.gson.Gson;

public class ModifyReplicationJobAttribute {
    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.
        ModifyReplicationJobAttributeRequest request = new ModifyReplicationJobAttributeRequest();
        // The ID of the migration task.
        request.setJobId("j-bp152mkfswviwbqj****");
        // The name of the migration task.
        request.setName("MyMigrationTask");
        // The description of the migration task.
        request.setDescription("This_is_my_migration_task");
        // The system disk size of the target Alibaba Cloud ECS instance.
        request.setSystemDiskSize(50);
        // The time when the migration task will be executed.
        //request.setScheduledStartTime("2019-06-04T13:35:00Z");
        // The ID of the target instance.
        //request.setInstanceId("i-bp12uyz75shn6jsp****");
        // The name of the target Alibaba Cloud image to be delivered in the migration task.
        //request.setImageName("smc-image");
        // The interval of running an incremental migration task.
        //request.setFrequency(12);
        // The index number and size of the data disk of the target Alibaba Cloud ECS instance.
        //List<ModifyReplicationJobAttributeRequest.DataDisk> datadisks = new ArrayList<>();
        //ModifyReplicationJobAttributeRequest.DataDisk datadisk = new ModifyReplicationJobAttributeRequest.DataDisk();
        // The index number of the data disk of the target Alibaba Cloud ECS instance.
        //datadisk.setIndex(1);
        // The size of the data disk of the target Alibaba Cloud ECS instance.
        //datadisk.setSize(100);
        //datadisks.add(datadisk);
        //request.setDataDisks(datadisks);
        // The maximum number of images to be retained by the incremental migration task by default.
        //request.setMaxNumberOfImageToKeep(10);
        // The type of the target that will be delivered in the migration task.
        //request.setTargetType("Image");
        // The instance type of the intermediate instance.
        //request.setInstanceType("ecs.c5.large");

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

Results

Response:

{
    "RequestId":"1C488B66-B819-4D14-8711-C4EAAA13AC01"
}