All Products
Search
Document Center

Data Online Migration:Manage tasks

Last Updated:Jun 17, 2026

You can use the SDK to create, update, query, list, and delete migration tasks, and to generate and retrieve migration reports.

Create a task

Note
  • This method creates a migration task. For more information, see CreateJob.

  • After you create the task, you must update its status to start it.

The following sample code creates a task.

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.*;
import java.util.List;

public class Demo {
   /** We strongly recommend that you do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and threaten the security of all resources in your account.*/
   static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
   static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
   /** Enter the ID of your Alibaba Cloud account.*/
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // Enter the task name.
      String jobName = "examplejob";
      // Enter the name of the source data address.
      String srcAddress = "examplesrcaddress";
      // Enter the name of the destination data address.
      String destAddress = "exampledestaddress";

      try {
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
         // This example uses the China (Beijing) region.
         config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
         config.setAccessKeyId(accessKeyId);
         config.setAccessKeySecret(accessKeySecret);
         // HTTP and HTTPS are supported. If you do not specify a protocol, HTTPS is used by default.
         config.setProtocol("http");
         Client client = new Client(config);
         CreateJobInfo info = new CreateJobInfo();
         info.name = jobName;
         info.srcAddress = srcAddress;
         info.destAddress = destAddress;
         /**
          overwriteMode and transferMode must be used together. The combinations are as follows:
          always,all: Overwrites all files.
          always,lastmodified: Overwrites files based on their last modified time.
          never,"": Does not overwrite any files.
        */
         /* The file overwrite mode. Valid values: 1. never 2. always */
         info.overwriteMode = "always";
         /* The file transfer mode. Valid values: 1. changed 2. all 3. lastmodified */
         info.transferMode = "lastmodified";

         // If maxImportTaskQps is set to 0 or left empty, the default value is used. If MaxBandWidth is set to 0 or left empty, the default value is used. The unit of maxBandWidth is bits.
         ImportQos importQos = new ImportQos();
         // Set maxBandWidth and maxImportTaskQps as needed.
         importQos.maxBandWidth = 1073741824L;
         importQos.maxImportTaskQps = 1000L;
         info.setImportQos(importQos);

         // Configure the scheduling rule. For more information about the parameters, see the API documentation.
         ScheduleRule scheduleRule = new ScheduleRule();
         // Set maxScheduleCount, startCronExpression, and suspendCronExpression as needed.
         scheduleRule.maxScheduleCount = 2L;
         scheduleRule.startCronExpression = "0 0 10 * * ?";
         scheduleRule.suspendCronExpression = "0 0 14 * * ?";
         info.setScheduleRule(scheduleRule);

         // Configure the filter rule. For more information about the parameters, see the API documentation.
         FilterRule filterRule = new FilterRule();
         // File filter. Set the value as needed.
         KeyFilters keyFilters = new KeyFilters();
         KeyFilterItem includekeyFilterItem = new KeyFilterItem();
         List<String> includeRegex = new LinkedList<>();
         includeRegex.add(".*.jpg");
         includeRegex.add(".*.jpeg");
         includekeyFilterItem.setRegex(includeRegex);
         KeyFilterItem excludekeyFilterItem = new KeyFilterItem();
         List<String> excludeRegex = new LinkedList<>();
         excludeRegex.add(".*.txt");
         excludeRegex.add(".*.js");
         excludekeyFilterItem.setRegex(excludeRegex);
         keyFilters.setIncludes(includekeyFilterItem);
         keyFilters.setExcludes(excludekeyFilterItem);
         filterRule.setKeyFilters(keyFilters);

         // Time filter. The time must be in UTC format. Set the value as needed.
         LastModifiedFilters lastModifiedFilters = new LastModifiedFilters();
         LastModifyFilterItem includeLastModifyFilterItem = new LastModifyFilterItem();
         List<TimeFilter> includeRegexs = new LinkedList<>();
         TimeFilter includeTimeFilter = new TimeFilter();
         includeTimeFilter.startTime = "2006-01-01T00:00:00Z";
         includeTimeFilter.endTime = "2006-12-31T23:59:59Z";
         includeRegexs.add(includeTimeFilter);
         includeLastModifyFilterItem.setTimeFilter(includeRegexs);
         LastModifyFilterItem excludeLastModifyFilterItem = new LastModifyFilterItem();
         List<TimeFilter> excludeRegexs = new LinkedList<>();
         TimeFilter excludeTimeFilter = new TimeFilter();
         excludeTimeFilter.startTime = "2008-01-01T00:00:00Z";
         excludeTimeFilter.endTime = "2008-12-31T23:59:59Z";
         excludeRegexs.add(excludeTimeFilter);
         excludeLastModifyFilterItem.setTimeFilter(excludeRegexs);
         lastModifiedFilters.setIncludes(includeLastModifyFilterItem);
         lastModifiedFilters.setExcludes(excludeLastModifyFilterItem);
         filterRule.setLastModifiedFilters(lastModifiedFilters);
         info.setFilterRule(filterRule);

         CreateJobRequest request = new CreateJobRequest();
         request.setImportJob(info);
         client.createJob(userId, request);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

Update a task

Note

After you create a task, use this method to start, pause, or close the task and to adjust rate limiting settings.

The following sample code updates the status of a task.

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.*;

public class Demo {
	/** We strongly recommend that you do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and threaten the security of all resources in your account.*/
	static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
	static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
	/** Enter the ID of your Alibaba Cloud account.*/
	static String userId = "11470***876***55";

	public static void main(String[] args) {
		// Enter the task name.
		String jobName = "examplejob";
		try {
			com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
			// This example uses the China (Beijing) region.
			config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
			config.setAccessKeyId(accessKeyId);
			config.setAccessKeySecret(accessKeySecret);
			// HTTP and HTTPS are supported. If you do not specify a protocol, HTTPS is used by default.
                        config.setProtocol("http");
			Client client = new Client(config);
			UpdateJobRequest updateJobRequest = new UpdateJobRequest();
			UpdateJobInfo updateJobInfo = new UpdateJobInfo();
			//Valid status values are IMPORT_JOB_LAUNCHING (start task), IMPORT_JOB_SUSPEND (pause task), and IMPORT_JOB_CLOSING (close task).
			updateJobInfo.setStatus("IMPORT_JOB_LAUNCHING");
			updateJobRequest.setImportJob(updateJobInfo);
			client.updateJob(userId, jobName, updateJobRequest);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

The following sample code updates the rate limiting settings for a task.

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.*;

public class Demo {
	/** We strongly recommend that you do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and threaten the security of all resources in your account.*/
	static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
	static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
	/** Enter the ID of your Alibaba Cloud account.*/
	static String userId = "11470***876***55";

	public static void main(String[] args) {
		// Enter the task name.
		String jobName = "examplejob";
		try {
			com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
			// This example uses the China (Beijing) region.
			config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
			config.setAccessKeyId(accessKeyId);
			config.setAccessKeySecret(accessKeySecret);
			// HTTP and HTTPS are supported. If you do not specify a protocol, HTTPS is used by default.
                        config.setProtocol("http");
			Client client = new Client(config);
			UpdateJobRequest updateJobRequest = new UpdateJobRequest();
			UpdateJobInfo updateJobInfo = new UpdateJobInfo();
			// Set maxBandWidth and maxImportTaskQps as needed.
			long maxBandWidth = 1610612736L;
			long maxImportTaskQps = 1500L;
			ImportQos qos = new ImportQos();
			qos.setMaxBandWidth(maxBandWidth);
			updateJobInfo.setImportQos(qos);
			qos.setMaxImportTaskQps(maxImportTaskQps);
			updateJobRequest.setImportJob(updateJobInfo);
			client.updateJob(userId, jobName, updateJobRequest);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Get task details

Note

Retrieve the details of a migration task by task name or task ID.

The following sample code retrieves the details of a task by task name.

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.*;
import com.google.gson.Gson;

public class Demo {
   /** We strongly recommend that you do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and threaten the security of all resources in your account.*/
   static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
   static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
   /** Enter the ID of your Alibaba Cloud account.*/
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // Enter the task name.
      String jobName = "examplejob";
      try {
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
         // This example uses the China (Beijing) region.
         config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
         config.setAccessKeyId(accessKeyId);
         config.setAccessKeySecret(accessKeySecret);
         // HTTP and HTTPS are supported. If you do not specify a protocol, HTTPS is used by default.
         config.setProtocol("http");
         Client client = new Client(config);
         GetJobRequest request = new GetJobRequest();
         GetJobResponse resp = client.getJob(userId, jobName, request);
         System.out.println(new Gson().toJson(resp.getBody().getImportJob()));
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

The following sample code retrieves the details of a task by task ID.

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.*;
import com.google.gson.Gson;

public class Demo {
	/** We strongly recommend that you do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and threaten the security of all resources in your account.*/
	static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
	static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
	/** Enter the ID of your Alibaba Cloud account.*/
	static String userId = "11470***876***55";

	public static void main(String[] args) {
		// Enter the task ID.
		String version = "b4155550-****-4371-****-9c73373480211";
		try {
			com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
			// This example uses the China (Beijing) region.
			config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
			config.setAccessKeyId(accessKeyId);
			config.setAccessKeySecret(accessKeySecret);
			// HTTP and HTTPS are supported. If you do not specify a protocol, HTTPS is used by default.
                        config.setProtocol("http");
			Client client = new Client(config);
			GetJobRequest request = new GetJobRequest();
			GetJobResponse resp = client.getJob(userId, version, request);
			System.out.println(new Gson().toJson(resp.body.getImportJob()));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Sample success response

{
  "ImportJob": {
    "Name": "test_name",
    "SrcAddress": "test_src_address",
    "DestAddress": "test_dest_address",
    "Status": "IMPORT_JOB_DOING",
    "EnableMultiVersioning": false,
    "CreateTime": "2024-05-01T12:00:00.000Z",
    "ModifyTime": "2024-05-01T12:00:00.000Z",
    "Version": "test_id",
    "Audit": {
      "LogMode": "off"
    },
    "OverwriteMode": "always",
    "TransferMode": "all",
    "Tags": "K1:V1,K2:V2",
    "ParentName": "test_parent_name",
    "ParentVersion": "7db93837-a5ee-4e3a-b3c8-800e7947dabc",
    "ConvertSymlinkTarget": false,
    "CreateReport": false,
    "Owner": "test_owner",
    "FilterRule": {
      "KeyFilters": {
        "Includes": {
          "Regex": [
            ".*\\.jpg$"
          ]
        },
        "Excludes": {
          "Regex": [
            ".*\\.jpg$"
          ]
        }
      },
      "LastModifiedFilters": {
        "Includes": {
          "TimeFilter": [
            {
              "StartTime": "2006-01-01T00:00:00Z",
              "EndTime": "2006-12-31T23:59:59Z"
            }
          ]
        },
        "Excludes": {
          "TimeFilter": [
            {
              "StartTime": "2006-01-01T00:00:00Z",
              "EndTime": "2006-12-31T23:59:59Z"
            }
          ]
        }
      },
      "FileTypeFilters": {
        "ExcludeSymlink": true,
        "ExcludeDir": true
      }
    },
    "ImportQos": {
      "MaxBandWidth": 1073741824,
      "MaxImportTaskQps": 1000
    },
    "ScheduleRule": {
      "StartCronExpression": "0 0 * * * ?",
      "SuspendCronExpression": "0 0 * * * ?",
      "MaxScheduleCount": 1
    }
  }
}

List tasks

Note

List all migration tasks for the current user in a specified region. Use Count and Marker for pagination.

The following sample code lists all tasks in an account.

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.*;
import com.google.gson.Gson;

public class Demo {
   /** We strongly recommend that you do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and threaten the security of all resources in your account.*/
   static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
   static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
   /** Enter the ID of your Alibaba Cloud account.*/
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      try {
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
         // This example uses the China (Beijing) region.
         config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
         config.setAccessKeyId(accessKeyId);
         config.setAccessKeySecret(accessKeySecret);
         // HTTP and HTTPS are supported. If you do not specify a protocol, HTTPS is used by default.
         config.setProtocol("http");
         Client client = new Client(config);
         ListJobRequest request = new ListJobRequest();
         // Set marker and count as needed.
         request.setCount(1);
         String marker = "";
         request.setMarker(marker);
         ListJobResponse resp = client.listJob(userId, request);
         System.out.println(new Gson().toJson(resp.getBody().getImportJobList()));
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

Sample success response

{
  "ImportJobList": {
    "NextMarker": "test_nex_marker",
    "Truncated": true,
    "ImportJob": [
      {
        "Name": "test_name",
        "SrcAddress": "test_src_address",
        "DestAddress": "test_dest_address",
        "Status": "IMPORT_JOB_DOING",
        "EnableMultiVersioning": false,
        "CreateTime": "2024-05-01T12:00:00.000Z",
        "ModifyTime": "2024-05-01T12:00:00.000Z",
        "Version": "test_id",
        "Audit": {
          "LogMode": "off"
        },
        "OverwriteMode": "always",
        "TransferMode": "all",
        "Tags": "K1:V1,K2:V2",
        "ParentName": "test_parent_name",
        "ParentVersion": "7db93837-a5ee-4e3a-b3c8-800e7947dabc",
        "ConvertSymlinkTarget": false,
        "CreateReport": false,
        "Owner": "test_owner",
        "FilterRule": {
          "KeyFilters": {
            "Includes": {
              "Regex": [
                ".*\\.jpg$"
              ]
            },
            "Excludes": {
              "Regex": [
                ".*\\.jpg$"
              ]
            }
          },
          "LastModifiedFilters": {
            "Includes": {
              "TimeFilter": [
                {
                  "StartTime": "2006-01-01T00:00:00Z",
                  "EndTime": "2006-12-31T23:59:59Z"
                }
              ]
            },
            "Excludes": {
              "TimeFilter": [
                {
                  "StartTime": "2006-01-01T00:00:00Z",
                  "EndTime": "2006-12-31T23:59:59Z"
                }
              ]
            }
          },
          "FileTypeFilters": {
            "ExcludeSymlink": true,
            "ExcludeDir": true
          }
        },
        "ImportQos": {
          "MaxBandWidth": 1073741824,
          "MaxImportTaskQps": 1000
        },
        "ScheduleRule": {
          "StartCronExpression": "0 0 * * * ?",
          "SuspendCronExpression": "0 0 * * * ?",
          "MaxScheduleCount": 1
        }
      }
    ]
  }
}

Get task retry information

Note
  • After a task runs, some files may fail to migrate. Data Online Migration creates a checklist of these failed files. You can use this method to retrieve the checklist for a specific task round. If ReadyRetry returns Ready, you can use the checklist to retry migrating the failed files.

  • The response provides the parameters needed to create a retry task.

  • This method checks whether failed files from a migration task can be retried.

The following sample code retrieves the retry information for a task in a specific round.

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.*;
import com.google.gson.Gson;

public class Demo {
   /** We strongly recommend that you do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and threaten the security of all resources in your account.*/
   static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
   static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
   /** Enter the ID of your Alibaba Cloud account.*/
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // Enter the task name.
      String jobName = "examplejob";
      // Enter the task round.
      int runtimeId = 1;
      try {
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
         // This example uses the China (Beijing) region.
         config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
         config.setAccessKeyId(accessKeyId);
         config.setAccessKeySecret(accessKeySecret);
         // HTTP and HTTPS are supported. If you do not specify a protocol, HTTPS is used by default.
         config.setProtocol("http");
         Client client = new Client(config);
         GetJobResultRequest request = new GetJobResultRequest();
         request.runtimeId = runtimeId;
         GetJobResultResponse resp = client.getJobResult(userId, jobName, request);
         System.out.println(new Gson().toJson(resp.body.importJobResult));
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

Sample success response

{
  "ImportJobResult": {
    "ReadyRetry": "Ready",
    "InvPath": "mainfest.json",
    "InvBucket": "test_sys_bucket",
    "InvDomain": "test_domain",
    "InvLocation": "oss",
    "InvAccessId": "test_access_id",
    "InvAccessSecret": "test_secret_key",
    "InvRegionId": "test_region_id",
    "AddressType": "ossinv",
    "TotalObjectCount": 1000,
    "CopiedObjectCount": 800,
    "FailedObjectCount": 200,
    "SkippedObjectCount": 200,
    "TotalObjectSize": 1000,
    "CopiedObjectSize": 800,
    "SkippedObjectSize": 800,
    "Version": "test_job_id"
  }
}

List task history

Note

Query the execution history of a specified task. Omit RuntimeId to list the history across all rounds.

The following sample code lists the history of a specified task.

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.*;
import com.google.gson.Gson;

public class Demo {
   /** We strongly recommend that you do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and threaten the security of all resources in your account.*/
   static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
   static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
   /** Enter the ID of your Alibaba Cloud account.*/
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // Enter the task name.
      String jobName = "examplejob";
      // Enter the task round. You can leave runtimeId unspecified to list the history of all rounds for the specified task.
      int runtimeId = 1;
      try {
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
         // This example uses the China (Beijing) region.
         config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
         config.setAccessKeyId(accessKeyId);
         config.setAccessKeySecret(accessKeySecret);
         // HTTP and HTTPS are supported. If you do not specify a protocol, HTTPS is used by default.
         config.setProtocol("http");
         Client client = new Client(config);
         ListJobHistoryRequest request = new ListJobHistoryRequest();
         // Set the following parameter values as needed.
         request.runtimeId = runtimeId;
         request.count = 1;
         request.marker = "";
         ListJobHistoryResponse resp = client.listJobHistory(userId, jobName, request);
         request.marker = resp.body.jobHistoryList.nextMarker;
         resp = client.listJobHistory(userId, jobName, request);
         System.out.println(new Gson().toJson(resp.body.jobHistoryList));
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

Sample success response

{
  "JobHistoryList": {
    "Truncated": "true",
    "NextMarker": "test_next_marker",
    "JobHistory": [
      {
        "Name": "test_name",
        "JobVersion": "test_id",
        "RuntimeId": "1",
        "CommitId": "2",
        "StartTime": "2024-05-01T12:00:00.000Z",
        "EndTime": "2024-05-01T12:00:00.000Z",
        "Status": "IMPORT_JOB_DOING",
        "TotalCount": 1000,
        "CopiedCount": 900,
        "FailedCount": 100,
        "TotalSize": 5368709120,
        "CopiedSize": 4294967296,
        "SkippedCount": 0,
        "SkippedSize": 0,
        "RuntimeState": "Normal",
        "Message": "test error msg.",
        "Operator": "user",
        "ListStatus": "Listing"
      }
    ]
  }
}

Delete a task

Note

Delete a migration task that you no longer need.

The following sample code deletes a task.

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.*;

public class Demo {
   /** We strongly recommend that you do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and threaten the security of all resources in your account.*/
   static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
   static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
   /** Enter the ID of your Alibaba Cloud account.*/
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // Enter the task name.
      String jobName = "examplejob";
      try {
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
         // This example uses the China (Beijing) region.
         config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
         config.setAccessKeyId(accessKeyId);
         config.setAccessKeySecret(accessKeySecret);
         // HTTP and HTTPS are supported. If you do not specify a protocol, HTTPS is used by default.
         config.setProtocol("http");
         Client client = new Client(config);
         DeleteJobRequest request = new DeleteJobRequest();
         client.deleteJob(userId, jobName, request);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

Create a task migration report

Note

This is an asynchronous call. After you call this method, the backend begins generating the migration report. To check whether the report is ready, call Get a task migration report.

The following sample code creates a migration report for a task.

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.*;

public class Demo {
   /** We strongly recommend that you do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and threaten the security of all resources in your account.*/
   static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
   static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
   /** Enter the ID of your Alibaba Cloud account.*/
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // Enter the task name. This parameter is required.
      String jobName = "examplejob";
      // Enter the task ID. This parameter is required.
      String version = "b4155550-****-4371-****-9c7337348021";
      // Enter the task round. This parameter is required.
      int runtimeId = 1;
      try {
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
         // This example uses the China (Beijing) region.
         config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
         config.setAccessKeyId(accessKeyId);
         config.setAccessKeySecret(accessKeySecret);
         // HTTP and HTTPS are supported. If you do not specify a protocol, HTTPS is used by default.
         config.setProtocol("http");
         Client client = new Client(config);
         CreateReportRequest request = new CreateReportRequest();
         CreateReportInfo info = new CreateReportInfo();
         info.jobName = jobName;
         info.version = version;
         info.runtimeId = runtimeId;
         request.setCreateReport(info);
         client.createReport(userId, request);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

Get a task migration report

Note

Retrieve the migration report for a specified task. The response indicates whether the report is generated and includes the report data if available.

The following sample code queries the migration report for a task.

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.*;
import com.google.gson.Gson;

public class Demo {
   /** We strongly recommend that you do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and threaten the security of all resources in your account.*/
   static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
   static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
   /** Enter the ID of your Alibaba Cloud account.*/
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // Enter the task ID. This parameter is required.
      String version = "b4155550-****-4371-****-9c7337348021";
      // Enter the task round. This parameter is required.
      int runtimeId = 1;
      try {
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
         // This example uses the China (Beijing) region.
         config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
         config.setAccessKeyId(accessKeyId);
         config.setAccessKeySecret(accessKeySecret);
         // HTTP and HTTPS are supported. If you do not specify a protocol, HTTPS is used by default.
         config.setProtocol("http");
         Client client = new Client(config);
         GetReportRequest request = new GetReportRequest();
         request.version = version;
         request.runtimeId = runtimeId;
         GetReportResponse resp = client.getReport(userId, request);
         System.out.println(new Gson().toJson(resp.body.getReportResponse));
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

Sample success response

{
  "GetReportResponse": {
    "Status": "Running",
    "ReportCreateTime": "2024-05-01T12:00:00.000Z",
    "ReportEndTime": "2024-05-01T12:00:00.000Z",
    "TotalCount": 1000,
    "CopiedCount": 800,
    "SkippedCount": 100,
    "FailedCount": 100,
    "JobCreateTime": "2024-05-01T12:00:00.000Z",
    "JobEndTime": "2024-05-01T12:00:00.000Z",
    "JobExecuteTime": "1000",
    "TotalListPrefix": "test_total_prefix/",
    "SkippedListPrefix": "test_skipped_prefix/",
    "FailedListPrefix": "test_failed_prefix/",
    "ErrorMessage": "test error msg."
  }
}