Class AbstractUpgradeManager
- java.lang.Object
-
- com.atlassian.bamboo.upgrade.AbstractUpgradeManager
-
- All Implemented Interfaces:
UpgradeManager
- Direct Known Subclasses:
BootstrapUpgradeManagerImpl,UpgradeManagerImpl
public abstract class AbstractUpgradeManager extends Object implements UpgradeManager
-
-
Field Summary
Fields Modifier and Type Field Description protected com.atlassian.config.ApplicationConfigurationapplicationConfigprotected BootstrapManagerbootstrapManagerprotected Comparator<String>buildNumberComparatorprotected StringfileNameprotected StringnewBuildNumberprotected StringoldBuildNumberprotected com.opensymphony.xwork2.TextProvidertextProviderprotected SortedMap<String,UpgradeTask>upgradeTasksprotected UpgradeUtilityBeanupgradeUtilityBeanprotected StringxPathExpression
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractUpgradeManager(@NotNull com.atlassian.config.ApplicationConfiguration applicationConfig, @NotNull String newBuildNumber, @NotNull String fileName, @NotNull String xPathExpression, @NotNull BootstrapManager bootstrapManager)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidclassifyUpgradeTask(@NotNull String bambooBuildNumber, @NotNull UpgradeTask task)protected SortedMap<String,UpgradeTask>createTasks(@NotNull String xPathExpression, @NotNull String installationBuildNumber, @NotNull String upgradeBuildNumber)Creates a mapping of build numbers to upgrade tasks.UpgradeTaskcreateUpgradeTask(String className)protected <E extends Exception>
voidforEachTask(@NotNull String xPathExpression, @NotNull String installationBuildNumber, @NotNull String upgradeBuildNumber, BambooClosures.Throwing1<UpgradeTask,E> action)Iterates over upgrade tasks, lazily instantiating them on the fly.@NotNull StringgetBuildNumber()This gets the current build numberprotected @NotNull StringgetDescription(@NotNull UpgradeTask task, String thisTaskBuildNumber)StringgetOldBuildNumber()protected org.dom4j.DocumentgetUpgradeDocument()SortedMap<String,UpgradeTask>getUpgradeTasks()Gets a map of upgrade tasks which need to run.booleanneedUpgrade()Determines whether we need to run the upgrade or not.protected voidpopulateRelevantUpgrades(@NotNull String buildNumberLo, @NotNull String buildNumberHi)protected StringrunUpgradeTask(@NotNull UpgradeTask task, @NotNull List<String> errors)voidsetTextProvider(com.opensymphony.xwork2.TextProvider textProvider)voidsetUpgradeUtilityBean(UpgradeUtilityBean upgradeUtilityBean)protected booleanshouldRunTask(@NotNull org.dom4j.Element element, @NotNull String installationBuildNumber, @NotNull String upgradeBuildNumber)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.atlassian.bamboo.upgrade.UpgradeManager
doUpgrade
-
-
-
-
Field Detail
-
buildNumberComparator
protected final Comparator<String> buildNumberComparator
-
oldBuildNumber
protected String oldBuildNumber
-
newBuildNumber
protected final String newBuildNumber
-
fileName
protected final String fileName
-
xPathExpression
protected final String xPathExpression
-
upgradeTasks
protected final SortedMap<String,UpgradeTask> upgradeTasks
-
applicationConfig
protected final com.atlassian.config.ApplicationConfiguration applicationConfig
-
bootstrapManager
protected final BootstrapManager bootstrapManager
-
upgradeUtilityBean
protected UpgradeUtilityBean upgradeUtilityBean
-
textProvider
protected com.opensymphony.xwork2.TextProvider textProvider
-
-
Constructor Detail
-
AbstractUpgradeManager
protected AbstractUpgradeManager(@NotNull @NotNull com.atlassian.config.ApplicationConfiguration applicationConfig, @NotNull @NotNull String newBuildNumber, @NotNull @NotNull String fileName, @NotNull @NotNull String xPathExpression, @NotNull @NotNull BootstrapManager bootstrapManager)
-
-
Method Detail
-
needUpgrade
public boolean needUpgrade()
Description copied from interface:UpgradeManagerDetermines whether we need to run the upgrade or not.- Specified by:
needUpgradein interfaceUpgradeManager- Returns:
booleanwhether the upgrade is needed
-
getBuildNumber
@NotNull public @NotNull String getBuildNumber()
Description copied from interface:UpgradeManagerThis gets the current build number- Specified by:
getBuildNumberin interfaceUpgradeManager- Returns:
- the current build number (stored in application config file)
-
populateRelevantUpgrades
protected void populateRelevantUpgrades(@NotNull @NotNull String buildNumberLo, @NotNull @NotNull String buildNumberHi) throws UpgradeException- Throws:
UpgradeException
-
classifyUpgradeTask
protected void classifyUpgradeTask(@NotNull @NotNull String bambooBuildNumber, @NotNull @NotNull UpgradeTask task) throws UpgradeException- Throws:
UpgradeException
-
createTasks
protected SortedMap<String,UpgradeTask> createTasks(@NotNull @NotNull String xPathExpression, @NotNull @NotNull String installationBuildNumber, @NotNull @NotNull String upgradeBuildNumber) throws UpgradeException
Creates a mapping of build numbers to upgrade tasks.All matching upgrade tasks are instantiated by this method. This means that if there's a problem with instantiating at least one upgrade task (for example due to broken Spring dependencies), this method will throw.
To lazily iterate over upgrade tasks, use
forEachTask(String, String, String, BambooClosures.Throwing1).- Throws:
UpgradeException
-
forEachTask
protected <E extends Exception> void forEachTask(@NotNull @NotNull String xPathExpression, @NotNull @NotNull String installationBuildNumber, @NotNull @NotNull String upgradeBuildNumber, @NotNull BambooClosures.Throwing1<UpgradeTask,E> action) throws UpgradeException, E extends Exception
Iterates over upgrade tasks, lazily instantiating them on the fly.Provided
actionwill be performed on all previous upgrade tasks before a new task is instantiated. This may be beneficial for validation tasks, to detect problems and report them nicely instead of relying on infrastructure exceptions. (For example, first upgrade task may detect broken DB configuration and fail, and subsequent one, requiring DB connection from Spring beans, won't even be created.)To eagerly instantiate all upgrade tasks, use
createTasks(String, String, String).- Throws:
UpgradeExceptionE extends Exception
-
createUpgradeTask
public UpgradeTask createUpgradeTask(String className) throws UpgradeException
- Throws:
UpgradeException
-
getUpgradeDocument
protected org.dom4j.Document getUpgradeDocument() throws org.dom4j.DocumentException- Throws:
org.dom4j.DocumentException
-
runUpgradeTask
protected String runUpgradeTask(@NotNull @NotNull UpgradeTask task, @NotNull @NotNull List<String> errors)
-
getDescription
@NotNull protected @NotNull String getDescription(@NotNull @NotNull UpgradeTask task, String thisTaskBuildNumber)
-
shouldRunTask
protected boolean shouldRunTask(@NotNull @NotNull org.dom4j.Element element, @NotNull @NotNull String installationBuildNumber, @NotNull @NotNull String upgradeBuildNumber)
-
getUpgradeTasks
public SortedMap<String,UpgradeTask> getUpgradeTasks()
Gets a map of upgrade tasks which need to run.- Returns:
SortedMapmap of upgrade tasks, keys are the string representations of the build number.
-
getOldBuildNumber
public String getOldBuildNumber()
- Specified by:
getOldBuildNumberin interfaceUpgradeManager- Returns:
- build number before upgrade
-
setUpgradeUtilityBean
public void setUpgradeUtilityBean(UpgradeUtilityBean upgradeUtilityBean)
-
setTextProvider
public void setTextProvider(com.opensymphony.xwork2.TextProvider textProvider)
-
-