-
Notifications
You must be signed in to change notification settings - Fork 526
feat(tool): add admin tool to help user start AutoMQ easily #670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
6d1c0ca
feat(tool): add automq kafka admin tool
KaimingWan 97c2fff
feat(tool): support precheck when execute admin tool
KaimingWan a8afa2a
feat(tool): optimize generate s3 url command
KaimingWan 29d3d69
feat(tool): support parse url
KaimingWan 7adbb64
feat(tool): enable generate config properties
KaimingWan 1188eeb
fix(tool): fix admin tool output
KaimingWan 70eb008
fix(tool): fix output style
KaimingWan 0416d32
fix(tool): fix get protocol
KaimingWan 8f6537e
fix(tool): fix admin tool output style
KaimingWan 5688a12
fix(tool): fix admin tool output style
KaimingWan f413ee8
fix(tool): fix admin tool output style
KaimingWan f1e8df6
fix(tool): fix not set listener correctly for server listeners
KaimingWan c0d7119
fix(tool): fix admin tool output style
KaimingWan b59d66f
fix(tool): fix admin tool output style
KaimingWan f568110
fix(tool): fix advertised listeners
KaimingWan 26ccb2b
fix(tool): fix not set bucket
KaimingWan b6fa038
fix(tool): fix output
KaimingWan 71bab07
fix(tool): rename parameter
KaimingWan 8821199
fix(tool): make http protocol not required
KaimingWan d3449bd
fix(tool): support s3 path style parameter
KaimingWan 683661e
feat(tool): add s3shell sdk and support load s3 url in kafka main
KaimingWan ac815ef
feat(tool): support start by s3 url
KaimingWan df2f1ab
fix(tool): fix system env set
KaimingWan 9579b81
fix(tool): optimize start command
KaimingWan 5222c3a
fix(tool): fix format storage
KaimingWan 5ab049e
fix(tool): suppress warning log
KaimingWan 7f1027a
chore(tool): refactor some code and add testcase
KaimingWan d080f72
fix(tool): fix controller only mode
KaimingWan b6f8cee
fix(tool): remove comment
KaimingWan b9ac6e8
fix(tool): fix testcase
KaimingWan bebad63
fix(tool): fix code style
KaimingWan 3a32086
fix(tool): remove useless pkg
KaimingWan 575cd09
chore: use gradle to manage new module
KaimingWan b25bd5b
chore: add check style
KaimingWan 0266d7b
fix(tool): remove useless template file
KaimingWan f6d8cd2
fix(tool): fix style
KaimingWan 12c11c0
chore: move args to kafka-run-class.sh
KaimingWan 382d108
chore: fix style
KaimingWan 075257d
refactor(tool): use sub-parser and remove useless code
KaimingWan 0b8f774
refactor(tool): move code to more suitable place
KaimingWan f0fa605
chore: use default 2c16g configuration in template config file
KaimingWan efa13e7
chore: open auth method and ops-bucket for automq enterprise
KaimingWan 9fe6e8e
chore: fix scala code indent
KaimingWan 612a406
Merge branch 'develop' into feat/admin_tool
KaimingWan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,18 @@ | ||
| #!/bin/bash | ||
| # 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. | ||
|
|
||
| exec $(dirname $0)/kafka-run-class.sh org.apache.kafka.tools.automq.AutoMQKafkaAdminTool "$@" | ||
|
|
This file contains hidden or 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 hidden or 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 hidden or 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,55 @@ | ||
| <!DOCTYPE import-control PUBLIC | ||
| "-//Puppy Crawl//DTD Import Control 1.1//EN" | ||
| "http://www.puppycrawl.com/dtds/import_control_1_1.dtd"> | ||
| <!-- | ||
| 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. | ||
| --> | ||
|
|
||
| <import-control pkg="com.automq"> | ||
|
|
||
| <!-- THINK HARD ABOUT THE LAYERING OF THE PROJECT BEFORE CHANGING THIS FILE --> | ||
|
|
||
| <!-- common library dependencies --> | ||
| <!-- common library dependencies --> | ||
| <allow pkg="java" /> | ||
| <allow pkg="javax.management" /> | ||
| <allow pkg="org.slf4j" /> | ||
| <allow pkg="org.junit" /> | ||
| <allow pkg="org.opentest4j" /> | ||
| <allow pkg="org.hamcrest" /> | ||
| <allow pkg="org.mockito" /> | ||
| <allow pkg="org.easymock" /> | ||
| <allow pkg="org.powermock" /> | ||
| <allow pkg="java.security" /> | ||
| <allow pkg="javax.net.ssl" /> | ||
| <allow pkg="javax.security" /> | ||
| <allow pkg="org.ietf.jgss" /> | ||
| <allow pkg="net.jqwik.api" /> | ||
| <allow pkg="io.netty" /> | ||
| <allow pkg="software.amazon.awssdk" /> | ||
| <allow pkg="com.automq.stream" /> | ||
| <allow pkg="org.apache.kafka.tools.automq"/> | ||
| <allow pkg="com.automq.s3shell"/> | ||
| <allow pkg="org.apache.commons.io"/> | ||
|
|
||
| <allow pkg="com.github.luben.zstd" /> | ||
| <allow pkg="com.google.common.cache" /> | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| </import-control> |
This file contains hidden or 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 hidden or 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 hidden or 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,34 @@ | ||
| /* | ||
| * 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 kafka.s3shell.util; | ||
|
|
||
| import java.lang.reflect.Field; | ||
| import java.util.Map; | ||
|
|
||
| public class EnvUtil { | ||
| public static void setEnv(String key, String value) { | ||
| try { | ||
| Map<String, String> env = System.getenv(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's weird that setting the environments using reflection here. S3StreamConfig already supports config credentials, consider setting ak/sk directly to avoid using reflection. |
||
| Field field = env.getClass().getDeclaredField("m"); | ||
| field.setAccessible(true); | ||
| Map<String, String> writableEnv = (Map<String, String>) field.get(env); | ||
| writableEnv.put(key, value); | ||
| } catch (Exception e) { | ||
| throw new IllegalStateException("Failed to set environment variable", e); | ||
| } | ||
| } | ||
| } | ||
44 changes: 44 additions & 0 deletions
44
core/src/main/java/kafka/s3shell/util/KafkaFormatUtil.java
This file contains hidden or 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,44 @@ | ||
| /* | ||
| * 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 kafka.s3shell.util; | ||
|
|
||
| import com.automq.s3shell.sdk.util.S3PropUtil; | ||
| import java.io.IOException; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
| import java.util.Properties; | ||
| import kafka.tools.StorageTool; | ||
|
|
||
| public class KafkaFormatUtil { | ||
| public static void formatStorage(String clusterId, Properties props) throws IOException { | ||
| String propFileName = String.format("automq-%s.properties", clusterId); | ||
| String propFilePath = "generated/" + propFileName; | ||
| String logDirPath = props.getProperty("log.dirs"); | ||
|
|
||
| Path propPath = Paths.get(propFilePath); | ||
| if (Files.exists(propPath)) { | ||
| //delete if exists | ||
| Files.delete(propPath); | ||
| } | ||
|
|
||
| S3PropUtil.persist(props, propFileName); | ||
| if (!Files.isDirectory(Paths.get(logDirPath)) || !Files.exists(Paths.get(logDirPath, "meta.properties"))) { | ||
| StorageTool.main(new String[] {"auto-format", "-t", clusterId, "-c=" + propFilePath}); | ||
| } | ||
| } | ||
| } |
116 changes: 116 additions & 0 deletions
116
core/src/main/java/kafka/s3shell/util/S3ShellPropUtil.java
This file contains hidden or 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,116 @@ | ||
| /* | ||
| * 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 kafka.s3shell.util; | ||
|
|
||
| import com.automq.s3shell.sdk.constant.ServerConfigKey; | ||
| import com.automq.s3shell.sdk.model.S3Url; | ||
| import com.automq.s3shell.sdk.util.S3PropUtil; | ||
| import java.io.IOException; | ||
| import java.util.List; | ||
| import java.util.Properties; | ||
| import joptsimple.OptionParser; | ||
| import joptsimple.OptionSet; | ||
| import org.apache.kafka.common.internals.FatalExitError; | ||
|
|
||
| import static kafka.log.stream.s3.ConfigUtils.ACCESS_KEY_NAME; | ||
| import static kafka.log.stream.s3.ConfigUtils.SECRET_KEY_NAME; | ||
|
|
||
| public class S3ShellPropUtil { | ||
|
|
||
| private static OptionParser acceptOption() { | ||
| OptionParser optionParser = new OptionParser(); | ||
| optionParser.accepts("override", "Optional property that should override values set in server.properties file") | ||
| .withRequiredArg() | ||
| .ofType(String.class); | ||
| optionParser.accepts("config", "Path to server.properties file") | ||
| .withRequiredArg() | ||
| .ofType(String.class); | ||
| optionParser.accepts("s3-url", "URL for S3 storage") | ||
| .withRequiredArg() | ||
| .ofType(String.class); | ||
| optionParser.accepts("version", "Print version information and exit."); | ||
| return optionParser; | ||
| } | ||
|
|
||
| public static Properties autoGenPropsByCmd(String[] args, String processRole) throws IOException { | ||
| if (args.length < 1) { | ||
| throw new FatalExitError(1); | ||
| } | ||
|
|
||
| Properties props = new Properties(); | ||
| switch (processRole) { | ||
| case "broker": | ||
| props.putAll(S3PropUtil.loadTemplateProps(S3PropUtil.BROKER_PROPS_PATH)); | ||
| break; | ||
| case "controller": | ||
| props.putAll(S3PropUtil.loadTemplateProps(S3PropUtil.CONTROLLER_PROPS_PATH)); | ||
| break; | ||
| case "broker,controller": | ||
| case "controller,broker": | ||
| props.putAll(S3PropUtil.loadTemplateProps(S3PropUtil.SERVER_PROPS_PATH)); | ||
| break; | ||
| default: | ||
| throw new IllegalArgumentException("Invalid process role:" + processRole); | ||
| } | ||
|
|
||
| // Handle --override options | ||
| OptionParser optionParser = acceptOption(); | ||
| OptionSet options = optionParser.parse(args); | ||
| handleOption(options, props); | ||
|
|
||
| return props; | ||
| } | ||
|
|
||
| private static void handleOption(OptionSet options, Properties props) { | ||
| S3Url s3Url = null; | ||
| if (options.has("s3-url")) { | ||
| String s3UrlStr = (String) options.valueOf("s3-url"); | ||
| s3Url = S3Url.parse(s3UrlStr); | ||
| props.put(ServerConfigKey.S3_ENDPOINT.getKeyName(), s3Url.getEndpointProtocol().getName() + "://" + s3Url.getS3Endpoint()); | ||
| props.put(ServerConfigKey.S3_REGION.getKeyName(), s3Url.getS3Region()); | ||
| props.put(ServerConfigKey.S3_BUCKET.getKeyName(), s3Url.getS3DataBucket()); | ||
| props.put(ServerConfigKey.S3_PATH_STYLE.getKeyName(), String.valueOf(s3Url.isS3PathStyle())); | ||
|
|
||
| // override system env | ||
| EnvUtil.setEnv(ACCESS_KEY_NAME, s3Url.getS3AccessKey()); | ||
| EnvUtil.setEnv(SECRET_KEY_NAME, s3Url.getS3SecretKey()); | ||
| } | ||
|
|
||
| if (options.has("override")) { | ||
| List<?> overrideOptions = options.valuesOf("override"); | ||
| for (Object o : overrideOptions) { | ||
| String option = (String) o; | ||
| String[] keyValue = option.split("=", 2); | ||
| if (keyValue.length == 2) { | ||
| props.setProperty(keyValue[0], keyValue[1]); | ||
| } else { | ||
| throw new IllegalArgumentException("Invalid override option format: " + option); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| //format storage | ||
| if (s3Url != null) { | ||
| try { | ||
| KafkaFormatUtil.formatStorage(s3Url.getClusterId(), props); | ||
| } catch (IOException e) { | ||
| throw new RuntimeException(String.format("Format storage failed for cluster:%s", s3Url.getClusterId()), e); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.