This is an automated email from the ASF dual-hosted git repository.
zirui pushed a commit to branch release-1.3.0
in repository https://gitbox.apache.org/repos/asf/inlong.git
The following commit(s) were added to refs/heads/release-1.3.0 by this push:
new 9e4d9296e [INLONG-5675][Agent] Support custom fixed ip for Agent
(#5677)
9e4d9296e is described below
commit 9e4d9296e9ff250d3600892a96b6b66c48b174a6
Author: ganfengtan <[email protected]>
AuthorDate: Thu Aug 25 10:14:59 2022 +0800
[INLONG-5675][Agent] Support custom fixed ip for Agent (#5677)
---
.../main/java/org/apache/inlong/agent/constant/AgentConstants.java | 2 ++
.../src/main/java/org/apache/inlong/agent/utils/AgentUtils.java | 4 ++++
.../test/java/org/apache/inlong/agent/common/TestAgentUtils.java | 6 ++++++
inlong-agent/agent-common/src/test/resources/agent.properties | 1 +
inlong-agent/agent-docker/agent-docker.sh | 1 +
inlong-agent/conf/agent.properties | 1 +
6 files changed, 15 insertions(+)
diff --git
a/inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/constant/AgentConstants.java
b/inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/constant/AgentConstants.java
index 2c1380f52..6af336097 100755
---
a/inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/constant/AgentConstants.java
+++
b/inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/constant/AgentConstants.java
@@ -169,6 +169,8 @@ public class AgentConstants {
public static final String AGENT_LOCAL_IP = "agent.local.ip";
public static final String DEFAULT_LOCAL_IP = "127.0.0.1";
+ public static final String CUSTOM_FIXED_IP = "agent.custom.fixed.ip";
+
public static final String AGENT_CLUSTER_NAME = "agent.cluster.name";
public static final String AGENT_CLUSTER_TAG = "agent.cluster.tag";
public static final String AGENT_CLUSTER_IN_CHARGES =
"agent.cluster.inCharges";
diff --git
a/inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/utils/AgentUtils.java
b/inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/utils/AgentUtils.java
index 20ef03e31..8aa8cbdcd 100644
---
a/inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/utils/AgentUtils.java
+++
b/inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/utils/AgentUtils.java
@@ -55,6 +55,7 @@ import static
org.apache.inlong.agent.constant.AgentConstants.AGENT_ENABLE_OOM_E
import static org.apache.inlong.agent.constant.AgentConstants.AGENT_LOCAL_IP;
import static org.apache.inlong.agent.constant.AgentConstants.AGENT_LOCAL_UUID;
import static
org.apache.inlong.agent.constant.AgentConstants.AGENT_LOCAL_UUID_OPEN;
+import static org.apache.inlong.agent.constant.AgentConstants.CUSTOM_FIXED_IP;
import static
org.apache.inlong.agent.constant.AgentConstants.DEFAULT_AGENT_LOCAL_UUID_OPEN;
import static
org.apache.inlong.agent.constant.AgentConstants.DEFAULT_ENABLE_OOM_EXIT;
import static org.apache.inlong.agent.constant.AgentConstants.DEFAULT_LOCAL_IP;
@@ -348,6 +349,9 @@ public class AgentUtils {
* Check agent ip from manager
*/
public static String fetchLocalIp() {
+ if
(StringUtils.isNoneBlank(AgentConfiguration.getAgentConf().get(CUSTOM_FIXED_IP,
null))) {
+ return AgentConfiguration.getAgentConf().get(CUSTOM_FIXED_IP);
+ }
return AgentConfiguration.getAgentConf().get(AGENT_LOCAL_IP,
getLocalIp());
}
diff --git
a/inlong-agent/agent-common/src/test/java/org/apache/inlong/agent/common/TestAgentUtils.java
b/inlong-agent/agent-common/src/test/java/org/apache/inlong/agent/common/TestAgentUtils.java
index 2c9f92137..abc41410f 100755
---
a/inlong-agent/agent-common/src/test/java/org/apache/inlong/agent/common/TestAgentUtils.java
+++
b/inlong-agent/agent-common/src/test/java/org/apache/inlong/agent/common/TestAgentUtils.java
@@ -89,4 +89,10 @@ public class TestAgentUtils {
Assert.assertNotEquals("127.0.0.1", AgentUtils.fetchLocalIp());
LOGGER.info("local ip is {}", AgentUtils.fetchLocalIp());
}
+
+ @Test
+ public void testCustomFixedIp() {
+ String ip = AgentUtils.fetchLocalIp();
+ Assert.assertNotEquals("127.0.0.1",ip);
+ }
}
diff --git a/inlong-agent/agent-common/src/test/resources/agent.properties
b/inlong-agent/agent-common/src/test/resources/agent.properties
index fee62f02f..fa95d663e 100755
--- a/inlong-agent/agent-common/src/test/resources/agent.properties
+++ b/inlong-agent/agent-common/src/test/resources/agent.properties
@@ -23,6 +23,7 @@ job.thread.running.core=10
agent.manager.vip.http.host=127.0.0.1
agent.manager.vip.http.port=8083
agent.fetcher.classname=org.apache.inlong.agent.plugin.fetcher.ManagerFetcher
+agent.custom.fixed.ip=
# metrics
metricDomains=Agent
diff --git a/inlong-agent/agent-docker/agent-docker.sh
b/inlong-agent/agent-docker/agent-docker.sh
index 12e419b2a..f6ecc9a21 100644
--- a/inlong-agent/agent-docker/agent-docker.sh
+++ b/inlong-agent/agent-docker/agent-docker.sh
@@ -38,6 +38,7 @@ agent.cluster.name=$CLUSTER_NAME
agent.cluster.inCharges=$CLUSTER_IN_CHARGES
agent.manager.auth.secretId=$MANAGER_OPENAPI_AUTH_ID
agent.manager.auth.secretKey=$MANAGER_OPENAPI_AUTH_KEY
+agent.custom.fixed.ip=$CUSTOM_FIXED_IP
EOF
# start
bash +x ${file_path}/bin/agent.sh start
diff --git a/inlong-agent/conf/agent.properties
b/inlong-agent/conf/agent.properties
index 8f68e8276..dc6785f32 100755
--- a/inlong-agent/conf/agent.properties
+++ b/inlong-agent/conf/agent.properties
@@ -51,6 +51,7 @@ agent.local.ip=127.0.0.1
agent.local.uuid=
agent.local.uuid.open=false
agent.enable.oom.exit=false
+agent.custom.fixed.ip=
###########################
# job/job manager config