Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
qianye1001 committed Jan 9, 2025
1 parent 76c017b commit 3f846a0
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
*/
package org.apache.rocketmq.remoting.protocol.header;

import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.apache.rocketmq.common.action.Action;
import org.apache.rocketmq.common.action.RocketMQAction;
import org.apache.rocketmq.remoting.CommandCustomHeader;
Expand All @@ -26,31 +28,46 @@

@RocketMQAction(value = RequestCode.EXPORT_ROCKSDB_CONFIG_TO_JSON, action = Action.GET)
public class RocksDBConfigToJsonRequestHeader implements CommandCustomHeader {
private static final String CONFIG_TYPE_SEPARATOR = ";";

public enum ConfigType {
topics,
subscriptionGroups,
consumerOffsets;

public static ConfigType fromString(String ordinal) {
return ConfigType.valueOf(ordinal);
public static List<ConfigType> fromString(String ordinal) {
String[] configTypeStrings = StringUtils.split(ordinal, CONFIG_TYPE_SEPARATOR);
List<ConfigType> configTypes = new ArrayList<>();
for (String configTypeString : configTypeStrings) {
if (StringUtils.isNotEmpty(configTypeString)) {
configTypes.add(ConfigType.valueOf(configTypeString));
}
}
return configTypes;
}

public static String toString(List<ConfigType> configTypes) {
StringBuilder sb = new StringBuilder();
for (ConfigType configType : configTypes) {
sb.append(configType.name()).append(CONFIG_TYPE_SEPARATOR);
}
return sb.toString();
}
}

@CFNotNull
private List<ConfigType> configType;
private String configType;

@Override
public void checkFields() throws RemotingCommandException {

}

public List<ConfigType> getConfigType() {
return configType;
return ConfigType.fromString(configType);
}

public void setConfigType(
List<ConfigType> configType) {
this.configType = configType;
public void setConfigType(List<ConfigType> configType) {
this.configType = ConfigType.toString(configType);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.ArrayList;
import java.util.List;
import org.junit.Test;

public class RocksDBConfigToJsonRequestHeaderTest {
@Test
public void configTypeTest() {
List<RocksDBConfigToJsonRequestHeader.ConfigType> configTypes = new ArrayList<>();
configTypes.add(RocksDBConfigToJsonRequestHeader.ConfigType.topics);
configTypes.add(RocksDBConfigToJsonRequestHeader.ConfigType.subscriptionGroups);

String string = RocksDBConfigToJsonRequestHeader.ConfigType.toString(configTypes);

List<RocksDBConfigToJsonRequestHeader.ConfigType> newConfigTypes = RocksDBConfigToJsonRequestHeader.ConfigType.fromString(string);
assert newConfigTypes.size() == 2;
assert configTypes.equals(newConfigTypes);

List<RocksDBConfigToJsonRequestHeader.ConfigType> topics = RocksDBConfigToJsonRequestHeader.ConfigType.fromString("topics");
assert topics.size() == 1;
assert topics.get(0).equals(RocksDBConfigToJsonRequestHeader.ConfigType.topics);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) t
if (commandLine.hasOption("configPath")) {
String configType = commandLine.getOptionValue("configType").trim();
try {
typeList.add(RocksDBConfigToJsonRequestHeader.ConfigType.fromString(configType));
typeList.addAll(RocksDBConfigToJsonRequestHeader.ConfigType.fromString(configType));
} catch (IllegalArgumentException e) {
System.out.print("Invalid configType: " + configType + " please input topics/subscriptionGroups/consumerOffsets \n");
return;
Expand All @@ -119,7 +119,7 @@ public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) t
String configType = commandLine.getOptionValue("configType").trim();
RocksDBConfigToJsonRequestHeader.ConfigType type;
try {
type = RocksDBConfigToJsonRequestHeader.ConfigType.fromString(configType);
type = RocksDBConfigToJsonRequestHeader.ConfigType.fromString(configType).get(0);
} catch (IllegalArgumentException e) {
System.out.print("Invalid configType: " + configType + " please input topics/subscriptionGroups/consumerOffsets \n");
return;
Expand Down

0 comments on commit 3f846a0

Please sign in to comment.