diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/Configuration.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/Configuration.java index 1df52bd0bc1..7ed51e3b48d 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/Configuration.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/Configuration.java @@ -70,6 +70,16 @@ public interface Configuration { */ Configuration setName(String name); + /** + * Returns the ID of the node. + */ + String getNodeID(); + + /** + * Sets the ID of the node. If not set, a UUID generated on first startup will be used instead. + */ + Configuration setNodeID(String nodeID); + /** * We use Bean-utils to pass in System.properties that start with {@link #setSystemPropertyPrefix(String)}. * The default should be 'brokerconfig.' (Including the "."). diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java index 0b78fab0c43..bcc7291c86a 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java @@ -153,6 +153,8 @@ public class ConfigurationImpl implements Configuration, Serializable { private String name = "localhost"; + private String nodeID = null; + private boolean persistenceEnabled = ActiveMQDefaultConfiguration.isDefaultPersistenceEnabled(); private int maxRedeliveryRecords = ActiveMQDefaultConfiguration.getDefaultMaxRedeliveryRecords(); @@ -2559,6 +2561,17 @@ public ConfigurationImpl setName(String name) { return this; } + @Override + public String getNodeID() { + return nodeID; + } + + @Override + public ConfigurationImpl setNodeID(String nodeID) { + this.nodeID = nodeID; + return this; + } + @Override public ConfigurationImpl setResolveProtocols(boolean resolveProtocols) { this.resolveProtocols = resolveProtocols; @@ -2707,6 +2720,7 @@ public int hashCode() { result = prime * result + (int) (messageExpiryScanPeriod ^ (messageExpiryScanPeriod >>> 32)); result = prime * result + messageExpiryThreadPriority; result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((nodeID == null) ? 0 : nodeID.hashCode()); result = prime * result + ((outgoingInterceptorClassNames == null) ? 0 : outgoingInterceptorClassNames.hashCode()); result = prime * result + ((pagingDirectory == null) ? 0 : pagingDirectory.hashCode()); result = prime * result + (persistDeliveryCountBeforeDelivery ? 1231 : 1237); @@ -2910,6 +2924,11 @@ public boolean equals(Object obj) { return false; } else if (!name.equals(other.name)) return false; + if (nodeID == null) { + if (other.nodeID != null) + return false; + } else if (!nodeID.equals(other.nodeID)) + return false; if (outgoingInterceptorClassNames == null) { if (other.outgoingInterceptorClassNames != null) return false; diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java index 9f6ab681e6a..0c25e5ce661 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java @@ -424,6 +424,8 @@ public void parseMainConfig(final Element e, final Configuration config) throws config.setName(getString(e, "name", config.getName(), NO_CHECK)); + config.setNodeID(getString(e, "node-id", config.getNodeID(), NO_CHECK)); + config.setSystemPropertyPrefix(getString(e, "system-property-prefix", config.getSystemPropertyPrefix(), NOT_NULL_OR_EMPTY)); NodeList haPolicyNodes = e.getElementsByTagName("ha-policy"); diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/NodeManager.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/NodeManager.java index 28baf1edf8f..7a0b1d2613a 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/NodeManager.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/NodeManager.java @@ -83,6 +83,15 @@ public SimpleString getNodeId() { } } + /** + * Returns the converted form of a given nodeID + * + * @param nodeID + */ + public String getConvertedNodeId(String nodeID) { + return new UUID(UUID.TYPE_TIME_BASED, UUID.stringToBytes(nodeID)).toString(); + } + public long readNodeActivationSequence() throws NodeManagerException { // TODO make it abstract throw new UnsupportedOperationException("TODO"); @@ -117,16 +126,14 @@ public UUID getUUID() { } /** - * Sets the nodeID. - *
- * Only used by replicating backups.
+ * Sets the nodeID
*
* @param nodeID
*/
public void setNodeID(String nodeID) {
synchronized (nodeIDGuard) {
- this.nodeID = new SimpleString(nodeID);
this.uuid = new UUID(UUID.TYPE_TIME_BASED, UUID.stringToBytes(nodeID));
+ this.nodeID = new SimpleString(uuid.toString());
}
}
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java
index 6877d7bc331..bcdfd5ef46d 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java
@@ -617,9 +617,35 @@ protected NodeManager createNodeManager(final File directory, boolean replicatin
} else {
manager = new FileLockNodeManager(directory, replicatingBackup, configuration.getJournalLockAcquisitionTimeout(), scheduledPool);
}
+
+ if (!replicatingBackup && configuration.getNodeID() != null) {
+ manager.setNodeID(toCompatibleNodeID(configuration.getNodeID()));
+ }
+
return manager;
}
+ private String toCompatibleNodeID(String nodeID) {
+ if (nodeID == null) {
+ return null;
+ }
+
+ final int len = nodeID.length();
+
+ if (!(len > 0)) {
+ return null;
+ }
+
+ if (len >= 16) {
+ nodeID = nodeID.substring(0, 16);
+ } else if (len % 2 != 0) {
+ // must be even for conversion to uuid, extend to next even
+ nodeID = nodeID + "+";
+ }
+
+ return nodeID.replace('-', '.');
+ }
+
@Override
public OperationContext newOperationContext() {
return getStorageManager().newContext(getExecutorFactory().getExecutor());
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/FileBasedNodeManager.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/FileBasedNodeManager.java
index 99adbdfc640..fc9b36a2256 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/FileBasedNodeManager.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/FileBasedNodeManager.java
@@ -208,7 +208,9 @@ protected final synchronized void createNodeId() throws IOException {
channel.write(id, 3);
channel.force(true);
} else if (read != 16) {
- setUUID(UUIDGenerator.getInstance().generateUUID());
+ if (getUUID() == null) {
+ setUUID(UUIDGenerator.getInstance().generateUUID());
+ }
id.put(getUUID().asBytes(), 0, 16);
id.position(0);
channel.write(id, 3);
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ReplicationBackupActivation.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ReplicationBackupActivation.java
index 44a93837d3a..b4c3c8c42a1 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ReplicationBackupActivation.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ReplicationBackupActivation.java
@@ -80,7 +80,7 @@ public ReplicationBackupActivation(final ActiveMQServerImpl activeMQServer,
// patch expectedNodeID
final String coordinationId = policy.getPrimaryPolicy().getCoordinationId();
if (coordinationId != null) {
- expectedNodeID = coordinationId;
+ expectedNodeID = activeMQServer.getNodeManager().getConvertedNodeId(coordinationId);
} else {
final SimpleString serverNodeID = activeMQServer.getNodeID();
if (serverNodeID == null || serverNodeID.isEmpty()) {
diff --git a/artemis-server/src/main/resources/schema/artemis-configuration.xsd b/artemis-server/src/main/resources/schema/artemis-configuration.xsd
index fc4e50e5786..511a893cc48 100644
--- a/artemis-server/src/main/resources/schema/artemis-configuration.xsd
+++ b/artemis-server/src/main/resources/schema/artemis-configuration.xsd
@@ -36,6 +36,15 @@
+