From 08fb0f97fef6e0178c7aafb239cda54b2176c243 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Boschi?= Date: Tue, 23 Aug 2022 17:57:07 +0200 Subject: [PATCH 1/6] [improve][cli] Pulsar shell: support for Windows --- bin/pulsar-shell.cmd | 96 +++++++++++++++++++ pulsar-client-tools/pom.xml | 5 + .../org/apache/pulsar/shell/PulsarShell.java | 1 - 3 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 bin/pulsar-shell.cmd diff --git a/bin/pulsar-shell.cmd b/bin/pulsar-shell.cmd new file mode 100644 index 0000000000000..fa033e2e03a94 --- /dev/null +++ b/bin/pulsar-shell.cmd @@ -0,0 +1,96 @@ +@echo off +rem Licensed to the Apache Software Foundation (ASF) under one or more +rem contributor license agreements. See the NOTICE file distributed with +rem this work for additional information regarding copyright ownership. +rem The ASF licenses this file to You under the Apache License, Version 2.0 +rem (the "License"); you may not use this file except in compliance with +rem the License. You may obtain a copy of the License at +rem +rem http://www.apache.org/licenses/LICENSE-2.0 +rem +rem Unless required by applicable law or agreed to in writing, software +rem distributed under the License is distributed on an "AS IS" BASIS, +rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +rem See the License for the specific language governing permissions and +rem limitations under the License. + + +if not "%JAVA_HOME%" == "" goto javaHomeSet +for %%i in (java.exe) do set "JAVACMD=%%~$PATH:i" +goto checkJavaCmd + +:javaHomeSet +set JAVACMD=%JAVA_HOME%\bin\java.exe + +if not exist "%JAVACMD%" ( + echo The JAVA_HOME environment variable is not defined correctly, so Pulsar Shell cannot be started. >&2 + echo JAVA_HOME is set to "%JAVA_HOME%", but "%JAVACMD%" does not exist. >&2 + goto error +) + +:checkJavaCmd +if not exist "%JAVACMD%" ( + echo The java.exe command does not exist in PATH nor is JAVA_HOME set, so Pulsar Shell cannot be started. >&2 + goto error +) + + +for %%i in ("%~dp0.") do SET "SCRIPT_PATH=%%~fi" +set "PULSAR_HOME_DIR=%SCRIPT_PATH%\..\" +for %%i in ("%PULSAR_HOME_DIR%.") do SET "PULSAR_HOME=%%~fi" +set "PULSAR_CLASSPATH=%PULSAR_CLASSPATH%;%PULSAR_HOME%\lib\*" + + +if "%PULSAR_CLIENT_CONF%" == "" set "PULSAR_CLIENT_CONF=%PULSAR_HOME%/conf/client.conf" +if "%PULSAR_LOG_CONF%" == "" set "PULSAR_LOG_CONF=%PULSAR_HOME%/conf/log4j2.yaml" + +set "PULSAR_LOG_CONF_DIR_TMP=%PULSAR_LOG_CONF%\..\" +for %%i in ("%PULSAR_LOG_CONF_DIR_TMP%.") do SET "PULSAR_LOG_CONF_DIR=%%~fi" +for %%a in ("%PULSAR_LOG_CONF%") do SET "PULSAR_LOG_CONF_BASENAME=%%~nxa" + +set "PULSAR_CLASSPATH=%PULSAR_CLASSPATH%;%PULSAR_LOG_CONF_DIR%" + +set "OPTS=%OPTS% "-Dlog4j.configurationFile=%PULSAR_LOG_CONF_BASENAME%"" +set "OPTS=%OPTS% "-Djava.net.preferIPv4Stack=true"" + +set "isjava8=false" +FOR /F "tokens=*" %%g IN ('"java -version 2>&1"') do ( + echo %%g|find "version" >nul + if errorlevel 0 ( + echo %%g|find "1.8" >nul + if errorlevel 0 ( + set "isjava8=true" + ) + ) +) + +if "%isjava8%" == "false" set "OPTS=%OPTS% "--add-opens java.base/sun.net=ALL-UNNAMED"" + +set "OPTS=-cp "%PULSAR_CLASSPATH% %OPTS%"" +set "OPTS=%OPTS% %PULSAR_EXTRA_OPTS%" + +if "%PULSAR_LOG_DIR%" == "" set "PULSAR_LOG_DIR=%PULSAR_HOME%/logs" +if "%PULSAR_LOG_APPENDER%" == "" set "PULSAR_LOG_APPENDER=RoutingAppender" +if "%PULSAR_LOG_LEVEL%" == "" set "PULSAR_LOG_LEVEL=info" +if "%PULSAR_LOG_ROOT_LEVEL%" == "" set "PULSAR_LOG_ROOT_LEVEL=%PULSAR_LOG_LEVEL%" +if "%PULSAR_ROUTING_APPENDER_DEFAULT%" == "" set "PULSAR_ROUTING_APPENDER_DEFAULT=Console" + +set "OPTS=%OPTS% "-Dpulsar.log.appender=%PULSAR_LOG_APPENDER%"" +set "OPTS=%OPTS% "-Dpulsar.log.dir=%PULSAR_LOG_DIR%"" +set "OPTS=%OPTS% "-Dpulsar.log.level=%PULSAR_LOG_LEVEL%"" +set "OPTS=%OPTS% "-Dpulsar.log.root.level=%PULSAR_LOG_ROOT_LEVEL%"" +set "OPTS=%OPTS% "-Dpulsar.routing.appender.default=%PULSAR_ROUTING_APPENDER_DEFAULT%"" + +set "OPTS=%OPTS% "-Dorg.jline.terminal.jansi=false"" +set "DEFAULT_CONFIG="-Dpulsar.shell.config.default=%PULSAR_CLIENT_CONF%"" + + +"%JAVACMD%" %OPTS% %DEFAULT_CONFIG% org.apache.pulsar.shell.PulsarShell %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +set ERROR_CODE=%ERROR_CODE% \ No newline at end of file diff --git a/pulsar-client-tools/pom.xml b/pulsar-client-tools/pom.xml index 87dd76b48d4b2..4f16d8ebf84b7 100644 --- a/pulsar-client-tools/pom.xml +++ b/pulsar-client-tools/pom.xml @@ -118,6 +118,11 @@ jline ${jline3.version} + + net.java.dev.jna + jna + runtime + org.apache.commons commons-text diff --git a/pulsar-client-tools/src/main/java/org/apache/pulsar/shell/PulsarShell.java b/pulsar-client-tools/src/main/java/org/apache/pulsar/shell/PulsarShell.java index 4195edaf1f209..cbc043fe0c7e1 100644 --- a/pulsar-client-tools/src/main/java/org/apache/pulsar/shell/PulsarShell.java +++ b/pulsar-client-tools/src/main/java/org/apache/pulsar/shell/PulsarShell.java @@ -216,7 +216,6 @@ public void reload(Properties properties) throws Exception { } public void run() throws Exception { - System.setProperty("org.jline.terminal.dumb", "true"); final Terminal terminal = TerminalBuilder.builder().build(); run((providersMap) -> { List completers = new ArrayList<>(); From 031427b288970f6160c4e9651b927a4b591234bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Boschi?= Date: Tue, 23 Aug 2022 18:06:26 +0200 Subject: [PATCH 2/6] add zip distro --- distribution/shell/src/assemble/shell.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/distribution/shell/src/assemble/shell.xml b/distribution/shell/src/assemble/shell.xml index 20265a6e82219..af1f229c7f7b0 100644 --- a/distribution/shell/src/assemble/shell.xml +++ b/distribution/shell/src/assemble/shell.xml @@ -24,6 +24,7 @@ shell tar.gz + zip true From fcbc72ee0463792f2a39deeaf0b840dd155e1239 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Boschi?= Date: Wed, 24 Aug 2022 10:50:15 +0200 Subject: [PATCH 3/6] revert JNA upgrade - implement pulsar-client and pulsar-admin --- bin/pulsar-admin-common.cmd | 85 +++++++++++++++++++++++++++++++++++++ bin/pulsar-admin.cmd | 32 ++++++++++++++ bin/pulsar-client.cmd | 34 +++++++++++++++ bin/pulsar-shell.cmd | 69 ++---------------------------- pom.xml | 2 +- 5 files changed, 155 insertions(+), 67 deletions(-) create mode 100644 bin/pulsar-admin-common.cmd create mode 100644 bin/pulsar-admin.cmd create mode 100644 bin/pulsar-client.cmd diff --git a/bin/pulsar-admin-common.cmd b/bin/pulsar-admin-common.cmd new file mode 100644 index 0000000000000..a1b7d4fd15684 --- /dev/null +++ b/bin/pulsar-admin-common.cmd @@ -0,0 +1,85 @@ +@echo off +rem Licensed to the Apache Software Foundation (ASF) under one or more +rem contributor license agreements. See the NOTICE file distributed with +rem this work for additional information regarding copyright ownership. +rem The ASF licenses this file to You under the Apache License, Version 2.0 +rem (the "License"); you may not use this file except in compliance with +rem the License. You may obtain a copy of the License at +rem +rem http://www.apache.org/licenses/LICENSE-2.0 +rem +rem Unless required by applicable law or agreed to in writing, software +rem distributed under the License is distributed on an "AS IS" BASIS, +rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +rem See the License for the specific language governing permissions and +rem limitations under the License. + + +if not "%JAVA_HOME%" == "" goto javaHomeSet +for %%i in (java.exe) do set "JAVACMD=%%~$PATH:i" +goto checkJavaCmd + +:javaHomeSet +set JAVACMD=%JAVA_HOME%\bin\java.exe + +if not exist "%JAVACMD%" ( + echo The JAVA_HOME environment variable is not defined correctly, so Pulsar Shell cannot be started. >&2 + echo JAVA_HOME is set to "%JAVA_HOME%", but "%JAVACMD%" does not exist. >&2 + goto error +) + +:checkJavaCmd +if not exist "%JAVACMD%" ( + echo The java.exe command does not exist in PATH nor is JAVA_HOME set, so Pulsar Shell cannot be started. >&2 + goto error +) + + +for %%i in ("%~dp0.") do SET "SCRIPT_PATH=%%~fi" +set "PULSAR_HOME_DIR=%SCRIPT_PATH%\..\" +for %%i in ("%PULSAR_HOME_DIR%.") do SET "PULSAR_HOME=%%~fi" +set "PULSAR_CLASSPATH=%PULSAR_CLASSPATH%;%PULSAR_HOME%\lib\*" + + +if "%PULSAR_CLIENT_CONF%" == "" set "PULSAR_CLIENT_CONF=%PULSAR_HOME%\conf\client.conf" +if "%PULSAR_LOG_CONF%" == "" set "PULSAR_LOG_CONF=%PULSAR_HOME%\conf\log4j2.yaml" + +set "PULSAR_LOG_CONF_DIR1=%PULSAR_LOG_CONF%\..\" +for %%i in ("%PULSAR_LOG_CONF_DIR1%.") do SET "PULSAR_LOG_CONF_DIR=%%~fi" +for %%a in ("%PULSAR_LOG_CONF%") do SET "PULSAR_LOG_CONF_BASENAME=%%~nxa" + +set "PULSAR_CLASSPATH=%PULSAR_CLASSPATH%;%PULSAR_LOG_CONF_DIR%" + +set "OPTS=%OPTS% -Dlog4j.configurationFile="%PULSAR_LOG_CONF_BASENAME%"" +set "OPTS=%OPTS% -Djava.net.preferIPv4Stack=true" + +set "isjava8=false" +FOR /F "tokens=*" %%g IN ('"java -version 2>&1"') do ( + echo %%g|find "version" >nul + if errorlevel 0 ( + echo %%g|find "1.8" >nul + if errorlevel 0 ( + set "isjava8=true" + ) + ) +) + +if "%isjava8%" == "false" set "OPTS=%OPTS% --add-opens java.base/sun.net=ALL-UNNAMED" + +set "OPTS=-cp "%PULSAR_CLASSPATH%" %OPTS%" +set "OPTS=%OPTS% %PULSAR_EXTRA_OPTS%" + +if "%PULSAR_LOG_DIR%" == "" set "PULSAR_LOG_DIR=%PULSAR_HOME%\logs" +if "%PULSAR_LOG_APPENDER%" == "" set "PULSAR_LOG_APPENDER=RoutingAppender" +if "%PULSAR_LOG_LEVEL%" == "" set "PULSAR_LOG_LEVEL=info" +if "%PULSAR_LOG_ROOT_LEVEL%" == "" set "PULSAR_LOG_ROOT_LEVEL=%PULSAR_LOG_LEVEL%" +if "%PULSAR_ROUTING_APPENDER_DEFAULT%" == "" set "PULSAR_ROUTING_APPENDER_DEFAULT=Console" + +set "OPTS=%OPTS% -Dpulsar.log.appender=%PULSAR_LOG_APPENDER%" +set "OPTS=%OPTS% -Dpulsar.log.dir=%PULSAR_LOG_DIR%" +set "OPTS=%OPTS% -Dpulsar.log.level=%PULSAR_LOG_LEVEL%" +set "OPTS=%OPTS% -Dpulsar.log.root.level=%PULSAR_LOG_ROOT_LEVEL%" +set "OPTS=%OPTS% -Dpulsar.routing.appender.default=%PULSAR_ROUTING_APPENDER_DEFAULT%" + +:error +set ERROR_CODE=1 diff --git a/bin/pulsar-admin.cmd b/bin/pulsar-admin.cmd new file mode 100644 index 0000000000000..b5ea85050a50d --- /dev/null +++ b/bin/pulsar-admin.cmd @@ -0,0 +1,32 @@ +@echo off +rem Licensed to the Apache Software Foundation (ASF) under one or more +rem contributor license agreements. See the NOTICE file distributed with +rem this work for additional information regarding copyright ownership. +rem The ASF licenses this file to You under the Apache License, Version 2.0 +rem (the "License"); you may not use this file except in compliance with +rem the License. You may obtain a copy of the License at +rem +rem http://www.apache.org/licenses/LICENSE-2.0 +rem +rem Unless required by applicable law or agreed to in writing, software +rem distributed under the License is distributed on an "AS IS" BASIS, +rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +rem See the License for the specific language governing permissions and +rem limitations under the License. + +for %%i in ("%~dp0.") do SET "SCRIPT_PATH=%%~fi" +set "PULSAR_HOME_DIR=%SCRIPT_PATH%\..\" +for %%i in ("%PULSAR_HOME_DIR%.") do SET "PULSAR_HOME=%%~fi" +call "%PULSAR_HOME%\bin\pulsar-admin-common.cmd" + +cd "%PULSAR_HOME%" +"%JAVACMD%" %OPTS% org.apache.pulsar.admin.cli.PulsarAdminTool %PULSAR_CLIENT_CONF% %* + +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +set ERROR_CODE=%ERROR_CODE% \ No newline at end of file diff --git a/bin/pulsar-client.cmd b/bin/pulsar-client.cmd new file mode 100644 index 0000000000000..8b9e9c5c93c91 --- /dev/null +++ b/bin/pulsar-client.cmd @@ -0,0 +1,34 @@ +@echo off +rem Licensed to the Apache Software Foundation (ASF) under one or more +rem contributor license agreements. See the NOTICE file distributed with +rem this work for additional information regarding copyright ownership. +rem The ASF licenses this file to You under the Apache License, Version 2.0 +rem (the "License"); you may not use this file except in compliance with +rem the License. You may obtain a copy of the License at +rem +rem http://www.apache.org/licenses/LICENSE-2.0 +rem +rem Unless required by applicable law or agreed to in writing, software +rem distributed under the License is distributed on an "AS IS" BASIS, +rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +rem See the License for the specific language governing permissions and +rem limitations under the License. + + +for %%i in ("%~dp0.") do SET "SCRIPT_PATH=%%~fi" +set "PULSAR_HOME_DIR=%SCRIPT_PATH%\..\" +for %%i in ("%PULSAR_HOME_DIR%.") do SET "PULSAR_HOME=%%~fi" +call "%PULSAR_HOME%\bin\pulsar-admin-common.cmd" + +cd "%PULSAR_HOME%" +"%JAVACMD%" %OPTS% org.apache.pulsar.client.cli.PulsarClientTool %PULSAR_CLIENT_CONF% %* + +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +set ERROR_CODE=%ERROR_CODE% + diff --git a/bin/pulsar-shell.cmd b/bin/pulsar-shell.cmd index fa033e2e03a94..94fcaa4e72589 100644 --- a/bin/pulsar-shell.cmd +++ b/bin/pulsar-shell.cmd @@ -14,76 +14,13 @@ rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. rem See the License for the specific language governing permissions and rem limitations under the License. - -if not "%JAVA_HOME%" == "" goto javaHomeSet -for %%i in (java.exe) do set "JAVACMD=%%~$PATH:i" -goto checkJavaCmd - -:javaHomeSet -set JAVACMD=%JAVA_HOME%\bin\java.exe - -if not exist "%JAVACMD%" ( - echo The JAVA_HOME environment variable is not defined correctly, so Pulsar Shell cannot be started. >&2 - echo JAVA_HOME is set to "%JAVA_HOME%", but "%JAVACMD%" does not exist. >&2 - goto error -) - -:checkJavaCmd -if not exist "%JAVACMD%" ( - echo The java.exe command does not exist in PATH nor is JAVA_HOME set, so Pulsar Shell cannot be started. >&2 - goto error -) - - for %%i in ("%~dp0.") do SET "SCRIPT_PATH=%%~fi" set "PULSAR_HOME_DIR=%SCRIPT_PATH%\..\" for %%i in ("%PULSAR_HOME_DIR%.") do SET "PULSAR_HOME=%%~fi" -set "PULSAR_CLASSPATH=%PULSAR_CLASSPATH%;%PULSAR_HOME%\lib\*" - - -if "%PULSAR_CLIENT_CONF%" == "" set "PULSAR_CLIENT_CONF=%PULSAR_HOME%/conf/client.conf" -if "%PULSAR_LOG_CONF%" == "" set "PULSAR_LOG_CONF=%PULSAR_HOME%/conf/log4j2.yaml" - -set "PULSAR_LOG_CONF_DIR_TMP=%PULSAR_LOG_CONF%\..\" -for %%i in ("%PULSAR_LOG_CONF_DIR_TMP%.") do SET "PULSAR_LOG_CONF_DIR=%%~fi" -for %%a in ("%PULSAR_LOG_CONF%") do SET "PULSAR_LOG_CONF_BASENAME=%%~nxa" - -set "PULSAR_CLASSPATH=%PULSAR_CLASSPATH%;%PULSAR_LOG_CONF_DIR%" - -set "OPTS=%OPTS% "-Dlog4j.configurationFile=%PULSAR_LOG_CONF_BASENAME%"" -set "OPTS=%OPTS% "-Djava.net.preferIPv4Stack=true"" - -set "isjava8=false" -FOR /F "tokens=*" %%g IN ('"java -version 2>&1"') do ( - echo %%g|find "version" >nul - if errorlevel 0 ( - echo %%g|find "1.8" >nul - if errorlevel 0 ( - set "isjava8=true" - ) - ) -) - -if "%isjava8%" == "false" set "OPTS=%OPTS% "--add-opens java.base/sun.net=ALL-UNNAMED"" - -set "OPTS=-cp "%PULSAR_CLASSPATH% %OPTS%"" -set "OPTS=%OPTS% %PULSAR_EXTRA_OPTS%" - -if "%PULSAR_LOG_DIR%" == "" set "PULSAR_LOG_DIR=%PULSAR_HOME%/logs" -if "%PULSAR_LOG_APPENDER%" == "" set "PULSAR_LOG_APPENDER=RoutingAppender" -if "%PULSAR_LOG_LEVEL%" == "" set "PULSAR_LOG_LEVEL=info" -if "%PULSAR_LOG_ROOT_LEVEL%" == "" set "PULSAR_LOG_ROOT_LEVEL=%PULSAR_LOG_LEVEL%" -if "%PULSAR_ROUTING_APPENDER_DEFAULT%" == "" set "PULSAR_ROUTING_APPENDER_DEFAULT=Console" - -set "OPTS=%OPTS% "-Dpulsar.log.appender=%PULSAR_LOG_APPENDER%"" -set "OPTS=%OPTS% "-Dpulsar.log.dir=%PULSAR_LOG_DIR%"" -set "OPTS=%OPTS% "-Dpulsar.log.level=%PULSAR_LOG_LEVEL%"" -set "OPTS=%OPTS% "-Dpulsar.log.root.level=%PULSAR_LOG_ROOT_LEVEL%"" -set "OPTS=%OPTS% "-Dpulsar.routing.appender.default=%PULSAR_ROUTING_APPENDER_DEFAULT%"" - -set "OPTS=%OPTS% "-Dorg.jline.terminal.jansi=false"" -set "DEFAULT_CONFIG="-Dpulsar.shell.config.default=%PULSAR_CLIENT_CONF%"" +call "%PULSAR_HOME%\bin\pulsar-admin-common.cmd" +set "OPTS=%OPTS% -Dorg.jline.terminal.jansi=false" +set "DEFAULT_CONFIG=-Dpulsar.shell.config.default="%PULSAR_CLIENT_CONF%"" "%JAVACMD%" %OPTS% %DEFAULT_CONFIG% org.apache.pulsar.shell.PulsarShell %* if ERRORLEVEL 1 goto error diff --git a/pom.xml b/pom.xml index 392da4a69d07e..29c5c20e6c381 100644 --- a/pom.xml +++ b/pom.xml @@ -211,7 +211,7 @@ flexible messaging model and an intuitive client API. 1.2.2 2.3.3 2.0.2 - 5.12.1 + 4.2.0 12.0.1 4.9.3 From f205b9328426fb0f3baa02a2530df535a46b98da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Boschi?= Date: Wed, 24 Aug 2022 18:08:46 +0200 Subject: [PATCH 4/6] fix license --- bin/pulsar-admin-common.cmd | 34 +++++++++++++++++++--------------- bin/pulsar-admin.cmd | 33 +++++++++++++++++++-------------- bin/pulsar-client.cmd | 34 +++++++++++++++++++--------------- bin/pulsar-shell.cmd | 33 +++++++++++++++++++-------------- 4 files changed, 76 insertions(+), 58 deletions(-) diff --git a/bin/pulsar-admin-common.cmd b/bin/pulsar-admin-common.cmd index a1b7d4fd15684..35dc203e4accd 100644 --- a/bin/pulsar-admin-common.cmd +++ b/bin/pulsar-admin-common.cmd @@ -1,19 +1,23 @@ -@echo off -rem Licensed to the Apache Software Foundation (ASF) under one or more -rem contributor license agreements. See the NOTICE file distributed with -rem this work for additional information regarding copyright ownership. -rem The ASF licenses this file to You under the Apache License, Version 2.0 -rem (the "License"); you may not use this file except in compliance with -rem the License. You may obtain a copy of the License at -rem -rem http://www.apache.org/licenses/LICENSE-2.0 -rem -rem Unless required by applicable law or agreed to in writing, software -rem distributed under the License is distributed on an "AS IS" BASIS, -rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -rem See the License for the specific language governing permissions and -rem limitations under the License. +@REM +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM +@echo off if not "%JAVA_HOME%" == "" goto javaHomeSet for %%i in (java.exe) do set "JAVACMD=%%~$PATH:i" diff --git a/bin/pulsar-admin.cmd b/bin/pulsar-admin.cmd index b5ea85050a50d..6aecec320a4cf 100644 --- a/bin/pulsar-admin.cmd +++ b/bin/pulsar-admin.cmd @@ -1,18 +1,23 @@ +@REM +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM + @echo off -rem Licensed to the Apache Software Foundation (ASF) under one or more -rem contributor license agreements. See the NOTICE file distributed with -rem this work for additional information regarding copyright ownership. -rem The ASF licenses this file to You under the Apache License, Version 2.0 -rem (the "License"); you may not use this file except in compliance with -rem the License. You may obtain a copy of the License at -rem -rem http://www.apache.org/licenses/LICENSE-2.0 -rem -rem Unless required by applicable law or agreed to in writing, software -rem distributed under the License is distributed on an "AS IS" BASIS, -rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -rem See the License for the specific language governing permissions and -rem limitations under the License. for %%i in ("%~dp0.") do SET "SCRIPT_PATH=%%~fi" set "PULSAR_HOME_DIR=%SCRIPT_PATH%\..\" diff --git a/bin/pulsar-client.cmd b/bin/pulsar-client.cmd index 8b9e9c5c93c91..0687fac2d32c9 100644 --- a/bin/pulsar-client.cmd +++ b/bin/pulsar-client.cmd @@ -1,19 +1,23 @@ -@echo off -rem Licensed to the Apache Software Foundation (ASF) under one or more -rem contributor license agreements. See the NOTICE file distributed with -rem this work for additional information regarding copyright ownership. -rem The ASF licenses this file to You under the Apache License, Version 2.0 -rem (the "License"); you may not use this file except in compliance with -rem the License. You may obtain a copy of the License at -rem -rem http://www.apache.org/licenses/LICENSE-2.0 -rem -rem Unless required by applicable law or agreed to in writing, software -rem distributed under the License is distributed on an "AS IS" BASIS, -rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -rem See the License for the specific language governing permissions and -rem limitations under the License. +@REM +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM +@echo off for %%i in ("%~dp0.") do SET "SCRIPT_PATH=%%~fi" set "PULSAR_HOME_DIR=%SCRIPT_PATH%\..\" diff --git a/bin/pulsar-shell.cmd b/bin/pulsar-shell.cmd index 94fcaa4e72589..107b39e130c73 100644 --- a/bin/pulsar-shell.cmd +++ b/bin/pulsar-shell.cmd @@ -1,18 +1,23 @@ +@REM +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM + @echo off -rem Licensed to the Apache Software Foundation (ASF) under one or more -rem contributor license agreements. See the NOTICE file distributed with -rem this work for additional information regarding copyright ownership. -rem The ASF licenses this file to You under the Apache License, Version 2.0 -rem (the "License"); you may not use this file except in compliance with -rem the License. You may obtain a copy of the License at -rem -rem http://www.apache.org/licenses/LICENSE-2.0 -rem -rem Unless required by applicable law or agreed to in writing, software -rem distributed under the License is distributed on an "AS IS" BASIS, -rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -rem See the License for the specific language governing permissions and -rem limitations under the License. for %%i in ("%~dp0.") do SET "SCRIPT_PATH=%%~fi" set "PULSAR_HOME_DIR=%SCRIPT_PATH%\..\" From 33c9c7d2d41a9ad481124ba46a3486e7c124661d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Boschi?= Date: Thu, 25 Aug 2022 11:59:38 +0200 Subject: [PATCH 5/6] improve error handling and pulsar-perf --- bin/pulsar-admin-common.cmd | 21 ++--- bin/pulsar-admin.cmd | 15 +--- bin/pulsar-client.cmd | 16 +--- bin/pulsar-perf.cmd | 164 ++++++++++++++++++++++++++++++++++++ bin/pulsar-shell.cmd | 13 +-- 5 files changed, 183 insertions(+), 46 deletions(-) create mode 100644 bin/pulsar-perf.cmd diff --git a/bin/pulsar-admin-common.cmd b/bin/pulsar-admin-common.cmd index 35dc203e4accd..b518734fa0bc8 100644 --- a/bin/pulsar-admin-common.cmd +++ b/bin/pulsar-admin-common.cmd @@ -19,22 +19,15 @@ @echo off -if not "%JAVA_HOME%" == "" goto javaHomeSet -for %%i in (java.exe) do set "JAVACMD=%%~$PATH:i" -goto checkJavaCmd - -:javaHomeSet -set JAVACMD=%JAVA_HOME%\bin\java.exe - -if not exist "%JAVACMD%" ( - echo The JAVA_HOME environment variable is not defined correctly, so Pulsar Shell cannot be started. >&2 - echo JAVA_HOME is set to "%JAVA_HOME%", but "%JAVACMD%" does not exist. >&2 - goto error +if "%JAVA_HOME%" == "" ( + for %%i in (java.exe) do set "JAVACMD=%%~$PATH:i" +) else ( + set "JAVACMD=%JAVA_HOME%\bin\java.exe" ) -:checkJavaCmd if not exist "%JAVACMD%" ( - echo The java.exe command does not exist in PATH nor is JAVA_HOME set, so Pulsar Shell cannot be started. >&2 + echo The JAVA_HOME environment variable is not defined correctly, so Pulsar CLI cannot be started. >&2 + echo JAVA_HOME is set to "%JAVA_HOME%", but "%JAVACMD%" does not exist. >&2 goto error ) @@ -86,4 +79,4 @@ set "OPTS=%OPTS% -Dpulsar.log.root.level=%PULSAR_LOG_ROOT_LEVEL%" set "OPTS=%OPTS% -Dpulsar.routing.appender.default=%PULSAR_ROUTING_APPENDER_DEFAULT%" :error -set ERROR_CODE=1 +exit /b 1 diff --git a/bin/pulsar-admin.cmd b/bin/pulsar-admin.cmd index 6aecec320a4cf..45bd8d4541fed 100644 --- a/bin/pulsar-admin.cmd +++ b/bin/pulsar-admin.cmd @@ -23,15 +23,8 @@ for %%i in ("%~dp0.") do SET "SCRIPT_PATH=%%~fi" set "PULSAR_HOME_DIR=%SCRIPT_PATH%\..\" for %%i in ("%PULSAR_HOME_DIR%.") do SET "PULSAR_HOME=%%~fi" call "%PULSAR_HOME%\bin\pulsar-admin-common.cmd" - +if ERRORLEVEL 1 ( + exit /b 1 +) cd "%PULSAR_HOME%" -"%JAVACMD%" %OPTS% org.apache.pulsar.admin.cli.PulsarAdminTool %PULSAR_CLIENT_CONF% %* - -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -set ERROR_CODE=%ERROR_CODE% \ No newline at end of file +"%JAVACMD%" %OPTS% org.apache.pulsar.admin.cli.PulsarAdminTool %PULSAR_CLIENT_CONF% %* \ No newline at end of file diff --git a/bin/pulsar-client.cmd b/bin/pulsar-client.cmd index 0687fac2d32c9..9e3cef45a25a7 100644 --- a/bin/pulsar-client.cmd +++ b/bin/pulsar-client.cmd @@ -23,16 +23,8 @@ for %%i in ("%~dp0.") do SET "SCRIPT_PATH=%%~fi" set "PULSAR_HOME_DIR=%SCRIPT_PATH%\..\" for %%i in ("%PULSAR_HOME_DIR%.") do SET "PULSAR_HOME=%%~fi" call "%PULSAR_HOME%\bin\pulsar-admin-common.cmd" - +if ERRORLEVEL 1 ( + exit /b 1 +) cd "%PULSAR_HOME%" -"%JAVACMD%" %OPTS% org.apache.pulsar.client.cli.PulsarClientTool %PULSAR_CLIENT_CONF% %* - -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -set ERROR_CODE=%ERROR_CODE% - +"%JAVACMD%" %OPTS% org.apache.pulsar.client.cli.PulsarClientTool %PULSAR_CLIENT_CONF% %* \ No newline at end of file diff --git a/bin/pulsar-perf.cmd b/bin/pulsar-perf.cmd new file mode 100644 index 0000000000000..1a6acfbf6de36 --- /dev/null +++ b/bin/pulsar-perf.cmd @@ -0,0 +1,164 @@ +@REM +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM + +@echo off + +if "%JAVA_HOME%" == "" ( + for %%i in (java.exe) do set "JAVACMD=%%~$PATH:i" +) else ( + set "JAVACMD=%JAVA_HOME%\bin\java.exe" +) + +if not exist "%JAVACMD%" ( + echo The JAVA_HOME environment variable is not defined correctly, so Pulsar CLI cannot be started. >&2 + echo JAVA_HOME is set to "%JAVA_HOME%", but "%JAVACMD%" does not exist. >&2 + exit /B 1 +) + +for %%i in ("%~dp0.") do SET "SCRIPT_PATH=%%~fi" +set "PULSAR_HOME_DIR=%SCRIPT_PATH%\..\" +for %%i in ("%PULSAR_HOME_DIR%.") do SET "PULSAR_HOME=%%~fi" +set "PULSAR_CLASSPATH=%PULSAR_CLASSPATH%;%PULSAR_HOME%\lib\*" + + +if "%PULSAR_CLIENT_CONF%" == "" set "PULSAR_CLIENT_CONF=%PULSAR_HOME%\conf\client.conf" +if "%PULSAR_LOG_CONF%" == "" set "PULSAR_LOG_CONF=%PULSAR_HOME%\conf\log4j2.yaml" + +set "PULSAR_LOG_CONF_DIR1=%PULSAR_LOG_CONF%\..\" +for %%i in ("%PULSAR_LOG_CONF_DIR1%.") do SET "PULSAR_LOG_CONF_DIR=%%~fi" +for %%a in ("%PULSAR_LOG_CONF%") do SET "PULSAR_LOG_CONF_BASENAME=%%~nxa" + +set "PULSAR_CLASSPATH=%PULSAR_CLASSPATH%;%PULSAR_LOG_CONF_DIR%" +if not "%PULSAR_EXTRA_CLASSPATH%" == "" set "PULSAR_CLASSPATH=%PULSAR_CLASSPATH%;%PULSAR_EXTRA_CLASSPATH%" + + +if "%PULSAR_PERFTEST_CONF%" == "" set "PULSAR_PERFTEST_CONF=%PULSAR_CLIENT_CONF%" + + +set "OPTS=%OPTS% -Dlog4j.configurationFile="%PULSAR_LOG_CONF_BASENAME%"" +set "OPTS=%OPTS% -Djava.net.preferIPv4Stack=true" + + +set "OPTS=-cp "%PULSAR_CLASSPATH%" %OPTS%" +set "OPTS=%OPTS% %PULSAR_EXTRA_OPTS%" + +if "%PULSAR_LOG_DIR%" == "" set "PULSAR_LOG_DIR=%PULSAR_HOME%\logs" +if "%PULSAR_LOG_FILE%" == "" set "PULSAR_LOG_FILE=pulsar-perftest.log" +if "%PULSAR_LOG_APPENDER%" == "" set "PULSAR_LOG_APPENDER=Console" +if "%PULSAR_LOG_LEVEL%" == "" set "PULSAR_LOG_LEVEL=info" +if "%PULSAR_LOG_ROOT_LEVEL%" == "" set "PULSAR_LOG_ROOT_LEVEL=%PULSAR_LOG_LEVEL%" + + +set "OPTS=%OPTS% -Dpulsar.log.appender=%PULSAR_LOG_APPENDER%" +set "OPTS=%OPTS% -Dpulsar.log.dir=%PULSAR_LOG_DIR%" +set "OPTS=%OPTS% -Dpulsar.log.level=%PULSAR_LOG_LEVEL%" +set "OPTS=%OPTS% -Dpulsar.log.root.level=%PULSAR_LOG_ROOT_LEVEL%" + +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 + + + +:error +set ERROR_CODE=1 +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 diff --git a/bin/pulsar-shell.cmd b/bin/pulsar-shell.cmd index 107b39e130c73..e8d0a59e4d9fd 100644 --- a/bin/pulsar-shell.cmd +++ b/bin/pulsar-shell.cmd @@ -23,16 +23,11 @@ for %%i in ("%~dp0.") do SET "SCRIPT_PATH=%%~fi" set "PULSAR_HOME_DIR=%SCRIPT_PATH%\..\" for %%i in ("%PULSAR_HOME_DIR%.") do SET "PULSAR_HOME=%%~fi" call "%PULSAR_HOME%\bin\pulsar-admin-common.cmd" +if ERRORLEVEL 1 ( + exit /b 1 +) set "OPTS=%OPTS% -Dorg.jline.terminal.jansi=false" set "DEFAULT_CONFIG=-Dpulsar.shell.config.default="%PULSAR_CLIENT_CONF%"" -"%JAVACMD%" %OPTS% %DEFAULT_CONFIG% org.apache.pulsar.shell.PulsarShell %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -set ERROR_CODE=%ERROR_CODE% \ No newline at end of file +"%JAVACMD%" %OPTS% %DEFAULT_CONFIG% org.apache.pulsar.shell.PulsarShell %* \ No newline at end of file From 7fb69faa774044b83e00da61ce89279d579b1a1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Boschi?= Date: Mon, 29 Aug 2022 16:07:14 +0200 Subject: [PATCH 6/6] re-revert jna --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 29c5c20e6c381..392da4a69d07e 100644 --- a/pom.xml +++ b/pom.xml @@ -211,7 +211,7 @@ flexible messaging model and an intuitive client API. 1.2.2 2.3.3 2.0.2 - 4.2.0 + 5.12.1 12.0.1 4.9.3