Skip to content

Commit

Permalink
Artemis Console next gen based on hawtIO 4
Browse files Browse the repository at this point in the history
  • Loading branch information
andytaylor committed Jan 10, 2025
1 parent fb1c6e3 commit bf8fd19
Show file tree
Hide file tree
Showing 118 changed files with 1,072 additions and 8,707 deletions.
6 changes: 0 additions & 6 deletions artemis-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,6 @@
<artifactId>artemis-openwire-protocol</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-plugin</artifactId>
<type>war</type>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-lockmanager-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public class Create extends InstallAbstract {
public static final String ETC_BOOTSTRAP_XML = "bootstrap.xml";
public static final String ETC_MANAGEMENT_XML = "management.xml";
public static final String ETC_BROKER_XML = "broker.xml";

public static final String ETC_OIDC_PROPERTIES = "hawtio-oidc.properties";
public static final String ETC_ARTEMIS_ROLES_PROPERTIES = "artemis-roles.properties";
public static final String ETC_ARTEMIS_USERS_PROPERTIES = "artemis-users.properties";
private static final String ETC_LOGIN_CONFIG = "login.config";
Expand Down Expand Up @@ -839,6 +839,7 @@ public Object run(ActionContext context) throws Exception {
}
writeEtc(ETC_BOOTSTRAP_XML, etcFolder, filters, false);
writeEtc(ETC_MANAGEMENT_XML, etcFolder, filters, false);
writeEtc(ETC_OIDC_PROPERTIES, etcFolder, filters, false);

if (relaxJolokia) {
filters.put("${jolokia.options}", "<!-- option relax-jolokia used, so strict-checking will be removed here -->");
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 @@ -143,28 +151,31 @@ 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);

final 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=");

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=");

File artemisUtilityProfileCmd = new File(etcFolder, Create.ETC_ARTEMIS_UTILITY_PROFILE_CMD);
File artemisUtilityProfileCmdTmp = new File(tmp, Create.ETC_ARTEMIS_UTILITY_PROFILE_CMD);
File artemisUtilityProfileCmdBkp = new File(etcBkp, Create.ETC_ARTEMIS_UTILITY_PROFILE_CMD);

if (artemisUtilityProfileCmd.exists()) {
write("etc/" + Create.ETC_ARTEMIS_UTILITY_PROFILE_CMD, artemisUtilityProfileCmdTmp, filters, false, false);
upgradeJDK(context, JDK_PREFIX_WINDOWS, "", KEEPING_JVM_ARGUMENTS, artemisUtilityProfileCmdTmp, artemisUtilityProfileCmd, artemisUtilityProfileCmdBkp,
"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, artemisUtilityProfileCmdTmp, artemisUtilityProfileCmd, artemisUtilityProfileCmdBkp,
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=");
} else {
if (data == null || data.equals("data")) {
dataFolder = getDATA(context, dataFolder, artemisProfileCmd, "set ARTEMIS_DATA_DIR=");
Expand All @@ -191,21 +202,24 @@ 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

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

File artemisProfile = new File(etcFolder, Create.ETC_ARTEMIS_PROFILE);
File artemisProfileTmp = new File(tmp, Create.ETC_ARTEMIS_PROFILE);
File artemisProfileBkp = new File(etcBkp, Create.ETC_ARTEMIS_PROFILE);

write("etc/" + Create.ETC_ARTEMIS_PROFILE, artemisProfileTmp, filters, false, false);
upgradeJDK(context, JDK_PREFIX_LINUX, "\"", KEEPING_JVM_ARGUMENTS, artemisProfileTmp, artemisProfile, artemisProfileBkp,
"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, artemisProfileTmp, artemisProfile, artemisProfileBkp,
keepPrefixAlternates, "ARTEMIS_INSTANCE=", "ARTEMIS_DATA_DIR=", "ARTEMIS_ETC_DIR=", "ARTEMIS_OOME_DUMP=", "ARTEMIS_INSTANCE_URI=", "ARTEMIS_INSTANCE_ETC_URI=", "HAWTIO_ROLES=");

File artemisUtilityProfile = new File(etcFolder, Create.ETC_ARTEMIS_UTILITY_PROFILE);
File artemisUtilityProfileTmp = new File(tmp, Create.ETC_ARTEMIS_UTILITY_PROFILE);
File artemisUtilityProfileBkp = new File(etcBkp, Create.ETC_ARTEMIS_UTILITY_PROFILE);

if (artemisUtilityProfile.exists()) {
write("etc/" + Create.ETC_ARTEMIS_UTILITY_PROFILE, artemisUtilityProfileTmp, filters, false, false);
upgradeJDK(context, JDK_PREFIX_LINUX, "\"", KEEPING_JVM_ARGUMENTS, artemisUtilityProfileTmp, artemisUtilityProfile, artemisUtilityProfileBkp,
"ARTEMIS_INSTANCE=", "ARTEMIS_DATA_DIR=", "ARTEMIS_ETC_DIR=", "ARTEMIS_OOME_DUMP=", "ARTEMIS_INSTANCE_URI=", "ARTEMIS_INSTANCE_ETC_URI=");
upgradeJDK(context, JDK_PREFIX_LINUX, "\"", KEEPING_JVM_ARGUMENTS_ALTERNATES, KEEPING_JVM_ARGUMENTS, artemisUtilityProfileTmp, artemisUtilityProfile, artemisUtilityProfileBkp,
keepPrefixAlternates, "ARTEMIS_INSTANCE=", "ARTEMIS_DATA_DIR=", "ARTEMIS_ETC_DIR=", "ARTEMIS_OOME_DUMP=", "ARTEMIS_INSTANCE_URI=", "ARTEMIS_INSTANCE_ETC_URI=", "HAWTIO_ROLES=");
} else {
if (data == null || data.equals("data")) {
dataFolder = getDATA(context, dataFolder, artemisProfile, "ARTEMIS_DATA_DIR=");
Expand All @@ -229,6 +243,20 @@ 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);

final File hawtioOIDC = new File(etcFolder, Create.ETC_OIDC_PROPERTIES);

if (!hawtioOIDC.exists()) {
context.out.println("Creating " + hawtioOIDC);
try (InputStream inputStream = openStream("etc/" + Create.ETC_OIDC_PROPERTIES);
OutputStream outputStream = new FileOutputStream(hawtioOIDC)) {
copy(inputStream, outputStream);
}
}

upgradeLogging(context, etcFolder, etcBkp);

context.out.println();
Expand Down Expand Up @@ -273,20 +301,25 @@ private File getPathFromFile(ActionContext context, File defaultPath, File file,
return defaultPath;
}

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 @@ -321,6 +354,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 @@ -329,6 +366,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 @@ -421,4 +464,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 @@ -122,7 +122,7 @@ fi
exec "$JAVACMD" \
$LOGGING_ARGS \
$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
Loading

0 comments on commit bf8fd19

Please sign in to comment.