diff options
| author | Keith Wall <kwall@apache.org> | 2014-05-20 15:04:11 +0000 |
|---|---|---|
| committer | Keith Wall <kwall@apache.org> | 2014-05-20 15:04:11 +0000 |
| commit | 65af0e588588f15bbb1498403ee49f3c41ed04a0 (patch) | |
| tree | 6c249ba8f011e0b033caa5ef77ec10fc5dbcfdc4 /qpid/java | |
| parent | 7371feb185388d4bedda4ac10ee7c78a17023a7e (diff) | |
| download | qpid-python-65af0e588588f15bbb1498403ee49f3c41ed04a0.tar.gz | |
QPID-5715: [Java Broker] Make virtualhosts respect the states ACTIVE and STOPPED
* Changes in virtualhost state are now persisted to store.
* VirtualHostState eliminated. The PASSIVE state used when a BDB HA Virtualhost is in replica is replaced by UNAVAILABLE.
Work by me and Andrew MacBean <andymacbean@gmail.com>.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1596281 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java')
15 files changed, 197 insertions, 144 deletions
diff --git a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeImpl.java b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeImpl.java index c019465176..4061da177b 100644 --- a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeImpl.java +++ b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeImpl.java @@ -44,6 +44,8 @@ import com.sleepycat.je.rep.util.ReplicationGroupAdmin; import com.sleepycat.je.rep.utilint.HostPortPair; import org.apache.log4j.Logger; + +import org.apache.qpid.server.exchange.ExchangeImpl; import org.apache.qpid.server.logging.messages.ConfigStoreMessages; import org.apache.qpid.server.model.Broker; import org.apache.qpid.server.model.BrokerModel; @@ -57,6 +59,7 @@ import org.apache.qpid.server.model.StateTransition; import org.apache.qpid.server.model.VirtualHost; import org.apache.qpid.server.model.VirtualHostNode; import org.apache.qpid.server.plugin.ConfiguredObjectTypeFactory; +import org.apache.qpid.server.queue.AMQQueue; import org.apache.qpid.server.security.SecurityManager; import org.apache.qpid.server.store.DurableConfigurationStore; import org.apache.qpid.server.store.VirtualHostStoreUpgraderAndRecoverer; @@ -66,7 +69,6 @@ import org.apache.qpid.server.store.berkeleydb.replication.ReplicatedEnvironment import org.apache.qpid.server.store.berkeleydb.replication.ReplicatedEnvironmentFacadeFactory; import org.apache.qpid.server.store.berkeleydb.replication.ReplicationGroupListener; import org.apache.qpid.server.util.ServerScopedRuntimeException; -import org.apache.qpid.server.virtualhost.VirtualHostState; import org.apache.qpid.server.virtualhostnode.AbstractVirtualHostNode; @ManagedObject( category = false, type = "BDB_HA" ) @@ -702,12 +704,41 @@ public class BDBHAVirtualHostNodeImpl extends AbstractVirtualHostNode<BDBHAVirtu ReplicaVirtualHost(Map<String, Object> attributes, VirtualHostNode<?> virtualHostNode) { super(attributes, virtualHostNode); - setState(VirtualHostState.PASSIVE); } @Override - public void onCreate() + protected <C extends ConfiguredObject> C addChild(final Class<C> childClass, + final Map<String, Object> attributes, + final ConfiguredObject... otherParents) + { + throwUnsupportedForReplica(); + return null; + } + + @Override + public ExchangeImpl createExchange(final Map<String, Object> attributes) + { + throwUnsupportedForReplica(); + return null; + } + + @Override + public AMQQueue<?> createQueue(final Map<String, Object> attributes) + { + throwUnsupportedForReplica(); + return null; + } + + @Override + public State getState() + { + return State.UNAVAILABLE; + } + + private void throwUnsupportedForReplica() { + throw new IllegalStateException("The virtual host state of " + getState() + + " does not permit this operation."); } } diff --git a/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostNodeRestTest.java b/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostNodeRestTest.java index 507ff07ee5..675b052a91 100644 --- a/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostNodeRestTest.java +++ b/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostNodeRestTest.java @@ -38,8 +38,6 @@ import org.apache.qpid.server.virtualhostnode.berkeleydb.BDBHAVirtualHostNode; import org.apache.qpid.systest.rest.QpidRestTestCase; import org.apache.qpid.test.utils.TestBrokerConfiguration; import org.apache.qpid.util.FileUtils; -import org.codehaus.jackson.JsonGenerationException; -import org.codehaus.jackson.map.JsonMappingException; public class BDBHAVirtualHostNodeRestTest extends QpidRestTestCase { @@ -97,7 +95,7 @@ public class BDBHAVirtualHostNodeRestTest extends QpidRestTestCase config.removeObjectConfiguration(VirtualHostNode.class, TEST3_VIRTUALHOST); } - public void testCreate3NodesCluster() throws Exception + public void testCreate3NodeGroup() throws Exception { createHANode(NODE1, _node1HaPort, _node1HaPort); assertNode(NODE1, _node1HaPort, _node1HaPort, NODE1); @@ -173,7 +171,7 @@ public class BDBHAVirtualHostNodeRestTest extends QpidRestTestCase assertEquals("Unexpected number of remote nodes on " + NODE2, 1, data.size()); } - private void createHANode(String nodeName, int nodePort, int helperPort) throws IOException, JsonGenerationException, JsonMappingException + private void createHANode(String nodeName, int nodePort, int helperPort) throws Exception { Map<String, Object> nodeData = new HashMap<String, Object>(); nodeData.put(BDBHAVirtualHostNode.NAME, nodeName); diff --git a/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/HAClusterManagementTest.java b/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/HAClusterManagementTest.java index c184ef8f8d..0ab10cc318 100644 --- a/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/HAClusterManagementTest.java +++ b/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/HAClusterManagementTest.java @@ -191,7 +191,7 @@ public class HAClusterManagementTest extends QpidBrokerTestCase catch (Exception e) { String message = e.getMessage(); - assertEquals("The virtual hosts state of PASSIVE does not permit this operation.", message); + assertEquals("The virtual host state of UNAVAILABLE does not permit this operation.", message); } try @@ -202,7 +202,7 @@ public class HAClusterManagementTest extends QpidBrokerTestCase catch (Exception e) { String message = e.getMessage(); - assertEquals("The virtual hosts state of PASSIVE does not permit this operation.", message); + assertEquals("The virtual host state of UNAVAILABLE does not permit this operation.", message); } } @@ -243,11 +243,11 @@ public class HAClusterManagementTest extends QpidBrokerTestCase catch (Exception e) { String message = e.getMessage(); - assertEquals("The virtual hosts state of PASSIVE does not permit this operation.", message); + assertEquals("The virtual host state of UNAVAILABLE does not permit this operation.", message); } Map<String, Object> attributes = _clusterCreator.getNodeAttributes(inactiveBrokerPort); - assertEquals("Inactive broker has unexpeced role", "REPLICA", attributes.get(BDBHAVirtualHostNode.ROLE)); + assertEquals("Inactive broker has unexpected role", "REPLICA", attributes.get(BDBHAVirtualHostNode.ROLE)); _clusterCreator.setNodeAttributes(inactiveBrokerPort, Collections.<String, Object>singletonMap(BDBHAVirtualHostNode.ROLE, "MASTER")); _clusterCreator.awaitNodeToAttainRole(inactiveBrokerPort, "MASTER"); diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/State.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/State.java index f021db009e..881991b2d2 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/State.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/State.java @@ -27,7 +27,8 @@ public enum State STOPPED, ACTIVE, DELETED, - ERRORED(false); + ERRORED(false), + UNAVAILABLE; private final boolean _valid; diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java index cd3d7c889c..2bec380820 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java @@ -23,7 +23,6 @@ package org.apache.qpid.server.virtualhost; import java.security.AccessControlException; import java.security.PrivilegedAction; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -37,6 +36,7 @@ import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; import javax.security.auth.Subject; @@ -108,7 +108,7 @@ public abstract class AbstractVirtualHost<X extends AbstractVirtualHost<X>> exte private final SystemNodeRegistry _systemNodeRegistry = new SystemNodeRegistry(); - private volatile VirtualHostState _state = VirtualHostState.INITIALISING; + private final AtomicReference<State> _state = new AtomicReference<>(State.UNINITIALIZED); private final StatisticsCounter _messagesDelivered, _dataDelivered, _messagesReceived, _dataReceived; @@ -273,18 +273,15 @@ public abstract class AbstractVirtualHost<X extends AbstractVirtualHost<X>> exte } } } - } - private void checkVHostStateIsActive() - { - checkVHostState(VirtualHostState.ACTIVE); + addChangeListener(new StoreUpdatingChangeListener()); } - private void checkVHostState(VirtualHostState... states) + private void checkVHostStateIsActive() { - if (!Arrays.asList(states).contains(getVirtualHostState())) + if (_state.get() != State.ACTIVE) { - throw new IllegalStateException("The virtual hosts state of " + getVirtualHostState() + throw new IllegalStateException("The virtual host state of " + _state.get() + " does not permit this operation."); } } @@ -392,24 +389,7 @@ public abstract class AbstractVirtualHost<X extends AbstractVirtualHost<X>> exte { return State.DELETED; } - VirtualHostState implementationState = getVirtualHostState(); - switch(implementationState) - { - case INITIALISING: - return State.UNINITIALIZED; - case ACTIVE: - return State.ACTIVE; - case PASSIVE: - // TODO - return State.ACTIVE; - case STOPPED: - return State.STOPPED; - case ERRORED: - return State.ERRORED; - default: - throw new IllegalStateException("Unsupported state:" + implementationState); - } - + return _state.get(); } @Override @@ -709,7 +689,7 @@ public abstract class AbstractVirtualHost<X extends AbstractVirtualHost<X>> exte //Stop Connections _connectionRegistry.close(); _dtxRegistry.close(); - closeStorage(); + closeMessageStore(); shutdownHouseKeeping(); _eventLogger.message(VirtualHostMessages.CLOSED(getName())); @@ -725,7 +705,7 @@ public abstract class AbstractVirtualHost<X extends AbstractVirtualHost<X>> exte } } - private void closeStorage() + private void closeMessageStore() { if (getMessageStore() != null) { @@ -808,11 +788,6 @@ public abstract class AbstractVirtualHost<X extends AbstractVirtualHost<X>> exte return _dtxRegistry; } - public VirtualHostState getVirtualHostState() - { - return _state; - } - public void block() { synchronized (_connectionRegistry) @@ -902,14 +877,9 @@ public abstract class AbstractVirtualHost<X extends AbstractVirtualHost<X>> exte } } - protected void setState(VirtualHostState state) + protected void reportIfError(State state) { - _state = state; - } - - protected void reportIfError(VirtualHostState state) - { - if (state == VirtualHostState.ERRORED) + if (state == State.ERRORED) { _eventLogger.message(VirtualHostMessages.ERRORED(getName())); } @@ -1239,6 +1209,16 @@ public abstract class AbstractVirtualHost<X extends AbstractVirtualHost<X>> exte return _housekeepingThreadCount; } + @StateTransition( currentState = { State.ACTIVE, State.ERRORED, State.UNINITIALIZED }, desiredState = State.STOPPED ) + protected void doStop() + { + closeChildren(); + shutdownHouseKeeping(); + closeMessageStore(); + _state.set(State.STOPPED); + + } + @StateTransition( currentState = { State.ACTIVE, State.QUIESCED, State.ERRORED }, desiredState = State.DELETED ) private void doDelete() { @@ -1250,11 +1230,7 @@ public abstract class AbstractVirtualHost<X extends AbstractVirtualHost<X>> exte { throw new IntegrityViolationException("Cannot delete default virtual host '" + hostName + "'"); } - if (getVirtualHostState() == VirtualHostState.ACTIVE - || getVirtualHostState() == VirtualHostState.INITIALISING) - { - close(); - } + close(); MessageStore ms = getMessageStore(); if (ms != null) @@ -1268,8 +1244,6 @@ public abstract class AbstractVirtualHost<X extends AbstractVirtualHost<X>> exte _logger.warn("Exception occurred on message store deletion", e); } } - setAttribute(VirtualHost.STATE, getState(), State.DELETED); - getDurableConfigurationStore().remove(asObjectRecord()); deleted(); } } @@ -1426,8 +1400,8 @@ public abstract class AbstractVirtualHost<X extends AbstractVirtualHost<X>> exte getDurableConfigurationStore().create(new ConfiguredObjectRecordImpl(record.getId(), record.getType(), record.getAttributes())); } - @StateTransition( currentState = {State.UNINITIALIZED, State.ERRORED, State.QUIESCED}, desiredState = State.ACTIVE ) - protected void activate() + @StateTransition( currentState = {State.UNINITIALIZED, State.ERRORED, State.QUIESCED, State.STOPPED}, desiredState = State.ACTIVE ) + private void onActivate() { _houseKeepingTasks = new ScheduledThreadPoolExecutor(getHousekeepingThreadCount()); @@ -1454,17 +1428,53 @@ public abstract class AbstractVirtualHost<X extends AbstractVirtualHost<X>> exte new MessageStoreRecoverer(this, getMessageStoreLogSubject()).recover(); - VirtualHostState finalState = VirtualHostState.ERRORED; + State finalState = State.ERRORED; try { initialiseHouseKeeping(getHousekeepingCheckPeriod()); - finalState = VirtualHostState.ACTIVE; + finalState = State.ACTIVE; } finally { - _state = finalState; - reportIfError(_state); + _state.set(finalState); + reportIfError(_state.get()); } + } + private class StoreUpdatingChangeListener implements ConfigurationChangeListener + { + @Override + public void stateChanged(final ConfiguredObject<?> object, final State oldState, final State newState) + { + if (newState == State.DELETED) + { + getDurableConfigurationStore().remove(asObjectRecord()); + object.removeChangeListener(this); + } + } + + @Override + public void childAdded(final ConfiguredObject<?> object, final ConfiguredObject<?> child) + { + + } + + @Override + public void childRemoved(final ConfiguredObject<?> object, final ConfiguredObject<?> child) + { + + } + + @Override + public void attributeSet(final ConfiguredObject<?> object, + final String attributeName, + final Object oldAttributeValue, + final Object newAttributeValue) + { + getDurableConfigurationStore().update(false, asObjectRecord()); + } + } + + } diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java index 3c892a4d65..2ca1f1f5c8 100755 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java @@ -104,8 +104,6 @@ public interface VirtualHostImpl< X extends VirtualHostImpl<X,Q,E>, Q extends AM ScheduledFuture<?> scheduleTask(long delay, Runnable timeoutTask); - VirtualHostState getVirtualHostState(); - public void block(); public void unblock(); diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostState.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostState.java deleted file mode 100644 index b3b30fab82..0000000000 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostState.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * - * 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.virtualhost; - -public enum VirtualHostState -{ - INITIALISING, - ACTIVE, - PASSIVE, - STOPPED, - /** Terminal state that signifies the virtual host has experienced an unexpected condition. */ - ERRORED -} diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostnode/AbstractStandardVirtualHostNode.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostnode/AbstractStandardVirtualHostNode.java index 1e270839bb..62c05991c5 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostnode/AbstractStandardVirtualHostNode.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostnode/AbstractStandardVirtualHostNode.java @@ -122,7 +122,7 @@ public abstract class AbstractStandardVirtualHostNode<X extends AbstractStandard { if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Creating new virtualhost with name : " + getName()); + LOGGER.debug("Creating new virtualhost with name : " + getName()); } Map<String, Object> hostAttributes = new HashMap<String, Object>(); hostAttributes.put(VirtualHost.MODEL_VERSION, BrokerModel.MODEL_VERSION); @@ -147,8 +147,6 @@ public abstract class AbstractStandardVirtualHostNode<X extends AbstractStandard } }); } - - host.start(); } @Override diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java index cec34bd890..64c2cdbd95 100644 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java @@ -584,11 +584,6 @@ public class MockVirtualHost implements VirtualHostImpl<MockVirtualHost, AMQQueu } - public VirtualHostState getVirtualHostState() - { - return VirtualHostState.ACTIVE; - } - public void block() { } diff --git a/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ServerConnectionDelegate.java b/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ServerConnectionDelegate.java index 6ea52549bf..56700b5ebd 100644 --- a/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ServerConnectionDelegate.java +++ b/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ServerConnectionDelegate.java @@ -44,13 +44,13 @@ import org.apache.qpid.common.ServerPropertyNames; import org.apache.qpid.properties.ConnectionStartProperties; import org.apache.qpid.server.configuration.BrokerProperties; import org.apache.qpid.server.model.Broker; +import org.apache.qpid.server.model.State; import org.apache.qpid.server.model.port.AmqpPort; import org.apache.qpid.server.protocol.AMQConnectionModel; import org.apache.qpid.server.security.SubjectCreator; import org.apache.qpid.server.security.auth.AuthenticationResult.AuthenticationStatus; import org.apache.qpid.server.security.auth.SubjectAuthenticationResult; import org.apache.qpid.server.virtualhost.VirtualHostImpl; -import org.apache.qpid.server.virtualhost.VirtualHostState; import org.apache.qpid.transport.Binary; import org.apache.qpid.transport.Connection; import org.apache.qpid.transport.ConnectionClose; @@ -224,7 +224,7 @@ public class ServerConnectionDelegate extends ServerDelegate return; } - if (vhost.getVirtualHostState() != VirtualHostState.ACTIVE) + if (vhost.getState() != State.ACTIVE) { sconn.setState(Connection.State.CLOSING); sconn.invoke(new ConnectionClose(ConnectionCloseCode.CONNECTION_FORCED, "Virtual host '"+vhostName+"' is not active")); diff --git a/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/handler/ConnectionOpenMethodHandler.java b/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/handler/ConnectionOpenMethodHandler.java index 24391f6d77..80a66292bf 100644 --- a/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/handler/ConnectionOpenMethodHandler.java +++ b/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/handler/ConnectionOpenMethodHandler.java @@ -30,13 +30,13 @@ import org.apache.qpid.framing.AMQShortString; import org.apache.qpid.framing.ConnectionOpenBody; import org.apache.qpid.framing.MethodRegistry; import org.apache.qpid.protocol.AMQConstant; +import org.apache.qpid.server.model.State; import org.apache.qpid.server.model.port.AmqpPort; import org.apache.qpid.server.protocol.v0_8.AMQProtocolSession; import org.apache.qpid.server.protocol.v0_8.state.AMQState; import org.apache.qpid.server.protocol.v0_8.state.AMQStateManager; import org.apache.qpid.server.protocol.v0_8.state.StateAwareMethodListener; import org.apache.qpid.server.virtualhost.VirtualHostImpl; -import org.apache.qpid.server.virtualhost.VirtualHostState; public class ConnectionOpenMethodHandler implements StateAwareMethodListener<ConnectionOpenBody> { @@ -93,7 +93,7 @@ public class ConnectionOpenMethodHandler implements StateAwareMethodListener<Con throw body.getConnectionException(AMQConstant.ACCESS_REFUSED, e.getMessage()); } - if (virtualHost.getVirtualHostState() != VirtualHostState.ACTIVE) + if (virtualHost.getState() != State.ACTIVE) { throw body.getConnectionException(AMQConstant.CONNECTION_FORCED, "Virtual host '" + virtualHost.getName() + "' is not active"); } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java index 691c533565..666409048c 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java @@ -30,6 +30,8 @@ import java.util.Map; import javax.jms.JMSException; +import junit.framework.TestCase; + import org.apache.qpid.client.AMQConnection; import org.apache.qpid.server.model.Binding; import org.apache.qpid.server.model.Broker; @@ -399,4 +401,15 @@ public class Asserts assertBinding(queueName, queueName, exchange, binding); } + public static void assertActualAndDesiredState(final String expectedDesiredState, + final String expectedActualState, + final Map<String, Object> data) + { + String name = (String) data.get(ConfiguredObject.NAME); + TestCase.assertEquals("Object with name " + name + " has unexpected desired state", + expectedDesiredState, + data.get(ConfiguredObject.DESIRED_STATE)); + TestCase.assertEquals("Object with name " + name + " has unexpected actual state", + expectedActualState, data.get(ConfiguredObject.STATE)); + } } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostNodeRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostNodeRestTest.java index ee638f6776..214a961b00 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostNodeRestTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostNodeRestTest.java @@ -85,20 +85,20 @@ public class VirtualHostNodeRestTest extends QpidRestTestCase startBroker(); String restUrl = "virtualhostnode/" + TEST3_VIRTUALHOST; - assertVirtualHostStates(restUrl, "STOPPED", "STOPPED"); + assertActualAndDesireStates(restUrl, "STOPPED", "STOPPED"); } public void testMutateState() throws Exception { String restUrl = "virtualhostnode/" + TEST3_VIRTUALHOST; - assertVirtualHostStates(restUrl, "ACTIVE", "ACTIVE"); + assertActualAndDesireStates(restUrl, "ACTIVE", "ACTIVE"); mutateVirtualHostDesiredState(restUrl, "STOPPED"); - assertVirtualHostStates(restUrl, "STOPPED", "STOPPED"); + assertActualAndDesireStates(restUrl, "STOPPED", "STOPPED"); mutateVirtualHostDesiredState(restUrl, "ACTIVE"); - assertVirtualHostStates(restUrl, "ACTIVE", "ACTIVE"); + assertActualAndDesireStates(restUrl, "ACTIVE", "ACTIVE"); } public void testMutateAttributes() throws Exception @@ -137,16 +137,12 @@ public class VirtualHostNodeRestTest extends QpidRestTestCase assertEquals("Host should be deleted", 0, virtualHostNodes.size()); } - private void assertVirtualHostStates(final String restUrl, - final String expectedDesiredState, - final String expectedActualState) throws IOException + private void assertActualAndDesireStates(final String restUrl, + final String expectedDesiredState, + final String expectedActualState) throws IOException { Map<String, Object> virtualhostNode = getRestTestHelper().getJsonAsSingletonList(restUrl); - assertEquals("Virtualhostnode has unexpected desired state", - expectedDesiredState, - virtualhostNode.get(VirtualHostNode.DESIRED_STATE)); - assertEquals("Virtualhostnode has unexpected actual state", - expectedActualState, virtualhostNode.get(VirtualHostNode.STATE)); + Asserts.assertActualAndDesiredState(expectedDesiredState, expectedActualState, virtualhostNode); } private void mutateVirtualHostDesiredState(final String restUrl, final String newState) throws IOException diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostRestTest.java index 546898eb7b..9d2d79f555 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostRestTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostRestTest.java @@ -22,6 +22,7 @@ package org.apache.qpid.systest.rest; import java.io.File; import java.io.IOException; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -129,8 +130,9 @@ public class VirtualHostRestTest extends QpidRestTestCase public void testDeleteHost() throws Exception { - int responseCode = getRestTestHelper().submitRequest("virtualhost/" + TEST3_VIRTUALHOST + "/" + TEST3_VIRTUALHOST, "DELETE"); - assertEquals("Unexpected response code", 200, responseCode); + getRestTestHelper().submitRequest("virtualhost/" + TEST3_VIRTUALHOST + "/" + TEST3_VIRTUALHOST, + "DELETE", + HttpServletResponse.SC_OK); List<Map<String, Object>> hosts = getRestTestHelper().getJsonAsList("virtualhost/" + TEST3_VIRTUALHOST); assertEquals("Host should be deleted", 0, hosts.size()); @@ -138,36 +140,66 @@ public class VirtualHostRestTest extends QpidRestTestCase public void testDeleteDefaultHostFails() throws Exception { - int responseCode = getRestTestHelper().submitRequest("virtualhost/" + TEST1_VIRTUALHOST, "DELETE"); - assertEquals("Unexpected response code", 409, responseCode); - - restartBroker(); - - List<Map<String, Object>> hosts = getRestTestHelper().getJsonAsList("virtualhost/" + TEST1_VIRTUALHOST); - assertEquals("Host should be deleted", 1, hosts.size()); + getRestTestHelper().submitRequest("virtualhost/" + TEST1_VIRTUALHOST, "DELETE", HttpServletResponse.SC_CONFLICT); } - public void testUpdateActiveHost() throws Exception + public void testMutateAttributes() throws Exception { String hostToUpdate = TEST3_VIRTUALHOST; String restHostUrl = "virtualhost/" + hostToUpdate + "/" + hostToUpdate; + Map<String, Object> hostDetails = getRestTestHelper().getJsonAsSingletonList(restHostUrl); Asserts.assertVirtualHost(hostToUpdate, hostDetails); - Map<String, Object> newAttributes = new HashMap<String, Object>(); - newAttributes.put(VirtualHost.NAME, hostToUpdate); - newAttributes.put(VirtualHost.DESCRIPTION, "This is a virtual host"); - - int response = getRestTestHelper().submitRequest(restHostUrl, "PUT", newAttributes); - assertEquals("Unexpected response code", 200, response); - - restartBroker(); + Map<String, Object> newAttributes = Collections.<String, Object>singletonMap(VirtualHost.DESCRIPTION, "This is a virtual host"); + getRestTestHelper().submitRequest(restHostUrl, "PUT", newAttributes, HttpServletResponse.SC_OK); Map<String, Object> rereadHostDetails = getRestTestHelper().getJsonAsSingletonList(restHostUrl); Asserts.assertVirtualHost(hostToUpdate, rereadHostDetails); assertEquals("This is a virtual host", rereadHostDetails.get(VirtualHost.DESCRIPTION)); } + public void testMutateState() throws Exception + { + String hostToUpdate = TEST3_VIRTUALHOST; + String restHostUrl = "virtualhost/" + hostToUpdate + "/" + hostToUpdate; + + assertActualAndDesireStates(restHostUrl, "ACTIVE", "ACTIVE"); + + Map<String, Object> newAttributes = Collections.<String, Object>singletonMap(VirtualHost.DESIRED_STATE, "STOPPED"); + getRestTestHelper().submitRequest(restHostUrl, "PUT", newAttributes, HttpServletResponse.SC_OK); + + assertActualAndDesireStates(restHostUrl, "STOPPED", "STOPPED"); + + newAttributes = Collections.<String, Object>singletonMap(VirtualHost.DESIRED_STATE, "ACTIVE"); + getRestTestHelper().submitRequest(restHostUrl, "PUT", newAttributes, HttpServletResponse.SC_OK); + + assertActualAndDesireStates(restHostUrl, "ACTIVE", "ACTIVE"); + } + + public void testRecoverVirtualHostInDesiredStateStoppedWithDescription() throws Exception + { + String hostToUpdate = TEST3_VIRTUALHOST; + String restUrl = "virtualhost/" + hostToUpdate + "/" + hostToUpdate; + + assertActualAndDesireStates(restUrl, "ACTIVE", "ACTIVE"); + + Map<String, Object> newAttributes = new HashMap<>(); + newAttributes.put(VirtualHost.DESIRED_STATE, "STOPPED"); + newAttributes.put(VirtualHost.DESCRIPTION, "My description"); + + getRestTestHelper().submitRequest(restUrl, "PUT", newAttributes, HttpServletResponse.SC_OK); + + assertActualAndDesireStates(restUrl, "STOPPED", "STOPPED"); + + restartBroker(); + + Map<String, Object> rereadVirtualhost = getRestTestHelper().getJsonAsSingletonList(restUrl); + Asserts.assertActualAndDesiredState("STOPPED", "STOPPED", rereadVirtualhost); + + assertEquals("Unexpected description after restart", "My description", rereadVirtualhost.get(VirtualHost.DESCRIPTION)); + } + public void testPutCreateQueue() throws Exception { String queueName = getTestQueueName(); @@ -497,7 +529,7 @@ public class VirtualHostRestTest extends QpidRestTestCase JsonMappingException { String storePath = getStoreLocation(hostName); - int responseCode = tryCreateVirtualHost(hostName, storeType, storePath, configPath); + int responseCode = tryCreateVirtualHostNode(hostName, storeType, storePath, configPath); assertEquals("Unexpected response code", 201, responseCode); return storePath; } @@ -507,7 +539,10 @@ public class VirtualHostRestTest extends QpidRestTestCase return new File(TMP_FOLDER, "store-" + hostName + "-" + System.currentTimeMillis()).getAbsolutePath(); } - private int tryCreateVirtualHost(String hostName, String virtualHostNodeType, String storePath, String configPath) throws IOException, + private int tryCreateVirtualHostNode(String hostName, + String virtualHostNodeType, + String storePath, + String configPath) throws IOException, JsonGenerationException, JsonMappingException { @@ -542,4 +577,12 @@ public class VirtualHostRestTest extends QpidRestTestCase assertNull("Unexpected connections", hostDetails.get(VIRTUALHOST_CONNECTIONS_ATTRIBUTE)); } + private void assertActualAndDesireStates(final String restUrl, + final String expectedDesiredState, + final String expectedActualState) throws IOException + { + Map<String, Object> virtualhost = getRestTestHelper().getJsonAsSingletonList(restUrl); + Asserts.assertActualAndDesiredState(expectedDesiredState, expectedActualState, virtualhost); + } + } diff --git a/qpid/java/test-profiles/JavaTransientExcludes b/qpid/java/test-profiles/JavaTransientExcludes index 82d2375015..2252d0962f 100644 --- a/qpid/java/test-profiles/JavaTransientExcludes +++ b/qpid/java/test-profiles/JavaTransientExcludes @@ -53,7 +53,8 @@ org.apache.qpid.systest.management.jmx.QueueManagementTest#testCopyMessageBetwee org.apache.qpid.test.unit.client.MaxDeliveryCountTest#testWhenBrokerIsRestartedAfterEnqeuingMessages -org.apache.qpid.systest.rest.VirtualHostRestTest#testUpdateActiveHost +org.apache.qpid.systest.rest.VirtualHostRestTest#testRecoverVirtualHostInDesiredStateStoppedWithDescription + org.apache.qpid.systest.rest.VirtualHostNodeRestTest#testCreateAndDeleteNodeWithTestProfileStore org.apache.qpid.systest.rest.VirtualHostNodeRestTest#testCreateAndDeleteNodeWithJsonStore |
