From 592e55c16d9dfdc04c85f8d80bf80cacef480721 Mon Sep 17 00:00:00 2001 From: Adam Rauch Date: Fri, 10 Jan 2025 15:27:23 -0800 Subject: [PATCH 1/2] Check all managed modules for upgrade suitability --- .../org/labkey/api/module/ModuleLoader.java | 54 +++++++------------ 1 file changed, 20 insertions(+), 34 deletions(-) diff --git a/api/src/org/labkey/api/module/ModuleLoader.java b/api/src/org/labkey/api/module/ModuleLoader.java index 82b9d474834..b75dba9a622 100644 --- a/api/src/org/labkey/api/module/ModuleLoader.java +++ b/api/src/org/labkey/api/module/ModuleLoader.java @@ -582,35 +582,31 @@ private void doInit(Execution execution) throws ServletException { // Refuse to start up if any LabKey-managed module has a schema version that's too old. Issue 46922. - // Modules that are designated as "managed" and reside in LabKey-managed repositories + // Collect all modules that are designated as "managed" var labkeyModules = _modules.stream() .filter(Module::shouldManageVersion) - .filter(this::isFromLabKeyRepository) // Do the check only for modules in LabKey repositories, Issue 47369 .toList(); - // Likely empty if running in dev mode... no need to log or do other work - if (!labkeyModules.isEmpty()) + _log.info("Checking {} to ensure {} recent enough to upgrade", StringUtilsLabKey.pluralize(labkeyModules.size(), "LabKey-managed module"), labkeyModules.size() > 1 ? "they're" : "it's"); + + // Module contexts with non-null schema versions + Map moduleContextMap = getAllModuleContexts().stream() + .filter(ctx -> ctx.getSchemaVersion() != null) + .collect(Collectors.toMap(ModuleContext::getName, ctx->ctx)); + + // List of " ()" of LabKey-managed modules with schemas where the installed + // version is less than "earliest upgrade version" + var tooOld = labkeyModules.stream() + .map(m -> moduleContextMap.get(m.getName())) + .filter(Objects::nonNull) + .filter(ctx -> ctx.getInstalledVersion() < Constants.getEarliestUpgradeVersion()) + .map(ctx -> ctx.getName() + " (" + ModuleContext.formatVersion(ctx.getInstalledVersion()) + ")") + .toList(); + + if (!tooOld.isEmpty()) { - _log.info("Checking {} to ensure {} recent enough to upgrade", StringUtilsLabKey.pluralize(labkeyModules.size(), "LabKey-managed module"), labkeyModules.size() > 1 ? "they're" : "it's"); - - // Module contexts with non-null schema versions - Map moduleContextMap = getAllModuleContexts().stream() - .filter(ctx -> ctx.getSchemaVersion() != null) - .collect(Collectors.toMap(ModuleContext::getName, ctx->ctx)); - - // Names of LabKey-managed modules with schemas where the installed version is less than "earliest upgrade version" - var tooOld = labkeyModules.stream() - .map(m -> moduleContextMap.get(m.getName())) - .filter(Objects::nonNull) - .filter(ctx -> ctx.getInstalledVersion() < Constants.getEarliestUpgradeVersion()) - .map(ModuleContext::getName) - .toList(); - - if (!tooOld.isEmpty()) - { - String countPhrase = 1 == tooOld.size() ? " of this module is" : "s of these modules are"; - throw new ConfigurationException("Can't upgrade this deployment. The installed schema version" + countPhrase + " too old: " + tooOld + " This version of LabKey Server supports upgrading modules from schema version " + Constants.getEarliestUpgradeVersion() + " and greater."); - } + String countPhrase = 1 == tooOld.size() ? " of this module is" : "s of these modules are"; + throw new ConfigurationException("Can't upgrade this deployment. The installed schema version" + countPhrase + " too old: " + tooOld + ". This version of LabKey Server supports upgrading modules from schema version " + ModuleContext.formatVersion(Constants.getEarliestUpgradeVersion()) + " and greater."); } } @@ -778,16 +774,6 @@ private void warnAboutDuplicateSchemas(Collection values) } } - /** - * Does this module live in a repository that's managed by LabKey Corporation? - * @param module a Module - * @return true if the module's VCS URL is non-null and includes "github.com:LabKey/" - */ - private boolean isFromLabKeyRepository(Module module) - { - return StringUtils.containsAny(module.getVcsUrl(), "github.com:LabKey/"); - } - /** * If a module is renamed, add , to the map below and the server will throw with a clear * message if a module with the old name is present at startup. From 9b7c2bd3a23cda3241a62cb8418a9afb8f915473 Mon Sep 17 00:00:00 2001 From: Adam Rauch Date: Fri, 10 Jan 2025 16:47:09 -0800 Subject: [PATCH 2/2] Use UpgradeInfo --- api/src/org/labkey/api/module/ModuleLoader.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/api/src/org/labkey/api/module/ModuleLoader.java b/api/src/org/labkey/api/module/ModuleLoader.java index b75dba9a622..2722961434d 100644 --- a/api/src/org/labkey/api/module/ModuleLoader.java +++ b/api/src/org/labkey/api/module/ModuleLoader.java @@ -477,11 +477,15 @@ public void updateModuleDirectory(File dir, File archive) private record UpgradeInfo(String moduleName, double installedVersion) { + private UpgradeInfo(ModuleContext context) + { + this(context.getName(), context.getInstalledVersion()); + } + @Override public String toString() { return moduleName + " (from schema version " + ModuleContext.formatVersion(installedVersion) + ")"; - } } @@ -600,7 +604,7 @@ private void doInit(Execution execution) throws ServletException .map(m -> moduleContextMap.get(m.getName())) .filter(Objects::nonNull) .filter(ctx -> ctx.getInstalledVersion() < Constants.getEarliestUpgradeVersion()) - .map(ctx -> ctx.getName() + " (" + ModuleContext.formatVersion(ctx.getInstalledVersion()) + ")") + .map(UpgradeInfo::new) .toList(); if (!tooOld.isEmpty()) @@ -681,7 +685,7 @@ public void addStaticWarnings(@NotNull Warnings warnings, boolean showAllWarning if (context.needsUpgrade(module.getSchemaVersion())) { context.setModuleState(ModuleState.InstallRequired); - modulesRequiringUpgrade.add(new UpgradeInfo(context.getName(), context.getInstalledVersion())); + modulesRequiringUpgrade.add(new UpgradeInfo(context)); addModuleToLockFile(context.getName(), lockFile); } else