Skip to content
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

Artemis Console next gen based on hawtIO 4 #5149

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions artemis-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-plugin</artifactId>
<artifactId>artemis-console-war</artifactId>
<type>war</type>
<version>${project.version}</version>
<version>${artemis-console-war-version}</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,20 @@
*/
package org.apache.activemq.artemis.cli.commands;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Stream;
Expand All @@ -36,8 +40,12 @@
@Command(name = "upgrade", description = "Update a broker instance to the current artemis.home, keeping all the data and broker.xml. Warning: backup your instance before using this command and compare the files.")
public class Upgrade extends InstallAbstract {

// these are the JVM argumnents we must keep between upgrades
private static final String[] KEEPING_JVM_ARGUMENTS = new String[]{"-Xmx", "-Djava.security.auth.login.config", "-Dhawtio.role="};
// These are the JVM arguments we must keep between upgrades
private static final String[] KEEPING_JVM_ARGUMENTS = new String[]{"-Xmx", "-Djava.security.auth.login.config", "-Dhawtio.roles="};

// These are the renamed JVM arguments we must keep between upgrades
// The keys MUST be one of the current KEEPING_JVM_ARGUMENTS args above, the values then being its old variant to be renamed.
private static final Map<String, String> KEEPING_JVM_ARGUMENTS_ALTERNATES = Map.of("-Dhawtio.roles=", "-Dhawtio.role=");

// this is the prefix where we can find the JDK arguments in Windows script
private static final String JDK_PREFIX_WINDOWS = "IF \"%JAVA_ARGS%\"==\"\" (set JAVA_ARGS=";
Expand Down Expand Up @@ -140,20 +148,22 @@ public Object run(ActionContext context) throws Exception {
final File serviceXml = new File(bin, Create.ARTEMIS_SERVICE_XML);
final File serviceXmlBkp = new File(binBkp, Create.ARTEMIS_SERVICE_XML);

Map<String, String> keepPrefixAlternates = Map.of("<startargument>-Dhawtio.roles=", "<startargument>-Dhawtio.role=");

write(Create.BIN_ARTEMIS_SERVICE_XML, serviceXmlTmp, filters, false, false);
upgrade(context, serviceXmlTmp, serviceXml, serviceXmlBkp,
upgrade(context, serviceXmlTmp, serviceXml, serviceXmlBkp, keepPrefixAlternates,
"<env name=\"ARTEMIS_INSTANCE\"", "<env name=\"ARTEMIS_INSTANCE_ETC\"",
"<env name=\"ARTEMIS_INSTANCE_URI\"", "<env name=\"ARTEMIS_INSTANCE_ETC_URI\"",
"<env name=\"ARTEMIS_DATA_DIR\"", "<logpath>", "<startargument>-Xmx", "<stopargument>-Xmx",
"<name>", "<id>", "<startargument>-Dhawtio.role=");
"<name>", "<id>", "<startargument>-Dhawtio.roles=");
gemmellr marked this conversation as resolved.
Show resolved Hide resolved

final File artemisProfileCmdTmp = new File(tmp, Create.ETC_ARTEMIS_PROFILE_CMD);
final File artemisProfileCmd = new File(etcFolder, Create.ETC_ARTEMIS_PROFILE_CMD);
final File artemisProfileCmdBkp = new File(etcBkp, Create.ETC_ARTEMIS_PROFILE_CMD);

write("etc/" + Create.ETC_ARTEMIS_PROFILE_CMD, artemisProfileCmdTmp, filters, false, false);
upgradeJDK(context, JDK_PREFIX_WINDOWS, "", KEEPING_JVM_ARGUMENTS, artemisProfileCmdTmp, artemisProfileCmd, artemisProfileCmdBkp,
"set ARTEMIS_INSTANCE=\"", "set ARTEMIS_DATA_DIR=", "set ARTEMIS_ETC_DIR=", "set ARTEMIS_OOME_DUMP=", "set ARTEMIS_INSTANCE_URI=", "set ARTEMIS_INSTANCE_ETC_URI=");
upgradeJDK(context, JDK_PREFIX_WINDOWS, "", KEEPING_JVM_ARGUMENTS_ALTERNATES, KEEPING_JVM_ARGUMENTS, artemisProfileCmdTmp, artemisProfileCmd, artemisProfileCmdBkp,
Collections.emptyMap(), "set ARTEMIS_INSTANCE=\"", "set ARTEMIS_DATA_DIR=", "set ARTEMIS_ETC_DIR=", "set ARTEMIS_OOME_DUMP=", "set ARTEMIS_INSTANCE_URI=", "set ARTEMIS_INSTANCE_ETC_URI=");
}

if (IS_NIX) {
Expand All @@ -170,10 +180,12 @@ public Object run(ActionContext context) throws Exception {
write(Create.BIN_ARTEMIS_SERVICE, artemisServiceTmp, filters, false, false);
upgrade(context, artemisServiceTmp, artemisService, artemisServiceBkp); // we replace the whole thing

Map<String, String> keepPrefixAlternates = Map.of("HAWTIO_ROLES=", "HAWTIO_ROLE=");

write("etc/" + Create.ETC_ARTEMIS_PROFILE, new File(tmp, Create.ETC_ARTEMIS_PROFILE), filters, false, false);
upgradeJDK(context, JDK_PREFIX_LINUX, "\"", KEEPING_JVM_ARGUMENTS,
new File(tmp, Create.ETC_ARTEMIS_PROFILE), new File(etcFolder, Create.ETC_ARTEMIS_PROFILE), new File(etcBkp, Create.ETC_ARTEMIS_PROFILE), "ARTEMIS_INSTANCE=",
"ARTEMIS_DATA_DIR=", "ARTEMIS_ETC_DIR=", "ARTEMIS_OOME_DUMP=", "ARTEMIS_INSTANCE_URI=", "ARTEMIS_INSTANCE_ETC_URI=", "HAWTIO_ROLE=");
upgradeJDK(context, JDK_PREFIX_LINUX, "\"", KEEPING_JVM_ARGUMENTS_ALTERNATES, KEEPING_JVM_ARGUMENTS,
new File(tmp, Create.ETC_ARTEMIS_PROFILE), new File(etcFolder, Create.ETC_ARTEMIS_PROFILE), new File(etcBkp, Create.ETC_ARTEMIS_PROFILE), keepPrefixAlternates,
"ARTEMIS_INSTANCE=", "ARTEMIS_DATA_DIR=", "ARTEMIS_ETC_DIR=", "ARTEMIS_OOME_DUMP=", "ARTEMIS_INSTANCE_URI=", "ARTEMIS_INSTANCE_ETC_URI=", "HAWTIO_ROLES=");
}

final File bootstrapXml = new File(etcFolder, Create.ETC_BOOTSTRAP_XML);
Expand All @@ -187,6 +199,10 @@ public Object run(ActionContext context) throws Exception {
"^(.*)<app url=(.*branding.*)$", "$1<app name=\"branding\" url=$2",
"^(.*)<app url=(.*plugin.*)$", "$1<app name=\"plugin\" url=$2",
"^(.*)<app url=\"([^\"]+)\"(.*)$", "$1<app name=\"$2\" url=\"$2\"$3");

//we remove the unwanted wars after updating them above just in case we are upgrading from an older version where the format was different
removeWars(context, bootstrapXml);

upgradeLogging(context, etcFolder, etcBkp);

context.out.println();
Expand Down Expand Up @@ -222,20 +238,26 @@ private String getLine(File cmd, String pattern) throws IOException {
}


private void upgradeJDK(ActionContext context, String jdkPrefix, String endOfLine, String[] keepArguments, File tmpFile, File targetFile, File bkpFile, String... keepingPrefixes) throws Exception {
private void upgradeJDK(ActionContext context, String jdkPrefix, String endOfLine, Map<String, String> keepArgumentAlternates, String[] keepArguments, File tmpFile, File targetFile, File bkpFile, Map<String, String> keepPrefixAlternates, String... keepingPrefixes) throws Exception {

final HashMap<String, String> replaceMatrix = new HashMap<>();
final HashMap<String, String> currentArguments = new HashMap<>();

doUpgrade(context, tmpFile, targetFile, bkpFile,
oldLine -> {
if (oldLine.trim().startsWith(jdkPrefix)) {
JVMArgumentParser.parseOriginalArgs(jdkPrefix, endOfLine, oldLine, keepArguments, currentArguments);
JVMArgumentParser.parseOriginalArgs(jdkPrefix, endOfLine, oldLine, keepArgumentAlternates, keepArguments, currentArguments);
return;
} else {
for (String prefix : keepingPrefixes) {
if (oldLine.trim().startsWith(prefix)) {
replaceMatrix.put(prefix, oldLine);
} else if (keepPrefixAlternates.containsKey(prefix)) {
String oldPrefix = keepPrefixAlternates.get(prefix);
if (oldLine.trim().startsWith(oldPrefix)) {
String renamedOldLine = oldLine.replaceFirst(oldPrefix, prefix);
replaceMatrix.put(prefix, renamedOldLine);
}
}
}
}
Expand Down Expand Up @@ -270,6 +292,10 @@ private void replaceLines(ActionContext context, File tmpFile, File targetFile,
}

private void upgrade(ActionContext context, File tmpFile, File targetFile, File bkpFile, String... keepingPrefixes) throws Exception {
upgrade(context, tmpFile, targetFile, bkpFile, Collections.emptyMap(), keepingPrefixes);
}

private void upgrade(ActionContext context, File tmpFile, File targetFile, File bkpFile, Map<String, String> keepPrefixAlternates, String... keepingPrefixes) throws Exception {
HashMap<String, String> replaceMatrix = new HashMap<>();

doUpgrade(context, tmpFile, targetFile, bkpFile,
Expand All @@ -278,6 +304,12 @@ private void upgrade(ActionContext context, File tmpFile, File targetFile, File
for (String prefix : keepingPrefixes) {
if (oldLine.trim().startsWith(prefix)) {
replaceMatrix.put(prefix, oldLine);
} else if (keepPrefixAlternates.containsKey(prefix)) {
String oldPrefix = keepPrefixAlternates.get(prefix);
if (oldLine.trim().startsWith(oldPrefix)) {
String renamedOldLine = oldLine.replaceFirst(oldPrefix, prefix);
replaceMatrix.put(prefix, renamedOldLine);
}
}
}
}
Expand Down Expand Up @@ -361,4 +393,31 @@ protected File findBackup(ActionContext context) throws IOException {
}
throw new RuntimeException("Too many backup folders in place already. Please remove some of the old-config-bkp.* folders");
}

private void removeWars(ActionContext context, File bootstrapXml) throws Exception {
StringBuilder sb = new StringBuilder();
boolean remove = false;
try (Stream<String> lines = Files.lines(bootstrapXml.toPath())) {
Iterator<String> linesIterator = lines.iterator();
while (linesIterator.hasNext()) {
String line = linesIterator.next();
if (line.matches("^(.*)<app name=(.*branding.*)$")) {
context.out.println("removing branding war as no longer needed");
remove = true;
} else if (line.matches("^(.*)<app name=(.*plugin.*)$")) {
context.out.println("removing plugin war as no longer needed");
remove = true;
} else {
sb.append(line).append(System.lineSeparator());
}
}
}
if (remove) {
try (InputStream inputStream = new ByteArrayInputStream(sb.toString().getBytes(StandardCharsets.UTF_8));
OutputStream outputStream = new FileOutputStream(bootstrapXml)) {
copy(inputStream, outputStream);
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,20 @@

public class JVMArgumentParser {

public static void parseOriginalArgs(String prefix, String endOfLine, String originalLine, String[] keepingPrefixes, Map<String, String> originalArgs) {
public static void parseOriginalArgs(String prefix, String endOfLine, String originalLine, Map<String, String> keepPrefixAlternates, String[] keepingPrefixes, Map<String, String> originalArgs) {
originalLine = originalLine.trim();
String line = originalLine.substring(prefix.length(), originalLine.length() - endOfLine.length());
String[] split = line.split(" ");
for (String s : split) {
for (String k : keepingPrefixes) {
if (s.startsWith(k)) {
originalArgs.put(k, s);
} else if (keepPrefixAlternates.containsKey(k)) {
String oldKey = keepPrefixAlternates.get(k);
if (s.startsWith(oldKey)) {
String renamed = s.replaceFirst(oldKey, k);
originalArgs.put(k, renamed);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ if [ -z "$ARTEMIS_INSTANCE" ] ; then
ARTEMIS_INSTANCE=`cd "$ARTEMIS_INSTANCE/.." && pwd`
fi

HAWTIO_ROLE="NO_HAWTIO_ROLE"
HAWTIO_ROLES="NO_HAWTIO_ROLES"

# Load Profile Data
ARTEMIS_INSTANCE_ETC='${artemis.instance.etc}'
Expand Down Expand Up @@ -102,7 +102,7 @@ fi

exec "$JAVACMD" \
$JAVA_ARGS \
-Dhawtio.role="$HAWTIO_ROLE" \
-Dhawtio.roles="$HAWTIO_ROLES" \
-Djava.security.auth.login.config="$ARTEMIS_INSTANCE_ETC/login.config" \
$ARTEMIS_CLUSTER_PROPS \
-classpath "$CLASSPATH" \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<startargument>-Dhawtio.disableProxy=true</startargument>
<startargument>-Dhawtio.realm=activemq</startargument>
<startargument>-Dhawtio.offline="true"</startargument>
<startargument>-Dhawtio.role=${role}</startargument>
<startargument>-Dhawtio.roles=${role}</startargument>
<startargument>-Dhawtio.rolePrincipalClasses=org.apache.activemq.artemis.spi.core.security.jaas.RolePrincipal</startargument>
<startargument>-Djolokia.policyLocation=%ARTEMIS_INSTANCE_ETC_URI%/jolokia-access.xml</startargument>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ ARTEMIS_INSTANCE_ETC_URI='${artemis.instance.etc.uri}'
#ARTEMIS_CLUSTER_PROPS="-Dactivemq.remoting.default.port=61617 -Dactivemq.remoting.amqp.port=5673 -Dactivemq.remoting.stomp.port=61614 -Dactivemq.remoting.hornetq.port=5446"

# Hawtio Properties
# HAWTIO_ROLE define the user role or roles required to be able to login to the console. Multiple roles to allow can
# HAWTIO_ROLES defines the user roles required to be able to login to the console. Multiple roles to allow can
# be separated by a comma. Set to '*' or an empty value to disable role checking when Hawtio authenticates a user.
HAWTIO_ROLE='${role}'
HAWTIO_ROLES='${role}'

# Java Opts
if [ -z "$JAVA_ARGS" ]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ rem Cluster Properties: Used to pass arguments to ActiveMQ Artemis which can be
rem set ARTEMIS_CLUSTER_PROPS=-Dactivemq.remoting.default.port=61617 -Dactivemq.remoting.amqp.port=5673 -Dactivemq.remoting.stomp.port=61614 -Dactivemq.remoting.hornetq.port=5446

rem Java Opts
IF "%JAVA_ARGS%"=="" (set JAVA_ARGS=${java-opts} -XX:AutoBoxCacheMax=20000 -XX:+PrintClassHistogram -XX:+UseG1GC -XX:+UseStringDeduplication -Xms512M -Xmx${java-memory} -Djava.security.auth.login.config=%ARTEMIS_ETC_DIR%\login.config -Dhawtio.disableProxy=true -Dhawtio.offline=true -Dhawtio.realm=activemq -Dhawtio.role=${role} -Dhawtio.rolePrincipalClasses=org.apache.activemq.artemis.spi.core.security.jaas.RolePrincipal -Dhawtio.http.strictTransportSecurity=max-age=31536000;includeSubDomains;preload -Djolokia.policyLocation=%ARTEMIS_INSTANCE_ETC_URI%\jolokia-access.xml -Dartemis.instance=%ARTEMIS_INSTANCE% --add-opens java.base/jdk.internal.misc=ALL-UNNAMED -Dlog4j2.disableJmx=true)
IF "%JAVA_ARGS%"=="" (set JAVA_ARGS=${java-opts} -XX:AutoBoxCacheMax=20000 -XX:+PrintClassHistogram -XX:+UseG1GC -XX:+UseStringDeduplication -Xms512M -Xmx${java-memory} -Djava.security.auth.login.config=%ARTEMIS_ETC_DIR%\login.config -Dhawtio.disableProxy=true -Dhawtio.offline=true -Dhawtio.realm=activemq -Dhawtio.roles=${role} -Dhawtio.rolePrincipalClasses=org.apache.activemq.artemis.spi.core.security.jaas.RolePrincipal -Dhawtio.http.strictTransportSecurity=max-age=31536000;includeSubDomains;preload -Djolokia.policyLocation=%ARTEMIS_INSTANCE_ETC_URI%\jolokia-access.xml -Dartemis.instance=%ARTEMIS_INSTANCE% --add-opens java.base/jdk.internal.misc=ALL-UNNAMED -Dlog4j2.disableJmx=true)

rem Logs Safepoints JVM pauses: Uncomment to enable them
rem In addition to the traditional GC logs you could enable some JVM flags to know any meaningful and "hidden" pause that could
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<!-- The web server is only bound to localhost by default -->
<web path="web" rootRedirectLocation="console">
<binding name="artemis" uri="${web.protocol}://${http.host}:${http.port}"${extra.web.attributes}>
<app name="branding" url="activemq-branding" war="activemq-branding.war"/>
<app name="plugin" url="artemis-plugin" war="artemis-plugin.war"/>
<app name="console" url="console" war="console.war"/>
</binding>
</web>
Loading