From d72bc79cdf9672bfefa2e3ab6e0c11194fface52 Mon Sep 17 00:00:00 2001 From: Michael Musgrove Date: Thu, 12 Dec 2024 18:22:26 +0000 Subject: [PATCH] JBTM-3955 Support for viewing logs in an activemq journal based store --- coordinator/pom.xml | 16 +++++++ .../management/BrowserCommand.java | 44 ++++++++++++++++--- 2 files changed, 53 insertions(+), 7 deletions(-) diff --git a/coordinator/pom.xml b/coordinator/pom.xml index 5c9b50a..0e3c00c 100644 --- a/coordinator/pom.xml +++ b/coordinator/pom.xml @@ -19,6 +19,7 @@ lra-coordinator/lra-coordinator + 2.30.0 @@ -73,6 +74,21 @@ + + + org.apache.activemq + artemis-journal + ${version.org.apache.activemq} + + + io.netty + netty + + + org.jboss.resteasy resteasy-client diff --git a/coordinator/src/main/java/io/narayana/lra/coordinator/management/BrowserCommand.java b/coordinator/src/main/java/io/narayana/lra/coordinator/management/BrowserCommand.java index 9ce0d60..37438b0 100644 --- a/coordinator/src/main/java/io/narayana/lra/coordinator/management/BrowserCommand.java +++ b/coordinator/src/main/java/io/narayana/lra/coordinator/management/BrowserCommand.java @@ -12,6 +12,8 @@ import com.arjuna.ats.arjuna.state.InputObjectState; import com.arjuna.ats.arjuna.tools.osb.mbean.ObjStoreBrowser; import com.arjuna.ats.arjuna.tools.osb.util.JMXServer; +import com.arjuna.ats.internal.arjuna.objectstore.hornetq.HornetqJournalEnvironmentBean; +import com.arjuna.ats.internal.arjuna.objectstore.hornetq.HornetqObjectStoreAdaptor; import com.arjuna.ats.internal.arjuna.recovery.RecoveryManagerImple; import com.arjuna.common.internal.util.propertyservice.BeanPopulator; import io.narayana.lra.coordinator.domain.model.FailedLongRunningAction; @@ -38,7 +40,6 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; import java.io.PrintStream; import java.util.ArrayList; import java.util.Arrays; @@ -50,7 +51,9 @@ * Browser for viewing LRA MBeans: * * java -cp target/lra-coordinator-jar-with-dependencies.jar io.narayana.lra.coordinator.management.BrowserCommand - * -s src/test/resources/test-store + * -s src/test/resources/test-store -h + * where -s points to the store directory and -h indicates whether to use the activemq journal based store + * (in which case the -s option must point to a valid journal store) */ public abstract class BrowserCommand { private static final String SYNTAX = "syntax: [-s ] | [-f ]]"; @@ -61,6 +64,7 @@ public abstract class BrowserCommand { private static List recordTypes = new ArrayList(); private static InputStream cmdSource; private static RecoveryManagerImple recoveryManager; + private static boolean isHQStore; private static String[][] LRA_OSB_TYPES = { // osTypeClassName, beanTypeClassName - see com.arjuna.ats.arjuna.tools.osb.mbean.ObjStoreBrowser @@ -106,7 +110,7 @@ static BrowserCommand getCommand(String name) { } private static void parseArgs(String[] args) throws FileNotFoundException { - String validOpts = "fs"; // command line options (modeled on the bash getopts command) + String validOpts = "fsh"; // command line options (modeled on the bash getopts command) StringBuilder sb = new StringBuilder(); for (int i = 0; i < args.length; i++) { @@ -129,6 +133,10 @@ private static void parseArgs(String[] args) throws FileNotFoundException { case 's': // set the location of the file based object store currentStoreDir = args[i]; + break; + case 'h': // use the Artemis Journal based store + isHQStore = Boolean.parseBoolean(args[i]); + break; default: throw new IllegalArgumentException(SYNTAX); @@ -207,11 +215,13 @@ protected void help(PrintStream printStream) { private static void setupStore(String storeDir) throws Exception { recoveryPropertyManager.getRecoveryEnvironmentBean().setRecoveryBackoffPeriod(1); Implementations.install(); + + // setup the store before starting recovery otherwise recovery won't use the desired store + setupStore(storeDir, isHQStore); + recoveryManager = new RecoveryManagerImple(false); recoveryManager.addModule(new LRARecoveryModule()); - setupStore(storeDir, false); - osb = new ObjStoreBrowser(); for(String[] typeAndBean: LRA_OSB_TYPES) { osb.addType(typeAndBean[0], typeAndBean[1], typeAndBean[2]); @@ -221,9 +231,28 @@ private static void setupStore(String storeDir) throws Exception { private static void setupStore(String storeDir, boolean hqstore) throws Exception { String storePath = new File(storeDir).getCanonicalPath(); + ObjectStoreEnvironmentBean commsObjStoreCommsEnvBean = + BeanPopulator.getNamedInstance(ObjectStoreEnvironmentBean.class, "communicationStore"); + ObjectStoreEnvironmentBean defObjStoreCommsEnvBean = + BeanPopulator.getDefaultInstance(ObjectStoreEnvironmentBean.class); + + if (hqstore) { + File hornetqStoreDir = new File(storeDir); + String storeClassName = com.arjuna.ats.internal.arjuna.objectstore.hornetq.HornetqObjectStoreAdaptor.class.getName(); + + BeanPopulator.getDefaultInstance(HornetqJournalEnvironmentBean.class) + .setStoreDir(hornetqStoreDir.getCanonicalPath()); + + defObjStoreCommsEnvBean.setObjectStoreType(storeClassName); + commsObjStoreCommsEnvBean.setObjectStoreDir(storeDir); + + defObjStoreCommsEnvBean.setObjectStoreType(storeClassName); + commsObjStoreCommsEnvBean.setObjectStoreType(storeClassName); + } else { + defObjStoreCommsEnvBean.setObjectStoreDir(storePath); + commsObjStoreCommsEnvBean.setObjectStoreDir(storePath); + } - BeanPopulator.getDefaultInstance(ObjectStoreEnvironmentBean.class).setObjectStoreDir(storePath); - BeanPopulator.getNamedInstance(ObjectStoreEnvironmentBean.class, "communicationStore").setObjectStoreDir(storePath); BeanPopulator.getDefaultInstance(CoreEnvironmentBean.class).setNodeIdentifier("no-recovery"); currentStoreDir = storeDir; @@ -312,6 +341,7 @@ private void processCommand(PrintStream printStream, Scanner scanner) { @Override void execute(PrintStream printStream, List args) throws Exception { getCommand(CommandName.START).cancel(); + StoreManager.shutdown(); } },