All Products
Search
Document Center

Data Online Migration:Data addresses

Last Updated:Jun 30, 2026

This topic describes how to use the SDK to manage data addresses. A data address is a source or destination for a data migration task.

Create a data address

The following example shows how to create a data address for Alibaba Cloud OSS.

Important
  • Before you create a data address for Alibaba Cloud OSS, you must configure a role and obtain the role name (rolename).

  • Depending on your scenario, you may need to associate an agent. For more information, see Migrate data by using an agent. This association method applies to all data address types.

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.AddressDetail;
import com.aliyun.hcs_mgw20240626.models.CreateAddressInfo;
import com.aliyun.hcs_mgw20240626.models.CreateAddressRequest;

public class Demo {
	/** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your code. Leaking your AccessKeys can compromise 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");
	/** Specify the ID of your Alibaba Cloud account. */
	static String userId = "11470***876***55";

	public static void main(String[] args) {
		// Specify the name of the data address.
		String addressName = "exampleaddress";
		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);
			AddressDetail detail = new AddressDetail();
			detail.addressType = "oss";
			// Replace the following with your actual values.
			detail.bucket = "examplebucket";
			detail.prefix = "***/";
			detail.regionId = "oss-cn-beijing";
			detail.role = "rolename_xxxxx";
			// A list of agents. Omit this parameter if no agents are required.
			detail.agentList = "agent1,agent2,agent3";
			CreateAddressRequest request = new CreateAddressRequest();
			CreateAddressInfo info = new CreateAddressInfo();
			info.name = addressName;
			info.setAddressDetail(detail);
			request.setImportAddress(info);
			client.createAddress(userId, request);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

The following example shows how to create a data address for an OSS inventory.

Important

Before you create a data address for an OSS inventory, you must configure a role and obtain the role name (rolename) and the inventory role name (invrolename).

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.AddressDetail;
import com.aliyun.hcs_mgw20240626.models.CreateAddressInfo;
import com.aliyun.hcs_mgw20240626.models.CreateAddressRequest;

public class Demo {
   /** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your code. Leaking your AccessKeys can compromise 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");
   /** Specify the ID of your Alibaba Cloud account. */
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // Specify the name of the data address.
      String addressName = "exampleaddress";
      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);
         AddressDetail detail = new AddressDetail();
         // The following parameters define the data to migrate.
         detail.addressType = "ossinv";
         detail.bucket = "examplebucket";
         detail.prefix = "***/";
         detail.regionId = "oss-cn-beijing";
         detail.role = "rolename_*******";
         // The following parameters define the inventory.
         detail.invLocation = "oss";
         detail.invAccessId = "***";
         detail.invAccessSecret = "******";
         detail.invBucket = "exampleinvbucket";
         detail.invRegionId = "oss-cn-beijing";
         detail.invRole = "invrolename_*******";
         detail.invPath = "dir/manifest.json";
         CreateAddressRequest request = new CreateAddressRequest();
         CreateAddressInfo info = new CreateAddressInfo();
         info.name = addressName;
         info.setAddressDetail(detail);
         request.setImportAddress(info);
         client.createAddress(userId, request);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

The following example shows how to create a data address for a generic inventory.

Important

Before you create a data address for a generic inventory, you must configure a role and obtain the role name (rolename) and the inventory role name (invrolename).

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.AddressDetail;
import com.aliyun.hcs_mgw20240626.models.CreateAddressInfo;
import com.aliyun.hcs_mgw20240626.models.CreateAddressRequest;

public class Demo {
   /** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your code. Leaking your AccessKeys can compromise 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");
   /** Specify the ID of your Alibaba Cloud account. */
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // Specify the name of the data address.
      String addressName = "exampleaddress";
      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);
         AddressDetail detail = new AddressDetail();
         // The following parameters specify information about the data to be migrated. Replace the values with your actual information.
         detail.addressType = "inv";
         // When addressType is "inv", valid values for dataType include: oss, s3, cos, obs, tos, qiniu, gcp, azure, ks3, bos, us3, and uss.
         detail.dataType = "oss";
         detail.bucket = "examplebucket";
         detail.prefix = "***/";
         detail.regionId = "oss-cn-beijing";
         detail.role = "rolename_*******";
         // The following parameters specify information about the inventory.
         detail.invLocation = "oss";
         detail.invAccessId = "***";
         detail.invAccessSecret = "******";
         detail.invBucket = "exampleinvbucket";
         detail.invRegionId = "oss-cn-beijing";
         detail.invRole = "invrolename_*******";
         detail.invPath = "dir/manifest.json";
         CreateAddressRequest request = new CreateAddressRequest();
         CreateAddressInfo info = new CreateAddressInfo();
         info.name = addressName;
         info.setAddressDetail(detail);
         request.setImportAddress(info);
         client.createAddress(userId, request);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

The following examples show how to create a data address for third-party cloud storage.

Amazon S3

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.AddressDetail;
import com.aliyun.hcs_mgw20240626.models.CreateAddressInfo;
import com.aliyun.hcs_mgw20240626.models.CreateAddressRequest;

public class Demo {
   /** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your code. Leaking your AccessKeys can compromise 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");
   /** Specify the ID of your Alibaba Cloud account. */
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // Specify the name of the data address.
      String addressName = "exampleaddress";
      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);
         AddressDetail detail = new AddressDetail();
         // The following parameters specify information about the data to be migrated. Replace the values with your actual information.
         detail.addressType = "s3";
         detail.accessId = "***";
         detail.accessSecret = "******";
         detail.domain = "s3.ap-southeast-1.amazonaws.com";
         detail.bucket = "examplebucket";
         detail.prefix = "***/";
         CreateAddressRequest request = new CreateAddressRequest();
         CreateAddressInfo info = new CreateAddressInfo();
         info.name = addressName;
         info.setAddressDetail(detail);
         request.setImportAddress(info);
         client.createAddress(userId, request);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

S3-compatible storage

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.AddressDetail;
import com.aliyun.hcs_mgw20240626.models.CreateAddressInfo;
import com.aliyun.hcs_mgw20240626.models.CreateAddressRequest;

public class Demo {
   /** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your code. Leaking your AccessKeys can compromise 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");
   /** Specify the ID of your Alibaba Cloud account. */
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // Specify the name of the data address.
      String addressName = "exampleaddress";
      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);
         AddressDetail detail = new AddressDetail();
         // The following parameters specify information about the data to be migrated. Replace the values with your actual information.
         detail.addressType = "s3compat";
         detail.accessId = "***";
         detail.accessSecret = "******";
         detail.domain = "<s3-compatible-url>";
         detail.bucket = "examplebucket";
         detail.prefix = "***/";
         CreateAddressRequest request = new CreateAddressRequest();
         CreateAddressInfo info = new CreateAddressInfo();
         info.name = addressName;
         info.setAddressDetail(detail);
         request.setImportAddress(info);
         client.createAddress(userId, request);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

Tencent COS

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.AddressDetail;
import com.aliyun.hcs_mgw20240626.models.CreateAddressInfo;
import com.aliyun.hcs_mgw20240626.models.CreateAddressRequest;

public class Demo {
   /** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your code. Leaking your AccessKeys can compromise 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");
   /** Specify the ID of your Alibaba Cloud account. */
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // Specify the name of the data address.
      String addressName = "exampleaddress";
      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);
         AddressDetail detail = new AddressDetail();
         // The following parameters specify information about the data to be migrated. Replace the values with your actual information.
         detail.addressType = "cos";
         detail.accessId = "***";
         detail.accessSecret = "******";
         detail.domain = "cos.ap-nanjing.myqcloud.com";
         detail.bucket = "examplebucket";
         detail.prefix = "***/";
         CreateAddressRequest request = new CreateAddressRequest();
         CreateAddressInfo info = new CreateAddressInfo();
         info.name = addressName;
         info.setAddressDetail(detail);
         request.setImportAddress(info);
         client.createAddress(userId, request);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

Huawei OBS

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.AddressDetail;
import com.aliyun.hcs_mgw20240626.models.CreateAddressInfo;
import com.aliyun.hcs_mgw20240626.models.CreateAddressRequest;

public class Demo {
   /** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your code. Leaking your AccessKeys can compromise 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");
   /** Specify the ID of your Alibaba Cloud account. */
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // Specify the name of the data address.
      String addressName = "exampleaddress";
      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);
         AddressDetail detail = new AddressDetail();
         // The following parameters specify information about the data to be migrated. Replace the values with your actual information.
         detail.addressType = "obs";
         detail.accessId = "***";
         detail.accessSecret = "******";
         detail.domain = "obs.cn-north-1.myhuaweicloud.com";
         detail.bucket = "examplebucket";
         detail.prefix = "***/";
         CreateAddressRequest request = new CreateAddressRequest();
         CreateAddressInfo info = new CreateAddressInfo();
         info.name = addressName;
         info.setAddressDetail(detail);
         request.setImportAddress(info);
         client.createAddress(userId, request);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

Volcengine TOS

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.AddressDetail;
import com.aliyun.hcs_mgw20240626.models.CreateAddressInfo;
import com.aliyun.hcs_mgw20240626.models.CreateAddressRequest;

public class Demo {
   /** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your code. Leaking your AccessKeys can compromise 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");
   /** Specify the ID of your Alibaba Cloud account. */
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // Specify the name of the data address.
      String addressName = "exampleaddress";
      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);
         AddressDetail detail = new AddressDetail();
         // The following parameters specify information about the data to be migrated. Replace the values with your actual information.
         detail.addressType = "tos";
         detail.accessId = "***";
         detail.accessSecret = "******";
         detail.domain = "tos-s3-cn-beijing.volces.com";
         detail.bucket = "examplebucket";
         detail.prefix = "***/";
         CreateAddressRequest request = new CreateAddressRequest();
         CreateAddressInfo info = new CreateAddressInfo();
         info.name = addressName;
         info.setAddressDetail(detail);
         request.setImportAddress(info);
         client.createAddress(userId, request);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

Qiniu Kodo

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.AddressDetail;
import com.aliyun.hcs_mgw20240626.models.CreateAddressInfo;
import com.aliyun.hcs_mgw20240626.models.CreateAddressRequest;

public class Demo {
   /** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your code. Leaking your AccessKeys can compromise 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");
   /** Specify the ID of your Alibaba Cloud account. */
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // Specify the name of the data address.
      String addressName = "exampleaddress";
      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);
         AddressDetail detail = new AddressDetail();
         // The following parameters specify information about the data to be migrated. Replace the values with your actual information.
         detail.addressType = "qiniu";
         detail.accessId = "***";
         detail.accessSecret = "******";
         // For more information about domains, see https://developer.qiniu.com/kodo/8527/kodo-domain-name-management
         detail.domain = "http://xxxx.com";
         detail.bucket = "examplebucket";
         detail.prefix = "***/";
         CreateAddressRequest request = new CreateAddressRequest();
         CreateAddressInfo info = new CreateAddressInfo();
         info.name = addressName;
         info.setAddressDetail(detail);
         request.setImportAddress(info);
         client.createAddress(userId, request);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

Google Cloud Storage

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.AddressDetail;
import com.aliyun.hcs_mgw20240626.models.CreateAddressInfo;
import com.aliyun.hcs_mgw20240626.models.CreateAddressRequest;

public class Demo {
   /** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your code. Leaking your AccessKeys can compromise 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");
   /** Specify the ID of your Alibaba Cloud account. */
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // Specify the name of the data address.
      String addressName = "exampleaddress";
      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);
         AddressDetail detail = new AddressDetail();
         // The following parameters specify information about the data to be migrated. Replace the values with your actual information.
         detail.addressType = "gcp";
         detail.accessId = "***";
         detail.accessSecret = "******";
         // Replace the domain with your actual value.
         detail.domain = "Cloud Storage URI";
         detail.bucket = "examplebucket";
         detail.prefix = "***/";
         CreateAddressRequest request = new CreateAddressRequest();
         CreateAddressInfo info = new CreateAddressInfo();
         info.name = addressName;
         info.setAddressDetail(detail);
         request.setImportAddress(info);
         client.createAddress(userId, request);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

Azure Blob Storage

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.AddressDetail;
import com.aliyun.hcs_mgw20240626.models.CreateAddressInfo;
import com.aliyun.hcs_mgw20240626.models.CreateAddressRequest;

public class Demo {
   /** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your code. Leaking your AccessKeys can compromise 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");
   /** Specify the ID of your Alibaba Cloud account. */
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // Specify the name of the data address.
      String addressName = "exampleaddress";
      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);
         AddressDetail detail = new AddressDetail();
         // The following parameters specify information about the data to be migrated. Replace the values with your actual information.
         detail.addressType = "azure";
         detail.accessId = "***";
         detail.accessSecret = "******";
         detail.domain = "https://<storage-account>.blob.core.windows.net";
         detail.bucket = "examplebucket";
         detail.prefix = "***/";
         CreateAddressRequest request = new CreateAddressRequest();
         CreateAddressInfo info = new CreateAddressInfo();
         info.name = addressName;
         info.setAddressDetail(detail);
         request.setImportAddress(info);
         client.createAddress(userId, request);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

Kingsoft KS3

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.AddressDetail;
import com.aliyun.hcs_mgw20240626.models.CreateAddressInfo;
import com.aliyun.hcs_mgw20240626.models.CreateAddressRequest;

public class Demo {
   /** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your code. Leaking your AccessKeys can compromise 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");
   /** Specify the ID of your Alibaba Cloud account. */
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // Specify the name of the data address.
      String addressName = "exampleaddress";
      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);
         AddressDetail detail = new AddressDetail();
         // The following parameters specify information about the data to be migrated. Replace the values with your actual information.
         detail.addressType = "ks3";
         detail.accessId = "***";
         detail.accessSecret = "******";
         detail.domain = "ks3-cn-beijing.ksyuncs.com";
         detail.bucket = "examplebucket";
         detail.prefix = "***/";
         CreateAddressRequest request = new CreateAddressRequest();
         CreateAddressInfo info = new CreateAddressInfo();
         info.name = addressName;
         info.setAddressDetail(detail);
         request.setImportAddress(info);
         client.createAddress(userId, request);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

Baidu BOS

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.AddressDetail;
import com.aliyun.hcs_mgw20240626.models.CreateAddressInfo;
import com.aliyun.hcs_mgw20240626.models.CreateAddressRequest;

public class Demo {
   /** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your code. Leaking your AccessKeys can compromise 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");
   /** Specify the ID of your Alibaba Cloud account. */
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // Specify the name of the data address.
      String addressName = "exampleaddress";
      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);
         AddressDetail detail = new AddressDetail();
         // The following parameters specify information about the data to be migrated. Replace the values with your actual information.
         detail.addressType = "bos";
         detail.accessId = "***";
         detail.accessSecret = "******";
         detail.domain = "bj.bcebos.com";
         detail.bucket = "examplebucket";
         detail.prefix = "***/";
         CreateAddressRequest request = new CreateAddressRequest();
         CreateAddressInfo info = new CreateAddressInfo();
         info.name = addressName;
         info.setAddressDetail(detail);
         request.setImportAddress(info);
         client.createAddress(userId, request);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

UCloud US3

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.AddressDetail;
import com.aliyun.hcs_mgw20240626.models.CreateAddressInfo;
import com.aliyun.hcs_mgw20240626.models.CreateAddressRequest;

public class Demo {
   /** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your code. Leaking your AccessKeys can compromise 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");
   /** Specify the ID of your Alibaba Cloud account. */
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // Specify the name of the data address.
      String addressName = "exampleaddress";
      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);
         AddressDetail detail = new AddressDetail();
         // The following parameters specify information about the data to be migrated. Replace the values with your actual information.
         detail.addressType = "us3";
         detail.accessId = "***";
         detail.accessSecret = "******";
         detail.domain = "cn-bj.ufileos.com";
         detail.bucket = "examplebucket";
         detail.prefix = "***/";
         CreateAddressRequest request = new CreateAddressRequest();
         CreateAddressInfo info = new CreateAddressInfo();
         info.name = addressName;
         info.setAddressDetail(detail);
         request.setImportAddress(info);
         client.createAddress(userId, request);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

UPYUN

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.AddressDetail;
import com.aliyun.hcs_mgw20240626.models.CreateAddressInfo;
import com.aliyun.hcs_mgw20240626.models.CreateAddressRequest;

public class Demo {
   /** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your code. Leaking your AccessKeys can compromise 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");
   /** Specify the ID of your Alibaba Cloud account. */
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // Specify the name of the data address.
      String addressName = "exampleaddress";
      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);
         AddressDetail detail = new AddressDetail();
         // The following parameters specify information about the data to be migrated. Replace the values with your actual information.
         detail.addressType = "uss";
         detail.accessId = "***";
         detail.accessSecret = "******";
         detail.domain = "s3.api.upyun.com";
         detail.bucket = "examplebucket";
         detail.prefix = "***/";
         CreateAddressRequest request = new CreateAddressRequest();
         CreateAddressInfo info = new CreateAddressInfo();
         info.name = addressName;
         info.setAddressDetail(detail);
         request.setImportAddress(info);
         client.createAddress(userId, request);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

The following example shows how to create a data address for the HTTP/HTTPS type.

Important

Before you create a data address for the HTTP/HTTPS type, you must configure a role and obtain the inventory role name (invrolename).

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.AddressDetail;
import com.aliyun.hcs_mgw20240626.models.CreateAddressInfo;
import com.aliyun.hcs_mgw20240626.models.CreateAddressRequest;

public class Demo {
	/** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your code. Leaking your AccessKeys can compromise 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");
	/** Specify the ID of your Alibaba Cloud account. */
	static String userId = "11470***876***55";

