Skip to content

Commit

Permalink
More logging and verify distribution contents
Browse files Browse the repository at this point in the history
  • Loading branch information
labkey-tchad committed May 23, 2024
1 parent 5c81608 commit 9dee258
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions server/embedded/src/org/labkey/embedded/EmbeddedExtractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public class EmbeddedExtractor
{
private static final Log LOG = LogFactory.getLog(EmbeddedExtractor.class);
private static final int BUFFER_SIZE = 1024 * 64;
private static final Set<String> EXPECTED_DIST_DIRS = Set.of("labkeywebapp", "modules");
public static final String LABKEYWEBAPP = "labkeywebapp";
private static final Set<String> EXPECTED_DIST_DIRS = Set.of(LABKEYWEBAPP, "modules");

private final File currentDir = new File("").getAbsoluteFile();
private final File labkeyServerJar;
Expand Down Expand Up @@ -76,23 +77,20 @@ private boolean shouldExtract(File webAppLocation)
File existingVersionFile = new File(webAppLocation, "WEB-INF/classes/VERSION");
File existingDistributionFile = new File(webAppLocation, "WEB-INF/classes/distribution");

LabKeyDistributionInfo incomingDistribution = getDistributionInfo();

// Likely upgrading from standalone Tomcat installation or webAppLocation doesn't exist.
if (!existingVersionFile.exists() || !existingDistributionFile.exists())
return true;

String existingVersion;
try
{
existingVersion = Files.readString(existingVersionFile.toPath()).trim();
}
catch (IOException e)
{
throw new RuntimeException(e);
LOG.info("Extracting new LabKey distribution - %s".formatted(incomingDistribution));
return true;
}

String existingVersion;
String existingDistributionName;
try
{
existingVersion = Files.readString(existingVersionFile.toPath()).trim();
existingDistributionName = Files.readString(existingDistributionFile.toPath()).trim();
}
catch (IOException e)
Expand All @@ -101,20 +99,24 @@ private boolean shouldExtract(File webAppLocation)
}

LabKeyDistributionInfo existingDistribution = new LabKeyDistributionInfo(existingVersion, existingDistributionName);
LabKeyDistributionInfo incomingDistribution = getDistributionInfo();

boolean shouldExtract = !existingDistribution.equals(incomingDistribution) ||
incomingDistribution.buildUrl == null; // Always redeploy distributions that aren't from TeamCity
if (shouldExtract)
if (!existingDistribution.equals(incomingDistribution))
{
LOG.info("Extracting new LabKey distribution (%s -> %s)".formatted(existingDistribution, incomingDistribution));
LOG.info("Updating LabKey deployment (%s -> %s)".formatted(existingDistribution, incomingDistribution));
return true;
}
else if (incomingDistribution.buildUrl == null)
{
LOG.info("Updating LabKey deployment (%s -> %s)".formatted(existingDistribution, incomingDistribution));
return true;
}
return shouldExtract;
return false;
}

/**
* Extract distribution info from bundled distribution.zip
* @return A list containing the version string
* Extract distribution info from bundled distribution.zip.
* Also verifies that distribution.zip contains expected files
* @return An object describing the distribution
*/
private LabKeyDistributionInfo getDistributionInfo()
{
Expand All @@ -141,11 +143,11 @@ private LabKeyDistributionInfo getDistributionInfo()
while (zipEntry != null)
{
distributionDirs.add(zipEntry.getName().split("/", 2)[0]);
if (!zipEntry.isDirectory() && zipEntry.getName().equals("labkeywebapp/WEB-INF/classes/VERSION"))
if (!zipEntry.isDirectory() && zipEntry.getName().equals(LABKEYWEBAPP + "/WEB-INF/classes/VERSION"))
{
version = StreamUtils.copyToString(zipIn, StandardCharsets.UTF_8).trim();
}
else if (!zipEntry.isDirectory() && zipEntry.getName().equals("labkeywebapp/WEB-INF/classes/distribution"))
else if (!zipEntry.isDirectory() && zipEntry.getName().equals(LABKEYWEBAPP + "/WEB-INF/classes/distribution"))
{
distributionName = StreamUtils.copyToString(zipIn, StandardCharsets.UTF_8).trim();
}
Expand Down Expand Up @@ -282,7 +284,7 @@ private void extractDistributionZip(InputStream zipInputStream, File destDir) th
{
String entryName = labkeyWebappDirName == null
? entry.getName()
: entry.getName().replaceFirst("^labkeywebapp", labkeyWebappDirName);
: entry.getName().replaceFirst("^" + LABKEYWEBAPP, labkeyWebappDirName);
File filePath = new File(destDir, entryName);
if (!entry.isDirectory())
{
Expand Down Expand Up @@ -426,6 +428,6 @@ public int hashCode()
@Override
public String toString()
{
return version + "(" + distributionName + ")";
return distributionName + ":" + version;
}
}

0 comments on commit 9dee258

Please sign in to comment.