All Products
Search
Document Center

Data Online Migration:Proxy

Last Updated:Dec 11, 2025

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

Create an agent

Note

Data Online Migration SDK does not automatically deploy an agent. Before you use an agent, you must deploy the agent. For more information, see Agent management. An agent is required only when you migrate data over an Express Connect circuit or a VPN gateway.

The following sample code shows how to create an agent:

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.CreateAgentInfo;
import com.aliyun.hcs_mgw20240626.models.CreateAgentRequest;

public class Demo {
	/** 
	  Do not hard-code the AccessKey ID or AccessKey secret into your project code. Otherwise, the AccessKey pair may be leaked, which compromises the security of all resources in your account.
	*/
	static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
	static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
	/** Enter the ID of your Alibaba Cloud account.*/
	static String userId = "11470***876***55";

	public static void main(String[] args) {
		// Enter the channel ID.
		String tunnelId = "ab31d1f9-****-4f62-****-914e4b2f78c7";
		// Enter the agent name.
		String agentName = "exampleagent";
		// The network to use. Enter public for the public network, or vpc for a leased line or VPN.
		String agentEndpoint = "public";
		// The deployment method. Only default is supported.
		String deployMethod = "default";
		try {
			com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
			// This example uses the 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 this parameter, HTTPS is used by default.
                        config.setProtocol("http");
			Client client = new Client(config);
			CreateAgentRequest request = new CreateAgentRequest();
			CreateAgentInfo info = new CreateAgentInfo();
			info.setName(agentName);
			info.setTunnelId(tunnelId);
			info.setAgentEndpoint(agentEndpoint);
			info.setDeployMethod(deployMethod);
			request.setImportAgent(info);
			client.createAgent(userId, request);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Query the status of an agent

The following sample code shows how to query the status of an agent:

package sample;

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

public class Demo {
   /** Do not hard-code the AccessKey ID or AccessKey secret into your project code. Otherwise, the AccessKey pair may be leaked, which compromises the security of all resources in your account.*/
   static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
   static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
   /** Enter the ID of your Alibaba Cloud account.*/
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // Enter the agent name.
      String agentName = "exampleagent";
      try {
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
         // This example uses the 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 this parameter, HTTPS is used by default.
         config.setProtocol("http");
         Client client = new Client(config);
         GetAgentStatusResponse resp = client.getAgentStatus(userId, agentName);
         // If the status field is OK, the agent is normal. Any other value indicates that the agent is abnormal.
         System.out.println(new Gson().toJson(resp.getBody().getImportAgentStatus()));
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

Sample success response

{
  "ImportAgentStatus": {
    "Status": "OK",
    "AgentIP": "192.168.0.2",
    "AgentVersion": "1.6.0"
  }
}

Query the details of an agent

The following sample code shows how to query the details of an agent:

package sample;

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

public class Demo {
   /** Do not hard-code the AccessKey ID or AccessKey secret into your project code. Otherwise, the AccessKey pair may be leaked, which compromises the security of all resources in your account.*/
   static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
   static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
   /** Enter the ID of your Alibaba Cloud account.*/
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // Enter the agent name.
      String agentName = "exampleagent";
      try {
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
         // This example uses the 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 this parameter, HTTPS is used by default.
         config.setProtocol("http");
         Client client = new Client(config);
         GetAgentResponse resp = client.getAgent(userId, agentName);
         System.out.println(new Gson().toJson(resp.getBody().getImportAgent()));
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

Sample success response

{
  "ImportAgent": {
    "Owner": "test_owner",
    "Name": "test_name",
    "CreateTime": "2024-05-01T12:00:00.000Z",
    "ModifyTime": "2024-05-01T12:00:00.000Z",
    "DeployMethod": "default",
    "AgentEndpoint": "vpc",
    "ActivationKey": "6af62558-970d-4f44-8663-4e297170fd6a",
    "Tags": "K1:V1,K2:V2",
    "Version": "test_agent_id",
    "TunnelId": "test_tunnel_id"
  }
}

Query a list of agents

The following sample code shows how to list all the agents within an Alibaba Cloud account:

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.ListAgentRequest;
import com.aliyun.hcs_mgw20240626.models.ListAgentResponse;
import com.google.gson.Gson;

public class Demo {
   /** Do not hard-code the AccessKey ID or AccessKey secret into your project code. Otherwise, the AccessKey pair may be leaked, which compromises the security of all resources in your account.*/
   static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
   static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
   /** Enter the ID of your Alibaba Cloud account.*/
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      try {
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
         // This example uses the 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 this parameter, HTTPS is used by default.
         config.setProtocol("http");
         Client client = new Client(config);
         ListAgentRequest request = new ListAgentRequest();
         // Set marker and count as needed.
	 String marker = "";
	 int count = 1;
	 request.setMarker(marker);
         request.setCount(count);
         ListAgentResponse resp = client.listAgent(userId, request);
         System.out.println(new Gson().toJson(resp.getBody().getImportAgentList()));
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

Sample success response

{
  "ImportAgentList": {
    "Truncated": true,
    "NextMarker": "test_next_marker",
    "ImportAgent": [
      {
        "Owner": "test_owner",
        "Name": "test_name",
        "CreateTime": "2024-05-01T12:00:00.000Z",
        "ModifyTime": "2024-05-01T12:00:00.000Z",
        "DeployMethod": "default",
        "AgentEndpoint": "vpc",
        "ActivationKey": "6af62558-970d-4f44-8663-4e297170fd6a",
        "Tags": "K1:V1,K2:V2",
        "Version": "test_agent_id",
        "TunnelId": "test_tunnel_id"
      }
    ]
  }
}

Delete an agent

The following sample code shows how to delete an agent:

package sample;

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

public class Demo {
   /** Do not hard-code the AccessKey ID or AccessKey secret into your project code. Otherwise, the AccessKey pair may be leaked, which compromises the security of all resources in your account.*/
   static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
   static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
   /** Enter the ID of your Alibaba Cloud account.*/
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // Enter the agent name.
      String agentName = "exampleagent";
      try {
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
         // This example uses the 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 this parameter, HTTPS is used by default.
         config.setProtocol("http");
         Client client = new Client(config);
         DeleteAgentResponse resp = client.deleteAgent(userId, agentName);
         System.out.println(resp.statusCode);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

What to do next

After you create an agent, you can create a data address. For more information, see Data addresses.