From 5e7475115d45d61261a5da7bc26e48b5d92deb5a Mon Sep 17 00:00:00 2001 From: jbertram Date: Mon, 10 Oct 2016 15:11:50 -0500 Subject: [PATCH] ARTEMIS-781 Add journal record for address binding --- .../core/config/CoreAddressConfiguration.java | 8 +- .../core/persistence/AddressBindingInfo.java | 34 +++++ .../PersistentAddressBindingEncoding.java | 135 ++++++++++++++++++ .../artemis/core/server/impl/AddressInfo.java | 33 ++++- .../config/impl/FileConfigurationTest.java | 7 +- .../config/XMLConfigurationMigration.java | 26 ++-- pom.xml | 1 + 7 files changed, 211 insertions(+), 33 deletions(-) create mode 100644 artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/AddressBindingInfo.java create mode 100644 artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/codec/PersistentAddressBindingEncoding.java diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/CoreAddressConfiguration.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/CoreAddressConfiguration.java index e01c3986e2..6327f79623 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/CoreAddressConfiguration.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/CoreAddressConfiguration.java @@ -21,13 +21,13 @@ import java.util.ArrayList; import java.util.List; import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration; -import org.apache.activemq.artemis.core.server.impl.AddressInfo.RoutingType; +import org.apache.activemq.artemis.core.server.impl.AddressInfo; public class CoreAddressConfiguration implements Serializable { private String name = null; - private RoutingType routingType = null; + private AddressInfo.RoutingType routingType = null; private Integer defaultMaxConsumers = ActiveMQDefaultConfiguration.getDefaultMaxQueueConsumers(); @@ -47,11 +47,11 @@ public class CoreAddressConfiguration implements Serializable { return this; } - public RoutingType getRoutingType() { + public AddressInfo.RoutingType getRoutingType() { return routingType; } - public CoreAddressConfiguration setRoutingType(RoutingType routingType) { + public CoreAddressConfiguration setRoutingType(AddressInfo.RoutingType routingType) { this.routingType = routingType; return this; } diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/AddressBindingInfo.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/AddressBindingInfo.java new file mode 100644 index 0000000000..83d37bc948 --- /dev/null +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/AddressBindingInfo.java @@ -0,0 +1,34 @@ +/* + * 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.persistence; + +import org.apache.activemq.artemis.api.core.SimpleString; +import org.apache.activemq.artemis.core.server.impl.AddressInfo; + +public interface AddressBindingInfo { + + long getId(); + + SimpleString getName(); + + boolean isAutoCreated(); + + SimpleString getUser(); + + AddressInfo.RoutingType getRoutingType(); + +} diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/codec/PersistentAddressBindingEncoding.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/codec/PersistentAddressBindingEncoding.java new file mode 100644 index 0000000000..9f473624a2 --- /dev/null +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/codec/PersistentAddressBindingEncoding.java @@ -0,0 +1,135 @@ +/* + * 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.persistence.impl.journal.codec; + +import org.apache.activemq.artemis.api.core.ActiveMQBuffer; +import org.apache.activemq.artemis.api.core.SimpleString; +import org.apache.activemq.artemis.core.journal.EncodingSupport; +import org.apache.activemq.artemis.core.persistence.AddressBindingInfo; +import org.apache.activemq.artemis.core.server.impl.AddressInfo; +import org.apache.activemq.artemis.utils.DataConstants; + +public class PersistentAddressBindingEncoding implements EncodingSupport, AddressBindingInfo { + + public long id; + + public SimpleString name; + + public boolean autoCreated; + + public SimpleString user; + + public AddressInfo.RoutingType routingType; + + public PersistentAddressBindingEncoding() { + } + + @Override + public String toString() { + return "PersistentAddressBindingEncoding [id=" + id + + ", name=" + + name + + ", user=" + + user + + ", autoCreated=" + + autoCreated + + ", routingType=" + + routingType + + "]"; + } + + public PersistentAddressBindingEncoding(final SimpleString name, + final SimpleString user, + final boolean autoCreated, + final AddressInfo.RoutingType routingType) { + this.name = name; + this.user = user; + this.autoCreated = autoCreated; + this.routingType = routingType; + } + + @Override + public long getId() { + return id; + } + + public void setId(final long id) { + this.id = id; + } + + @Override + public SimpleString getName() { + return name; + } + + @Override + public SimpleString getUser() { + return user; + } + + @Override + public boolean isAutoCreated() { + return autoCreated; + } + + @Override + public AddressInfo.RoutingType getRoutingType() { + return routingType; + } + + @Override + public void decode(final ActiveMQBuffer buffer) { + name = buffer.readSimpleString(); + + String metadata = buffer.readNullableSimpleString().toString(); + if (metadata != null) { + String[] elements = metadata.split(";"); + for (String element : elements) { + String[] keyValuePair = element.split("="); + if (keyValuePair.length == 2) { + if (keyValuePair[0].equals("user")) { + user = SimpleString.toSimpleString(keyValuePair[1]); + } + } + } + } + + autoCreated = buffer.readBoolean(); + routingType = AddressInfo.RoutingType.getType(buffer.readByte()); + } + + @Override + public void encode(final ActiveMQBuffer buffer) { + buffer.writeSimpleString(name); + buffer.writeNullableSimpleString(createMetadata()); + buffer.writeBoolean(autoCreated); + buffer.writeByte(routingType.getType()); + } + + @Override + public int getEncodeSize() { + return SimpleString.sizeofString(name) + DataConstants.SIZE_BOOLEAN + + SimpleString.sizeofNullableString(createMetadata()) + + DataConstants.SIZE_BYTE; + } + + private SimpleString createMetadata() { + StringBuilder metadata = new StringBuilder(); + metadata.append("user=").append(user).append(";"); + return SimpleString.toSimpleString(metadata.toString()); + } +} diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AddressInfo.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AddressInfo.java index 03c3fa0b4d..4c6ec1f2af 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AddressInfo.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AddressInfo.java @@ -16,18 +16,13 @@ */ package org.apache.activemq.artemis.core.server.impl; -import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration; import org.apache.activemq.artemis.api.core.SimpleString; public class AddressInfo { - public enum RoutingType { - MULTICAST, ANYCAST - } - private final SimpleString name; - private RoutingType routingType = RoutingType.MULTICAST; + private RoutingType routingType = RoutingType.Multicast; private boolean defaultDeleteOnNoConsumers; @@ -64,4 +59,30 @@ public class AddressInfo { public SimpleString getName() { return name; } + + public enum RoutingType { + Multicast, Anycast; + + public byte getType() { + switch (this) { + case Multicast: + return 0; + case Anycast: + return 1; + default: + return -1; + } + } + + public static RoutingType getType(byte type) { + switch (type) { + case 0: + return Multicast; + case 1: + return Anycast; + default: + return null; + } + } + } } diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationTest.java index 1569b8a94b..ba9cc1a554 100644 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationTest.java +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationTest.java @@ -52,9 +52,6 @@ import org.apache.activemq.artemis.core.settings.impl.SlowConsumerPolicy; import org.junit.Assert; import org.junit.Test; -import static org.apache.activemq.artemis.core.server.impl.AddressInfo.RoutingType.ANYCAST; -import static org.apache.activemq.artemis.core.server.impl.AddressInfo.RoutingType.MULTICAST; - public class FileConfigurationTest extends ConfigurationImplTest { private final String fullConfigurationName = "ConfigurationTest-full-config.xml"; @@ -379,7 +376,7 @@ public class FileConfigurationTest extends ConfigurationImplTest { // Addr 1 CoreAddressConfiguration addressConfiguration = conf.getAddressConfigurations().get(0); assertEquals("addr1", addressConfiguration.getName()); - assertEquals(ANYCAST, addressConfiguration.getRoutingType()); + assertEquals(AddressInfo.RoutingType.Anycast, addressConfiguration.getRoutingType()); assertEquals(2, addressConfiguration.getQueueConfigurations().size()); // Addr 1 Queue 1 @@ -405,7 +402,7 @@ public class FileConfigurationTest extends ConfigurationImplTest { // Addr 2 addressConfiguration = conf.getAddressConfigurations().get(1); assertEquals("addr2", addressConfiguration.getName()); - assertEquals(MULTICAST, addressConfiguration.getRoutingType()); + assertEquals(AddressInfo.RoutingType.Multicast, addressConfiguration.getRoutingType()); assertEquals(2, addressConfiguration.getQueueConfigurations().size()); // Addr 2 Queue 1 diff --git a/artemis-tools/src/main/java/org/apache/activemq/artemis/tools/migrate/config/XMLConfigurationMigration.java b/artemis-tools/src/main/java/org/apache/activemq/artemis/tools/migrate/config/XMLConfigurationMigration.java index 56833ea612..90be53c1fb 100644 --- a/artemis-tools/src/main/java/org/apache/activemq/artemis/tools/migrate/config/XMLConfigurationMigration.java +++ b/artemis-tools/src/main/java/org/apache/activemq/artemis/tools/migrate/config/XMLConfigurationMigration.java @@ -50,19 +50,16 @@ public class XMLConfigurationMigration { if (args.length == 0) { System.err.println("Invalid args"); printUsage(); - } - else { + } else { File input = new File(args[0]); if (input.isDirectory()) { System.out.println("Scanning directory: " + input.getAbsolutePath()); recursiveTransform(input); - } - else { + } else { if (args.length != 2) { System.err.println("Invalid args"); printUsage(); - } - else { + } else { transform(input, new File(args[1])); } } @@ -70,13 +67,11 @@ public class XMLConfigurationMigration { } private static void recursiveTransform(File root) throws Exception { - for ( File file : root.listFiles()) - { + for (File file : root.listFiles()) { scanAndTransform(file); } } - public static void scanAndTransform(File pFile) throws Exception { try { for (File f : pFile.listFiles()) { @@ -93,14 +88,12 @@ public class XMLConfigurationMigration { file.renameTo(r); } } - } - catch (Exception e) { + } catch (Exception e) { //continue } } } - } - catch (NullPointerException e) { + } catch (NullPointerException e) { System.out.println(pFile.getAbsoluteFile()); } } @@ -125,9 +118,7 @@ public class XMLConfigurationMigration { migration.write(output, properties); return true; } - } - catch (Exception e) - { + } catch (Exception e) { System.err.println("Error tranforming document"); e.printStackTrace(); } @@ -174,8 +165,7 @@ public class XMLConfigurationMigration { if (addresses.containsKey(addressName)) { address = addresses.get(addressName); - } - else { + } else { address = new Address(); address.setName(addressName); addresses.put(addressName, address); diff --git a/pom.xml b/pom.xml index 794fcf48c9..30c96cd1e8 100644 --- a/pom.xml +++ b/pom.xml @@ -1269,6 +1269,7 @@ docs/**/_book/ **/target/ **/META-INF/services/* + **/META-INF/MANIFEST.MF **/*.iml **/*.jceks **/*.jks