Author: orudyy
Date: Tue Apr 30 14:41:08 2013
New Revision: 1477667

URL: http://svn.apache.org/r1477667
Log:
QPID-4778: Introduce additional states for configured objects: ERRORED and 
REPLICA

Added:
    
qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/model/VirtualHostTest.java
Modified:
    
qpid/trunk/qpid/java/bdbstore/jmx/src/test/java/org/apache/qpid/server/store/berkeleydb/HAClusterManagementTest.java
    
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/model/State.java
    
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java
    
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java

Modified: 
qpid/trunk/qpid/java/bdbstore/jmx/src/test/java/org/apache/qpid/server/store/berkeleydb/HAClusterManagementTest.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/bdbstore/jmx/src/test/java/org/apache/qpid/server/store/berkeleydb/HAClusterManagementTest.java?rev=1477667&r1=1477666&r2=1477667&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/bdbstore/jmx/src/test/java/org/apache/qpid/server/store/berkeleydb/HAClusterManagementTest.java
 (original)
+++ 
qpid/trunk/qpid/java/bdbstore/jmx/src/test/java/org/apache/qpid/server/store/berkeleydb/HAClusterManagementTest.java
 Tue Apr 30 14:41:08 2013
@@ -235,7 +235,7 @@ public class HAClusterManagementTest ext
         catch  (Exception e)
         {
             String message = e.getMessage();
-            assertEquals(message, "The virtual hosts state of INITIALISING 
does not permit this operation.");
+            assertEquals("The virtual hosts state of PASSIVE does not permit 
this operation.", message);
         }
 
         try
@@ -246,7 +246,7 @@ public class HAClusterManagementTest ext
         catch  (Exception e)
         {
             String message = e.getMessage();
-            assertEquals(message, "The virtual hosts state of INITIALISING 
does not permit this operation.");
+            assertEquals("The virtual hosts state of PASSIVE does not permit 
this operation.", message);
         }
     }
 

Modified: 
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/model/State.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/model/State.java?rev=1477667&r1=1477666&r2=1477667&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/model/State.java
 (original)
+++ 
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/model/State.java
 Tue Apr 30 14:41:08 2013
@@ -26,5 +26,7 @@ public enum State
     QUIESCED,
     STOPPED,
     ACTIVE,
-    DELETED
+    DELETED,
+    REPLICA,
+    ERRORED
 }

Modified: 
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java?rev=1477667&r1=1477666&r2=1477667&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java
 (original)
+++ 
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java
 Tue Apr 30 14:41:08 2013
@@ -449,12 +449,13 @@ public final class VirtualHostAdapter ex
             case ACTIVE:
                 return State.ACTIVE;
             case PASSIVE:
-                return State.QUIESCED;
+                return State.REPLICA;
             case STOPPED:
                 return State.STOPPED;
+            case ERRORED:
+                return State.ERRORED;
             default:
-                // unexpected state
-                return null;
+                throw new IllegalStateException("Unsupported state:" + 
implementationState);
             }
         }
     }
@@ -1002,19 +1003,27 @@ public final class VirtualHostAdapter ex
             {
                 throw new IntegrityViolationException("Cannot delete default 
virtual host '" + hostName + "'");
             }
-            if (_virtualHost != null && _virtualHost.getState() == 
org.apache.qpid.server.virtualhost.State.ACTIVE)
-            {
-                setDesiredState(currentState, State.STOPPED);
-            }
-            MessageStore ms = _virtualHost.getMessageStore();
-            _virtualHost = null;
-            try
-            {
-                ms.onDelete();
-            }
-            catch(Exception e)
+            if (_virtualHost != null)
             {
-                LOGGER.warn("Exception occured on store deletion", e);
+                if (_virtualHost.getState() == 
org.apache.qpid.server.virtualhost.State.ACTIVE)
+                {
+                    setDesiredState(currentState, State.STOPPED);
+                }
+
+                MessageStore ms = _virtualHost.getMessageStore();
+                if (ms != null)
+                {
+                    try
+                    {
+                        ms.onDelete();
+                    }
+                    catch(Exception e)
+                    {
+                        LOGGER.warn("Exception occured on store deletion", e);
+                    }
+                }
+
+                _virtualHost = null;
             }
             setAttribute(VirtualHost.STATE, getActualState(), State.DELETED);
             return true;

Modified: 
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java?rev=1477667&r1=1477666&r2=1477667&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java
 (original)
+++ 
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java
 Tue Apr 30 14:41:08 2013
@@ -296,6 +296,10 @@ public class VirtualHostImpl implements 
         messageStore.addEventListener(new AfterActivationListener(), 
Event.AFTER_ACTIVATE);
         messageStore.addEventListener(new BeforeCloseListener(), 
Event.BEFORE_CLOSE);
         messageStore.addEventListener(new BeforePassivationListener(), 
Event.BEFORE_PASSIVATE);
+        if (messageStore instanceof HAMessageStore)
+        {
+            messageStore.addEventListener(new AfterInitialisationListener(), 
Event.AFTER_INIT);
+        }
 
         VirtualHostConfigRecoveryHandler recoveryHandler = new 
VirtualHostConfigRecoveryHandler(this);
 
@@ -689,6 +693,15 @@ public class VirtualHostImpl implements 
 
     }
 
