mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Merge branch 'feature/RM-5927_v20PatchesRunWhenV22Upgrade' into 'master'
RM-5927 Add appliesToVersion to v20 v21 patches See merge request records-management/records-management!764
This commit is contained in:
@@ -46,6 +46,7 @@
|
|||||||
<property name="retryingTransactionHelper" ref="retryingTransactionHelper"/>
|
<property name="retryingTransactionHelper" ref="retryingTransactionHelper"/>
|
||||||
<property name="behaviourFilter" ref="policyBehaviourFilter" />
|
<property name="behaviourFilter" ref="policyBehaviourFilter" />
|
||||||
<property name="modulePatchExecuter" ref="rm.modulePatchExecuter" />
|
<property name="modulePatchExecuter" ref="rm.modulePatchExecuter" />
|
||||||
|
<property name="registryService" ref="registryService" />
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
@@ -27,12 +27,18 @@
|
|||||||
|
|
||||||
package org.alfresco.module.org_alfresco_module_rm.patch.compatibility;
|
package org.alfresco.module.org_alfresco_module_rm.patch.compatibility;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
import org.alfresco.module.org_alfresco_module_rm.patch.ModulePatchExecuterImpl;
|
import org.alfresco.module.org_alfresco_module_rm.patch.ModulePatchExecuterImpl;
|
||||||
|
import org.alfresco.repo.admin.registry.RegistryKey;
|
||||||
|
import org.alfresco.repo.admin.registry.RegistryService;
|
||||||
import org.alfresco.repo.module.AbstractModuleComponent;
|
import org.alfresco.repo.module.AbstractModuleComponent;
|
||||||
|
import org.alfresco.repo.module.ModuleComponentHelper;
|
||||||
|
import org.alfresco.repo.module.ModuleVersionNumber;
|
||||||
import org.alfresco.repo.policy.BehaviourFilter;
|
import org.alfresco.repo.policy.BehaviourFilter;
|
||||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||||
import org.apache.commons.logging.Log;
|
import org.slf4j.Logger;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -44,8 +50,12 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
public abstract class ModulePatchComponent extends AbstractModuleComponent
|
public abstract class ModulePatchComponent extends AbstractModuleComponent
|
||||||
{
|
{
|
||||||
|
private static final String REGISTRY_PATH_MODULES = "modules";
|
||||||
|
private static final String REGISTRY_PROPERTY_INSTALLED_VERSION = "installedVersion";
|
||||||
|
private static final String REGISTRY_PROPERTY_CURRENT_VERSION = "currentVersion";
|
||||||
|
|
||||||
/** logger */
|
/** logger */
|
||||||
protected static final Log LOGGER = LogFactory.getLog(ModulePatchComponent.class);
|
protected static final Logger LOGGER = LoggerFactory.getLogger(ModulePatchComponent.class);
|
||||||
|
|
||||||
/** Retrying transaction helper */
|
/** Retrying transaction helper */
|
||||||
protected RetryingTransactionHelper retryingTransactionHelper;
|
protected RetryingTransactionHelper retryingTransactionHelper;
|
||||||
@@ -56,6 +66,9 @@ public abstract class ModulePatchComponent extends AbstractModuleComponent
|
|||||||
/** module patch executer */
|
/** module patch executer */
|
||||||
protected ModulePatchExecuterImpl modulePatchExecuter;
|
protected ModulePatchExecuterImpl modulePatchExecuter;
|
||||||
|
|
||||||
|
/** Registry service */
|
||||||
|
protected RegistryService registryService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param retryingTransactionHelper retrying transaction helper
|
* @param retryingTransactionHelper retrying transaction helper
|
||||||
*/
|
*/
|
||||||
@@ -80,6 +93,14 @@ public abstract class ModulePatchComponent extends AbstractModuleComponent
|
|||||||
this.modulePatchExecuter = modulePatchExecuter;
|
this.modulePatchExecuter = modulePatchExecuter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param registryService Registry service
|
||||||
|
*/
|
||||||
|
public void setRegistryService(RegistryService registryService)
|
||||||
|
{
|
||||||
|
this.registryService = registryService;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init method
|
* Init method
|
||||||
*/
|
*/
|
||||||
@@ -95,13 +116,22 @@ public abstract class ModulePatchComponent extends AbstractModuleComponent
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void executeInternal()
|
protected void executeInternal()
|
||||||
|
{
|
||||||
|
ModuleVersionNumber moduleInstalledVersionNumber = getModuleVersionNumber(REGISTRY_PROPERTY_INSTALLED_VERSION);
|
||||||
|
ModuleVersionNumber moduleCurrentVersionNumber = getModuleVersionNumber(REGISTRY_PROPERTY_CURRENT_VERSION);
|
||||||
|
|
||||||
|
String moduleName = getName();
|
||||||
|
|
||||||
|
if (isVersionLaterThan(moduleInstalledVersionNumber, moduleCurrentVersionNumber))
|
||||||
|
{
|
||||||
|
LOGGER.info("Module patch component '{}' is skipped for upgrade from version {} to version {}",
|
||||||
|
moduleName, moduleInstalledVersionNumber, moduleCurrentVersionNumber);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (LOGGER.isInfoEnabled())
|
LOGGER.info("Module patch component '{}' is executing ...", moduleName);
|
||||||
{
|
|
||||||
LOGGER.info("Module patch component '" + getName() + "' is executing ...");
|
|
||||||
}
|
|
||||||
|
|
||||||
// execute path within an isolated transaction
|
// execute path within an isolated transaction
|
||||||
retryingTransactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
|
retryingTransactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
|
||||||
@@ -123,21 +153,54 @@ public abstract class ModulePatchComponent extends AbstractModuleComponent
|
|||||||
|
|
||||||
}, false, true);
|
}, false, true);
|
||||||
|
|
||||||
if (LOGGER.isInfoEnabled())
|
LOGGER.info(" ... completed module patch '{}'", moduleName);
|
||||||
{
|
|
||||||
LOGGER.info(" ... completed module patch '" + getName() + "'");
|
} catch (Exception exception)
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception exception)
|
|
||||||
{
|
{
|
||||||
// record the exception otherwise it gets swallowed
|
// record the exception otherwise it gets swallowed
|
||||||
if (LOGGER.isInfoEnabled())
|
LOGGER.info(" ... error encountered. {}", exception.getMessage(), exception);
|
||||||
{
|
|
||||||
LOGGER.info(" ... error encountered. " + exception.getMessage(), exception);
|
|
||||||
}
|
|
||||||
throw exception;
|
throw exception;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to get the ModuleVersionNumber.
|
||||||
|
*/
|
||||||
|
private ModuleVersionNumber getModuleVersionNumber(String registryProperty)
|
||||||
|
{
|
||||||
|
String moduleId = modulePatchExecuter.getModuleId();
|
||||||
|
RegistryKey moduleKeyVersion = new RegistryKey(ModuleComponentHelper.URI_MODULES_1_0,
|
||||||
|
new String[]{REGISTRY_PATH_MODULES, moduleId, registryProperty});
|
||||||
|
Serializable moduleVersion = this.registryService.getProperty(moduleKeyVersion);
|
||||||
|
|
||||||
|
return new ModuleVersionNumber(moduleVersion.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to determine if this is an upgrade from a version that already includes the early (v2.0, v2.1)
|
||||||
|
* patches.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private boolean isVersionLaterThan(ModuleVersionNumber installedModuleVersionNumber,
|
||||||
|
ModuleVersionNumber currentModuleVersionNumber)
|
||||||
|
{
|
||||||
|
// assume that the v2.0 and v2.1 patches should be run
|
||||||
|
boolean versionLaterThan = false;
|
||||||
|
|
||||||
|
// if this is an upgrade as opposed to a fresh install
|
||||||
|
if (installedModuleVersionNumber.compareTo(currentModuleVersionNumber) != 0)
|
||||||
|
{
|
||||||
|
// if the installed version is later than the minimum version number of this patch
|
||||||
|
ModuleVersionNumber minVersion = this.getAppliesFromVersionNumber();
|
||||||
|
if (installedModuleVersionNumber.compareTo(minVersion) >= 0)
|
||||||
|
{
|
||||||
|
versionLaterThan = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return versionLaterThan;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute patch work.
|
* Execute patch work.
|
||||||
|
Reference in New Issue
Block a user