Skip to content

Commit

Permalink
[improve][cli] PIP-343: Refactor pulsar-perf to subcommand (#22388)
Browse files Browse the repository at this point in the history
Co-authored-by: Zixuan Liu <nodeces@gmail.com>
  • Loading branch information
crossoverJie and nodece authored May 2, 2024
1 parent 4f3cc6c commit 6f75569
Show file tree
Hide file tree
Showing 24 changed files with 1,320 additions and 1,436 deletions.
65 changes: 1 addition & 64 deletions bin/pulsar-perf
Original file line number Diff line number Diff line change
Expand Up @@ -84,37 +84,6 @@ add_maven_deps_to_classpath() {
fi
PULSAR_CLASSPATH=${CLASSPATH}:`cat "${f}"`
}
pulsar_help() {
cat <<EOF
Usage: pulsar-perf <command>
where command is one of:
produce Run a producer
consume Run a consumer
transaction Run a transaction repeatedly
read Run a topic reader
websocket-producer Run a websocket producer
managed-ledger Write directly on managed-ledgers
monitor-brokers Continuously receive broker data and/or load reports
simulation-client Run a simulation server acting as a Pulsar client
simulation-controller Run a simulation controller to give commands to servers
gen-doc Generate documentation automatically.
help This help message
or command is the full name of a class with a defined main() method.
Environment variables:
PULSAR_LOG_CONF Log4j configuration file (default $DEFAULT_LOG_CONF)
PULSAR_CLIENT_CONF Configuration file for client (default: $DEFAULT_CLIENT_CONF)
PULSAR_EXTRA_OPTS Extra options to be passed to the jvm
PULSAR_EXTRA_CLASSPATH Add extra paths to the pulsar classpath
These variable can also be set in conf/pulsar_env.sh
EOF
}

if [ -d "$PULSAR_HOME/lib" ]; then
PULSAR_CLASSPATH="$PULSAR_CLASSPATH:$PULSAR_HOME/lib/*"
Expand Down Expand Up @@ -162,36 +131,4 @@ OPTS="$OPTS -Dpulsar.log.file=$PULSAR_LOG_FILE"
#Change to PULSAR_HOME to support relative paths
cd "$PULSAR_HOME"

# if no args specified, show usage
if [ $# = 0 ]; then
pulsar_help;
exit 1;
fi

# get arguments
COMMAND=$1
shift

if [ "$COMMAND" == "produce" ]; then
exec $JAVA $OPTS org.apache.pulsar.testclient.PerformanceProducer --conf-file $PULSAR_PERFTEST_CONF "$@"
elif [ "$COMMAND" == "consume" ]; then
exec $JAVA $OPTS org.apache.pulsar.testclient.PerformanceConsumer --conf-file $PULSAR_PERFTEST_CONF "$@"
elif [ "$COMMAND" == "transaction" ]; then
exec $JAVA $OPTS org.apache.pulsar.testclient.PerformanceTransaction --conf-file $PULSAR_PERFTEST_CONF "$@"
elif [ "$COMMAND" == "read" ]; then
exec $JAVA $OPTS org.apache.pulsar.testclient.PerformanceReader --conf-file $PULSAR_PERFTEST_CONF "$@"
elif [ "$COMMAND" == "monitor-brokers" ]; then
exec $JAVA $OPTS org.apache.pulsar.testclient.BrokerMonitor "$@"
elif [ "$COMMAND" == "simulation-client" ]; then
exec $JAVA $OPTS org.apache.pulsar.testclient.LoadSimulationClient "$@"
elif [ "$COMMAND" == "simulation-controller" ]; then
exec $JAVA $OPTS org.apache.pulsar.testclient.LoadSimulationController "$@"
elif [ "$COMMAND" == "websocket-producer" ]; then
exec $JAVA $OPTS org.apache.pulsar.proxy.socket.client.PerformanceClient "$@"
elif [ "$COMMAND" == "managed-ledger" ]; then
exec $JAVA $OPTS org.apache.pulsar.testclient.ManagedLedgerWriter "$@"
elif [ "$COMMAND" == "gen-doc" ]; then
exec $JAVA $OPTS org.apache.pulsar.testclient.CmdGenerateDocumentation "$@"
else
pulsar_help;
fi
exec $JAVA $OPTS org.apache.pulsar.testclient.PulsarPerfTestTool $PULSAR_PERFTEST_CONF "$@"
84 changes: 1 addition & 83 deletions bin/pulsar-perf.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -72,67 +72,7 @@ set "OPTS=%OPTS% -Dpulsar.log.level=%PULSAR_LOG_LEVEL%"
set "OPTS=%OPTS% -Dpulsar.log.root.level=%PULSAR_LOG_ROOT_LEVEL%"
set "OPTS=%OPTS% -Dpulsar.log.immediateFlush=%PULSAR_LOG_IMMEDIATE_FLUSH%"

set "COMMAND=%1"

for /f "tokens=1,* delims= " %%a in ("%*") do set "_args=%%b"

if "%COMMAND%" == "produce" (
call :execCmdWithConfigFile org.apache.pulsar.testclient.PerformanceProducer
exit /B %ERROR_CODE%
)
if "%COMMAND%" == "consume" (
call :execCmdWithConfigFile org.apache.pulsar.testclient.PerformanceConsumer
exit /B %ERROR_CODE%
)
if "%COMMAND%" == "transaction" (
call :execCmdWithConfigFile org.apache.pulsar.testclient.PerformanceTransaction
exit /B %ERROR_CODE%
)
if "%COMMAND%" == "read" (
call :execCmdWithConfigFile org.apache.pulsar.testclient.PerformanceReader
exit /B %ERROR_CODE%
)
if "%COMMAND%" == "monitor-brokers" (
call :execCmd org.apache.pulsar.testclient.BrokerMonitor
exit /B %ERROR_CODE%
)
if "%COMMAND%" == "simulation-client" (
call :execCmd org.apache.pulsar.testclient.LoadSimulationClient
exit /B %ERROR_CODE%
)
if "%COMMAND%" == "simulation-controller" (
call :execCmd org.apache.pulsar.testclient.LoadSimulationController
exit /B %ERROR_CODE%
)
if "%COMMAND%" == "websocket-producer" (
call :execCmd org.apache.pulsar.proxy.socket.client.PerformanceClient
exit /B %ERROR_CODE%
)
if "%COMMAND%" == "managed-ledger" (
call :execCmd org.apache.pulsar.testclient.ManagedLedgerWriter
exit /B %ERROR_CODE%
)
if "%COMMAND%" == "gen-doc" (
call :execCmd org.apache.pulsar.testclient.CmdGenerateDocumentation
exit /B %ERROR_CODE%
)

call :usage
exit /B %ERROR_CODE%

:execCmdWithConfigFile
"%JAVACMD%" %OPTS% %1 --conf-file "%PULSAR_PERFTEST_CONF%" %_args%
if ERRORLEVEL 1 (
call :error
)
goto :eof

:execCmd
"%JAVACMD%" %OPTS% %1 %_args%
if ERRORLEVEL 1 (
call :error
)
goto :eof
"%JAVACMD%" %OPTS% org.apache.pulsar.testclient.PulsarPerfTestTool "%PULSAR_PERFTEST_CONF%" %*



Expand All @@ -142,25 +82,3 @@ goto :eof




:usage
echo Usage: pulsar-perf COMMAND
echo where command is one of:
echo produce Run a producer
echo consume Run a consumer
echo transaction Run a transaction repeatedly
echo read Run a topic reader
echo websocket-producer Run a websocket producer
echo managed-ledger Write directly on managed-ledgers
echo monitor-brokers Continuously receive broker data and/or load reports
echo simulation-client Run a simulation server acting as a Pulsar client
echo simulation-controller Run a simulation controller to give commands to servers
echo gen-doc Generate documentation automatically.
echo help This help message
echo or command is the full name of a class with a defined main() method.
echo Environment variables:
echo PULSAR_LOG_CONF Log4j configuration file (default %PULSAR_HOME%\logs)
echo PULSAR_CLIENT_CONF Configuration file for client (default: %PULSAR_HOME%\conf\client.conf)
echo PULSAR_EXTRA_OPTS Extra options to be passed to the jvm
echo PULSAR_EXTRA_CLASSPATH Add extra paths to the pulsar classpath
goto error
Loading

0 comments on commit 6f75569

Please sign in to comment.