summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Gemmell <robbie@apache.org>2013-03-10 22:33:43 +0000
committerRobert Gemmell <robbie@apache.org>2013-03-10 22:33:43 +0000
commit54bfebd60800c46458072769555d86402fd830db (patch)
tree10d1a78ff2fe712888d6b2eb8c786cbfe686a9a5
parent66992683e1310209c24435c8ff1d0ced0e94cd5a (diff)
downloadqpid-python-54bfebd60800c46458072769555d86402fd830db.tar.gz
QPID-4596: remove manipulation of store files, and vhost store type etc.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1454943 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java159
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostRestTest.java69
2 files changed, 1 insertions, 227 deletions
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java
index eaf187c95c..40af67f211 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java
@@ -1054,163 +1054,6 @@ public final class VirtualHostAdapter extends AbstractAdapter implements Virtual
@Override
protected void changeAttributes(Map<String, Object> attributes)
{
- if (State.ACTIVE.equals(getActualState()))
- {
- throw new IllegalStateException("Cannot change host attributes on active virtual host. This operation is only supported in management mode.");
- }
- Map<String, Object> newAttributes = MapValueConverter.convert(attributes, ATTRIBUTE_TYPES);
- validateConfigurationAndCopyStoreIntoNewLocationIfRequired(newAttributes);
- super.changeAttributes(newAttributes);
- }
-
- private void validateConfigurationAndCopyStoreIntoNewLocationIfRequired(Map<String, Object> newAttributes)
- {
- String name = (String)getAttribute(NAME);
- String configPath = (String)getAttribute(CONFIG_PATH);
- String storePath = (String)getAttribute(STORE_PATH);
- String storeType = (String)getAttribute(STORE_TYPE);
-
- String newConfigPath = (String)newAttributes.get(CONFIG_PATH);
- String newStorePath = (String)newAttributes.get(STORE_PATH);
- String newStoreType = (String)newAttributes.get(STORE_TYPE);
-
- String newName = (String)newAttributes.get(NAME);
- if (newName != null && !newName.equals(name))
- {
- if (name.equals(_broker.getAttribute(Broker.DEFAULT_VIRTUAL_HOST)))
- {
- throw new IntegrityViolationException("Cannot rename virtual host '" + name + "' as it is set as a default." +
- " Change the broker default virtual host before renaming");
- }
- }
- if (newConfigPath != null)
- {
- // try to open new configuration xml and extract information about message store
- try
- {
- Map<String, String> storeDetails = getStoreDetailsFromVirtualHostConfigXml(name, configPath);
- newStorePath = storeDetails.get(STORE_PATH);
- newStoreType = storeDetails.get(STORE_TYPE);
- }
- catch (Exception e)
- {
- throw new IllegalConfigurationException("Cannot open new virtual host configuration at " + newConfigPath, e);
- }
- newAttributes.put(STORE_PATH, null);
- newAttributes.put(STORE_TYPE, null);
- }
- else
- {
- newAttributes.put(CONFIG_PATH, null);
- }
-
- if (configPath != null )
- {
- // try to identify store type and location in order to copy old store into a new location
- try
- {
- Map<String, String> storeDetails = getStoreDetailsFromVirtualHostConfigXml(name, configPath);
- storePath = storeDetails.get(STORE_PATH);
- storeType = storeDetails.get(STORE_TYPE);
- }
- catch (Exception e)
- {
- // old configuration might be broken
- LOGGER.warn("Cannot open virtual host cofiguration at " + configPath + ". Ignoring old broken configuration.", e);
- }
- }
-
- if (storeType != null && storePath != null && newStoreType != null)
- {
- File oldStoreLocation = new File(storePath);
- if (oldStoreLocation.exists())
- {
- if (newStoreType.equals(newStoreType))
- {
- File newStoreLocation = new File(newStorePath);
- if (!oldStoreLocation.equals(newStoreLocation))
- {
- if (LOGGER.isInfoEnabled())
- {
- LOGGER.info("Copying store for virtual host '" + name + "' from '"
- + oldStoreLocation.getAbsolutePath() + "' into '" + newStoreLocation.getAbsolutePath() + "'");
- }
- copyStoreFiles(oldStoreLocation, newStoreLocation);
- }
- }
- else
- {
- LOGGER.warn("Requested a message store of different type ("
- + newStoreType + ") than existing store (" + storeType
- + "). At the moment, copying of data is not supported for stores of different types."
- + " As result an empty new store will be created and old data will be lost.");
- }
- }
- else
- {
- if (LOGGER.isInfoEnabled())
- {
- LOGGER.info("Virtual host '" + name + "' store does not exists at " + oldStoreLocation.getAbsolutePath() + ". Skipping srore copying...");
- }
- }
- }
- }
-
- private void copyStoreFiles(File oldStoreLocation, File newStoreLocation)
- {
- if (!newStoreLocation.exists() && !newStoreLocation.getParentFile().exists())
- {
- newStoreLocation.getParentFile().mkdirs();
- }
- try
- {
- if (oldStoreLocation.isFile())
- {
- if (!newStoreLocation.exists())
- {
- newStoreLocation.createNewFile();
- }
- FileUtils.copy(oldStoreLocation, newStoreLocation);
- }
- else
- {
- if (!newStoreLocation.exists())
- {
- newStoreLocation.mkdir();
- }
- FileUtils.copyRecursive(oldStoreLocation, newStoreLocation);
- }
- }
- catch (Exception e)
- {
- throw new IllegalConfigurationException("Cannot copy store data into a new location at " + newStoreLocation, e);
- }
- }
-
- private Map<String, String> getStoreDetailsFromVirtualHostConfigXml(String name, String configPath) throws Exception
- {
- Map<String, String> storeDetails = new HashMap<String, String>();
- VirtualHostConfiguration configuration = new VirtualHostConfiguration(name, new File(configPath) , _broker);
- String storePath = configuration.getStoreConfiguration().getString("environment-path");
- String storeType = configuration.getStoreConfiguration().getString("type");
- if (storeType == null)
- {
- String storeClass = configuration.getStoreConfiguration().getString("class");
- if (storeClass != null)
- {
- final Class<?> clazz = Class.forName(storeClass);
- final Object o = clazz.newInstance();
-
- if (o instanceof MessageStore)
- {
- MessageStore ms = (MessageStore)o;
- storeType = ms.getStoreType();
- }
- }
- }
-
- storeDetails.put(STORE_PATH, storePath);
- storeDetails.put(STORE_TYPE, storeType);
- return storeDetails;
+ throw new UnsupportedOperationException("Changing attributes on virtualhosts is not supported.");
}
}
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 c5dfb84d40..c65f8bbd08 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
@@ -206,75 +206,6 @@ public class VirtualHostRestTest extends QpidRestTestCase
assertEquals("Unexpected config path", configPath, hostDetails.get(VirtualHost.CONFIG_PATH));
}
- public void testUpdateInManagementMode() throws Exception
- {
- String hostToUpdate = TEST3_VIRTUALHOST;
- Map<String, Object> hostDetails = getRestTestHelper().getJsonAsSingletonList("/rest/virtualhost/" + hostToUpdate);
- Asserts.assertVirtualHost(hostToUpdate, hostDetails);
- String configPath = (String)hostDetails.get(VirtualHost.CONFIG_PATH);
- String storeType = (String)hostDetails.get(VirtualHost.STORE_TYPE);
- assertNotNull("Unexpected host configuration", configPath);
- assertNotNull("Unexpected store type", storeType);
-
- String queueName = getTestQueueName();
- if (isBrokerStorePersistent())
- {
- String storePath = (String)hostDetails.get(VirtualHost.STORE_PATH);
- assertNotNull("Unexpected store path", storePath);
-
- // add a durable queue to the host
- // in order to test whether host store is copied into a new location
- Map<String, Object> queueData = new HashMap<String, Object>();
- queueData.put(Queue.NAME, queueName);
- queueData.put(Queue.DURABLE, Boolean.TRUE);
- int response = getRestTestHelper().submitRequest("/rest/queue/" + hostToUpdate + "/" + queueName, "PUT", queueData);
- assertEquals("Unexpected response code for queue creation", 201, response);
- }
-
- // stop broker as it is running not in management mode
- stopBroker(0);
-
- // start broker in management mode
- startBroker(0, true);
-
- String newStoreType = getTestProfileMessageStoreType();
- String newStorePath = getStoreLocation(hostToUpdate);
- Map<String, Object> newAttributes = new HashMap<String, Object>();
- newAttributes.put(VirtualHost.NAME, hostToUpdate);
- newAttributes.put(VirtualHost.STORE_TYPE, newStoreType);
- newAttributes.put(VirtualHost.STORE_PATH, newStorePath);
- newAttributes.put(VirtualHost.CONFIG_PATH, null);
-
- try
- {
- int response = getRestTestHelper().submitRequest("/rest/virtualhost/" + hostToUpdate, "PUT", newAttributes);
- assertEquals("Unexpected response code for virtual host update", 200, response);
-
- restartBroker();
-
- hostDetails = getRestTestHelper().getJsonAsSingletonList("/rest/virtualhost/" + hostToUpdate);
- Asserts.assertVirtualHost(hostToUpdate, hostDetails);
- assertEquals("Unexpected config type", newStoreType, hostDetails.get(VirtualHost.STORE_TYPE));
-
- if (isBrokerStorePersistent())
- {
- assertEquals("Unexpected config path", newStorePath, hostDetails.get(VirtualHost.STORE_PATH));
-
- // the virtual host store should be copied into a new location
- // check existence of the queue
- List<Map<String, Object>> queues = getRestTestHelper().getJsonAsList("/rest/queue/" + hostToUpdate + "/" + queueName);
- assertEquals("Queue is not found. Looks like message store was not copied", 1, queues.size());
- }
- }
- finally
- {
- if (newStorePath != null)
- {
- FileUtils.delete(new File(newStorePath), true);
- }
- }
- }
-
public void testPutCreateQueue() throws Exception
{
String queueName = getTestQueueName();