	public static void main(String[] args) {
		// Specify the name of the data address.
		String addressName = "exampleaddress";
		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);
			AddressDetail detail = new AddressDetail();
			// The following parameters specify information about the data to be migrated. Replace the values with your actual information.
			detail.addressType = "http";
			detail.invLocation = "oss";
			detail.invBucket = "exampleinvbucket";
			detail.invRegionId = "oss-cn-beijing";
			detail.invRole = "invrolename_*******";
			detail.invPath = "dir/manifest.json";
			CreateAddressRequest request = new CreateAddressRequest();
			CreateAddressInfo info = new CreateAddressInfo();
			info.name = addressName;
			info.setAddressDetail(detail);
			request.setImportAddress(info);
			client.createAddress(userId, request);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

The following example shows how to create a data address for the LocalFS type. A LocalFS data address requires an associated agent.

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.AddressDetail;
import com.aliyun.hcs_mgw20240626.models.CreateAddressInfo;
import com.aliyun.hcs_mgw20240626.models.CreateAddressRequest;

public class Demo {
	/** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your code. Leaking your AccessKeys can compromise 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");
	/** Specify the ID of your Alibaba Cloud account. */
	static String userId = "11470***876***55";

	public static void main(String[] args) {
		// Specify the name of the data address.
		String addressName = "exampleaddress";
		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);
			AddressDetail detail = new AddressDetail();
			// The following parameters specify information about the data to be migrated. Replace the values with your actual information.
			detail.addressType = "local";
			detail.prefix = "/***/";
			// A list of agents.
			detail.agentList = "agent1,agent2,agent3"
			CreateAddressRequest request = new CreateAddressRequest();
			CreateAddressInfo info = new CreateAddressInfo();
			info.name = addressName;
			info.setAddressDetail(detail);
			request.setImportAddress(info);
			client.createAddress(userId, request);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Data address details

The following example shows how to get the details of a data address.

package sample;

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

public class Demo {
	/** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your code. Leaking your AccessKeys can compromise 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");
	/** Specify the ID of your Alibaba Cloud account. */
	static String userId = "11470***876***55";

