geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r395030 - in /geronimo/branches/1.1/modules: kernel/src/java/org/apache/geronimo/kernel/config/ kernel/src/test/org/apache/geronimo/kernel/config/ system/src/test/org/apache/geronimo/system/configuration/
Date Tue, 18 Apr 2006 20:31:50 GMT
Author: dain
Date: Tue Apr 18 13:31:48 2006
New Revision: 395030

URL: http://svn.apache.org/viewcvs?rev=395030&view=rev
Log:
Added reload command to ConfigurationManager
Reload optionally supports loading a new version of the cofiguration and will attemp to rollback
the existing version in the case of a failure

Modified:
    geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationManager.java
    geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationModel.java
    geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationStatus.java
    geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/LifecycleException.java
    geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/SimpleConfigurationManager.java
    geronimo/branches/1.1/modules/kernel/src/test/org/apache/geronimo/kernel/config/ConfigurationManagerTest.java
    geronimo/branches/1.1/modules/system/src/test/org/apache/geronimo/system/configuration/ConfigInstallerTest.java

Modified: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationManager.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationManager.java?rev=395030&r1=395029&r2=395030&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationManager.java
(original)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationManager.java
Tue Apr 18 13:31:48 2006
@@ -19,6 +19,7 @@
 import java.io.IOException;
 import java.util.List;
 import org.apache.geronimo.kernel.repository.Artifact;
+import org.apache.geronimo.kernel.repository.Version;
 import org.apache.geronimo.gbean.AbstractName;
 
 /**
@@ -230,6 +231,77 @@
      * @throws LifecycleException if there is a problem loading the configuration
      */
     LifecycleResults restartConfiguration(Artifact configurationId, LifecycleMonitor monitor)
