This topic describes how to use the SMC Java SDK to call the StopReplicationJob operation to stop a migration task.

Background information

You can call the StopReplicationJob operation to stop a migration task. For more information, see StopReplicationJob.

Sample code

The following code can be used to stop a migration task:

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.StartReplicationJobResponse;
import com.aliyuncs.smc.model.v20190601.StopReplicationJobRequest;
import com.aliyuncs.smc.model.v20190601.StopReplicationJobResponse;
import com.google.gson.Gson;

public class StopReplicationJob {
    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.
        StopReplicationJobRequest request = new StopReplicationJobRequest();
        // The ID of the migration task.
        request.setJobId("j-bp152mkfswviwbqj****");

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

Result

{
    "RequestId":"473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E"
}