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:
Sara Aspery
2018-01-18 15:36:41 +00:00
2 changed files with 94 additions and 30 deletions

View File

@@ -46,6 +46,7 @@
<property name="retryingTransactionHelper" ref="retryingTransactionHelper"/>
<property name="behaviourFilter" ref="policyBehaviourFilter" />
<property name="modulePatchExecuter" ref="rm.modulePatchExecuter" />
<property name="registryService" ref="registryService" />
</bean>
</beans>

View File

@@ -27,12 +27,18 @@
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.repo.admin.registry.RegistryKey;
import org.alfresco.repo.admin.registry.RegistryService;
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.transaction.RetryingTransactionHelper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
@@ -44,8 +50,12 @@ import org.apache.commons.logging.LogFactory;
@Deprecated
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 */
protected static final Log LOGGER = LogFactory.getLog(ModulePatchComponent.class);
protected static final Logger LOGGER = LoggerFactory.getLogger(ModulePatchComponent.class);
/** Retrying transaction helper */
protected RetryingTransactionHelper retryingTransactionHelper;
@@ -56,6 +66,9 @@ public abstract class ModulePatchComponent extends AbstractModuleComponent
/** module patch executer */
protected ModulePatchExecuterImpl modulePatchExecuter;
/** Registry service */
protected RegistryService registryService;
/**
* @param retryingTransactionHelper retrying transaction helper
*/
@@ -80,6 +93,14 @@ public abstract class ModulePatchComponent extends AbstractModuleComponent
this.modulePatchExecuter = modulePatchExecuter;
}
/**
* @param registryService Registry service
*/
public void setRegistryService(RegistryService registryService)
{
this.registryService = registryService;
}
/**
* Init method
*/
@@ -96,47 +117,89 @@ public abstract class ModulePatchComponent extends AbstractModuleComponent
@Override
protected void executeInternal()
{
try
ModuleVersionNumber moduleInstalledVersionNumber = getModuleVersionNumber(REGISTRY_PROPERTY_INSTALLED_VERSION);
ModuleVersionNumber moduleCurrentVersionNumber = getModuleVersionNumber(REGISTRY_PROPERTY_CURRENT_VERSION);
String moduleName = getName();
if (isVersionLaterThan(moduleInstalledVersionNumber, moduleCurrentVersionNumber))
{
if (LOGGER.isInfoEnabled())
LOGGER.info("Module patch component '{}' is skipped for upgrade from version {} to version {}",
moduleName, moduleInstalledVersionNumber, moduleCurrentVersionNumber);
}
else
{
try
{
LOGGER.info("Module patch component '" + getName() + "' is executing ...");
}
// execute path within an isolated transaction
retryingTransactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{
@Override
public Void execute()
LOGGER.info("Module patch component '{}' is executing ...", moduleName);
// execute path within an isolated transaction
retryingTransactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{
behaviourFilter.disableBehaviour();
try
@Override
public Void execute()
{
executePatch();
behaviourFilter.disableBehaviour();
try
{
executePatch();
}
finally
{
behaviourFilter.enableBehaviour();
}
return null;
}
finally
{
behaviourFilter.enableBehaviour();
}
return null;
}
}, false, true);
}, false, true);
if (LOGGER.isInfoEnabled())
LOGGER.info(" ... completed module patch '{}'", moduleName);
} catch (Exception exception)
{
LOGGER.info(" ... completed module patch '" + getName() + "'");
// record the exception otherwise it gets swallowed
LOGGER.info(" ... error encountered. {}", exception.getMessage(), exception);
throw exception;
}
}
catch (Exception 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)
{
// record the exception otherwise it gets swallowed
if (LOGGER.isInfoEnabled())
// if the installed version is later than the minimum version number of this patch
ModuleVersionNumber minVersion = this.getAppliesFromVersionNumber();
if (installedModuleVersionNumber.compareTo(minVersion) >= 0)
{
LOGGER.info(" ... error encountered. " + exception.getMessage(), exception);
versionLaterThan = true;
}
throw exception;
}
return versionLaterThan;
}
/**