All Products
Search
Document Center

Data Online Migration:Data addresses

Last Updated:Dec 11, 2025

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

Create a data address

The following sample code shows how to create an OSS-type data address:

Important
  • Before creating an OSS-type data address, you must configure a role and obtain the rolename.

  • Whether you need to associate an agent depends on your situation. For more information, see Migration with agents - Overview. The method for associating agents with other data addresses is the same as in this example.

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 {
	/** Do not save your AccessKey ID and AccessKey secret in your project code. If you leak your AccessKey pair, the security of all resources in your account is at risk.*/
	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);
			// HTTPS and HTTP 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";
			// Set the following parameters to your actual values.
			detail.bucket = "examplebucket";
			detail.prefix = "***/";
			detail.regionId = "oss-cn-beijing";
			detail.role = "rolename_xxxxx";
			// The list of agents. Do not specify this parameter if you do not need to associate an agent.
			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 sample code shows how to create a data address of the OSS inventory type:

Important

Before creating a data address of the OSS inventory type, you must configure a role and obtain the rolename and 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 {
   /** Do not save your AccessKey ID and AccessKey secret in your project code. If you leak your AccessKey pair, the security of all resources in your account is at risk.*/
   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);
         // HTTPS and HTTP 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 are related to the data to be migrated. Set them to your actual values.
         detail.addressType = "ossinv";
         detail.bucket = "examplebucket";
         detail.prefix = "***/";
         detail.regionId = "oss-cn-beijing";
         detail.role = "rolename_*******";
         // The following parameters are related to 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 sample code shows how to create a generic inventory data address.

Important

Before you create an inventory data address, you must configure a role and obtain the rolename and 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 {
   /** Do not save your AccessKey ID and AccessKey secret in your project code. If you leak your AccessKey pair, the security of all resources in your account is at risk.*/
   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);
         // HTTPS and HTTP 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 are related to the data to be migrated. Set them to your actual values.
         detail.addressType = "inv";
         // If you set addressType to inv, valid values for dataType are 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 are related to 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 sample code shows how to create a data address of a third-party source type:

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 {
   /** Do not save your AccessKey ID and AccessKey secret in your project code. If you leak your AccessKey pair, the security of all resources in your account is at risk.*/
   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);
         // HTTPS and HTTP 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 are related to the data to be migrated. Set them to your actual values.
         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();
      }
   }
}

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 {
   /** Do not save your AccessKey ID and AccessKey secret in your project code. If you leak your AccessKey pair, the security of all resources in your account is at risk.*/
   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);
         // HTTPS and HTTP 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 are related to the data to be migrated. Set them to your actual values.
         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();
      }
   }
}

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 {
   /** Do not save your AccessKey ID and AccessKey secret in your project code. If you leak your AccessKey pair, the security of all resources in your account is at risk.*/
   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);
         // HTTPS and HTTP 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 are related to the data to be migrated. Set them to your actual values.
         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();
      }
   }
}

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 {
   /** Do not save your AccessKey ID and AccessKey secret in your project code. If you leak your AccessKey pair, the security of all resources in your account is at risk.*/
   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);
         // HTTPS and HTTP 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 are related to the data to be migrated. Set them to your actual values.
         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

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 {
   /** Do not save your AccessKey ID and AccessKey secret in your project code. If you leak your AccessKey pair, the security of all resources in your account is at risk.*/
   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);
         // HTTPS and HTTP 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 are related to the data to be migrated. Set them to your actual values.
         detail.addressType = "qiniu";
         detail.accessId = "***";
         detail.accessSecret = "******";
         // For more information about domain names, 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();
      }
   }
}