throws NoSuchConfigException, LifecycleException;
+
+    /**
+     * Reloads the specified configuration and all configurations that have a dependency
on the
+     * specified configuration
+     *
+     * @param configurationId the configuration identifier
+     * @return the results of the operation
+     * @throws NoSuchConfigException if the configuration is not loaded
+     * @throws LifecycleException if there is a problem loading the configuration
+     */
+    LifecycleResults reloadConfiguration(Artifact configurationId) throws NoSuchConfigException,
LifecycleException;
+
+    /**
+     * Reloads the specified configuration and all configurations that have a dependency
on the
+     * specified configuration
+     *
+     * @param configurationId the configuration identifier
+     * @param monitor the monitor that should receive events as the operation is carried
out
+     * @return the results of the operation
+     * @throws NoSuchConfigException if the configuration is not loaded
+     * @throws LifecycleException if there is a problem loading the configuration
+     */
+    LifecycleResults reloadConfiguration(Artifact configurationId, LifecycleMonitor monitor)
throws NoSuchConfigException, LifecycleException;
+
+    /**
+     * Reloads the specified configuration and all configurations that have a dependency
on the
+     * specified configuration
+     *
+     * @param configurationId the configuration identifier
+     * @param version new version to load from the config store
+     * @return the results of the operation
+     * @throws NoSuchConfigException if the configuration is not loaded
+     * @throws LifecycleException if there is a problem loading the configuration
+     */
+    LifecycleResults reloadConfiguration(Artifact configurationId, Version version) throws
NoSuchConfigException, LifecycleException;
+
+    /**
+     * Reloads the specified configuration and all configurations that have a dependency
on the
+     * specified configuration
+     *
+     * @param configurationId the configuration identifier
+     * @param monitor the monitor that should receive events as the operation is carried
out
+     * @param version new version to load from the config store
+     * @return the results of the operation
+     * @throws NoSuchConfigException if the configuration is not loaded
+     * @throws LifecycleException if there is a problem loading the configuration
+     */
+    LifecycleResults reloadConfiguration(Artifact configurationId, Version version, LifecycleMonitor
monitor) throws NoSuchConfigException, LifecycleException;
+
+    /**
+     * Reloads the specified configuration and all configurations that have a dependency
on the
+     * specified configuration
+     *
+     * @param configurationData the configuration to load
+     * @return the results of the operation
+     * @throws NoSuchConfigException if the configuration is not loaded
+     * @throws LifecycleException if there is a problem loading the configuration
+     */
+    LifecycleResults reloadConfiguration(ConfigurationData configurationData) throws NoSuchConfigException,
LifecycleException;
+
+    /**
+     * Reloads the specified configuration and all configurations that have a dependency
on the
+     * specified configuration
+     *
+     * @param configurationData the configuration to load
+     * @param monitor the monitor that should receive events as the operation is carried
out
+     * @return the results of the operation
+     * @throws NoSuchConfigException if the configuration is not loaded
+     * @throws LifecycleException if there is a problem loading the configuration
+     */
+    LifecycleResults reloadConfiguration(ConfigurationData configurationData, LifecycleMonitor
monitor) throws NoSuchConfigException, LifecycleException;
 
     /**
      * Unstalls the specified configuration from the server.   This operation can not be
reversed.

Modified: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationModel.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationModel.java?rev=395030&r1=395029&r2=395030&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationModel.java
(original)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationModel.java
Tue Apr 18 13:31:48 2006
@@ -121,11 +121,23 @@
     }
 
     public LinkedHashSet unload(Artifact configurationId) throws NoSuchConfigException {
+        return unload(configurationId, true);
+    }
+
+    public LinkedHashSet unload(Artifact configurationId, boolean gc) throws NoSuchConfigException
{
         ConfigurationStatus configurationStatus = (ConfigurationStatus) configurations.get(configurationId);
         if (configurationStatus == null) {
             throw new NoSuchConfigException(configurationId);
         }
-        return configurationStatus.unload();
+        return configurationStatus.unload(gc);
+    }
+
+    public LinkedHashSet reload(Artifact configurationId) throws NoSuchConfigException {
+        ConfigurationStatus configurationStatus = (ConfigurationStatus) configurations.get(configurationId);
+        if (configurationStatus == null) {
+            throw new NoSuchConfigException(configurationId);
+        }
+        return configurationStatus.reload();
     }
 
     public Set getLoaded() {

Modified: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationStatus.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationStatus.java?rev=395030&r1=395029&r2=395030&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationStatus.java
(original)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationStatus.java
Tue Apr 18 13:31:48 2006
@@ -264,13 +264,13 @@
         restartList.add(this);
     }
 
-    public LinkedHashSet unload() {
+    public LinkedHashSet unload(boolean gc) {
         if (!loaded) {
             throw new IllegalStateException(configurationId + " is not loaded");
         }
 
         LinkedHashSet unloadStatuses = new LinkedHashSet();
-        unloadInternal(unloadStatuses);
+        unloadInternal(unloadStatuses, gc);
 
         LinkedHashSet unloadIds = new LinkedHashSet(unloadStatuses.size());
         for (Iterator iterator = unloadStatuses.iterator(); iterator.hasNext();) {
@@ -281,7 +281,7 @@
         return unloadIds;
     }
 
-    private void unloadInternal(LinkedHashSet unloadList) {
+    private void unloadInternal(LinkedHashSet unloadList, boolean gc) {
         // if we aren't loaded, there is nothing to do
         if (!loaded) {
             return;
@@ -291,7 +291,7 @@
         for (Iterator iterator = loadChildren.iterator(); iterator.hasNext();) {
             ConfigurationStatus child = (ConfigurationStatus) iterator.next();
             if (child.isLoaded()) {
-                child.unloadInternal(unloadList);
+                child.unloadInternal(unloadList, gc);
             }
         }
 
@@ -303,14 +303,53 @@
             userLoaded = false;
             unloadList.add(this);
 
-            // visit all non-user loaded parents
-            for (Iterator iterator = loadParents.iterator(); iterator.hasNext();) {
-                ConfigurationStatus parent = (ConfigurationStatus) iterator.next();
-                if (!parent.isUserLoaded() && unloadList.containsAll(parent.loadChildren))
{
-                    parent.unloadInternal(unloadList);
+            // if we are garbage collecting, visit parents
+            if (gc) {
+                // visit all non-user loaded parents
+                for (Iterator iterator = loadParents.iterator(); iterator.hasNext();) {
+                    ConfigurationStatus parent = (ConfigurationStatus) iterator.next();
+                    if (!parent.isUserLoaded() && unloadList.containsAll(parent.loadChildren))
{
+                        parent.unloadInternal(unloadList, gc);
+                    }
                 }
             }
         }
+    }
+
+    public LinkedHashSet reload() {
+        if (!loaded) {
+            throw new IllegalStateException(configurationId + " is not loaded");
+        }
+
+        LinkedHashSet reloadStatuses = new LinkedHashSet();
+        reloadInternal(reloadStatuses);
+
+        LinkedHashSet reloadIds = new LinkedHashSet(reloadStatuses.size());
+        for (Iterator iterator = reloadStatuses.iterator(); iterator.hasNext();) {
+            ConfigurationStatus configurationStatus = (ConfigurationStatus) iterator.next();
+            reloadIds.add(configurationStatus.configurationId);
+        }
+
+        userLoaded = true;
+        return reloadIds;
+    }
+
+    private void reloadInternal(LinkedHashSet reloadList) {
+        // if we aren't loaded, there is nothing to do
+        if (!loaded) {
+            return;
+        }
+
+        // visit all children
+        for (Iterator iterator = loadChildren.iterator(); iterator.hasNext();) {
+            ConfigurationStatus child = (ConfigurationStatus) iterator.next();
+            if (child.isLoaded()) {
+                child.reloadInternal(reloadList);
+            }
+        }
+
+        // add this node to the reload list
+        reloadList.add(this);
     }
 
     public String toString() {

Modified: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/LifecycleException.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/LifecycleException.java?rev=395030&r1=395029&r2=395030&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/LifecycleException.java
(original)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/LifecycleException.java
Tue Apr 18 13:31:48 2006
@@ -29,7 +29,7 @@
     public LifecycleException(String command, Artifact configurationId, LifecycleResults
lifecycleResults) {
         this(command, configurationId, lifecycleResults, lifecycleResults.getFailedCause(configurationId));
     }
-    
+
     public LifecycleException(String command, Artifact configurationId, LifecycleResults
lifecycleResults, Throwable cause) {
         super(command + " of " + configurationId + " failed", cause);
         this.command = command;
@@ -45,7 +45,7 @@
         return configurationId;
     }
 
-    public LifecycleResults getCommandResults() {
+    public LifecycleResults getLifecycleResults() {
         return lifecycleResults;
     }
 }

Modified: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/SimpleConfigurationManager.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/SimpleConfigurationManager.java?rev=395030&r1=395029&r2=395030&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/SimpleConfigurationManager.java
(original)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/SimpleConfigurationManager.java
Tue Apr 18 13:31:48 2006
@@ -38,6 +38,7 @@
 import org.apache.geronimo.kernel.repository.Environment;
 import org.apache.geronimo.kernel.repository.ImportType;
 import org.apache.geronimo.kernel.repository.MissingDependencyException;
+import org.apache.geronimo.kernel.repository.Version;
 
 /**
  * @version $Rev$ $Date$
@@ -569,20 +570,6 @@
         return results;
     }
 
-    private static void addConfigurationsToMonitor(LifecycleMonitor monitor, LinkedHashSet
configurations) {
-        for (Iterator iterator = configurations.iterator(); iterator.hasNext();) {
-            Artifact configurationId = (Artifact) iterator.next();
-            monitor.addConfiguration(configurationId);
-        }
-    }
-
-    private static LinkedHashSet reverse(LinkedHashSet restartList) {
-        ArrayList reverseRestartList = new ArrayList(restartList);
-        Collections.reverse(reverseRestartList);
-        restartList = new LinkedHashSet(reverseRestartList);
-        return restartList;
-    }
-
     public synchronized LifecycleResults unloadConfiguration(Artifact id) throws NoSuchConfigException
{
         return unloadConfiguration(id, NullLifecycleMonitor.INSTANCE);
     }
@@ -631,6 +618,233 @@
         }
     }
 
+    public synchronized LifecycleResults reloadConfiguration(Artifact id) throws NoSuchConfigException,
LifecycleException {
+        return reloadConfiguration(id, NullLifecycleMonitor.INSTANCE);
+    }
+
+    public synchronized LifecycleResults reloadConfiguration(Artifact id, LifecycleMonitor
monitor) throws NoSuchConfigException, LifecycleException {
+        return reloadConfiguration(id, id.getVersion(), monitor);
+    }
+
+    public synchronized LifecycleResults reloadConfiguration(Artifact id, Version version)
throws NoSuchConfigException, LifecycleException {
+        return reloadConfiguration(id, id.getVersion(), NullLifecycleMonitor.INSTANCE);
+    }
+
+    public synchronized LifecycleResults reloadConfiguration(Artifact id, Version version,
LifecycleMonitor monitor) throws NoSuchConfigException, LifecycleException {
+        Configuration configuration = getConfiguration(id);
+        if (configuration == null) {
+            throw new NoSuchConfigException(id);
+        }
+        ConfigurationData existingConfigurationData = configuration.getConfigurationData();
+        UnloadedConfiguration existingUnloadedConfiguration = new UnloadedConfiguration(existingConfigurationData,
getResolvedParentIds(configuration));
+
+        Artifact newId = new Artifact(id.getGroupId(), id.getArtifactId(), version, id.getType());
+
+        // reload the ConfigurationData from a store
+        ConfigurationData configurationData = null;
+        try {
+            configurationData = loadConfigurationData(newId, monitor);
+        } catch (Exception e) {
+            LifecycleResults results = new LifecycleResults();
+            results.addFailed(id, e);
+            monitor.finished();
+            throw new LifecycleException("reload", id, results);
+        }
+
+        return reloadConfiguration(existingUnloadedConfiguration, configurationData, monitor);
+    }
+
+    public LifecycleResults reloadConfiguration(ConfigurationData configurationData) throws
LifecycleException, NoSuchConfigException {
+        return reloadConfiguration(configurationData, NullLifecycleMonitor.INSTANCE);
+    }
+
+    public LifecycleResults reloadConfiguration(ConfigurationData configurationData, LifecycleMonitor
monitor) throws LifecycleException, NoSuchConfigException {
+        Configuration configuration = getConfiguration(configurationData.getId());
+        if (configuration == null) {
+            throw new NoSuchConfigException(configurationData.getId());
+        }
+        ConfigurationData existingConfigurationData = configuration.getConfigurationData();
+        UnloadedConfiguration existingUnloadedConfiguration = new UnloadedConfiguration(existingConfigurationData,
getResolvedParentIds(configuration));
+        return reloadConfiguration(existingUnloadedConfiguration, configurationData, monitor);
+    }
+
+    private LifecycleResults reloadConfiguration(UnloadedConfiguration existingUnloadedConfiguration,
ConfigurationData newConfigurationData, LifecycleMonitor monitor) throws LifecycleException,
NoSuchConfigException {
+        LifecycleResults results = new LifecycleResults();
+
+        // recursively load configurations from the reloaded child to the parents
+        // this will catch any new parents
+        LinkedHashMap unloadedConfigurations = new LinkedHashMap();
+        try {
+            loadDepthFirst(newConfigurationData, unloadedConfigurations, monitor);
+        } catch (Exception e) {
+            results.addFailed(newConfigurationData.getId(), e);
+            monitor.finished();
+            throw new LifecycleException("load", newConfigurationData.getId(), results);
+        }
+
+        // get a list of the started configuration
+        Set started = configurationModel.getStarted();
+
+        // add all of the child configurations that we will need to reload to the unloaded
map
+        //   note: we are iterating in reverse order
+        for (Iterator iterator = reverse(configurationModel.reload(newConfigurationData.getId())).iterator();
iterator.hasNext();) {
+            Artifact configurationId = (Artifact) iterator.next();
+            if (unloadedConfigurations.containsKey(configurationId)) {
+                continue;
+            }
+
+            Configuration configuration = getConfiguration(configurationId);
+            ConfigurationData data = configuration.getConfigurationData();
+            LinkedHashSet resolvedParentIds = getResolvedParentIds(configuration);
+            unloadedConfigurations.put(configurationId, new UnloadedConfiguration(data, resolvedParentIds));
+            monitor.addConfiguration(configurationId);
+        }
+
+        // unload the configuations
+        //   note: we are iterating in reverse order
+        for (Iterator iterator = reverse(unloadedConfigurations).keySet().iterator(); iterator.hasNext();)
{
+            Artifact configurationId = (Artifact) iterator.next();
+            Configuration configuration = getConfiguration(configurationId);
+
+            // first make sure it is stopped
+            if (started.contains(configurationId)) {
+                monitor.stopping(configurationId);
+                stop(configuration);
+                monitor.succeeded(configurationId);
+                results.addRestarted(configurationId);
+            } else {
+                // call stop just to be sure the beans aren't running
+                stop(configuration);
+            }
+
+            // now unload it
+            monitor.unloading(configurationId);
+            unload(configuration);
+            monitor.succeeded(configurationId);
+        }
+
+        // reload the configurations
+        Map actuallyLoaded = new LinkedHashMap(unloadedConfigurations.size());
+        for (Iterator iterator = unloadedConfigurations.entrySet().iterator(); iterator.hasNext();)
{
+            Map.Entry entry = (Map.Entry) iterator.next();
+            Artifact configurationId = (Artifact) entry.getKey();
+            UnloadedConfiguration unloadedConfiguration = (UnloadedConfiguration) entry.getValue();
+
+            // skip the configurations that have alredy failed or were stopped
+            if (results.wasFailed(configurationId) || results.wasStopped(configurationId))
{
+                continue;
+            }
+
+            // try to load the configuation
+            Configuration configuration = null;
+            try {
+                monitor.loading(configurationId);
+                configuration = load(unloadedConfiguration.getConfigurationData(), unloadedConfiguration.getResolvedParentIds(),
actuallyLoaded);
+                monitor.succeeded(configurationId);
+
+                results.addReloaded(configurationId);
+
+                // if the configuration was started before restart it
+                if (started.contains(configurationId)) {
+                    monitor.starting(configurationId);
+                    start(configuration);
+                    monitor.succeeded(configurationId);
+                    results.addRestarted(configurationId);
+                }
+
+                actuallyLoaded.put(configurationId, configuration);
+                configurations.put(configurationId, configuration);
+            } catch (Exception e) {
+                // the configuraiton failed to restart
+                results.addFailed(configurationId, e);
+                monitor.failed(configurationId, e);
+
+                // unload the configuration if it was loaded and failed in start
+                if (configuration != null) {
+                    unload(configuration);
+                }
+
+                // if this is root configuration, attempt to reinstate the original configuration
+                boolean reinstatedExisting = false;
+                if (configurationId.equals(newConfigurationData.getId())) {
+                    configuration = null;
+                    try {
+                        configuration = load(existingUnloadedConfiguration.getConfigurationData(),
+                                existingUnloadedConfiguration.getResolvedParentIds(),
+                                actuallyLoaded);
+
+                        results.addReloaded(configurationId);
+
+                        // if the configuration was started before restart it
+                        if (started.contains(configurationId)) {
+                            start(configuration);
+                            results.addRestarted(configurationId);
+                        }
+
+                        actuallyLoaded.put(configurationId, configuration);
+                        configurations.put(configurationId, configuration);
+
+                        reinstatedExisting = true;
+                    } catch (Exception ignored) {
+                        // we tried our best
+                        if (configuration != null) {
+                            unload(configuration);
+                        }
+                    }
+                }
+
+                if (!reinstatedExisting) {
+                    // officially unload the configuration in the model (without gc)
+                    LinkedHashSet unloadList = configurationModel.unload(configurationId,
false);
+                    configurationModel.removeConfiguration(configurationId);
+
+                    // all of the configurations to be unloaded must be in our unloaded list,
or the model is corrupt
+                    if (!unloadedConfigurations.keySet().containsAll(unloadList)) {
+                        throw new AssertionError("Configuration data model is corrupt.  
You must restart your server.");
+                    }
+
+                    // add the children of the failed configuration to the results as unloaded
+                    for (Iterator iterator1 = unloadList.iterator(); iterator1.hasNext();)
{
+                        Artifact failedId = (Artifact) iterator1.next();
+
+                        // if any of the failed configuration is in the reloaded set, the
model is
+                        // corrupt because we loaded a child before a parent
+                        if (results.wasLoaded(failedId)) {
+                            throw new AssertionError("Configuration data model is corrupt.
  You must restart your server.");
+                        }
+
+                        if (!results.wasFailed(failedId)) {
+                            results.addUnloaded(failedId);
+                            if (started.contains(configurationId)) {
+                                results.addStopped(failedId);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+        monitor.finished();
+        if (results.wasFailed(newConfigurationData.getId()) || !results.wasReloaded(newConfigurationData.getId()))
{
+            throw new LifecycleException("reload", newConfigurationData.getId(), results);
+        }
+
+        return results;
+    }
+
+    private static LinkedHashSet getResolvedParentIds(Configuration configuration) {
+        LinkedHashSet resolvedParentIds = new LinkedHashSet();
+        for (Iterator iterator1 = configuration.getClassParents().iterator(); iterator1.hasNext();)
{
+            Configuration classParent = (Configuration) iterator1.next();
+            resolvedParentIds.add(classParent.getId());
+        }
+        for (Iterator iterator1 = configuration.getServiceParents().iterator(); iterator1.hasNext();)
{
+            Configuration serviceParent = (Configuration) iterator1.next();
+            resolvedParentIds.add(serviceParent.getId());
+        }
+        return resolvedParentIds;
+    }
+
     public synchronized void uninstallConfiguration(Artifact configurationId) throws IOException,
NoSuchConfigException {
         if (configurations.containsKey(configurationId)) {
             stopConfiguration(configurationId);
@@ -649,5 +863,33 @@
 
     private List getStoreList() {
         return new ArrayList(stores);
+    }
+
+    private static void addConfigurationsToMonitor(LifecycleMonitor monitor, LinkedHashSet
configurations) {
+        for (Iterator iterator = configurations.iterator(); iterator.hasNext();) {
+            Artifact configurationId = (Artifact) iterator.next();
+            monitor.addConfiguration(configurationId);
+        }
+    }
+
+    private static LinkedHashSet reverse(LinkedHashSet set) {
+        ArrayList reverseList = new ArrayList(set);
+        Collections.reverse(reverseList);
+        set = new LinkedHashSet(reverseList);
+        return set;
+    }
+
+    private static LinkedHashMap reverse(LinkedHashMap map) {
+        ArrayList reverseEntrySet = new ArrayList(map.entrySet());
+        Collections.reverse(reverseEntrySet);
+
+        map = new LinkedHashMap(reverseEntrySet.size());
+        for (Iterator iterator = reverseEntrySet.iterator(); iterator.hasNext();) {
+            Map.Entry entry = (Map.Entry) iterator.next();
+            Object key = entry.getKey();
+            Object value = entry.getValue();
+            map.put(key, value);
+        }
+        return map;
     }
 }

Modified: geronimo/branches/1.1/modules/kernel/src/test/org/apache/geronimo/kernel/config/ConfigurationManagerTest.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/test/org/apache/geronimo/kernel/config/ConfigurationManagerTest.java?rev=395030&r1=395029&r2=395030&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/test/org/apache/geronimo/kernel/config/ConfigurationManagerTest.java
(original)
+++ geronimo/branches/1.1/modules/kernel/src/test/org/apache/geronimo/kernel/config/ConfigurationManagerTest.java
Tue Apr 18 13:31:48 2006
@@ -35,6 +35,7 @@
 import org.apache.geronimo.gbean.GBeanData;
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
+import org.apache.geronimo.gbean.AbstractNameQuery;
 import org.apache.geronimo.kernel.Kernel;
 import org.apache.geronimo.kernel.KernelFactory;
 import org.apache.geronimo.kernel.management.State;
@@ -60,12 +61,16 @@
     private AbstractName gbean1;
     private AbstractName gbean2;
     private AbstractName gbean3;
+    private TestConfigStore configStore;
 
     public void testLoad() throws Exception {
         configurationManager.loadConfiguration(artifact3);
         assertTrue(configurationManager.isLoaded(artifact3));
         assertTrue(configurationManager.isLoaded(artifact2));
         assertTrue(configurationManager.isLoaded(artifact1));
+        assertFalse(configurationManager.isRunning(artifact3));
+        assertFalse(configurationManager.isRunning(artifact2));
+        assertFalse(configurationManager.isRunning(artifact1));
         assertTrue(kernel.isLoaded(Configuration.getConfigurationAbstractName(artifact3)))
;
         assertTrue(kernel.isLoaded(Configuration.getConfigurationAbstractName(artifact2)))
;
         assertTrue(kernel.isLoaded(Configuration.getConfigurationAbstractName(artifact1)))
;
@@ -81,6 +86,9 @@
         assertFalse(configurationManager.isLoaded(artifact3));
         assertFalse(configurationManager.isLoaded(artifact2));
         assertFalse(configurationManager.isLoaded(artifact1));
+        assertFalse(configurationManager.isRunning(artifact3));
+        assertFalse(configurationManager.isRunning(artifact2));
+        assertFalse(configurationManager.isRunning(artifact1));
         assertFalse(kernel.isLoaded(Configuration.getConfigurationAbstractName(artifact3)))
;
         assertFalse(kernel.isLoaded(Configuration.getConfigurationAbstractName(artifact2)))
;
         assertFalse(kernel.isLoaded(Configuration.getConfigurationAbstractName(artifact1)))
;
@@ -91,6 +99,9 @@
         assertTrue(configurationManager.isLoaded(artifact3));
         assertTrue(configurationManager.isLoaded(artifact2));
         assertTrue(configurationManager.isLoaded(artifact1));
+        assertFalse(configurationManager.isRunning(artifact3));
+        assertFalse(configurationManager.isRunning(artifact2));
+        assertFalse(configurationManager.isRunning(artifact1));
         assertTrue(kernel.isLoaded(Configuration.getConfigurationAbstractName(artifact3)))
;
         assertTrue(kernel.isLoaded(Configuration.getConfigurationAbstractName(artifact2)))
;
         assertTrue(kernel.isLoaded(Configuration.getConfigurationAbstractName(artifact1)))
;
@@ -102,6 +113,9 @@
         assertFalse(kernel.isLoaded(gbean3));
 
         configurationManager.startConfiguration(artifact3);
+        assertTrue(configurationManager.isRunning(artifact3));
+        assertTrue(configurationManager.isRunning(artifact2));
+        assertTrue(configurationManager.isRunning(artifact1));
         assertTrue(kernel.isLoaded(gbean1));
         assertTrue(kernel.isLoaded(gbean2));
         assertTrue(kernel.isLoaded(gbean3));
@@ -111,6 +125,12 @@
 
 
         configurationManager.stopConfiguration(artifact3);
+        assertTrue(configurationManager.isLoaded(artifact3));
+        assertTrue(configurationManager.isLoaded(artifact2));
+        assertTrue(configurationManager.isLoaded(artifact1));
+        assertFalse(configurationManager.isRunning(artifact3));
+        assertFalse(configurationManager.isRunning(artifact2));
+        assertFalse(configurationManager.isRunning(artifact1));
         assertFalse(kernel.isLoaded(gbean1));
         assertFalse(kernel.isLoaded(gbean2));
         assertFalse(kernel.isLoaded(gbean3));
@@ -118,6 +138,9 @@
         configurationManager.unloadConfiguration(artifact3);
         assertFalse(configurationManager.isLoaded(artifact3));
         assertFalse(configurationManager.isLoaded(artifact2));
+        assertFalse(configurationManager.isRunning(artifact3));
+        assertFalse(configurationManager.isRunning(artifact2));
+        assertFalse(configurationManager.isRunning(artifact1));
         assertFalse(configurationManager.isLoaded(artifact1));
         assertFalse(kernel.isLoaded(Configuration.getConfigurationAbstractName(artifact3)))
;
         assertFalse(kernel.isLoaded(Configuration.getConfigurationAbstractName(artifact2)))
;
@@ -230,6 +253,213 @@
         assertFalse(kernel.isLoaded(Configuration.getConfigurationAbstractName(artifact1)))
;
     }
 
+    public void testReload() throws Exception {
+        configurationManager.loadConfiguration(artifact3);
+        configurationManager.startConfiguration(artifact3);
+        Object g1 = kernel.getGBean(gbean1);
+        Object g2 = kernel.getGBean(gbean2);
+        Object g3 = kernel.getGBean(gbean3);
+        assertSame(g1, kernel.getGBean(gbean1));
+        assertSame(g2, kernel.getGBean(gbean2));
+        assertSame(g3, kernel.getGBean(gbean3));
+        Configuration configuration1 = configurationManager.getConfiguration(artifact1);
+        Configuration configuration2 = configurationManager.getConfiguration(artifact2);
+        Configuration configuration3 = configurationManager.getConfiguration(artifact3);
+
+        LifecycleResults results = configurationManager.reloadConfiguration(artifact1);
+
+        // check the results
+        assertTrue(results.wasReloaded(artifact1));
+        assertTrue(results.wasReloaded(artifact2));
+        assertTrue(results.wasReloaded(artifact3));
+        assertTrue(results.wasRestarted(artifact1));
+        assertTrue(results.wasRestarted(artifact2));
+        assertTrue(results.wasRestarted(artifact3));
+
+        // check the state of the configuration manager
+        assertTrue(configurationManager.isLoaded(artifact1));
+        assertTrue(configurationManager.isLoaded(artifact2));
+        assertTrue(configurationManager.isLoaded(artifact3));
+        assertTrue(configurationManager.isRunning(artifact1));
+        assertTrue(configurationManager.isRunning(artifact2));
+        assertTrue(configurationManager.isRunning(artifact3));
+        assertNotSame(configuration1, configurationManager.getConfiguration(artifact1));
+        assertNotSame(configuration2, configurationManager.getConfiguration(artifact2));
+        assertNotSame(configuration3, configurationManager.getConfiguration(artifact3));
+
+        // check the state of the kernel
+        assertTrue(kernel.isLoaded(Configuration.getConfigurationAbstractName(artifact3)))
;
+        assertTrue(kernel.isLoaded(Configuration.getConfigurationAbstractName(artifact2)))
;
+        assertTrue(kernel.isLoaded(Configuration.getConfigurationAbstractName(artifact1)))
;
+        assertTrue(kernel.isRunning(Configuration.getConfigurationAbstractName(artifact3)))
;
+        assertTrue(kernel.isRunning(Configuration.getConfigurationAbstractName(artifact2)))
;
+        assertTrue(kernel.isRunning(Configuration.getConfigurationAbstractName(artifact1)))
;
+        assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(Configuration.getConfigurationAbstractName(artifact3)))
;
+        assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(Configuration.getConfigurationAbstractName(artifact2)))
;
+        assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(Configuration.getConfigurationAbstractName(artifact1)))
;
+        assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(gbean1)) ;
+        assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(gbean2)) ;
+        assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(gbean3)) ;
+        assertNotSame(g1, kernel.getGBean(gbean1));
+        assertNotSame(g2, kernel.getGBean(gbean2));
+        assertNotSame(g3, kernel.getGBean(gbean3));
+
+        configurationManager.stopConfiguration(artifact3);
+        assertFalse(kernel.isLoaded(gbean1));
+        assertFalse(kernel.isLoaded(gbean2));
+        assertFalse(kernel.isLoaded(gbean3));
+
+        configurationManager.unloadConfiguration(artifact3);
+        assertFalse(configurationManager.isLoaded(artifact3));
+        assertFalse(configurationManager.isLoaded(artifact2));
+        assertFalse(kernel.isLoaded(Configuration.getConfigurationAbstractName(artifact3)))
;
+        assertFalse(kernel.isLoaded(Configuration.getConfigurationAbstractName(artifact2)))
;
+
+        // artifact 1 should still be loaded since it was user loaded above
+        assertTrue(configurationManager.isLoaded(artifact1));
+        assertTrue(kernel.isLoaded(Configuration.getConfigurationAbstractName(artifact1)))
;
+
+        configurationManager.unloadConfiguration(artifact1);
+        assertFalse(configurationManager.isLoaded(artifact1));
+        assertFalse(kernel.isLoaded(Configuration.getConfigurationAbstractName(artifact1)))
;
+    }
+
+    public void testReloadException() throws Exception {
+        configurationManager.loadConfiguration(artifact3);
+        configurationManager.startConfiguration(artifact3);
+        Object g1 = kernel.getGBean(gbean1);
+        Object g2 = kernel.getGBean(gbean2);
+        kernel.getGBean(gbean3);
+
+        // make gbean3 fail and Reload all configs
+        shouldFail.add(gbean3.getObjectName().getCanonicalName());
+        LifecycleResults results = configurationManager.reloadConfiguration(artifact1);
+
+        // check the results
+        assertTrue(results.wasReloaded(artifact1));
+        assertTrue(results.wasReloaded(artifact2));
+        assertTrue(results.wasReloaded(artifact3));
+        assertTrue(results.wasRestarted(artifact1));
+        assertTrue(results.wasRestarted(artifact2));
+        assertTrue(results.wasRestarted(artifact3));
+
+        // all configuration except 3 should be loaded
+        assertFalse(configurationManager.isLoaded(artifact3));
+        assertTrue(configurationManager.isLoaded(artifact2));
+        assertTrue(configurationManager.isLoaded(artifact1));
+        assertFalse(kernel.isLoaded(Configuration.getConfigurationAbstractName(artifact3)))
;
+        assertTrue(kernel.isLoaded(Configuration.getConfigurationAbstractName(artifact2)))
;
+        assertTrue(kernel.isLoaded(Configuration.getConfigurationAbstractName(artifact1)))
;
+        assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(Configuration.getConfigurationAbstractName(artifact2)))
;
+        assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(Configuration.getConfigurationAbstractName(artifact1)))
;
+
+        // configuration 3 should not be running
+        assertTrue(configurationManager.isRunning(artifact1));
+        assertTrue(configurationManager.isRunning(artifact2));
+        assertFalse(configurationManager.isRunning(artifact3));
+        assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(gbean1)) ;
+        assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(gbean2)) ;
+        assertFalse(kernel.isLoaded(gbean3));
+
+        // make sure that gbean 1 and 2 were recreated
+        assertNotSame(g1, kernel.getGBean(gbean1));
+        assertNotSame(g2, kernel.getGBean(gbean2));
+
+        configurationManager.unloadConfiguration(artifact1);
+        assertFalse(configurationManager.isLoaded(artifact3));
+        assertFalse(configurationManager.isLoaded(artifact2));
+        assertFalse(configurationManager.isLoaded(artifact1));
+        assertFalse(kernel.isLoaded(Configuration.getConfigurationAbstractName(artifact3)))
;
+        assertFalse(kernel.isLoaded(Configuration.getConfigurationAbstractName(artifact2)))
;
+        assertFalse(kernel.isLoaded(Configuration.getConfigurationAbstractName(artifact1)))
;
+    }
+
+    public void testReloadFallback() throws Exception {
+        configurationManager.loadConfiguration(artifact3);
+        configurationManager.startConfiguration(artifact3);
+        Object g1 = kernel.getGBean(gbean1);
+        Object g2 = kernel.getGBean(gbean2);
+        Object g3 = kernel.getGBean(gbean3);
+        assertSame(g1, kernel.getGBean(gbean1));
+        assertSame(g2, kernel.getGBean(gbean2));
+        assertSame(g3, kernel.getGBean(gbean3));
+        Configuration configuration1 = configurationManager.getConfiguration(artifact1);
+        Configuration configuration2 = configurationManager.getConfiguration(artifact2);
+        Configuration configuration3 = configurationManager.getConfiguration(artifact3);
+
+        Environment environment = new Environment();
+        environment.setConfigId(artifact1);
+        ConfigurationData configurationData1 = new ConfigurationData(environment, kernel.getNaming());
+        configurationData1.setConfigurationStore(configStore);
+        GBeanData gbeanData = configurationData1.addGBean("gbean1", TestBean.getGBeanInfo());
+        gbeanData.setReferencePattern("nonExistantReference", new AbstractNameQuery("some.non.existant.Clazz"));
+        configurations.put(artifact1, configurationData1);
+
+        LifecycleResults results = null;
+        try {
+            configurationManager.reloadConfiguration(artifact1);
+            fail("Expected LifecycleException");
+        } catch (LifecycleException expected) {
+            results = expected.getLifecycleResults();
+        }
+
+        // check the results
+        assertTrue(results.wasFailed(artifact1));
+        assertTrue(results.wasReloaded(artifact1));
+        assertTrue(results.wasReloaded(artifact2));
+        assertTrue(results.wasReloaded(artifact3));
+        assertTrue(results.wasRestarted(artifact1));
+        assertTrue(results.wasRestarted(artifact2));
+        assertTrue(results.wasRestarted(artifact3));
+
+        // check the state of the configuration manager
+        assertTrue(configurationManager.isLoaded(artifact1));
+        assertTrue(configurationManager.isLoaded(artifact2));
+        assertTrue(configurationManager.isLoaded(artifact3));
+        assertTrue(configurationManager.isRunning(artifact1));
+        assertTrue(configurationManager.isRunning(artifact2));
+        assertTrue(configurationManager.isRunning(artifact3));
+        assertNotSame(configuration1, configurationManager.getConfiguration(artifact1));
+        assertNotSame(configuration2, configurationManager.getConfiguration(artifact2));
+        assertNotSame(configuration3, configurationManager.getConfiguration(artifact3));
+
+        // check the state of the kernel
+        assertTrue(kernel.isLoaded(Configuration.getConfigurationAbstractName(artifact3)))
;
+        assertTrue(kernel.isLoaded(Configuration.getConfigurationAbstractName(artifact2)))
;
+        assertTrue(kernel.isLoaded(Configuration.getConfigurationAbstractName(artifact1)))
;
+        assertTrue(kernel.isRunning(Configuration.getConfigurationAbstractName(artifact3)))
;
+        assertTrue(kernel.isRunning(Configuration.getConfigurationAbstractName(artifact2)))
;
+        assertTrue(kernel.isRunning(Configuration.getConfigurationAbstractName(artifact1)))
;
+        assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(Configuration.getConfigurationAbstractName(artifact3)))
;
+        assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(Configuration.getConfigurationAbstractName(artifact2)))
;
+        assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(Configuration.getConfigurationAbstractName(artifact1)))
;
+        assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(gbean1)) ;
+        assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(gbean2)) ;
+        assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(gbean3)) ;
+        assertNotSame(g1, kernel.getGBean(gbean1));
+        assertNotSame(g2, kernel.getGBean(gbean2));
+        assertNotSame(g3, kernel.getGBean(gbean3));
+
+        configurationManager.stopConfiguration(artifact3);
+        assertFalse(kernel.isLoaded(gbean1));
+        assertFalse(kernel.isLoaded(gbean2));
+        assertFalse(kernel.isLoaded(gbean3));
+
+        configurationManager.unloadConfiguration(artifact3);
+        assertFalse(configurationManager.isLoaded(artifact3));
+        assertFalse(configurationManager.isLoaded(artifact2));
+        assertFalse(kernel.isLoaded(Configuration.getConfigurationAbstractName(artifact3)))
;
+        assertFalse(kernel.isLoaded(Configuration.getConfigurationAbstractName(artifact2)))
;
+
+        // artifact 1 should still be loaded since it was user loaded above
+        assertTrue(configurationManager.isLoaded(artifact1));
+        assertTrue(kernel.isLoaded(Configuration.getConfigurationAbstractName(artifact1)))
;
+
+        configurationManager.unloadConfiguration(artifact1);
+        assertFalse(configurationManager.isLoaded(artifact1));
+        assertFalse(kernel.isLoaded(Configuration.getConfigurationAbstractName(artifact1)))
;
+    }
+
     private static final Set shouldFail = new HashSet();
     private static void checkFail(String objectName) {
         if (shouldFail.contains(objectName)) {
@@ -240,6 +470,8 @@
     protected void setUp() throws Exception {
         super.setUp();
 
+        shouldFail.clear();
+
         kernel = KernelFactory.newInstance().createKernel("test");
         kernel.boot();
 
@@ -249,7 +481,7 @@
         assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(artifactManagerData.getAbstractName()));
         ArtifactManager artifactManager = (ArtifactManager) kernel.getGBean(artifactManagerData.getAbstractName());
 
-        TestConfigStore configStore = new TestConfigStore();
+        configStore = new TestConfigStore();
         TestRepository testRepository = new TestRepository();
         DefaultArtifactResolver artifactResolver = new DefaultArtifactResolver(artifactManager,
testRepository);
 

Modified: geronimo/branches/1.1/modules/system/src/test/org/apache/geronimo/system/configuration/ConfigInstallerTest.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/system/src/test/org/apache/geronimo/system/configuration/ConfigInstallerTest.java?rev=395030&r1=395029&r2=395030&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/system/src/test/org/apache/geronimo/system/configuration/ConfigInstallerTest.java
(original)
+++ geronimo/branches/1.1/modules/system/src/test/org/apache/geronimo/system/configuration/ConfigInstallerTest.java
Tue Apr 18 13:31:48 2006
@@ -40,6 +40,7 @@
 import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.kernel.repository.FileWriteMonitor;
 import org.apache.geronimo.kernel.repository.WritableListableRepository;
+import org.apache.geronimo.kernel.repository.Version;
 import org.apache.geronimo.system.serverinfo.BasicServerInfo;
 import org.apache.geronimo.system.threads.ThreadPool;
 
@@ -200,6 +201,30 @@
         }
 
         public LifecycleResults restartConfiguration(Artifact configurationId, LifecycleMonitor
monitor) throws NoSuchConfigException, LifecycleException {
+            return null;
+        }
+
+        public LifecycleResults reloadConfiguration(Artifact configurationId) throws NoSuchConfigException,
LifecycleException {
+            return null;
+        }
+
+        public LifecycleResults reloadConfiguration(Artifact configurationId, LifecycleMonitor
monitor) throws NoSuchConfigException, LifecycleException {
+            return null;
+        }
+
+        public LifecycleResults reloadConfiguration(Artifact configurationId, Version version)
throws NoSuchConfigException, LifecycleException {
+            return null;
+        }
+
+        public LifecycleResults reloadConfiguration(Artifact configurationId, Version version,
LifecycleMonitor monitor) throws NoSuchConfigException, LifecycleException {
+            return null;
+        }
+
+        public LifecycleResults reloadConfiguration(ConfigurationData configurationData)
throws NoSuchConfigException, LifecycleException {
+            return null;
+        }
+
+        public LifecycleResults reloadConfiguration(ConfigurationData configurationData,
LifecycleMonitor monitor) throws NoSuchConfigException, LifecycleException {
             return null;
         }
 



Mime
View raw message