From 2888a3737c9ad0e36c9c3a31f3d054528012748b Mon Sep 17 00:00:00 2001 From: Derek Hulley Date: Thu, 26 Apr 2007 14:21:01 +0000 Subject: [PATCH] Fixed module startup bug The ModuleComponent 'appliesFromVersion' and 'appliesToVersion' properties were being compared to the module's new version number. In actual fact, components' applicability must be against the original installation version number. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5561 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../messages/module-messages.properties | 2 + .../repo/module/ModuleComponentHelper.java | 64 ++++++++++++------- .../repo/module/ModuleDetailsImpl.java | 4 +- 3 files changed, 44 insertions(+), 26 deletions(-) diff --git a/config/alfresco/messages/module-messages.properties b/config/alfresco/messages/module-messages.properties index 9b74d67d3a..6b6fd6a804 100644 --- a/config/alfresco/messages/module-messages.properties +++ b/config/alfresco/messages/module-messages.properties @@ -6,6 +6,8 @@ module.msg.installing= Installing module ''{0}'' version {1}. module.msg.upgrading= Upgrading module ''{0}'' version {1} (was {2}). module.msg.missing= A previously-installed module ''{0}'' (version {1}) is not present in your distribution. +module.warn.no_install_version=Module ''{0}'' had no install version. Assuming version {1} was installed. + module.err.downgrading_not_supported=\nDowngrading of modules is not supported.\nModule ''{0}'' version {1} is currently installed and must be uninstalled before version {2} can be installed. module.err.unsupported_repo_version=\nModule ''{0}'' version {1} is incompatible with the current repository version {2}.\n The repository version required must be in range [{3} : {4}]. module.err.already_executed=The module component has already been executed: {0}.{1} diff --git a/source/java/org/alfresco/repo/module/ModuleComponentHelper.java b/source/java/org/alfresco/repo/module/ModuleComponentHelper.java index 5208db88e2..d95e6af4e5 100644 --- a/source/java/org/alfresco/repo/module/ModuleComponentHelper.java +++ b/source/java/org/alfresco/repo/module/ModuleComponentHelper.java @@ -71,6 +71,7 @@ public class ModuleComponentHelper private static final String MSG_STARTING = "module.msg.starting"; private static final String MSG_INSTALLING = "module.msg.installing"; private static final String MSG_UPGRADING = "module.msg.upgrading"; + private static final String WARN_NO_INSTALL_VERSION = "module.warn.no_install_version"; private static final String ERR_UNSUPPORTED_REPO_VERSION = "module.err.unsupported_repo_version"; private static final String ERR_NO_DOWNGRADE = "module.err.downgrading_not_supported"; private static final String ERR_COMPONENT_ALREADY_REGISTERED = "module.err.component_already_registered"; @@ -332,7 +333,7 @@ public class ModuleComponentHelper private void startModule(ModuleDetails module, Set executedComponents) { String moduleId = module.getId(); - VersionNumber moduleVersion = module.getVersion(); + VersionNumber moduleNewVersion = module.getVersion(); // Check if the module needs a rename first renameModule(module); @@ -347,7 +348,7 @@ public class ModuleComponentHelper // The current repo version is not supported throw AlfrescoRuntimeException.create( ERR_UNSUPPORTED_REPO_VERSION, - moduleId, moduleVersion, repoVersionNumber, minRepoVersionNumber, maxRepoVersionNumber); + moduleId, moduleNewVersion, repoVersionNumber, minRepoVersionNumber, maxRepoVersionNumber); } // Get the module details from the registry @@ -357,37 +358,50 @@ public class ModuleComponentHelper RegistryKey moduleKeyCurrentVersion = new RegistryKey( ModuleComponentHelper.URI_MODULES_1_0, REGISTRY_PATH_MODULES, moduleId, REGISTRY_PROPERTY_CURRENT_VERSION); - VersionNumber versionCurrent = (VersionNumber) registryService.getProperty(moduleKeyCurrentVersion); + VersionNumber moduleInstallVersion = (VersionNumber) registryService.getProperty(moduleKeyInstalledVersion); + VersionNumber moduleCurrentVersion = (VersionNumber) registryService.getProperty(moduleKeyCurrentVersion); String msg = null; - if (versionCurrent == null) // There is no current version + if (moduleCurrentVersion == null) // No previous record of it { - msg = I18NUtil.getMessage(MSG_INSTALLING, moduleId, moduleVersion); + msg = I18NUtil.getMessage(MSG_INSTALLING, moduleId, moduleNewVersion); // Record the install version - registryService.addProperty(moduleKeyInstalledVersion, moduleVersion); + registryService.addProperty(moduleKeyInstalledVersion, moduleNewVersion); + moduleInstallVersion = moduleNewVersion; + moduleCurrentVersion = moduleNewVersion; } else // It is an upgrade or is the same { - if (versionCurrent.compareTo(moduleVersion) == 0) // The current version is the same + // Check that we have an installed version + if (moduleInstallVersion == null) { - msg = I18NUtil.getMessage(MSG_STARTING, moduleId, moduleVersion); + // A current version, but no installed version + logger.warn(I18NUtil.getMessage(WARN_NO_INSTALL_VERSION, moduleId, moduleCurrentVersion)); + // Record the install version + registryService.addProperty(moduleKeyInstalledVersion, moduleCurrentVersion); + moduleInstallVersion = moduleCurrentVersion; } - else if (versionCurrent.compareTo(moduleVersion) > 0) // Downgrading not supported + + if (moduleCurrentVersion.compareTo(moduleNewVersion) == 0) // The current version is the same { - throw AlfrescoRuntimeException.create(ERR_NO_DOWNGRADE, moduleId, versionCurrent, moduleVersion); + msg = I18NUtil.getMessage(MSG_STARTING, moduleId, moduleNewVersion); + } + else if (moduleCurrentVersion.compareTo(moduleNewVersion) > 0) // Downgrading not supported + { + throw AlfrescoRuntimeException.create(ERR_NO_DOWNGRADE, moduleId, moduleCurrentVersion, moduleNewVersion); } else // This is an upgrade { - msg = I18NUtil.getMessage(MSG_UPGRADING, moduleId, moduleVersion, versionCurrent); + msg = I18NUtil.getMessage(MSG_UPGRADING, moduleId, moduleNewVersion, moduleCurrentVersion); } } loggerService.info(msg); // Record the current version - registryService.addProperty(moduleKeyCurrentVersion, moduleVersion); + registryService.addProperty(moduleKeyCurrentVersion, moduleNewVersion); Map componentsByName = getComponents(moduleId); for (ModuleComponent component : componentsByName.values()) { - executeComponent(module, component, executedComponents); + executeComponent(moduleId, moduleInstallVersion, component, executedComponents); } // Done @@ -400,7 +414,11 @@ public class ModuleComponentHelper /** * Execute the component, respecting dependencies. */ - private void executeComponent(ModuleDetails module, ModuleComponent component, Set executedComponents) + private void executeComponent( + String moduleId, + VersionNumber moduleInstallVersion, + ModuleComponent component, + Set executedComponents) { // Ignore if it has been executed in this run already if (executedComponents.contains(component)) @@ -415,26 +433,24 @@ public class ModuleComponentHelper } // Check the version applicability - VersionNumber moduleVersion = module.getVersion(); VersionNumber minVersion = component.getAppliesFromVersionNumber(); VersionNumber maxVersion = component.getAppliesToVersionNumber(); - if (moduleVersion.compareTo(minVersion) < 0 || moduleVersion.compareTo(maxVersion) > 0) + if (moduleInstallVersion.compareTo(minVersion) < 0 || moduleInstallVersion.compareTo(maxVersion) > 0) { // It is out of the allowable range for execution so we just ignore it if (logger.isDebugEnabled()) { - logger.debug("Skipping component that doesn't apply to the current version: \n" + - " Component: " + component + "\n" + - " Module: " + module + "\n" + - " Version: " + moduleVersion + "\n" + - " Applies From : " + minVersion + "\n" + - " Applies To : " + maxVersion); + logger.debug("Skipping component that doesn't apply to the module installation version: \n" + + " Component: " + component + "\n" + + " Module: " + moduleId + "\n" + + " Install Version: " + moduleInstallVersion + "\n" + + " Applies From : " + minVersion + "\n" + + " Applies To : " + maxVersion); } return; } // Construct the registry key to store the execution date - String moduleId = component.getModuleId(); String name = component.getName(); RegistryKey executionDateKey = new RegistryKey( ModuleComponentHelper.URI_MODULES_1_0, @@ -458,7 +474,7 @@ public class ModuleComponentHelper List dependencies = component.getDependsOn(); for (ModuleComponent dependency : dependencies) { - executeComponent(module, dependency, executedComponents); + executeComponent(moduleId, moduleInstallVersion, dependency, executedComponents); } // Execute the component itself component.execute(); diff --git a/source/java/org/alfresco/repo/module/ModuleDetailsImpl.java b/source/java/org/alfresco/repo/module/ModuleDetailsImpl.java index a8f603269a..2e5f6a688f 100644 --- a/source/java/org/alfresco/repo/module/ModuleDetailsImpl.java +++ b/source/java/org/alfresco/repo/module/ModuleDetailsImpl.java @@ -65,8 +65,8 @@ public class ModuleDetailsImpl implements ModuleDetails private ModuleDetailsImpl() { aliases = new ArrayList(0); - repoVersionMin = new VersionNumber("0.0.0"); - repoVersionMax = new VersionNumber("999.999.999"); + repoVersionMin = VersionNumber.VERSION_ZERO; + repoVersionMax = VersionNumber.VERSION_BIG; this.installState = ModuleInstallState.UNKNOWN; }