diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/DescribeJournal.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/DescribeJournal.java index 20210124b9..1842a5848e 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/DescribeJournal.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/DescribeJournal.java @@ -40,7 +40,10 @@ import static org.apache.activemq.artemis.core.persistence.impl.journal.JournalR import static org.apache.activemq.artemis.core.persistence.impl.journal.JournalRecordIds.UPDATE_DELIVERY_COUNT; import java.io.File; +import java.io.InputStreamReader; import java.io.PrintStream; +import java.io.Reader; +import java.net.URL; import java.util.HashMap; import java.util.LinkedList; import java.util.List; @@ -51,7 +54,9 @@ import javax.transaction.xa.Xid; import org.apache.activemq.artemis.api.core.ActiveMQBuffer; import org.apache.activemq.artemis.api.core.ActiveMQBuffers; import org.apache.activemq.artemis.api.core.Message; +import org.apache.activemq.artemis.core.config.Configuration; import org.apache.activemq.artemis.core.config.impl.ConfigurationImpl; +import org.apache.activemq.artemis.core.config.impl.FileConfiguration; import org.apache.activemq.artemis.core.io.SequentialFileFactory; import org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory; import org.apache.activemq.artemis.core.journal.EncodingSupport; @@ -82,8 +87,12 @@ import org.apache.activemq.artemis.core.persistence.impl.journal.codec.Scheduled import org.apache.activemq.artemis.core.server.LargeServerMessage; import org.apache.activemq.artemis.spi.core.protocol.MessagePersister; import org.apache.activemq.artemis.utils.Base64; +import org.apache.activemq.artemis.utils.XMLUtil; import org.apache.activemq.artemis.utils.XidCodecSupport; - +import org.jboss.logging.Logger; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; /** * Outputs a String description of the Journals contents. @@ -92,8 +101,40 @@ import org.apache.activemq.artemis.utils.XidCodecSupport; */ public final class DescribeJournal { + private static final Logger logger = Logger.getLogger(DescribeJournal.class); + private final List records; private final List preparedTransactions; + private static final Configuration CONFIGURATION; + + static { + String instanceFolder = System.getProperty("artemis.instance"); + if (instanceFolder != null) { + CONFIGURATION = new FileConfiguration(); + File configFile = new File(instanceFolder + "/etc/broker.xml"); + URL url; + + try { + url = configFile.toURI().toURL(); + Reader reader = new InputStreamReader(url.openStream()); + String xml = XMLUtil.readerToString(reader); + xml = XMLUtil.replaceSystemProps(xml); + Element e = XMLUtil.stringToElement(xml); + + String root = ((FileConfiguration) CONFIGURATION).getRootElement(); + NodeList children = e.getElementsByTagName(root); + if (root != null && children.getLength() > 0) { + Node item = children.item(0); + XMLUtil.validate(item, ((FileConfiguration) CONFIGURATION).getSchema()); + ((FileConfiguration) CONFIGURATION).parse((Element) item, url); + } + } catch (Exception e) { + logger.error("failed to load broker.xml", e); + } + } else { + CONFIGURATION = new ConfigurationImpl(); + } + } public DescribeJournal(List records, List preparedTransactions) { this.records = records; @@ -128,9 +169,7 @@ public final class DescribeJournal { SequentialFileFactory messagesFF = new NIOSequentialFileFactory(messagesDir, null, 1); // Will use only default values. The load function should adapt to anything different - ConfigurationImpl defaultValues = new ConfigurationImpl(); - - JournalImpl messagesJournal = new JournalImpl(defaultValues.getJournalFileSize(), defaultValues.getJournalMinFiles(), defaultValues.getJournalPoolFiles(), 0, 0, messagesFF, "activemq-data", "amq", 1); + JournalImpl messagesJournal = new JournalImpl(CONFIGURATION.getJournalFileSize(), CONFIGURATION.getJournalMinFiles(), CONFIGURATION.getJournalPoolFiles(), 0, 0, messagesFF, "activemq-data", "amq", 1); return describeJournal(messagesFF, messagesJournal, messagesDir, out, safe); } diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/JournalDataPrintTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/JournalDataPrintTest.java new file mode 100644 index 0000000000..8e8b0d3b06 --- /dev/null +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/JournalDataPrintTest.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + *
+ * http://www.apache.org/licenses/LICENSE-2.0 + *
+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.activemq.artemis.tests.integration.journal; + +import org.apache.activemq.artemis.cli.commands.tools.PrintData; +import org.apache.activemq.artemis.core.config.FileDeploymentManager; +import org.apache.activemq.artemis.core.config.impl.FileConfiguration; +import org.apache.activemq.artemis.core.config.impl.SecurityConfiguration; +import org.apache.activemq.artemis.core.server.ActiveMQServer; +import org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl; +import org.apache.activemq.artemis.jms.server.config.impl.FileJMSConfiguration; +import org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager; +import org.apache.activemq.artemis.spi.core.security.jaas.InVMLoginModule; +import org.apache.activemq.artemis.tests.util.ActiveMQTestBase; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.io.File; + +public class JournalDataPrintTest extends ActiveMQTestBase { + + protected ActiveMQServer server; + + @Override + @Before + public void setUp() throws Exception { + super.setUp(); + } + + @Test + public void testJournalDataPrint() throws Exception { + ActiveMQServer server = getActiveMQServer("dataprint/etc/broker.xml"); + try { + server.start(); + server.stop(); + System.setProperty("artemis.instance", + this.getClass().getClassLoader().getResource("dataprint").getFile()); + PrintData.printData(server.getConfiguration().getBindingsLocation().getAbsoluteFile(), server.getConfiguration().getJournalLocation().getAbsoluteFile(), server.getConfiguration().getPagingLocation().getAbsoluteFile()); + + // list journal file + File dirFile = server.getConfiguration().getJournalLocation().getAbsoluteFile(); + File[] files = dirFile.listFiles(); + for (int i = 0; i < files.length; i++) { + File journalFile = files[i]; + Assert.assertEquals(30 * 1024 * 1024L, journalFile.length()); + } + + server.start(); + } finally { + try { + server.stop(); + } catch (Exception e) { + } + } + } + + protected ActiveMQServer getActiveMQServer(String brokerConfig) throws Exception { + FileConfiguration fc = new FileConfiguration(); + FileJMSConfiguration fileConfiguration = new FileJMSConfiguration(); + FileDeploymentManager deploymentManager = new FileDeploymentManager(brokerConfig); + deploymentManager.addDeployable(fc); + deploymentManager.addDeployable(fileConfiguration); + deploymentManager.readConfiguration(); + + ActiveMQJAASSecurityManager sm = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), new SecurityConfiguration()); + + recreateDirectory(fc.getBindingsDirectory()); + recreateDirectory(fc.getJournalDirectory()); + recreateDirectory(fc.getPagingDirectory()); + recreateDirectory(fc.getLargeMessagesDirectory()); + + return addServer(new ActiveMQServerImpl(fc, sm)); + } +} diff --git a/tests/integration-tests/src/test/resources/dataprint/etc/broker.xml b/tests/integration-tests/src/test/resources/dataprint/etc/broker.xml new file mode 100644 index 0000000000..01b5591c50 --- /dev/null +++ b/tests/integration-tests/src/test/resources/dataprint/etc/broker.xml @@ -0,0 +1,84 @@ + + + + + + + + + 0.0.0.0 + + 100 + + false + + false + + + NIO + + ./target/tmp/printdata/paging + + ./target/tmp/printdata/bindings + + ./target/tmp/printdata/journal + + ./target/tmp/printdata/large-messages + + 2 + + -1 + + 30Mb + + +
+ + + + + +
+
+ + + + + +
+
+ + + + + false + DLQ + ExpiryQueue + 0 + 10Mb + 10 + BLOCK + + +
+