	public static void main(String[] args) {
		// Specify the name of the data address.
		String addressName = "exampleaddress";
		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);
			GetAddressResponse resp = client.getAddress(userId, addressName);
			System.out.println(new Gson().toJson(resp.getBody().getImportAddress()));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Sample success response

{
  "ImportAddress": {
    "Owner": "test_owner",
    "Name": "test_name",
    "AddressDetail": {
      "AddressType": "ossinv",
      "Bucket": "test_bucket",
      "Domain": "test_domain",
      "Prefix": "test_prefix",
      "AccessId": "test_access_id",
      "AccessSecret": "test_secret_key",
      "Role": "test_role",
      "InvDomain": "test_inv_domain",
      "InvBucket": "test_inv_bucket",
      "InvAccessId": "test_inv_access_id",
      "InvAccessSecret": "test_inv_secret_key",
      "InvPath": "manifest.json",
      "InvRole": "test_inv_role",
      "InvLocation": "oss",
      "AgentList": "agent1,agent2",
      "RegionId": "test_region_id",
      "InvRegionId": "test_inv_region_id"
    },
    "CreateTime": "2024-05-01T12:00:00.000Z",
    "ModifyTime": "2024-05-01T12:00:00.000Z",
    "VerifyTime": "2024-05-01T12:00:00.000Z",
    "Version": "test_id",
    "Tags": "K1:V1,K2:V2",
    "Status": "available",
    "VerifyResult": {
      "HttpCode": "400",
      "ErrorCode": "InvalidArgument",
      "ErrorMsg": "Invalid argument."
    }
  }
}

Verify data address

The following example shows how to verify a data address.

package sample;

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

public class Demo {
   /** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your code. Leaking your AccessKeys can compromise 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");
   /** Specify the ID of your Alibaba Cloud account. */
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // Specify the name of the data address.
      String addressName = "exampleaddress";
      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);
         VerifyAddressResponse resp = client.verifyAddress(userId, addressName);
         // The data address is valid only if the status field is "available". Any other value indicates that the address is invalid.
         System.out.println(new Gson().toJson(resp.getBody().verifyAddressResponse.status));
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

Sample success response (available)

{
  "VerifyAddressResponse": {
    "Status": "available",
    "VerifyTime": "2024-05-01T12:00:00.000Z",
    "ErrorCode": "",
    "ErrorMessage": ""
  }
}

Sample success response (unavailable)

{
  "VerifyAddressResponse": {
    "Status": "unavailable",
    "VerifyTime": "2024-05-01T12:00:00.000Z",
    "ErrorCode": "400",
    "ErrorMessage": "Invalid argument."
  }
}

List data addresses

The following example shows how to list all data addresses in your Alibaba Cloud account.

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.ListAddressRequest;
import com.aliyun.hcs_mgw20240626.models.ListAddressResponse;
import com.google.gson.Gson;

public class Demo {
   /** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your code. Leaking your AccessKeys can compromise 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");
   /** Specify 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);
         ListAddressRequest request = new ListAddressRequest();
         // Replace the marker and count values with your actual values.
         String marker = "";
         int count = 1;
         request.setMarker(marker);
         request.setCount(count);
         ListAddressResponse resp = client.listAddress(userId, request);
         System.out.println(new Gson().toJson(resp.getBody().getImportAddressList()));
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

Sample success response

{
  "ImportAddressList": {
    "Truncated": true,
    "NextMarker": "test_marker",
    "ImportAddress": [
      {
        "Owner": "test_owner",
        "Name": "test_name",
        "AddressDetail": {
          "AddressType": "ossinv",
          "Bucket": "test_bucket",
          "Domain": "test_domain",
          "Prefix": "test_prefix",
          "AccessId": "test_access_id",
          "AccessSecret": "test_secret_key",
          "Role": "test_role",
          "InvDomain": "test_inv_domain",
          "InvBucket": "test_inv_bucket",
          "InvAccessId": "test_inv_access_id",
          "InvAccessSecret": "test_inv_secret_key",
          "InvPath": "manifest.json",
          "InvRole": "test_inv_role",
          "InvLocation": "oss",
          "AgentList": "agent1,agent2",
          "RegionId": "test_region_id",
          "InvRegionId": "test_inv_region_id"
        },
        "CreateTime": "2024-05-01T12:00:00.000Z",
        "ModifyTime": "2024-05-01T12:00:00.000Z",
        "VerifyTime": "2024-05-01T12:00:00.000Z",
        "Version": "test_id",
        "Tags": "K1:V1,K2:V2",
        "Status": "available",
        "VerifyResult": {
          "HttpCode": "400",
          "ErrorCode": "InvalidArgument",
          "ErrorMsg": "Invalid argument."
        }
      }
    ]
  }
}

Update data address

The following example shows how to update the agents associated with a data address. This is useful for scaling agents up or down.

Important

You must specify at least one agent name. The agent's tunnel cannot be changed. Otherwise, the update will fail.

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 code. Leaking your AccessKeys can compromise 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");
   /** Specify the ID of your Alibaba Cloud account. */
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // Specify the name of the data address.
      String addressName = "exampleaddress";
      // Specify a comma-separated list of agent names. The list cannot be empty.
      String agentList = "exampleagent1,exampleagent2,exampleagent3...";
      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);
         UpdateAddressRequest request = new UpdateAddressRequest();
         UpdateAddressInfo info = new UpdateAddressInfo();
         info.setAgentList(agentList);
         request.setImportAddress(info);
         client.updateAddress(userId, addressName, request);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

Delete data address

The following example shows how to delete a data address.

package sample;

import com.aliyun.hcs_mgw20240626.Client;

public class Demo {
   /** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your code. Leaking your AccessKeys can compromise 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");
   /** Specify the ID of your Alibaba Cloud account. */
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // Specify the name of the data address.
      String addressName = "exampleaddress";
      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);
         client.deleteAddress(userId, addressName);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

Next steps

After you create a data address, you can create a task. For more information, see Manage tasks.