-
Notifications
You must be signed in to change notification settings - Fork 11.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* [ISSUE #9111] Broker Support export RocksDB Config to json file and enhance admin tools
- Loading branch information
1 parent
f6249e5
commit b30afe8
Showing
13 changed files
with
463 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
.../org/apache/rocketmq/remoting/protocol/header/ExportRocksDBConfigToJsonRequestHeader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* 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.apache.commons.lang3.StringUtils; | ||
import org.apache.rocketmq.common.action.Action; | ||
import org.apache.rocketmq.common.action.RocketMQAction; | ||
import org.apache.rocketmq.remoting.CommandCustomHeader; | ||
import org.apache.rocketmq.remoting.annotation.CFNotNull; | ||
import org.apache.rocketmq.remoting.exception.RemotingCommandException; | ||
import org.apache.rocketmq.remoting.protocol.RequestCode; | ||
|
||
@RocketMQAction(value = RequestCode.EXPORT_ROCKSDB_CONFIG_TO_JSON, action = Action.GET) | ||
public class ExportRocksDBConfigToJsonRequestHeader implements CommandCustomHeader { | ||
private static final String CONFIG_TYPE_SEPARATOR = ";"; | ||
|
||
public enum ConfigType { | ||
TOPICS("topics"), | ||
SUBSCRIPTION_GROUPS("subscriptionGroups"), | ||
CONSUMER_OFFSETS("consumerOffsets"); | ||
|
||
private final String typeName; | ||
|
||
ConfigType(String typeName) { | ||
this.typeName = typeName; | ||
} | ||
|
||
public static ConfigType getConfigTypeByName(String typeName) { | ||
for (ConfigType configType : ConfigType.values()) { | ||
if (configType.getTypeName().equalsIgnoreCase(typeName.trim())) { | ||
return configType; | ||
} | ||
} | ||
throw new IllegalArgumentException("Unknown config type: " + typeName); | ||
} | ||
|
||
public static List<ConfigType> fromString(String ordinal) { | ||
String[] configTypeNames = StringUtils.split(ordinal, CONFIG_TYPE_SEPARATOR); | ||
List<ConfigType> configTypes = new ArrayList<>(); | ||
for (String configTypeName : configTypeNames) { | ||
if (StringUtils.isNotEmpty(configTypeName)) { | ||
configTypes.add(getConfigTypeByName(configTypeName)); | ||
} | ||
} | ||
return configTypes; | ||
} | ||
|
||
public static String toString(List<ConfigType> configTypes) { | ||
StringBuilder sb = new StringBuilder(); | ||
for (ConfigType configType : configTypes) { | ||
sb.append(configType.getTypeName()).append(CONFIG_TYPE_SEPARATOR); | ||
} | ||
return sb.toString(); | ||
} | ||
|
||
public String getTypeName() { | ||
return typeName; | ||
} | ||
} | ||
|
||
@CFNotNull | ||
private String configType; | ||
|
||
@Override | ||
public void checkFields() throws RemotingCommandException { | ||
|
||
} | ||
|
||
public List<ConfigType> fetchConfigType() { | ||
return ConfigType.fromString(configType); | ||
} | ||
|
||
public void updateConfigType(List<ConfigType> configType) { | ||
this.configType = ConfigType.toString(configType); | ||
} | ||
|
||
public String getConfigType() { | ||
return configType; | ||
} | ||
|
||
public void setConfigType(String configType) { | ||
this.configType = configType; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
.../apache/rocketmq/remoting/protocol/header/ExportRocksDBConfigToJsonRequestHeaderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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.Assert; | ||
import org.junit.Test; | ||
|
||
public class ExportRocksDBConfigToJsonRequestHeaderTest { | ||
@Test | ||
public void configTypeTest() { | ||
List<ExportRocksDBConfigToJsonRequestHeader.ConfigType> configTypes = new ArrayList<>(); | ||
configTypes.add(ExportRocksDBConfigToJsonRequestHeader.ConfigType.TOPICS); | ||
configTypes.add(ExportRocksDBConfigToJsonRequestHeader.ConfigType.SUBSCRIPTION_GROUPS); | ||
|
||
String string = ExportRocksDBConfigToJsonRequestHeader.ConfigType.toString(configTypes); | ||
|
||
List<ExportRocksDBConfigToJsonRequestHeader.ConfigType> newConfigTypes = ExportRocksDBConfigToJsonRequestHeader.ConfigType.fromString(string); | ||
assert newConfigTypes.size() == 2; | ||
assert configTypes.equals(newConfigTypes); | ||
|
||
List<ExportRocksDBConfigToJsonRequestHeader.ConfigType> topics = ExportRocksDBConfigToJsonRequestHeader.ConfigType.fromString("topics"); | ||
assert topics.size() == 1; | ||
assert topics.get(0).equals(ExportRocksDBConfigToJsonRequestHeader.ConfigType.TOPICS); | ||
|
||
List<ExportRocksDBConfigToJsonRequestHeader.ConfigType> mix = ExportRocksDBConfigToJsonRequestHeader.ConfigType.fromString("toPics; subScriptiongroups"); | ||
assert mix.size() == 2; | ||
assert mix.get(0).equals(ExportRocksDBConfigToJsonRequestHeader.ConfigType.TOPICS); | ||
assert mix.get(1).equals(ExportRocksDBConfigToJsonRequestHeader.ConfigType.SUBSCRIPTION_GROUPS); | ||
|
||
Assert.assertThrows(IllegalArgumentException.class, () -> { | ||
ExportRocksDBConfigToJsonRequestHeader.ConfigType.fromString("topics; subscription"); | ||
}); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.