+    private final class AfterInitialisationListener implements EventListener
+    {
+        public void event(Event event)
+        {
+            _state = State.PASSIVE;
+        }
+
+    }
+
     private final class BeforeCloseListener implements EventListener
     {
         @Override

Added: 
qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/model/VirtualHostTest.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/model/VirtualHostTest.java?rev=1477667&view=auto
==============================================================================
--- 
qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/model/VirtualHostTest.java
 (added)
+++ 
qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/model/VirtualHostTest.java
 Tue Apr 30 14:41:08 2013
@@ -0,0 +1,205 @@
+/*
+ *
+ * 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.qpid.server.model;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.File;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import junit.framework.TestCase;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.RecovererProvider;
+import org.apache.qpid.server.configuration.startup.VirtualHostRecoverer;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
+import org.apache.qpid.server.logging.SystemOutMessageLogger;
+import org.apache.qpid.server.logging.actors.CurrentActor;
+import org.apache.qpid.server.logging.actors.TestLogActor;
+import org.apache.qpid.server.stats.StatisticsGatherer;
+import org.apache.qpid.server.store.Event;
+import org.apache.qpid.server.store.EventListener;
+import org.apache.qpid.server.store.EventManager;
+import org.apache.qpid.server.store.MemoryMessageStore;
+import org.apache.qpid.server.store.NullMessageStore;
+import org.apache.qpid.server.store.StateManager;
+import org.apache.qpid.server.util.BrokerTestHelper;
+import org.apache.qpid.test.utils.TestFileUtils;
+
+public class VirtualHostTest extends TestCase
+{
+
+    private Broker _broker;
+    private StatisticsGatherer _statisticsGatherer;
+    private RecovererProvider _recovererProvider;
+
+    @Override
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+        CurrentActor.set(new TestLogActor(new SystemOutMessageLogger()));
+
+        _broker = BrokerTestHelper.createBrokerMock();
+        TaskExecutor taslExecutor = mock(TaskExecutor.class);
+        when(taslExecutor.isTaskExecutorThread()).thenReturn(true);
+        when(_broker.getTaskExecutor()).thenReturn(taslExecutor);
+
+        _recovererProvider = mock(RecovererProvider.class);
+        _statisticsGatherer = mock(StatisticsGatherer.class);
+    }
+
+    @Override
+    protected void tearDown() throws Exception
+    {
+        super.tearDown();
+        CurrentActor.remove();
+    }
+
+    public void testInitialisingState()
+    {
+        VirtualHost host = createHost();
+
+        assertEquals("Unexpected state", State.INITIALISING, 
host.getAttribute(VirtualHost.STATE));
+    }
+
+    public void testActiveState()
+    {
+        VirtualHost host = createHost();
+
+        host.setDesiredState(State.INITIALISING, State.ACTIVE);
+        assertEquals("Unexpected state", State.ACTIVE, 
host.getAttribute(VirtualHost.STATE));
+    }
+
+    public void testQuiescedState()
+    {
+        Map<String, Object> attributes = new HashMap<String, Object>();
+        attributes.put(VirtualHost.NAME, getName());
+        attributes.put(VirtualHost.STORE_TYPE, MemoryMessageStore.TYPE);
+        attributes.put(VirtualHost.STATE, State.QUIESCED);
+
+        VirtualHost host = createHost(attributes);
+
+        assertEquals("Unexpected state", State.QUIESCED, 
host.getAttribute(VirtualHost.STATE));
+
+        host.setDesiredState(State.QUIESCED, State.ACTIVE);
+        assertEquals("Unexpected state", State.ACTIVE, 
host.getAttribute(VirtualHost.STATE));
+    }
+
+    public void testStoppedState()
+    {
+        VirtualHost host = createHost();
+
+        assertEquals("Unexpected state", State.INITIALISING, 
host.getAttribute(VirtualHost.STATE));
+
+        host.setDesiredState(State.INITIALISING, State.ACTIVE);
+        assertEquals("Unexpected state", State.ACTIVE, 
host.getAttribute(VirtualHost.STATE));
+
+        host.setDesiredState(State.ACTIVE, State.STOPPED);
+        assertEquals("Unexpected state", State.STOPPED, 
host.getAttribute(VirtualHost.STATE));
+    }
+
+    public void testDeletedState()
+    {
+        VirtualHost host = createHost();
+
+        assertEquals("Unexpected state", State.INITIALISING, 
host.getAttribute(VirtualHost.STATE));
+
+        host.setDesiredState(State.INITIALISING, State.DELETED);
+        assertEquals("Unexpected state", State.DELETED, 
host.getAttribute(VirtualHost.STATE));
+    }
+
+    public void testReplicaState()
+    {
+        File configPath = TestFileUtils.createTempFile(this, ".xml",
+                "<virtualhost><store><class>" + 
ReplicaMessageStore.class.getName() + "</class></store></virtualhost>");
+        try
+        {
+            Map<String, Object> attributes = new HashMap<String, Object>();
+            attributes.put(VirtualHost.NAME, getName());
+            attributes.put(VirtualHost.CONFIG_PATH, 
configPath.getAbsolutePath());
+
+            VirtualHost host = createHost(attributes);
+
+            assertEquals("Unexpected state", State.INITIALISING, 
host.getAttribute(VirtualHost.STATE));
+
+            host.setDesiredState(State.INITIALISING, State.ACTIVE);
+
+            assertEquals("Unexpected state", State.REPLICA, 
host.getAttribute(VirtualHost.STATE));
+        }
+        finally
+        {
+            configPath.delete();
+        }
+    }
+
+    private VirtualHost createHost()
+    {
+        Map<String, Object> attributes = new HashMap<String, Object>();
+        attributes.put(VirtualHost.NAME, getName());
+        attributes.put(VirtualHost.STORE_TYPE, MemoryMessageStore.TYPE);
+
+        VirtualHost host = createHost(attributes);
+        return host;
+    }
+
+    private VirtualHost createHost(Map<String, Object> attributes)
+    {
+        ConfigurationEntry entry = new ConfigurationEntry(UUID.randomUUID(), 
VirtualHost.class.getSimpleName(), attributes,
+                Collections.<UUID> emptySet(), null);
+
+        return new 
VirtualHostRecoverer(_statisticsGatherer).create(_recovererProvider, entry, 
_broker);
+    }
+
+    public static final class ReplicaMessageStore extends NullMessageStore
+    {
+        private final EventManager _eventManager = new EventManager();
+        private final StateManager _stateManager = new 
StateManager(_eventManager);
+
+        @Override
+        public void activate() throws Exception
+        {
+            
_stateManager.attainState(org.apache.qpid.server.store.State.INITIALISING);
+            
_stateManager.attainState(org.apache.qpid.server.store.State.INITIALISED);
+            
_stateManager.attainState(org.apache.qpid.server.store.State.ACTIVATING);
+            
_stateManager.attainState(org.apache.qpid.server.store.State.ACTIVE);
+
+            // this should change the virtual host state to PASSIVE
+            
_stateManager.attainState(org.apache.qpid.server.store.State.INITIALISED);
+        }
+
+        @Override
+        public void addEventListener(EventListener eventListener, Event... 
events)
+        {
+            _eventManager.addEventListener(eventListener, events);
+        }
+
+        @Override
+        public String getStoreType()
+        {
+            return ReplicaMessageStore.class.getSimpleName();
+        }
+    }
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to