Repository: apache/rocketmq (Java) — Feature

Issue:
Add vm arguments to set useTLS for all server.
When a server needs to call other services as a client, it may be need to set the useTLS value. So we can use the vm arguments for all server (broker, controller in namesrv, controller) .


Discussion:

Resolving patch:
diff --git a/broker/src/main/java/org/apache/rocketmq/broker/BrokerStartup.java b/broker/src/main/java/org/apache/rocketmq/broker/BrokerStartup.java
--- a/broker/src/main/java/org/apache/rocketmq/broker/BrokerStartup.java
+++ b/broker/src/main/java/org/apache/rocketmq/broker/BrokerStartup.java
@@ -34,10 +34,8 @@
 import org.apache.rocketmq.logging.InternalLogger;
 import org.apache.rocketmq.logging.InternalLoggerFactory;
 import org.apache.rocketmq.remoting.common.RemotingUtil;
-import org.apache.rocketmq.remoting.common.TlsMode;
 import org.apache.rocketmq.remoting.netty.NettyClientConfig;
 import org.apache.rocketmq.remoting.netty.NettyServerConfig;
-import org.apache.rocketmq.remoting.netty.TlsSystemConfig;
 import org.apache.rocketmq.remoting.protocol.RemotingCommand;
 import org.apache.rocketmq.srvutil.ServerUtil;
 import org.apache.rocketmq.store.config.BrokerRole;
@@ -45,8 +43,6 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static org.apache.rocketmq.remoting.netty.TlsSystemConfig.TLS_ENABLE;
-
 public class BrokerStartup {
     public static Properties properties = null;
     public static CommandLine commandLine = null;
@@ -102,9 +98,6 @@ public static BrokerController createBrokerController(String[] args) {
             final BrokerConfig brokerConfig = new BrokerConfig();
             final NettyServerConfig nettyServerConfig = new NettyServerConfig();
             final NettyClientConfig nettyClientConfig = new NettyClientConfig();
-
-            nettyClientConfig.setUseTLS(Boolean.parseBoolean(System.getProperty(TLS_ENABLE,
-                String.valueOf(TlsSystemConfig.tlsMode == TlsMode.ENFORCING))));
             nettyServerConfig.setListenPort(10911);
             final MessageStoreConfig messageStoreConfig = new MessageStoreConfig();
 
diff --git a/container/src/main/java/org/apache/rocketmq/container/BrokerContainerStartup.java b/container/src/main/java/org/apache/rocketmq/container/BrokerContainerStartup.java
--- a/container/src/main/java/org/apache/rocketmq/container/BrokerContainerStartup.java
+++ b/container/src/main/java/org/apache/rocketmq/container/BrokerContainerStartup.java
@@ -39,11 +39,9 @@
 import org.apache.rocketmq.logging.InternalLogger;
 import org.apache.rocketmq.logging.InternalLoggerFactory;
 import org.apache.rocketmq.remoting.common.RemotingUtil;
-import org.apache.rocketmq.remoting.common.TlsMode;
 import org.apache.rocketmq.remoting.netty.NettyClientConfig;
 import org.apache.rocketmq.remoting.netty.NettyServerConfig;
 import org.apache.rocketmq.remoting.netty.NettySystemConfig;
-import org.apache.rocketmq.remoting.netty.TlsSystemConfig;
 import org.apache.rocketmq.remoting.protocol.RemotingCommand;
 import org.apache.rocketmq.srvutil.ServerUtil;
 import org.apache.rocketmq.store.config.MessageStoreConfig;
@@ -272,9 +270,6 @@ public static BrokerContainer createBrokerContainer(String[] args) {
             final BrokerContainerConfig containerConfig = new BrokerContainerConfig();
             final NettyServerConfig nettyServerConfig = new NettyServerConfig();
             final NettyClientConfig nettyClientConfig = new NettyClientConfig();
-
-            nettyClientConfig.setUseTLS(Boolean.parseBoolean(System.getProperty(TlsSystemConfig.TLS_ENABLE,
-                String.valueOf(TlsSystemConfig.tlsMode == TlsMode.ENFORCING))));
             nettyServerConfig.setListenPort(10811);
 
             if (commandLine.hasOption(BROKER_CONTAINER_CONFIG_OPTION)) {
diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyClientConfig.java b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyClientConfig.java
--- a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyClientConfig.java
+++ b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyClientConfig.java
@@ -16,6 +16,10 @@
  */
 package org.apache.rocketmq.remoting.netty;
 
+import org.apache.rocketmq.remoting.common.TlsMode;
+
+import static org.apache.rocketmq.remoting.netty.TlsSystemConfig.TLS_ENABLE;
+
 public class NettyClientConfig {
     /**
      * Worker thread number
@@ -38,7 +42,9 @@ public class NettyClientConfig {
     private boolean clientPooledByteBufAllocatorEnable = false;
     private boolean clientCloseSocketIfTimeout = NettySystemConfig.clientCloseSocketIfTimeout;
 
-    private boolean useTLS;
+    private boolean useTLS = Boolean.parseBoolean(System.getProperty(TLS_ENABLE,
+        String.valueOf(TlsSystemConfig.tlsMode == TlsMode.ENFORCING)));
+
     private String socksProxyConfig = "{}";
 
     private int writeBufferHighWaterMark = NettySystemConfig.writeBufferHighWaterMark;


Test patch:
diff --git a/remoting/src/test/java/org/apache/rocketmq/remoting/netty/NettyClientConfigTest.java b/remoting/src/test/java/org/apache/rocketmq/remoting/netty/NettyClientConfigTest.java
--- a/remoting/src/test/java/org/apache/rocketmq/remoting/netty/NettyClientConfigTest.java
+++ b/remoting/src/test/java/org/apache/rocketmq/remoting/netty/NettyClientConfigTest.java
@@ -27,7 +27,7 @@
 public class NettyClientConfigTest {
 
     @Test
-    public void testChangeConfigBySystemProperty() throws NoSuchFieldException, IllegalAccessException {
+    public void testChangeConfigBySystemProperty() {
 
 
         System.setProperty(NettySystemConfig.COM_ROCKETMQ_REMOTING_CLIENT_WORKER_SIZE, "1");
@@ -36,6 +36,7 @@ public void testChangeConfigBySystemProperty() throws NoSuchFieldException, Ille
         System.setProperty(NettySystemConfig.COM_ROCKETMQ_REMOTING_SOCKET_SNDBUF_SIZE, "16383");
         System.setProperty(NettySystemConfig.COM_ROCKETMQ_REMOTING_SOCKET_RCVBUF_SIZE, "16384");
         System.setProperty(NettySystemConfig.COM_ROCKETMQ_REMOTING_CLIENT_CLOSE_SOCKET_IF_TIMEOUT, "false");
+        System.setProperty(TlsSystemConfig.TLS_ENABLE, "true");
 
 
         NettySystemConfig.socketSndbufSize =
@@ -60,5 +61,6 @@ public void testChangeConfigBySystemProperty() throws NoSuchFieldException, Ille
         assertThat(changedConfig.getClientSocketSndBufSize()).isEqualTo(16383);
         assertThat(changedConfig.getClientSocketRcvBufSize()).isEqualTo(16384);
         assertThat(changedConfig.isClientCloseSocketIfTimeout()).isEqualTo(false);
+        assertThat(changedConfig.isUseTLS()).isEqualTo(true);
     }
 }