gcp

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 {
   /** Do not save your AccessKey ID and AccessKey secret in your project code. If you leak your AccessKey pair, the security of all resources in your account is at risk.*/
   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);
         // HTTPS and HTTP 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 are related to the data to be migrated. Set them to your actual values.
         detail.addressType = "gcp";
         detail.accessId = "***";
         detail.accessSecret = "******";
         // Set the domain parameter to 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

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 {
   /** Do not save your AccessKey ID and AccessKey secret in your project code. If you leak your AccessKey pair, the security of all resources in your account is at risk.*/
   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);
         // HTTPS and HTTP 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 are related to the data to be migrated. Set them to your actual values.
         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();
      }
   }
}

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 {
   /** Do not save your AccessKey ID and AccessKey secret in your project code. If you leak your AccessKey pair, the security of all resources in your account is at risk.*/
   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);
         // HTTPS and HTTP 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 are related to the data to be migrated. Set them to your actual values.
         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();
      }
   }
}

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 {
   /** Do not save your AccessKey ID and AccessKey secret in your project code. If you leak your AccessKey pair, the security of all resources in your account is at risk.*/
   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);
         // HTTPS and HTTP 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 are related to the data to be migrated. Set them to your actual values.
         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 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 {
   /** Do not save your AccessKey ID and AccessKey secret in your project code. If you leak your AccessKey pair, the security of all resources in your account is at risk.*/
   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);
         // HTTPS and HTTP 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 are related to the data to be migrated. Set them to your actual values.
         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();
      }
   }
}

youpai

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 {
   /** Do not save your AccessKey ID and AccessKey secret in your project code. If you leak your AccessKey pair, the security of all resources in your account is at risk.*/
   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);
         // HTTPS and HTTP 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 are related to the data to be migrated. Set them to your actual values.
         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 sample code shows how to create an HTTP-type data address:

Important

Before creating an HTTP-type data address, you must configure a role and obtain the 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 {
	/** Do not save your AccessKey ID and AccessKey secret in your project code. If you leak your AccessKey pair, the security of all resources in your account is at risk.*/
	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);
			// HTTPS and HTTP 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 are related to the data to be migrated. Set them to your actual values.
			detail.addressType = "http";
			detail.invLocation = "oss";
			detail.invBucket = "exampleinvbucket";
			detail.invDomain = "oss-cn-beijing.aliyuncs.com";
			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 sample code shows how to create a LocalFS-type data address. This type must be associated with an 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 {
	/** Do not save your AccessKey ID and AccessKey secret in your project code. If you leak your AccessKey pair, the security of all resources in your account is at risk.*/
	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);
			// HTTPS and HTTP 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 are related to the data to be migrated. Set them to your actual values.
			detail.addressType = "local";
			detail.prefix = "/***/";
			// The 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();
		}
	}
}

Query the details of a data address

The following sample code shows how to query 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 {
	/** Do not save your AccessKey ID and AccessKey secret in your project code. If you leak your AccessKey pair, the security of all resources in your account is at risk.*/
	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);
			// HTTPS and HTTP 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 a data address

The following sample code shows how to verify the availability of 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 {
   /** Do not save your AccessKey ID and AccessKey secret in your project code. If you leak your AccessKey pair, the security of all resources in your account is at risk.*/
   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);
         // HTTPS and HTTP 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 when the status field is set to available. Any other value indicates that the data address is invalid.
         System.out.println(new Gson().toJson(resp.getBody().verifyAddressResponse.status));
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

Sample success response for a valid data address:

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

Example of an unavailable default return address

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

List data addresses

The following sample code shows how to list all the data addresses within 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 {
   /** Do not save your AccessKey ID and AccessKey secret in your project code. If you leak your AccessKey pair, the security of all resources in your account is at risk.*/
   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);
         // HTTPS and HTTP 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();
         // Set marker and count to 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 a data address

The following sample code shows how to update the agents associated with a data address in scenarios where agents need to be scaled up or down:

Important

You must specify at least one agent name. Changing the agent tunnel will cause the update to fail.

package sample;

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

public class Demo {
   /** Do not save your AccessKey ID and AccessKey secret in your project code. If you leak your AccessKey pair, the security of all resources in your account is at risk.*/
   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);
         // HTTPS and HTTP 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 a data address

The following sample code shows how to delete a specific data address:

package sample;

import com.aliyun.hcs_mgw20240626.Client;

public class Demo {
   /** Do not save your AccessKey ID and AccessKey secret in your project code. If you leak your AccessKey pair, the security of all resources in your account is at risk.*/
   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);
         // HTTPS and HTTP 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();
      }
   }
}

What to do next

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