[rhmessaging-commits] rhmessaging commits: r3681 - in store/trunk/java/bdbstore/src/tools/java/org/apache/qpid/server: store/berkeleydb and 1 other directories.

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Thu Oct 22 11:52:21 EDT 2009


Author: ritchiem
Date: 2009-10-22 11:52:21 -0400 (Thu, 22 Oct 2009)
New Revision: 3681

Added:
   store/trunk/java/bdbstore/src/tools/java/org/apache/qpid/server/util/
   store/trunk/java/bdbstore/src/tools/java/org/apache/qpid/server/util/NullApplicationRegistry.java
Modified:
   store/trunk/java/bdbstore/src/tools/java/org/apache/qpid/server/store/berkeleydb/BDBStoreUpgrade.java
Log:
Fixed a few NPE potentials and cleaned up the output of the StoreUpgrade script. Copied NAR from Apache as it has been made a Test only class.

Modified: store/trunk/java/bdbstore/src/tools/java/org/apache/qpid/server/store/berkeleydb/BDBStoreUpgrade.java
===================================================================
--- store/trunk/java/bdbstore/src/tools/java/org/apache/qpid/server/store/berkeleydb/BDBStoreUpgrade.java	2009-10-22 14:41:36 UTC (rev 3680)
+++ store/trunk/java/bdbstore/src/tools/java/org/apache/qpid/server/store/berkeleydb/BDBStoreUpgrade.java	2009-10-22 15:52:21 UTC (rev 3681)
@@ -139,18 +139,25 @@
         {
             if (_interactive)
             {
-                System.out.println("Upgrade destination: '" + toDir + "'");
+                if (toDir == null)
+                {
+                    System.out.println("Upgrading in place:" + fromDir);
+                }
+                else
+                {
+                    System.out.println("Upgrade destination: '" + toDir + "'");
+                }
 
                 if (userInteract("Upgrade destination exists do you wish to replace it?"))
                 {
                     if (!FileUtils.delete(_toDir, true))
                     {
-                        throw new IllegalArgumentException("Unable to remove upgrade destination '" + toDir + "'");
+                        throw new IllegalArgumentException("Unable to remove upgrade destination '" + _toDir + "'");
                     }
                 }
                 else
                 {
-                    throw new IllegalArgumentException("Upgrade destination '" + toDir + "' already exists. ");
+                    throw new IllegalArgumentException("Upgrade destination '" + _toDir + "' already exists. ");
                 }
             }
             else
@@ -159,19 +166,19 @@
                 {
                     if (!FileUtils.delete(_toDir, true))
                     {
-                        throw new IllegalArgumentException("Unable to remove upgrade destination '" + toDir + "'");
+                        throw new IllegalArgumentException("Unable to remove upgrade destination '" + _toDir + "'");
                     }
                 }
                 else
                 {
-                    throw new IllegalArgumentException("Upgrade destination '" + toDir + "' already exists. ");
+                    throw new IllegalArgumentException("Upgrade destination '" + _toDir + "' already exists. ");
                 }
             }
         }
 
         if (!_toDir.mkdirs())
         {
-            throw new IllegalArgumentException("Upgrade destination '" + toDir + "' could not be created. "
+            throw new IllegalArgumentException("Upgrade destination '" + _toDir + "' could not be created. "
                                                + "Ensure the path is correct and that the permissions are correct.");
         }
 
@@ -297,7 +304,7 @@
                 if (userInteract("Do you wish to perform a DB backup now? " +
                                  "(Store will be backed up to '" + backup.getName() + "')"))
                 {
-                    performDBBackup(fromDir, backupDir, force);
+                    performDBBackup(fromDir, backup, force);
                 }
                 else
                 {
@@ -682,23 +689,37 @@
         boolean interactive = !_commandLine.hasOption(OPTION_QUIET_SHORT);
         boolean force = _commandLine.hasOption(OPTION_FORCE_SHORT);
 
-        for (File store : stores)
+        try{
+            for (File store : stores)
+            {
+
+                // if toDir is null then we are upgrading inplace so we don't need
+                // to provide an upgraded toDir when upgrading multiple stores.
+                if (toDir == null ||
+                    // Check to see if we are upgrading a store specified in
+                    // fromDir or if the directories are nested.
+                    (stores.length > 0
+                     && stores[0].toString().length() == fromDir.length()))
+                {
+                    upgrade(store, toDir, backupDir, interactive, force);
+                }
+                else
+                {
+                    // Add the extra part of path from store to the toDir
+                    upgrade(store, toDir + File.separator + store.toString().substring(fromDir.length()), backupDir, interactive, force);
+                }
+            }
+        }
+        catch (RuntimeException re)
         {
-
-            // if toDir is null then we are upgrading inplace so we don't need
-            // to provide an upgraded toDir when upgrading multiple stores.
-            if (toDir == null ||
-                // Check to see if we are upgrading a store specified in
-                // fromDir or if the directories are nested.
-                (stores.length > 0
-                 && stores[0].toString().length() == fromDir.length()))
+            if (!re.getMessage().equals("User aborted process"))
             {
-                upgrade(store, toDir, backupDir, interactive, force);
+                re.printStackTrace();
+                _logger.error("Upgrade Failed: " + re.getMessage());
             }
             else
             {
-                // Add the extra part of path from store to the toDir
-                upgrade(store, toDir + File.separator + store.toString().substring(fromDir.length()), backupDir, interactive, force);
+                _logger.error("Upgrade stopped : User aborted");
             }
         }
 
@@ -748,10 +769,34 @@
         {
             _logger.error("Upgrade not started due to: " + iae.getMessage());
         }
+        catch (DatabaseException de)
+        {
+            if (de.getMessage().endsWith("Error: Unable to load BDBStore as version 1. Store on disk contains version 2 data."))
+            {
+                System.out.println("Store '" + fromDir + "' has already been upgraded to version 2.");
+            }
+            else
+            {
+                de.printStackTrace();
+                _logger.error("Upgrade Failed: " + de.getMessage());
+            }
+        }
+        catch (RuntimeException re)
+        {
+            if (!re.getMessage().equals("User aborted process"))
+            {
+                re.printStackTrace();
+                _logger.error("Upgrade Failed: " + re.getMessage());
+            }
+            else
+            {
+                throw re;
+            }
+        }
         catch (Exception e)
         {
             e.printStackTrace();
-            _logger.error("Upgrade Failed: " + e.getMessage());            
+            _logger.error("Upgrade Failed: " + e.getMessage());
         }
     }
 

Added: store/trunk/java/bdbstore/src/tools/java/org/apache/qpid/server/util/NullApplicationRegistry.java
===================================================================
--- store/trunk/java/bdbstore/src/tools/java/org/apache/qpid/server/util/NullApplicationRegistry.java	                        (rev 0)
+++ store/trunk/java/bdbstore/src/tools/java/org/apache/qpid/server/util/NullApplicationRegistry.java	2009-10-22 15:52:21 UTC (rev 3681)
@@ -0,0 +1,117 @@
+/*
+ *
+ * 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.util;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.qpid.server.configuration.ServerConfiguration;
+import org.apache.qpid.server.configuration.VirtualHostConfiguration;
+import org.apache.qpid.server.logging.NullRootMessageLogger;
+import org.apache.qpid.server.logging.actors.CurrentActor;
+import org.apache.qpid.server.logging.actors.BrokerActor;
+import org.apache.qpid.server.management.NoopManagedObjectRegistry;
+import org.apache.qpid.server.plugins.PluginManager;
+import org.apache.qpid.server.registry.ApplicationRegistry;
+import org.apache.qpid.server.security.access.ACLManager;
+import org.apache.qpid.server.security.access.plugins.AllowAll;
+import org.apache.qpid.server.security.auth.database.PropertiesPrincipalDatabaseManager;
+import org.apache.qpid.server.security.auth.manager.PrincipalDatabaseAuthenticationManager;
+import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Properties;
+import java.util.NoSuchElementException;
+
+public class NullApplicationRegistry extends ApplicationRegistry
+{
+    public NullApplicationRegistry() throws ConfigurationException
+    {
+        super(new ServerConfiguration(new PropertiesConfiguration()));
+    }
+
+    public void initialise(int instanceID) throws Exception
+    {
+        _logger.info("Initialising NullApplicationRegistry");
+
+        _rootMessageLogger = new NullRootMessageLogger();
+
+        //We should use a Test Actor Here not the Broker Actor
+        CurrentActor.set(new BrokerActor(_rootMessageLogger));
+
+        _configuration.setHousekeepingExpiredMessageCheckPeriod(200);
+
+        Properties users = new Properties();
+
+        users.put("guest", "guest");
+
+        _databaseManager = new PropertiesPrincipalDatabaseManager("default", users);
+
+        _accessManager = new ACLManager(_configuration.getSecurityConfiguration(), _pluginManager, AllowAll.FACTORY);
+
+        _authenticationManager = new PrincipalDatabaseAuthenticationManager(null, null);
+
+        _managedObjectRegistry = new NoopManagedObjectRegistry();
+        _virtualHostRegistry = new VirtualHostRegistry(this);
+        PropertiesConfiguration vhostProps = new PropertiesConfiguration();
+        VirtualHostConfiguration hostConfig = new VirtualHostConfiguration("test", vhostProps);
+        VirtualHost dummyHost = new VirtualHost(hostConfig);
+        _virtualHostRegistry.registerVirtualHost(dummyHost);
+        _virtualHostRegistry.setDefaultVirtualHostName("test");
+        _pluginManager = new PluginManager("");
+        _startup = new Exception("NAR");
+
+    }
+       private Exception _startup;
+    public Collection<String> getVirtualHostNames()
+    {
+        String[] hosts = {"test"};
+        return Arrays.asList(hosts);
+    }
+
+    @Override
+    public void close() throws Exception
+    {
+        CurrentActor.set(new BrokerActor(_rootMessageLogger));
+
+        try
+        {
+            super.close();                                                  
+        }
+        finally
+        {
+            try
+            {
+                CurrentActor.remove();
+            }
+            catch (NoSuchElementException npe)
+            {
+                _startup.printStackTrace();
+                _startup.printStackTrace(System.err);
+            }
+
+        }
+    }
+}
+
+
+



More information about the rhmessaging-commits mailing list