All Products
Search
Document Center

Data Online Migration:Manage tasks

Last Updated:Jun 06, 2025

This topic describes how to use Data Online Migration SDK for Java to manage tasks.

Create a task

Important

After the task is created, you must update its status to start it.

The following sample code shows how to create a task. For more information, see CreateJob.

package sample;

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

public class Demo {
   /** Do not store the AccessKey pair in the code. Otherwise, AccessKey pair leak may occur and all resources within your Alibaba Cloud account may be exposed to security risks. */
   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();
         // Specify the region. In this example, the China (Beijing) region is selected. 
         config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
         config.setAccessKeyId(accessKeyId);
         config.setAccessKeySecret(accessKeySecret);
         Client client = new Client(config);
         CreateJobInfo info = new CreateJobInfo();
         info.name = jobName;
         info.srcAddress = srcAddress;
         info.destAddress = destAddress;
         /**
          The overwriteMode and transferMode parameters must be used in combination. The following combinations are supported:
          always,all: overwrite all files
          always,lastmodified: overwrite files based on the last modification time
          never,changed: do not overwrite files
        */
         /* The file overwriting method. Valid values: never and always. */
         info.overwriteMode = "always";
         /* The file transfer method. Valid values: changed, all, and lastmodified. */
         info.transferMode = "lastmodified";

         // If you set the maxImportTaskQps parameter to 0 or leave the parameter empty, the default value is used. If you set the MaxBandWidth parameter to 0 or leave the parameter empty, the default value is used. Unit: bit/s. 
         ImportQos importQos = new ImportQos();
         // Specify the maxBandWidth and maxImportTaskQps parameters as needed. 
         importQos.maxBandWidth = 1073741824L;
         importQos.maxImportTaskQps = 1000L;
         info.setImportQos(importQos);

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

         // Configure the filtering rule. For more information, see the corresponding API documentation. 
         FilterRule filterRule = new FilterRule();
         // Specify the file filter 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);

         // Specify the time filter as needed. The time must be in UTC. 
         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

After creating a task, use this method to start, suspend, or stop the task. You can also use this method to adjust the task throttling settings.

The following sample code shows how to update the status of a task. For more information, see UpdateJob.

package sample;

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

public class Demo {
	/** Do not store the AccessKey pair in the code. Otherwise, AccessKey pair leak may occur and all resources within your Alibaba Cloud account may be exposed to security risks. */
	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();
			// Specify the region. In this example, the China (Beijing) region is selected. 
			config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
			config.setAccessKeyId(accessKeyId);
			config.setAccessKeySecret(accessKeySecret);
			Client client = new Client(config);
			UpdateJobRequest updateJobRequest = new UpdateJobRequest();
			UpdateJobInfo updateJobInfo = new UpdateJobInfo();
			// Valid values: IMPORT_JOB_LAUNCHING (start the task), IMPORT_JOB_SUSPEND (suspend the task), and IMPORT_JOB_CLOSING (stop the task).
			updateJobInfo.setStatus("IMPORT_JOB_LAUNCHING");
			updateJobRequest.setImportJob(updateJobInfo);
			client.updateJob(userId, jobName, updateJobRequest);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

The following sample code shows how to update the throttling settings of a task:

package sample;

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

public class Demo {
	/** Do not store the AccessKey pair in the code. Otherwise, AccessKey pair leak may occur and all resources within your Alibaba Cloud account may be exposed to security risks. */
	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();
			// Specify the region. In this example, the China (Beijing) region is selected. 
			config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
			config.setAccessKeyId(accessKeyId);
			config.setAccessKeySecret(accessKeySecret);
			Client client = new Client(config);
			UpdateJobRequest updateJobRequest = new UpdateJobRequest();
			UpdateJobInfo updateJobInfo = new UpdateJobInfo();
			// Specify the maxBandWidth and maxImportTaskQps parameters 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();
		}
	}
}

Query the details of a task

The following sample code shows how to query the details of a task by task name. For more information, see GetJob.

package sample;

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

public class Demo {
   /** Do not store the AccessKey pair in the code. Otherwise, AccessKey pair leak may occur and all resources within your Alibaba Cloud account may be exposed to security risks. */
   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();
         // Specify the region. In this example, the China (Beijing) region is selected. 
         config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
         config.setAccessKeyId(accessKeyId);
         config.setAccessKeySecret(accessKeySecret);
         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 shows how to query the details of a task by using the task ID:

package sample;

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

public class Demo {
	/** Do not store the AccessKey pair in the code. Otherwise, AccessKey pair leak may occur and all resources within your Alibaba Cloud account may be exposed to security risks. */
	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();
			// Specify the region. In this example, the China (Beijing) region is selected. 
			config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
			config.setAccessKeyId(accessKeyId);
			config.setAccessKeySecret(accessKeySecret);
			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-31T59:59:59Z"
            }
          ]
        },
        "Excludes": {
          "TimeFilter": [
            {
              "StartTime": "2006-01-01T00:00:00Z",
              "EndTime": "2006-12-31T59:59:59Z"
            }
          ]
        }
      },
      "FileTypeFilters": {
        "ExcludeSymlink": true,
        "ExcludeDir": true
      }
    },
    "ImportQos": {
      "MaxBandWidth": 1073741824,
      "MaxImportTaskQps": 1000
    },
    "ScheduleRule": {
      "StartCronExpression": "0 0 * * * ?",
      "SuspendCronExpression": "0 0 * * * ?",
      "MaxScheduleCount": 1
    }
  }
}

