本文介绍如何通过SMC Java SDK调用StopReplicationJob停止一个迁移任务。

背景信息

您可以调用StopReplicationJob接口停止一个迁移任务,详情请参见StopReplicationJob

代码示例

以下代码适用于停止一个迁移任务:

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) {
        //初始化AcsClient实例,设置地域ID及您的AccessKey信息
        DefaultProfile profile = DefaultProfile.getProfile("<region-Id>", "<accessKeyId>", "<accessSecret>");
        IAcsClient client = new DefaultAcsClient(profile);

        //创建API请求,并设置参数
        StopReplicationJobRequest request = new StopReplicationJobRequest();
        //迁移任务ID
        request.setJobId("j-bp152mkfswviwbqj****");

        //发送请求获取返回值或处理异常
        try {
            StopReplicationJobResponse response = client.getAcsResponse(request);
            System.out.println(new Gson().toJson(response));
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}

执行结果

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