You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ro...@apache.org on 2013/03/10 23:33:44 UTC

svn commit: r1454943 - in /qpid/trunk/qpid/java: broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostRestTest.java

Author: robbie
Date: Sun Mar 10 22:33:43 2013
New Revision: 1454943

URL: http://svn.apache.org/r1454943
Log:
QPID-4596: remove manipulation of store files, and vhost store type etc.

Modified:
    qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java
    qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostRestTest.java

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=1454943&r1=1454942&r2=1454943&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 Sun Mar 10 22:33:43 2013
@@ -1054,163 +1054,6 @@ public final class VirtualHostAdapter ex
     @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.");
     }
 }

Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostRestTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostRestTest.java?rev=1454943&r1=1454942&r2=1454943&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostRestTest.java (original)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostRestTest.java Sun Mar 10 22:33:43 2013
@@ -206,75 +206,6 @@ public class VirtualHostRestTest extends
         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();



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org