List tasks

The following sample code shows how to list all the tasks within your Alibaba Cloud account. For more information, see ListJob.

package sample;

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

public class Demo {
   /** Do not store the AccessKey pair in the code. Otherwise, AccessKey pair leak may occur and all resources within your Alibaba Cloud account may be exposed to security risks. */
   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();
         // Specify the region. In this example, the China (Beijing) region is selected. 
         config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
         config.setAccessKeyId(accessKeyId);
         config.setAccessKeySecret(accessKeySecret);
         Client client = new Client(config);
         ListJobRequest request = new ListJobRequest();
         // Specify the marker and count parameters 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-31T59:59:59Z"
                }
              ]
            },
            "Excludes": {
              "TimeFilter": [
                {
                  "StartTime": "2006-01-01T00:00:00Z",
                  "EndTime": "2006-12-31T59:59:59Z"
                }
              ]
            }
          },
          "FileTypeFilters": {
            "ExcludeSymlink": true,
            "ExcludeDir": true
          }
        },
        "ImportQos": {
          "MaxBandWidth": 1073741824,
          "MaxImportTaskQps": 1000
        },
        "ScheduleRule": {
          "StartCronExpression": "0 0 * * * ?",
          "SuspendCronExpression": "0 0 * * * ?",
          "MaxScheduleCount": 1
        }
      }
    ]
  }
}

Query the retry information about a task

After the task is completed, some files may fail to migrate. Data Online Migration creates a checklist for these failed files. Use the following sample code to obtain the checklist information of failed files for a specified round. If the returned result is Ready, you can use this checklist to retry the failed files.

For more information, see GetJobResult.

package sample;

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

public class Demo {
   /** Do not store the AccessKey pair in the code. Otherwise, AccessKey pair leak may occur and all resources within your Alibaba Cloud account may be exposed to security risks. */
   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";
      // Specify the number of the task round. 
      int runtimeId = 1;
      try {
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
         // Specify the region. In this example, the China (Beijing) region is selected. 
         config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
         config.setAccessKeyId(accessKeyId);
         config.setAccessKeySecret(accessKeySecret);
         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,
    "TotalObjectSize": 1000,
    "CopiedObjectSize": 800,
    "Version": "test_job_id"
  }
}

List the historical records of a task

The following sample code shows how to list the historical records of a task. For more information, see ListJobHistory.

package sample;

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

public class Demo {
   /** Do not store the AccessKey pair in the code. Otherwise, AccessKey pair leak may occur and all resources within your Alibaba Cloud account may be exposed to security risks. */
   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";
      // Specify the number of the task round. You can leave the runtimeId parameter empty, which specifies that the historical records of a task in all rounds are queried. 
      int runtimeId = 1;
      try {
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
         // Specify the region. In this example, the China (Beijing) region is selected. 
         config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
         config.setAccessKeyId(accessKeyId);
         config.setAccessKeySecret(accessKeySecret);
         Client client = new Client(config);
         ListJobHistoryRequest request = new ListJobHistoryRequest();
         // Specify the following parameters 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": 1000,
        "CopiedSize": 1000,
        "RuntimeState": "Normal",
        "Message": "test error msg.",
        "Operator": "user",
        "ListStatus": "Listing"
      }
    ]
  }
}

Delete a task

The following sample code shows how to delete a task. For more information, see DeleteJob.

package sample;

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

public class Demo {
   /** Do not store the AccessKey pair in the code. Otherwise, AccessKey pair leak may occur and all resources within your Alibaba Cloud account may be exposed to security risks. */
   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();
         // Specify the region. In this example, the China (Beijing) region is selected. 
         config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
         config.setAccessKeyId(accessKeyId);
         config.setAccessKeySecret(accessKeySecret);
         Client client = new Client(config);
         DeleteJobRequest request = new DeleteJobRequest();
         client.deleteJob(userId, jobName, request);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

Generate a migration report for a task

A migration report is generated in asynchronous mode. After a request is sent, the migration report is generated in the backend. You must query the migration report of a task to obtain the results.

The following sample code shows how to generate a migration report for a task. For more information, see CreateReport.

package sample;

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

public class Demo {
   /** Do not store the AccessKey pair in the code. Otherwise, AccessKey pair leak may occur and all resources within your Alibaba Cloud account may be exposed to security risks. */
   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) {
      // Required. Enter the task name. 
      String jobName = "examplejob";
      // Required. Enter the task ID. 
      String version = "b4155550-****-4371-****-9c7337348021";
      // Required. Enter the number of the task round. 
      int runtimeId = 1;
      try {
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
         // Specify the region. In this example, the China (Beijing) region is selected. 
         config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
         config.setAccessKeyId(accessKeyId);
         config.setAccessKeySecret(accessKeySecret);
         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();
      }
   }
}

Query the migration report of a task

The following sample code shows how to check whether a migration report is created for the specified task and obtain the migration report. For more information, see GetReport.

package sample;

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

public class Demo {
   /** Do not store the AccessKey pair in the code. Otherwise, AccessKey pair leak may occur and all resources within your Alibaba Cloud account may be exposed to security risks. */
   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) {
      // Required. Enter the task ID. 
      String version = "b4155550-****-4371-****-9c7337348021";
      // Required. Enter the number of the task round. 
      int runtimeId = 1;
      try {
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
         // Specify the region. In this example, the China (Beijing) region is selected. 
         config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
         config.setAccessKeyId(accessKeyId);
         config.setAccessKeySecret(accessKeySecret);
         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."
  }
}