activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From martyntay...@apache.org
Subject [2/3] activemq-artemis git commit: ARTEMIS-305 - fixing colocated configuration can have mismatch of policies
Date Wed, 25 Nov 2015 11:28:18 GMT
ARTEMIS-305 - fixing colocated configuration can have mismatch of policies

https://issues.apache.org/jira/browse/ARTEMIS-305


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/b34ee871
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/b34ee871
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/b34ee871

Branch: refs/heads/master
Commit: b34ee8717f24448900cf89811e9ca0a37f3882e1
Parents: db04192
Author: Andy Taylor <andy.tayls67@gmail.com>
Authored: Fri Nov 20 10:38:21 2015 +0000
Committer: Andy Taylor <andy.tayls67@gmail.com>
Committed: Wed Nov 25 09:45:39 2015 +0000

----------------------------------------------------------------------
 .../artemis/core/config/ConfigurationUtils.java | 30 ++++++++----
 .../core/server/ActiveMQMessageBundle.java      |  3 ++
 .../config/impl/HAPolicyConfigurationTest.java  | 48 ++++++++++++++++++++
 .../colocated-hapolicy-config-null-backup.xml   | 42 +++++++++++++++++
 .../colocated-hapolicy-config2-null-backup.xml  | 37 +++++++++++++++
 5 files changed, 152 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b34ee871/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/ConfigurationUtils.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/ConfigurationUtils.java
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/ConfigurationUtils.java
index f1bb89c..bd626a5 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/ConfigurationUtils.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/ConfigurationUtils.java
@@ -81,22 +81,36 @@ public final class ConfigurationUtils {
          case COLOCATED: {
             ColocatedPolicyConfiguration pc = (ColocatedPolicyConfiguration) conf;
 
-            HAPolicyConfiguration backupConf = pc.getBackupConfig();
-            BackupPolicy backupPolicy;
-            if (backupConf == null) {
-               backupPolicy = new ReplicaPolicy();
-            }
-            else {
-               backupPolicy = (BackupPolicy) getHAPolicy(backupConf);
-            }
             HAPolicyConfiguration liveConf = pc.getLiveConfig();
             HAPolicy livePolicy;
+            //if null default to colocated
             if (liveConf == null) {
                livePolicy = new ReplicatedPolicy();
             }
             else {
                livePolicy = getHAPolicy(liveConf);
             }
+            HAPolicyConfiguration backupConf = pc.getBackupConfig();
+            BackupPolicy backupPolicy;
+            if (backupConf == null) {
+               if (livePolicy instanceof ReplicatedPolicy) {
+                  backupPolicy = new ReplicaPolicy();
+               }
+               else if (livePolicy instanceof SharedStoreMasterPolicy) {
+                  backupPolicy = new SharedStoreSlavePolicy();
+               }
+               else {
+                  throw ActiveMQMessageBundle.BUNDLE.liveBackupMismatch();
+               }
+            }
+            else {
+               backupPolicy = (BackupPolicy) getHAPolicy(backupConf);
+            }
+
+            if ((livePolicy instanceof ReplicatedPolicy && !(backupPolicy instanceof
ReplicaPolicy)) ||
+                  (livePolicy instanceof SharedStoreMasterPolicy && !(backupPolicy
instanceof SharedStoreSlavePolicy))) {
+               throw ActiveMQMessageBundle.BUNDLE.liveBackupMismatch();
+            }
             return new ColocatedPolicy(pc.isRequestBackup(), pc.getBackupRequestRetries(),
pc.getBackupRequestRetryInterval(), pc.getMaxBackups(), pc.getBackupPortOffset(), pc.getExcludedConnectors(),
livePolicy, backupPolicy);
          }
 

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b34ee871/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQMessageBundle.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQMessageBundle.java
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQMessageBundle.java
index a08a1f4..a46d240 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQMessageBundle.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQMessageBundle.java
@@ -362,4 +362,7 @@ public interface ActiveMQMessageBundle {
 
    @Message(id = 119114, value = "Replication synchronization process timed out after waiting
{0} milliseconds", format = Message.Format.MESSAGE_FORMAT)
    IllegalStateException replicationSynchronizationTimeout(long timeout);
+
+   @Message(id = 119115, value = "Colocated Policy hasn't different type live and backup",
format = Message.Format.MESSAGE_FORMAT)
+   ActiveMQIllegalStateException liveBackupMismatch();
 }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b34ee871/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/HAPolicyConfigurationTest.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/HAPolicyConfigurationTest.java
b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/HAPolicyConfigurationTest.java
index 7fd25f1..59019dd 100644
--- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/HAPolicyConfigurationTest.java
+++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/HAPolicyConfigurationTest.java
@@ -334,6 +334,31 @@ public class HAPolicyConfigurationTest extends ActiveMQTestBase {
    }
 
    @Test
+   public void colocatedTestNullBackup() throws Exception {
+      Configuration configuration = createConfiguration("colocated-hapolicy-config-null-backup.xml");
+      ActiveMQServerImpl server = new ActiveMQServerImpl(configuration);
+      try {
+         server.start();
+         Activation activation = server.getActivation();
+         assertTrue(activation instanceof ColocatedActivation);
+         HAPolicy haPolicy = server.getHAPolicy();
+         assertTrue(haPolicy instanceof ColocatedPolicy);
+         ColocatedPolicy colocatedPolicy = (ColocatedPolicy) haPolicy;
+         ReplicatedPolicy livePolicy = (ReplicatedPolicy) colocatedPolicy.getLivePolicy();
+         assertNotNull(livePolicy);
+
+         assertEquals(livePolicy.getGroupName(), "purple");
+         assertTrue(livePolicy.isCheckForLiveServer());
+         assertEquals(livePolicy.getClusterName(), "abcdefg");
+         ReplicaPolicy backupPolicy = (ReplicaPolicy) colocatedPolicy.getBackupPolicy();
+         assertNotNull(backupPolicy);
+      }
+      finally {
+         server.stop();
+      }
+   }
+
+   @Test
    public void colocatedTest2() throws Exception {
       Configuration configuration = createConfiguration("colocated-hapolicy-config2.xml");
       ActiveMQServerImpl server = new ActiveMQServerImpl(configuration);
@@ -358,6 +383,29 @@ public class HAPolicyConfigurationTest extends ActiveMQTestBase {
       }
    }
 
+   @Test
+   public void colocatedTest2nullbackup() throws Exception {
+      Configuration configuration = createConfiguration("colocated-hapolicy-config2-null-backup.xml");
+      ActiveMQServerImpl server = new ActiveMQServerImpl(configuration);
+      try {
+         server.start();
+         Activation activation = server.getActivation();
+         assertTrue(activation instanceof ColocatedActivation);
+         HAPolicy haPolicy = server.getHAPolicy();
+         assertTrue(haPolicy instanceof ColocatedPolicy);
+         ColocatedPolicy colocatedPolicy = (ColocatedPolicy) haPolicy;
+         SharedStoreMasterPolicy livePolicy = (SharedStoreMasterPolicy) colocatedPolicy.getLivePolicy();
+         assertNotNull(livePolicy);
+
+         assertFalse(livePolicy.isFailoverOnServerShutdown());
+         SharedStoreSlavePolicy backupPolicy = (SharedStoreSlavePolicy) colocatedPolicy.getBackupPolicy();
+         assertNotNull(backupPolicy);
+      }
+      finally {
+         server.stop();
+      }
+   }
+
    private void liveOnlyTest(String file) throws Exception {
       Configuration configuration = createConfiguration(file);
       ActiveMQServerImpl server = new ActiveMQServerImpl(configuration);

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b34ee871/artemis-server/src/test/resources/colocated-hapolicy-config-null-backup.xml
----------------------------------------------------------------------
diff --git a/artemis-server/src/test/resources/colocated-hapolicy-config-null-backup.xml b/artemis-server/src/test/resources/colocated-hapolicy-config-null-backup.xml
new file mode 100644
index 0000000..5b6b6d5
--- /dev/null
+++ b/artemis-server/src/test/resources/colocated-hapolicy-config-null-backup.xml
@@ -0,0 +1,42 @@
+<!--
+  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 ../../../../activemq-server/src/main/resources/schema/artemis-server.xsd">
+   <core xmlns="urn:activemq:core">
+      <discovery-groups>
+         <discovery-group name="wahey"/>
+      </discovery-groups>
+      <ha-policy>
+         <replication>
+            <colocated>
+               <backup-request-retries>44</backup-request-retries>
+               <backup-request-retry-interval>33</backup-request-retry-interval>
+               <max-backups>3</max-backups>
+               <request-backup>false</request-backup>
+               <backup-port-offset>33</backup-port-offset>
+               <master>
+                  <group-name>purple</group-name>
+                  <check-for-live-server>true</check-for-live-server>
+                  <cluster-name>abcdefg</cluster-name>
+               </master>
+            </colocated>
+         </replication>
+      </ha-policy>
+   </core>
+</configuration>

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b34ee871/artemis-server/src/test/resources/colocated-hapolicy-config2-null-backup.xml
----------------------------------------------------------------------
diff --git a/artemis-server/src/test/resources/colocated-hapolicy-config2-null-backup.xml
b/artemis-server/src/test/resources/colocated-hapolicy-config2-null-backup.xml
new file mode 100644
index 0000000..e420033
--- /dev/null
+++ b/artemis-server/src/test/resources/colocated-hapolicy-config2-null-backup.xml
@@ -0,0 +1,37 @@
+<!--
+  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 ../../../../activemq-server/src/main/resources/schema/artemis-server.xsd">
+   <core xmlns="urn:activemq:core">
+      <ha-policy>
+         <shared-store>
+            <colocated>
+               <backup-request-retries>44</backup-request-retries>
+               <backup-request-retry-interval>33</backup-request-retry-interval>
+               <max-backups>3</max-backups>
+               <request-backup>false</request-backup>
+               <backup-port-offset>33</backup-port-offset>
+               <master>
+                  <failover-on-shutdown>false</failover-on-shutdown>
+               </master>
+            </colocated>
+         </shared-store>
+      </ha-policy>
+   </core>
+</configuration>


Mime
View raw message