ARTEMIS-1959 server startup failure caused by './artemis data print'
Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/7a76d95e Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/7a76d95e Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/7a76d95e Branch: refs/heads/master Commit: 7a76d95e60f029e8ca1e1b9c05c53146c11bbb8f Parents: 8ce8087 Author: 17103355 <[email protected]> Authored: Thu Jun 28 19:53:28 2018 +0800 Committer: Justin Bertram <[email protected]> Committed: Mon Jul 2 13:06:41 2018 -0500 ---------------------------------------------------------------------- .../impl/journal/DescribeJournal.java | 47 +++++++++- .../journal/JournalDataPrintTest.java | 90 ++++++++++++++++++++ .../src/test/resources/dataprint/etc/broker.xml | 84 ++++++++++++++++++ 3 files changed, 217 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7a76d95e/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/DescribeJournal.java ---------------------------------------------------------------------- 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 2021012..1842a58 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<RecordInfo> records; private final List<PreparedTransactionInfo> 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<RecordInfo> records, List<PreparedTransactionInfo> 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); } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7a76d95e/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/JournalDataPrintTest.java ---------------------------------------------------------------------- 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 0000000..8e8b0d3 --- /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 + * <br> + * http://www.apache.org/licenses/LICENSE-2.0 + * <br> + * 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)); + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7a76d95e/tests/integration-tests/src/test/resources/dataprint/etc/broker.xml ---------------------------------------------------------------------- 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 0000000..01b5591 --- /dev/null +++ b/tests/integration-tests/src/test/resources/dataprint/etc/broker.xml @@ -0,0 +1,84 @@ +<?xml version='1.0'?> +<!-- +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. +--> + +<configuration xmlns="urn:activemq" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="urn:activemq /schema/artemis-configuration.xsd"> + + + <core xmlns="urn:activemq:core"> + + <name>0.0.0.0</name> + + <configuration-file-refresh-period>100</configuration-file-refresh-period> + + <persistence-enabled>false</persistence-enabled> + + <security-enabled>false</security-enabled> + + <!-- this could be ASYNCIO or NIO + --> + <journal-type>NIO</journal-type> + + <paging-directory>./target/tmp/printdata/paging</paging-directory> + + <bindings-directory>./target/tmp/printdata/bindings</bindings-directory> + + <journal-directory>./target/tmp/printdata/journal</journal-directory> + + <large-messages-directory>./target/tmp/printdata/large-messages</large-messages-directory> + + <journal-min-files>2</journal-min-files> + + <journal-pool-files>-1</journal-pool-files> + + <journal-file-size>30Mb</journal-file-size> + + <addresses> + <address name="mytopic_2"> + <multicast> + <queue name="queue.A" /> + <queue name="queue.B" /> + <queue name="queue.C" /> + </multicast> + </address> + <address name="mytopic_1"> + <multicast> + <queue name="queue.A" /> + <queue name="queue.B" /> + <queue name="queue.C" /> + </multicast> + </address> + </addresses> + + <address-settings> + <!--default for catch all--> + <address-setting match="#"> + <auto-create-queues>false</auto-create-queues> + <dead-letter-address>DLQ</dead-letter-address> + <expiry-address>ExpiryQueue</expiry-address> + <redelivery-delay>0</redelivery-delay> + <max-size-bytes>10Mb</max-size-bytes> + <message-counter-history-day-limit>10</message-counter-history-day-limit> + <address-full-policy>BLOCK</address-full-policy> + </address-setting> + </address-settings> + </core> +</configuration>
