Skip to content

Commit

Permalink
JBTM-3955 Support for viewing logs in an activemq journal based store
Browse files Browse the repository at this point in the history
  • Loading branch information
mmusgrov committed Dec 18, 2024
1 parent c5b5dfb commit d72bc79
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 7 deletions.
16 changes: 16 additions & 0 deletions coordinator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

<properties>
<lra.coordinator.path>lra-coordinator/lra-coordinator</lra.coordinator.path>
<version.org.apache.activemq>2.30.0</version.org.apache.activemq>
</properties>

<dependencies>
Expand Down Expand Up @@ -73,6 +74,21 @@
</exclusion>
</exclusions>
</dependency>
<!--
remark: the next dependency, namely org.apache.activemq:artemis-journal, is also depended upon
by org.jboss.narayana.arjunacore:arjuna but that uses <scope>provided</scope>
-->
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-journal</artifactId>
<version>${version.org.apache.activemq}</version>
<exclusions>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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 <true|false>
* 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 <store location>] | [-f <command file>]]";
Expand All @@ -61,6 +64,7 @@ public abstract class BrowserCommand {
private static List<String> recordTypes = new ArrayList<String>();
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
Expand Down Expand Up @@ -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++) {
Expand All @@ -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);
Expand Down Expand Up @@ -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]);
Expand All @@ -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;
Expand Down Expand Up @@ -312,6 +341,7 @@ private void processCommand(PrintStream printStream, Scanner scanner) {
@Override
void execute(PrintStream printStream, List<String> args) throws Exception {
getCommand(CommandName.START).cancel();
StoreManager.shutdown();
}
},

Expand Down

0 comments on commit d72bc79

Please sign in to comment.