This topic describes how to use the SMC SDK for Java to call the DeleteReplicationJob operation to delete a migration task.

Background information

You can delete a migration task by calling the DeleteReplicationJob operation. For more information, see DeleteReplicationJob.

Note
  • Deleted migration tasks cannot be restored.
  • After a migration task is deleted, the associated resources such as the intermediate instance are automatically released.

Sample code

Use the following code to delete 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.DeleteReplicationJobRequest;
import com.aliyuncs.smc.model.v20190601.DeleteReplicationJobResponse;
import com.google.gson.Gson;

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

        // Send the request to obtain the return value or handle the exceptions.
        try {
            DeleteReplicationJobResponse 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"
}