Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 26 additions & 36 deletions api/src/org/labkey/api/module/ModuleLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) + ")";

}
}

Expand Down Expand Up @@ -582,35 +586,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<String, ModuleContext> moduleContextMap = getAllModuleContexts().stream()
.filter(ctx -> ctx.getSchemaVersion() != null)
.collect(Collectors.toMap(ModuleContext::getName, ctx->ctx));

// List of "<name> (<installedSchemaVersion>)" 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(UpgradeInfo::new)
.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<String, ModuleContext> 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.");
}
}

Expand Down Expand Up @@ -685,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
Expand Down Expand Up @@ -778,16 +778,6 @@ private void warnAboutDuplicateSchemas(Collection<ModuleContext> 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 <old name>, <new name> to the map below and the server will throw with a clear
* message if a module with the old name is present at startup.
Expand Down