This is an automated email from the ASF dual-hosted git repository. jinrongtong pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/rocketmq.git
The following commit(s) were added to refs/heads/develop by this push: new 38d267672a Remove getBrokerClusterAclConfig from admin and server (#7486) 38d267672a is described below commit 38d267672aefbbdc6456c5e404a8b9e8608a9dd3 Author: rongtong <jinrongto...@163.com> AuthorDate: Tue Oct 24 15:15:08 2023 +0800 Remove getBrokerClusterAclConfig from admin and server (#7486) * Remove getBrokerClusterAclConfig from admin and server * Add @Deprecated annotation to GET_BROKER_CLUSTER_ACL_CONFIG request code --- .../broker/processor/AdminBrokerProcessor.java | 26 ---- .../rocketmq/client/impl/MQClientAPIImpl.java | 27 ----- .../rocketmq/client/impl/MQClientAPIImplTest.java | 27 ----- .../rocketmq/remoting/protocol/RequestCode.java | 1 + .../GetBrokerClusterAclConfigResponseBody.java | 45 ------- .../GetBrokerClusterAclConfigResponseHeader.java | 42 ------- .../rocketmq/tools/admin/DefaultMQAdminExt.java | 7 -- .../tools/admin/DefaultMQAdminExtImpl.java | 7 -- .../apache/rocketmq/tools/admin/MQAdminExt.java | 4 - .../rocketmq/tools/command/MQAdminStartup.java | 2 - .../command/acl/GetAccessConfigSubCommand.java | 132 --------------------- .../command/acl/GetAccessConfigSubCommandTest.java | 39 ------ 12 files changed, 1 insertion(+), 358 deletions(-) diff --git a/broker/src/main/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessor.java b/broker/src/main/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessor.java index dd4ec960fe..0b7a6d2068 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessor.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessor.java @@ -49,7 +49,6 @@ import org.apache.rocketmq.broker.filter.ExpressionMessageFilter; import org.apache.rocketmq.broker.plugin.BrokerAttachedPlugin; import org.apache.rocketmq.broker.subscription.SubscriptionGroupManager; import org.apache.rocketmq.broker.transaction.queue.TransactionalMessageUtil; -import org.apache.rocketmq.common.AclConfig; import org.apache.rocketmq.common.BrokerConfig; import org.apache.rocketmq.common.KeyBuilder; import org.apache.rocketmq.common.LockCallback; @@ -130,8 +129,6 @@ import org.apache.rocketmq.remoting.protocol.header.ExchangeHAInfoResponseHeader import org.apache.rocketmq.remoting.protocol.header.GetAllProducerInfoRequestHeader; import org.apache.rocketmq.remoting.protocol.header.GetAllTopicConfigResponseHeader; import org.apache.rocketmq.remoting.protocol.header.GetBrokerAclConfigResponseHeader; -import org.apache.rocketmq.remoting.protocol.header.GetBrokerClusterAclConfigResponseBody; -import org.apache.rocketmq.remoting.protocol.header.GetBrokerClusterAclConfigResponseHeader; import org.apache.rocketmq.remoting.protocol.header.GetBrokerConfigResponseHeader; import org.apache.rocketmq.remoting.protocol.header.GetConsumeStatsInBrokerHeader; import org.apache.rocketmq.remoting.protocol.header.GetConsumeStatsRequestHeader; @@ -311,8 +308,6 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { return updateGlobalWhiteAddrsConfig(ctx, request); case RequestCode.RESUME_CHECK_HALF_MESSAGE: return resumeCheckHalfMessage(ctx, request); - case RequestCode.GET_BROKER_CLUSTER_ACL_CONFIG: - return getBrokerClusterAclConfig(ctx, request); case RequestCode.GET_TOPIC_CONFIG: return getTopicConfig(ctx, request); case RequestCode.UPDATE_AND_CREATE_STATIC_TOPIC: @@ -699,27 +694,6 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { return null; } - private RemotingCommand getBrokerClusterAclConfig(ChannelHandlerContext ctx, RemotingCommand request) { - - final RemotingCommand response = RemotingCommand.createResponseCommand(GetBrokerClusterAclConfigResponseHeader.class); - - try { - AccessValidator accessValidator = this.brokerController.getAccessValidatorMap().get(PlainAccessValidator.class); - GetBrokerClusterAclConfigResponseBody body = new GetBrokerClusterAclConfigResponseBody(); - AclConfig aclConfig = accessValidator.getAllAclConfig(); - body.setGlobalWhiteAddrs(aclConfig.getGlobalWhiteAddrs()); - body.setPlainAccessConfigs(aclConfig.getPlainAccessConfigs()); - response.setCode(ResponseCode.SUCCESS); - response.setBody(body.encode()); - response.setRemark(null); - return response; - } catch (Exception e) { - LOGGER.error("Failed to generate a proper getBrokerClusterAclConfig response", e); - } - - return null; - } - private RemotingCommand getUnknownCmdResponse(ChannelHandlerContext ctx, RemotingCommand request) { String error = " request type " + request.getCode() + " not supported"; final RemotingCommand response = diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/MQClientAPIImpl.java b/client/src/main/java/org/apache/rocketmq/client/impl/MQClientAPIImpl.java index e152be8119..6074081c10 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/MQClientAPIImpl.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/MQClientAPIImpl.java @@ -53,7 +53,6 @@ import org.apache.rocketmq.client.impl.producer.TopicPublishInfo; import org.apache.rocketmq.client.producer.SendCallback; import org.apache.rocketmq.client.producer.SendResult; import org.apache.rocketmq.client.producer.SendStatus; -import org.apache.rocketmq.common.AclConfig; import org.apache.rocketmq.common.BoundaryType; import org.apache.rocketmq.common.MQVersion; import org.apache.rocketmq.common.MixAll; @@ -154,7 +153,6 @@ import org.apache.rocketmq.remoting.protocol.header.EndTransactionRequestHeader; import org.apache.rocketmq.remoting.protocol.header.ExtraInfoUtil; import org.apache.rocketmq.remoting.protocol.header.GetAllProducerInfoRequestHeader; import org.apache.rocketmq.remoting.protocol.header.GetBrokerAclConfigResponseHeader; -import org.apache.rocketmq.remoting.protocol.header.GetBrokerClusterAclConfigResponseBody; import org.apache.rocketmq.remoting.protocol.header.GetConsumeStatsInBrokerHeader; import org.apache.rocketmq.remoting.protocol.header.GetConsumeStatsRequestHeader; import org.apache.rocketmq.remoting.protocol.header.GetConsumerConnectionListRequestHeader; @@ -520,31 +518,6 @@ public class MQClientAPIImpl implements NameServerUpdateCallback { } - public AclConfig getBrokerClusterConfig(final String addr, - final long timeoutMillis) throws InterruptedException, RemotingTimeoutException, - RemotingSendRequestException, RemotingConnectException, MQBrokerException { - RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_BROKER_CLUSTER_ACL_CONFIG, null); - - RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), request, timeoutMillis); - assert response != null; - switch (response.getCode()) { - case ResponseCode.SUCCESS: { - if (response.getBody() != null) { - GetBrokerClusterAclConfigResponseBody body = - GetBrokerClusterAclConfigResponseBody.decode(response.getBody(), GetBrokerClusterAclConfigResponseBody.class); - AclConfig aclConfig = new AclConfig(); - aclConfig.setGlobalWhiteAddrs(body.getGlobalWhiteAddrs()); - aclConfig.setPlainAccessConfigs(body.getPlainAccessConfigs()); - return aclConfig; - } - } - default: - break; - } - throw new MQBrokerException(response.getCode(), response.getRemark(), addr); - - } - public SendResult sendMessage( final String addr, final String brokerName, diff --git a/client/src/test/java/org/apache/rocketmq/client/impl/MQClientAPIImplTest.java b/client/src/test/java/org/apache/rocketmq/client/impl/MQClientAPIImplTest.java index c152d38ea5..cf399802ba 100644 --- a/client/src/test/java/org/apache/rocketmq/client/impl/MQClientAPIImplTest.java +++ b/client/src/test/java/org/apache/rocketmq/client/impl/MQClientAPIImplTest.java @@ -37,7 +37,6 @@ import org.apache.rocketmq.client.producer.DefaultMQProducer; import org.apache.rocketmq.client.producer.SendCallback; import org.apache.rocketmq.client.producer.SendResult; import org.apache.rocketmq.client.producer.SendStatus; -import org.apache.rocketmq.common.AclConfig; import org.apache.rocketmq.common.MixAll; import org.apache.rocketmq.common.PlainAccessConfig; import org.apache.rocketmq.common.TopicConfig; @@ -62,8 +61,6 @@ import org.apache.rocketmq.remoting.protocol.header.AckMessageRequestHeader; import org.apache.rocketmq.remoting.protocol.header.ChangeInvisibleTimeRequestHeader; import org.apache.rocketmq.remoting.protocol.header.ChangeInvisibleTimeResponseHeader; import org.apache.rocketmq.remoting.protocol.header.ExtraInfoUtil; -import org.apache.rocketmq.remoting.protocol.header.GetBrokerClusterAclConfigResponseBody; -import org.apache.rocketmq.remoting.protocol.header.GetBrokerClusterAclConfigResponseHeader; import org.apache.rocketmq.remoting.protocol.header.GetConsumerListByGroupResponseBody; import org.apache.rocketmq.remoting.protocol.header.GetConsumerListByGroupResponseHeader; import org.apache.rocketmq.remoting.protocol.header.GetEarliestMsgStoretimeResponseHeader; @@ -700,30 +697,6 @@ public class MQClientAPIImplTest { mqClientAPI.createTopic(brokerAddr, topic, new TopicConfig(), 10000); } - @Test - public void testGetBrokerClusterConfig() throws Exception { - doAnswer(new Answer<RemotingCommand>() { - @Override - public RemotingCommand answer(InvocationOnMock mock) { - RemotingCommand request = mock.getArgument(1); - - RemotingCommand response = RemotingCommand.createResponseCommand(GetBrokerClusterAclConfigResponseHeader.class); - GetBrokerClusterAclConfigResponseBody body = new GetBrokerClusterAclConfigResponseBody(); - body.setGlobalWhiteAddrs(Collections.singletonList("1.1.1.1")); - body.setPlainAccessConfigs(Collections.singletonList(new PlainAccessConfig())); - response.setBody(body.encode()); - response.makeCustomHeaderToNet(); - response.setCode(ResponseCode.SUCCESS); - response.setOpaque(request.getOpaque()); - return response; - } - }).when(remotingClient).invokeSync(anyString(), any(RemotingCommand.class), anyLong()); - - AclConfig aclConfig = mqClientAPI.getBrokerClusterConfig(brokerAddr, 10000); - assertThat(aclConfig.getPlainAccessConfigs()).size().isGreaterThan(0); - assertThat(aclConfig.getGlobalWhiteAddrs()).size().isGreaterThan(0); - } - @Test public void testViewMessage() throws Exception { doAnswer(new Answer<RemotingCommand>() { diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RequestCode.java b/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RequestCode.java index 0b1a5e0104..1811deba20 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RequestCode.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RequestCode.java @@ -80,6 +80,7 @@ public class RequestCode { public static final int UPDATE_GLOBAL_WHITE_ADDRS_CONFIG = 53; + @Deprecated public static final int GET_BROKER_CLUSTER_ACL_CONFIG = 54; public static final int GET_TIMER_CHECK_POINT = 60; diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/header/GetBrokerClusterAclConfigResponseBody.java b/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/header/GetBrokerClusterAclConfigResponseBody.java deleted file mode 100644 index 4987242c2a..0000000000 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/header/GetBrokerClusterAclConfigResponseBody.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.rocketmq.remoting.protocol.header; - -import java.util.List; -import org.apache.rocketmq.common.PlainAccessConfig; -import org.apache.rocketmq.remoting.protocol.RemotingSerializable; - -public class GetBrokerClusterAclConfigResponseBody extends RemotingSerializable { - - private List<String> globalWhiteAddrs; - - private List<PlainAccessConfig> plainAccessConfigs; - - public List<String> getGlobalWhiteAddrs() { - return globalWhiteAddrs; - } - - public void setGlobalWhiteAddrs(List<String> globalWhiteAddrs) { - this.globalWhiteAddrs = globalWhiteAddrs; - } - - public List<PlainAccessConfig> getPlainAccessConfigs() { - return plainAccessConfigs; - } - - public void setPlainAccessConfigs(List<PlainAccessConfig> plainAccessConfigs) { - this.plainAccessConfigs = plainAccessConfigs; - } -} diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/header/GetBrokerClusterAclConfigResponseHeader.java b/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/header/GetBrokerClusterAclConfigResponseHeader.java deleted file mode 100644 index 7de73aa4da..0000000000 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/header/GetBrokerClusterAclConfigResponseHeader.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.rocketmq.remoting.protocol.header; - -import java.util.List; -import org.apache.rocketmq.common.PlainAccessConfig; -import org.apache.rocketmq.remoting.CommandCustomHeader; -import org.apache.rocketmq.remoting.annotation.CFNotNull; -import org.apache.rocketmq.remoting.exception.RemotingCommandException; - -public class GetBrokerClusterAclConfigResponseHeader implements CommandCustomHeader { - - @CFNotNull - private List<PlainAccessConfig> plainAccessConfigs; - - @Override - public void checkFields() throws RemotingCommandException { - } - - public List<PlainAccessConfig> getPlainAccessConfigs() { - return plainAccessConfigs; - } - - public void setPlainAccessConfigs(List<PlainAccessConfig> plainAccessConfigs) { - this.plainAccessConfigs = plainAccessConfigs; - } -} diff --git a/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExt.java b/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExt.java index f0a08dfb1a..40bd5d56d3 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExt.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExt.java @@ -25,7 +25,6 @@ import org.apache.rocketmq.client.ClientConfig; import org.apache.rocketmq.client.QueryResult; import org.apache.rocketmq.client.exception.MQBrokerException; import org.apache.rocketmq.client.exception.MQClientException; -import org.apache.rocketmq.common.AclConfig; import org.apache.rocketmq.common.Pair; import org.apache.rocketmq.common.PlainAccessConfig; import org.apache.rocketmq.common.TopicConfig; @@ -231,12 +230,6 @@ public class DefaultMQAdminExt extends ClientConfig implements MQAdminExt { return defaultMQAdminExtImpl.examineBrokerClusterAclVersionInfo(addr); } - @Override - public AclConfig examineBrokerClusterAclConfig( - String addr) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { - return defaultMQAdminExtImpl.examineBrokerClusterAclConfig(addr); - } - @Override public void createAndUpdateSubscriptionGroupConfig(String addr, SubscriptionGroupConfig config) throws RemotingException, diff --git a/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExtImpl.java b/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExtImpl.java index 1ebff6d8af..331b24d606 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExtImpl.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExtImpl.java @@ -45,7 +45,6 @@ import org.apache.rocketmq.client.exception.MQBrokerException; import org.apache.rocketmq.client.exception.MQClientException; import org.apache.rocketmq.client.impl.MQClientManager; import org.apache.rocketmq.client.impl.factory.MQClientInstance; -import org.apache.rocketmq.common.AclConfig; import org.apache.rocketmq.common.KeyBuilder; import org.apache.rocketmq.common.MixAll; import org.apache.rocketmq.common.Pair; @@ -305,12 +304,6 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { return this.mqClientInstance.getMQClientAPIImpl().getBrokerClusterAclInfo(addr, timeoutMillis); } - @Override - public AclConfig examineBrokerClusterAclConfig( - String addr) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { - return this.mqClientInstance.getMQClientAPIImpl().getBrokerClusterConfig(addr, timeoutMillis); - } - @Override public void createAndUpdateSubscriptionGroupConfig(String addr, SubscriptionGroupConfig config) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { diff --git a/tools/src/main/java/org/apache/rocketmq/tools/admin/MQAdminExt.java b/tools/src/main/java/org/apache/rocketmq/tools/admin/MQAdminExt.java index 7dcfc4fa5e..3148fc0987 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/admin/MQAdminExt.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/admin/MQAdminExt.java @@ -24,7 +24,6 @@ import java.util.Set; import org.apache.rocketmq.client.MQAdmin; import org.apache.rocketmq.client.exception.MQBrokerException; import org.apache.rocketmq.client.exception.MQClientException; -import org.apache.rocketmq.common.AclConfig; import org.apache.rocketmq.common.Pair; import org.apache.rocketmq.common.PlainAccessConfig; import org.apache.rocketmq.common.TopicConfig; @@ -110,9 +109,6 @@ public interface MQAdminExt extends MQAdmin { final String addr) throws RemotingException, MQBrokerException, InterruptedException, MQClientException; - AclConfig examineBrokerClusterAclConfig(final String addr) throws RemotingException, MQBrokerException, - InterruptedException, MQClientException; - void createAndUpdateSubscriptionGroupConfig(final String addr, final SubscriptionGroupConfig config) throws RemotingException, MQBrokerException, InterruptedException, MQClientException; diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/MQAdminStartup.java b/tools/src/main/java/org/apache/rocketmq/tools/command/MQAdminStartup.java index 788fa83c2c..35f0074822 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/MQAdminStartup.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/MQAdminStartup.java @@ -29,7 +29,6 @@ import org.apache.rocketmq.remoting.protocol.RemotingCommand; import org.apache.rocketmq.srvutil.ServerUtil; import org.apache.rocketmq.tools.command.acl.ClusterAclConfigVersionListSubCommand; import org.apache.rocketmq.tools.command.acl.DeleteAccessConfigSubCommand; -import org.apache.rocketmq.tools.command.acl.GetAccessConfigSubCommand; import org.apache.rocketmq.tools.command.acl.UpdateAccessConfigSubCommand; import org.apache.rocketmq.tools.command.acl.UpdateGlobalWhiteAddrSubCommand; import org.apache.rocketmq.tools.command.broker.BrokerConsumeStatsSubCommad; @@ -248,7 +247,6 @@ public class MQAdminStartup { initCommand(new DeleteAccessConfigSubCommand()); initCommand(new ClusterAclConfigVersionListSubCommand()); initCommand(new UpdateGlobalWhiteAddrSubCommand()); - initCommand(new GetAccessConfigSubCommand()); initCommand(new UpdateStaticTopicSubCommand()); initCommand(new RemappingStaticTopicSubCommand()); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/acl/GetAccessConfigSubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/acl/GetAccessConfigSubCommand.java deleted file mode 100644 index f1c9a14969..0000000000 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/acl/GetAccessConfigSubCommand.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.rocketmq.tools.command.acl; - -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.OptionGroup; -import org.apache.commons.cli.Options; -import org.apache.rocketmq.client.exception.MQBrokerException; -import org.apache.rocketmq.client.exception.MQClientException; -import org.apache.rocketmq.common.AclConfig; -import org.apache.rocketmq.common.PlainAccessConfig; -import org.apache.rocketmq.remoting.RPCHook; -import org.apache.rocketmq.remoting.exception.RemotingException; -import org.apache.rocketmq.srvutil.ServerUtil; -import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; -import org.apache.rocketmq.tools.command.CommandUtil; -import org.apache.rocketmq.tools.command.SubCommand; -import org.apache.rocketmq.tools.command.SubCommandException; - -import java.lang.reflect.Field; -import java.util.List; -import java.util.Set; - -public class GetAccessConfigSubCommand implements SubCommand { - @Override - public String commandName() { - return "getAclConfig"; - } - - @Override - public String commandAlias() { - return "getAccessConfigSubCommand"; - } - - @Override - public String commandDesc() { - return "List all of acl config information in cluster."; - } - - @Override - public Options buildCommandlineOptions(Options options) { - OptionGroup optionGroup = new OptionGroup(); - - Option opt = new Option("b", "brokerAddr", true, "query acl config version for which broker"); - optionGroup.addOption(opt); - - opt = new Option("c", "clusterName", true, "query acl config version for specified cluster"); - optionGroup.addOption(opt); - - optionGroup.setRequired(true); - options.addOptionGroup(optionGroup); - - return options; - } - - @Override - public void execute(CommandLine commandLine, Options options, - RPCHook rpcHook) throws SubCommandException { - - DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); - defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); - - try { - - if (commandLine.hasOption('b')) { - String addr = commandLine.getOptionValue('b').trim(); - defaultMQAdminExt.start(); - printClusterBaseInfo(defaultMQAdminExt, addr); - return; - - } else if (commandLine.hasOption('c')) { - String clusterName = commandLine.getOptionValue('c').trim(); - - defaultMQAdminExt.start(); - - Set<String> masterSet = - CommandUtil.fetchMasterAddrByClusterName(defaultMQAdminExt, clusterName); - for (String addr : masterSet) { - printClusterBaseInfo(defaultMQAdminExt, addr); - } - return; - } - - ServerUtil.printCommandLineHelp("mqadmin " + this.commandName(), options); - } catch (Exception e) { - throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e); - } finally { - defaultMQAdminExt.shutdown(); - } - } - - private void printClusterBaseInfo( - final DefaultMQAdminExt defaultMQAdminExt, final String addr) throws - InterruptedException, MQBrokerException, RemotingException, MQClientException, IllegalAccessException { - AclConfig aclConfig = defaultMQAdminExt.examineBrokerClusterAclConfig(addr); - List<PlainAccessConfig> configs = aclConfig.getPlainAccessConfigs(); - List<String> globalWhiteAddrs = aclConfig.getGlobalWhiteAddrs(); - System.out.printf("\n"); - System.out.printf("%-20s: %s\n", "globalWhiteRemoteAddresses", globalWhiteAddrs.toString()); - System.out.printf("\n"); - System.out.printf("accounts:\n"); - if (configs != null && configs.size() > 0) { - for (PlainAccessConfig config : configs) { - Field[] fields = config.getClass().getDeclaredFields(); - for (Field field : fields) { - field.setAccessible(true); - if (field.get(config) != null) { - System.out.printf("%-1s %-18s: %s\n", "", field.getName(), field.get(config).toString()); - } else { - System.out.printf("%-1s %-18s: %s\n", "", field.getName(), ""); - } - } - System.out.printf("\n"); - } - } - } -} diff --git a/tools/src/test/java/org/apache/rocketmq/tools/command/acl/GetAccessConfigSubCommandTest.java b/tools/src/test/java/org/apache/rocketmq/tools/command/acl/GetAccessConfigSubCommandTest.java deleted file mode 100644 index ae4eca4356..0000000000 --- a/tools/src/test/java/org/apache/rocketmq/tools/command/acl/GetAccessConfigSubCommandTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.rocketmq.tools.command.acl; - -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.Options; -import org.apache.rocketmq.srvutil.ServerUtil; -import org.junit.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -public class GetAccessConfigSubCommandTest { - - @Test - public void testExecute() { - GetAccessConfigSubCommand cmd = new GetAccessConfigSubCommand(); - Options options = ServerUtil.buildCommandlineOptions(new Options()); - String[] subargs = new String[] {"-c default-cluster"}; - final CommandLine commandLine = - ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, - cmd.buildCommandlineOptions(options), new DefaultParser()); - assertThat(commandLine.getOptionValue('c').trim()).isEqualTo("default-cluster"); - } -}