ARTEMIS-1954 Fixing RedeployTest and moving JMS Parsing
This commit is contained in:
parent
eda38ccf89
commit
b2d04b9ceb
|
@ -18,22 +18,16 @@ package org.apache.activemq.artemis.integration;
|
|||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.activemq.artemis.api.core.RoutingType;
|
||||
import org.apache.activemq.artemis.core.config.CoreAddressConfiguration;
|
||||
import org.apache.activemq.artemis.core.config.CoreQueueConfiguration;
|
||||
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.LegacyJMSConfiguration;
|
||||
import org.apache.activemq.artemis.core.server.ActiveMQComponent;
|
||||
import org.apache.activemq.artemis.core.server.ActiveMQServer;
|
||||
import org.apache.activemq.artemis.core.server.ServiceComponent;
|
||||
import org.apache.activemq.artemis.dto.ServerDTO;
|
||||
import org.apache.activemq.artemis.integration.bootstrap.ActiveMQBootstrapLogger;
|
||||
import org.apache.activemq.artemis.jms.server.config.JMSQueueConfiguration;
|
||||
import org.apache.activemq.artemis.jms.server.config.TopicConfiguration;
|
||||
import org.apache.activemq.artemis.jms.server.config.impl.FileJMSConfiguration;
|
||||
import org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager;
|
||||
|
||||
public class FileBroker implements Broker {
|
||||
|
@ -60,49 +54,14 @@ public class FileBroker implements Broker {
|
|||
//todo if we start to pullout more configs from the main config then we should pull out the configuration objects from factories if available
|
||||
FileConfiguration configuration = new FileConfiguration();
|
||||
|
||||
// Keep this as we still want to parse destinations in the <jms> element
|
||||
FileJMSConfiguration jmsConfiguration = new FileJMSConfiguration();
|
||||
LegacyJMSConfiguration legacyJMSConfiguration = new LegacyJMSConfiguration(configuration);
|
||||
|
||||
FileDeploymentManager fileDeploymentManager = new FileDeploymentManager(configurationUrl);
|
||||
fileDeploymentManager.addDeployable(configuration).addDeployable(jmsConfiguration);
|
||||
fileDeploymentManager.addDeployable(configuration).addDeployable(legacyJMSConfiguration);
|
||||
fileDeploymentManager.readConfiguration();
|
||||
|
||||
createDirectories(configuration);
|
||||
|
||||
/**
|
||||
* This is a bit of a hack for backwards config compatibility since we no longer want to start the broker
|
||||
* using the JMSServerManager which would normally deploy JMS destinations. Here we take the JMS destination
|
||||
* configurations from the parsed JMS configuration and add them to the core configuration.
|
||||
*
|
||||
* It's also important here that we are adding them to the core ADDRESS configurations as those will be
|
||||
* deployed first and therefore their configuration will take precedence over other legacy queue configurations
|
||||
* which are deployed later. This is so we can maintain support for configurations like those found in the
|
||||
* bridge and divert examples where there are JMS and core queues with the same name (which was itself a bit
|
||||
* of a hack).
|
||||
*
|
||||
* This should be removed when support for the old "jms" configuation element is also removed.
|
||||
*/
|
||||
{
|
||||
for (JMSQueueConfiguration jmsQueueConfig : jmsConfiguration.getQueueConfigurations()) {
|
||||
List<CoreAddressConfiguration> coreAddressConfigurations = configuration.getAddressConfigurations();
|
||||
coreAddressConfigurations.add(new CoreAddressConfiguration()
|
||||
.setName(jmsQueueConfig.getName())
|
||||
.addRoutingType(RoutingType.ANYCAST)
|
||||
.addQueueConfiguration(new CoreQueueConfiguration()
|
||||
.setAddress(jmsQueueConfig.getName())
|
||||
.setName(jmsQueueConfig.getName())
|
||||
.setFilterString(jmsQueueConfig.getSelector())
|
||||
.setRoutingType(RoutingType.ANYCAST)));
|
||||
}
|
||||
|
||||
for (TopicConfiguration topicConfig : jmsConfiguration.getTopicConfigurations()) {
|
||||
List<CoreAddressConfiguration> coreAddressConfigurations = configuration.getAddressConfigurations();
|
||||
coreAddressConfigurations.add(new CoreAddressConfiguration()
|
||||
.setName(topicConfig.getName())
|
||||
.addRoutingType(RoutingType.MULTICAST));
|
||||
}
|
||||
}
|
||||
|
||||
components = fileDeploymentManager.buildService(securityManager, ManagementFactory.getPlatformMBeanServer());
|
||||
|
||||
ArrayList<ActiveMQComponent> componentsByStartOrder = getComponentsByStartOrder(components);
|
||||
|
|
|
@ -0,0 +1,196 @@
|
|||
/*
|
||||
* 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.core.config.impl;
|
||||
|
||||
import javax.management.MBeanServer;
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.validation.Schema;
|
||||
import javax.xml.validation.SchemaFactory;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.activemq.artemis.api.core.RoutingType;
|
||||
import org.apache.activemq.artemis.core.config.Configuration;
|
||||
import org.apache.activemq.artemis.core.config.CoreAddressConfiguration;
|
||||
import org.apache.activemq.artemis.core.config.CoreQueueConfiguration;
|
||||
import org.apache.activemq.artemis.core.deployers.Deployable;
|
||||
import org.apache.activemq.artemis.core.server.ActiveMQComponent;
|
||||
import org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager;
|
||||
import org.apache.activemq.artemis.utils.XMLConfigurationUtil;
|
||||
import org.apache.activemq.artemis.utils.XMLUtil;
|
||||
import org.jboss.logging.Logger;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
public class LegacyJMSConfiguration implements Deployable {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(LegacyJMSConfiguration.class);
|
||||
|
||||
private static final String CONFIGURATION_SCHEMA_URL = "schema/artemis-jms.xsd";
|
||||
|
||||
private static final String CONFIGURATION_SCHEMA_ROOT_ELEMENT = "jms";
|
||||
|
||||
private static final String NAME_ATTR = "name";
|
||||
|
||||
private static final String QUEUE_NODE_NAME = "queue";
|
||||
|
||||
private static final String QUEUE_SELECTOR_NODE_NAME = "selector";
|
||||
|
||||
private static final String TOPIC_NODE_NAME = "topic";
|
||||
|
||||
private static final String JMX_DOMAIN_NAME = "jmx-domain";
|
||||
|
||||
private static final boolean DEFAULT_QUEUE_DURABILITY = true;
|
||||
|
||||
private URL configurationUrl;
|
||||
|
||||
final Configuration configuration;
|
||||
|
||||
|
||||
public LegacyJMSConfiguration(Configuration configuration) {
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void parse(Element config, URL url) throws Exception {
|
||||
parseConfiguration(config);
|
||||
}
|
||||
|
||||
public Configuration getConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isParsed() {
|
||||
// always return false here so that the FileDeploymentManager will not invoke buildService()
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRootElement() {
|
||||
return CONFIGURATION_SCHEMA_ROOT_ELEMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildService(ActiveMQSecurityManager securityManager,
|
||||
MBeanServer mBeanServer,
|
||||
Map<String, Deployable> deployables,
|
||||
Map<String, ActiveMQComponent> components) throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSchema() {
|
||||
return CONFIGURATION_SCHEMA_URL;
|
||||
}
|
||||
|
||||
|
||||
public void parseConfiguration(final InputStream input) throws Exception {
|
||||
Reader reader = new InputStreamReader(input);
|
||||
String xml = XMLUtil.readerToString(reader);
|
||||
xml = XMLUtil.replaceSystemProps(xml);
|
||||
Element e = XMLUtil.stringToElement(xml);
|
||||
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
|
||||
Schema schema = schemaFactory.newSchema(XMLUtil.findResource(CONFIGURATION_SCHEMA_URL));
|
||||
parseConfiguration(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the JMS Configuration XML
|
||||
*/
|
||||
public void parseConfiguration(final Node rootnode) throws Exception {
|
||||
|
||||
Element e = (Element) rootnode;
|
||||
|
||||
String[] elements = new String[]{QUEUE_NODE_NAME, TOPIC_NODE_NAME};
|
||||
for (String element : elements) {
|
||||
NodeList children = e.getElementsByTagName(element);
|
||||
for (int i = 0; i < children.getLength(); i++) {
|
||||
Node node = children.item(i);
|
||||
Node keyNode = node.getAttributes().getNamedItem(NAME_ATTR);
|
||||
if (keyNode == null) {
|
||||
logger.warn("Configuration missing jms key " + node);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (node.getNodeName().equals(TOPIC_NODE_NAME)) {
|
||||
parseTopicConfiguration(node);
|
||||
} else if (node.getNodeName().equals(QUEUE_NODE_NAME)) {
|
||||
parseQueueConfiguration(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the topic node as a TopicConfiguration object
|
||||
*
|
||||
* @param node
|
||||
* @return topic configuration
|
||||
* @throws Exception
|
||||
*/
|
||||
public void parseTopicConfiguration(final Node node) throws Exception {
|
||||
String topicName = node.getAttributes().getNamedItem(NAME_ATTR).getNodeValue();
|
||||
List<CoreAddressConfiguration> coreAddressConfigurations = configuration.getAddressConfigurations();
|
||||
coreAddressConfigurations.add(new CoreAddressConfiguration()
|
||||
.setName(topicName)
|
||||
.addRoutingType(RoutingType.MULTICAST));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the Queue Configuration node as a QueueConfiguration object
|
||||
*
|
||||
* @param node
|
||||
* @return jms queue configuration
|
||||
* @throws Exception
|
||||
*/
|
||||
public void parseQueueConfiguration(final Node node) throws Exception {
|
||||
Element e = (Element) node;
|
||||
NamedNodeMap atts = node.getAttributes();
|
||||
String queueName = atts.getNamedItem(NAME_ATTR).getNodeValue();
|
||||
String selectorString = null;
|
||||
boolean durable = XMLConfigurationUtil.getBoolean(e, "durable", DEFAULT_QUEUE_DURABILITY);
|
||||
NodeList children = node.getChildNodes();
|
||||
for (int i = 0; i < children.getLength(); i++) {
|
||||
Node child = children.item(i);
|
||||
|
||||
if (QUEUE_SELECTOR_NODE_NAME.equals(children.item(i).getNodeName())) {
|
||||
Node selectorNode = children.item(i);
|
||||
Node attNode = selectorNode.getAttributes().getNamedItem("string");
|
||||
selectorString = attNode.getNodeValue();
|
||||
}
|
||||
}
|
||||
|
||||
List<CoreAddressConfiguration> coreAddressConfigurations = configuration.getAddressConfigurations();
|
||||
coreAddressConfigurations.add(new CoreAddressConfiguration()
|
||||
.setName(queueName)
|
||||
.addRoutingType(RoutingType.ANYCAST)
|
||||
.addQueueConfiguration(new CoreQueueConfiguration()
|
||||
.setAddress(queueName)
|
||||
.setName(queueName)
|
||||
.setFilterString(selectorString)
|
||||
.setRoutingType(RoutingType.ANYCAST)));
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -22,6 +22,7 @@ import java.lang.management.ManagementFactory;
|
|||
import org.apache.activemq.artemis.core.config.Configuration;
|
||||
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.LegacyJMSConfiguration;
|
||||
import org.apache.activemq.artemis.core.config.impl.SecurityConfiguration;
|
||||
import org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl;
|
||||
import org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager;
|
||||
|
@ -71,7 +72,8 @@ public final class ActiveMQServers {
|
|||
final ActiveMQSecurityManager securityManager) throws Exception {
|
||||
|
||||
FileConfiguration config = new FileConfiguration();
|
||||
new FileDeploymentManager(configURL).addDeployable(config).readConfiguration();
|
||||
LegacyJMSConfiguration legacyJMSConfiguration = new LegacyJMSConfiguration(config);
|
||||
new FileDeploymentManager(configURL).addDeployable(config).addDeployable(legacyJMSConfiguration).readConfiguration();
|
||||
|
||||
ActiveMQServer server = ActiveMQServers.newActiveMQServer(config, mbeanServer, securityManager);
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.util.concurrent.TimeUnit;
|
|||
import org.apache.activemq.artemis.core.config.Configuration;
|
||||
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.LegacyJMSConfiguration;
|
||||
import org.apache.activemq.artemis.core.server.ActiveMQServer;
|
||||
import org.apache.activemq.artemis.core.server.cluster.ClusterConnection;
|
||||
import org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl;
|
||||
|
@ -122,7 +123,8 @@ public class EmbeddedActiveMQ {
|
|||
configResourcePath = "broker.xml";
|
||||
FileDeploymentManager deploymentManager = new FileDeploymentManager(configResourcePath);
|
||||
FileConfiguration config = new FileConfiguration();
|
||||
deploymentManager.addDeployable(config);
|
||||
LegacyJMSConfiguration legacyJMSConfiguration = new LegacyJMSConfiguration(config);
|
||||
deploymentManager.addDeployable(config).addDeployable(legacyJMSConfiguration);
|
||||
deploymentManager.readConfiguration();
|
||||
configuration = config;
|
||||
}
|
||||
|
|
|
@ -66,6 +66,7 @@ import org.apache.activemq.artemis.core.config.DivertConfiguration;
|
|||
import org.apache.activemq.artemis.core.config.HAPolicyConfiguration;
|
||||
import org.apache.activemq.artemis.core.config.StoreConfiguration;
|
||||
import org.apache.activemq.artemis.core.config.impl.ConfigurationImpl;
|
||||
import org.apache.activemq.artemis.core.config.impl.LegacyJMSConfiguration;
|
||||
import org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration;
|
||||
import org.apache.activemq.artemis.core.deployers.impl.FileConfigurationParser;
|
||||
import org.apache.activemq.artemis.core.filter.Filter;
|
||||
|
@ -3151,6 +3152,9 @@ public class ActiveMQServerImpl implements ActiveMQServer {
|
|||
public void reload(URL uri) throws Exception {
|
||||
if (isActive()) {
|
||||
Configuration config = new FileConfigurationParser().parseMainConfig(uri.openStream());
|
||||
LegacyJMSConfiguration legacyJMSConfiguration = new LegacyJMSConfiguration(config);
|
||||
legacyJMSConfiguration.parseConfiguration(uri.openStream());
|
||||
|
||||
ActiveMQServerLogger.LOGGER.reloadingConfiguration("security");
|
||||
securityRepository.swap(config.getSecurityRoles().entrySet());
|
||||
configuration.setSecurityRoles(config.getSecurityRoles());
|
||||
|
|
Loading…
Reference in New Issue