Skip to content

Commit

Permalink
Download bundles from maven or S3 directly and no longer from the upd…
Browse files Browse the repository at this point in the history
…ate provider
  • Loading branch information
michaeloffner committed Jan 22, 2024
1 parent f98658b commit 2a5f1eb
Show file tree
Hide file tree
Showing 10 changed files with 2,256 additions and 123 deletions.
3 changes: 2 additions & 1 deletion ant/build-core.xml
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@
<jvmarg value="-Dlucee.extensions.install=true"/>
<jvmarg value="-Dlucee.full.null.support=false"/>
<!-- this checks to see that all the required bundles are provided, so that none are missing -->
<jvmarg value="-Dlucee.enable.bundle.download=false"/>
<jvmarg value="-Dlucee.enable.bundle.download=false"/><!-- we do always download to make sure this is available -->
<jvmarg value="-Dlucee.cli.printExceptions=true"/>
<jvmarg value="-Dlucee.ssl.checkserveridentity=false"/>
</java>
Expand Down Expand Up @@ -552,6 +552,7 @@
<jvmarg value="-Dlucee.cli.printExceptions=true"/>
<jvmarg value="-Dlucee.ssl.checkserveridentity=false"/>
<jvmarg value="-DLUCEE_BUILD_ENV=${LUCEE_BUILD_ENV}"/>
<jvmarg value="-Dlucee.enable.bundle.download=always"/>
<!--
<jvmarg value="-XX:StartFlightRecording=disk=true,dumponexit=true,filename=${temp}/../lucee-testcases.jfr,maxsize=1024m,maxage=1d,settings=profile,path-to-gc-roots=true"/>
<jvmarg value="-Dlucee.system.out=file:.../out.txt"/>
Expand Down
21 changes: 21 additions & 0 deletions core/src/main/java/lucee/commons/io/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
**/
package lucee.commons.io;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
Expand All @@ -29,6 +33,7 @@

import lucee.commons.io.res.Resource;
import lucee.commons.io.res.util.ResourceUtil;
import lucee.loader.util.Util;

/**
* Helper methods for file objects
Expand Down Expand Up @@ -211,4 +216,20 @@ private static Resource _createTempResourceFromLockedResource(Resource res, bool
return temp;
}

public static void move(File src, File dest) throws IOException {
boolean moved = src.renameTo(dest);
if (!moved) {
BufferedInputStream is = new BufferedInputStream(new FileInputStream(src));
BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(dest));
try {
Util.copy(is, os, false, false); // is set false here, because copy does not close in case of an exception
}
finally {
IOUtil.closeEL(is);
IOUtil.closeEL(os);
}
if (!src.delete()) src.deleteOnExit();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import lucee.commons.io.SystemUtil;
import lucee.commons.io.log.LogUtil;
import lucee.commons.lang.SerializableObject;
import lucee.runtime.MappingImpl;
import lucee.runtime.PageSource;
import lucee.runtime.PageSourceImpl;
Expand All @@ -17,6 +18,7 @@ public class PageSourcePoolWatcher {
private PageSourcePoolWatcherThread thread;
private final MappingImpl mapping;
private PageSourcePool pageSourcePool;
private SerializableObject token = new SerializableObject();

public PageSourcePoolWatcher(MappingImpl mapping, PageSourcePool pageSourcePool, Map<String, SoftReference<PageSource>> pageSources) {
this.mapping = mapping;
Expand All @@ -26,16 +28,26 @@ public PageSourcePoolWatcher(MappingImpl mapping, PageSourcePool pageSourcePool,

public void startIfNecessary() {
if (thread == null || !thread.isAlive()) {
thread = new PageSourcePoolWatcherThread();
thread.setPriority(Thread.MIN_PRIORITY);
thread.start();
synchronized (token) {
if (thread == null || !thread.isAlive()) {
thread = new PageSourcePoolWatcherThread();
thread.setPriority(Thread.MIN_PRIORITY);
thread.start();
}
}

}
}

public void stopIfNecessary() {
if (thread != null) {
thread.active(false);
thread = null;
synchronized (token) {
if (thread != null) {
thread.active(false);
thread = null;
}
}

}
}

Expand Down
1,361 changes: 1,361 additions & 0 deletions core/src/main/java/lucee/runtime/config/s3/BundleProvider.java

Large diffs are not rendered by default.

32 changes: 12 additions & 20 deletions core/src/main/java/lucee/runtime/osgi/OSGiUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,11 @@
import lucee.loader.osgi.BundleUtil;
import lucee.loader.util.Util;
import lucee.runtime.config.Config;
import lucee.runtime.config.ConfigServer;
import lucee.runtime.config.ConfigWebFactory;
import lucee.runtime.config.ConfigWebUtil;
import lucee.runtime.config.Identification;
import lucee.runtime.config.s3.BundleProvider;
import lucee.runtime.engine.CFMLEngineImpl;
import lucee.runtime.engine.ThreadLocalConfigServer;
import lucee.runtime.engine.ThreadLocalPageContext;
import lucee.runtime.exp.PageException;
import lucee.runtime.op.Caster;
Expand Down Expand Up @@ -753,13 +752,12 @@ public static Bundle _loadBundle(BundleContext bc, final BundleRange bundleRange
if (bundleRange.getVersionRange() != null && !bundleRange.getVersionRange().isEmpty()) {
// TODO not only check for from version, request a range, but that needs an adjustment with the
// provider
BundleFile _bf = improveFileName(factory.getBundleDirectory(),
BundleFile.getInstance(factory.downloadBundle(bundleRange.getName(), bundleRange.getVersionRange().getFrom().getVersion().toString(), id)));
File f = BundleProvider.getInstance().downloadBundle(new BundleDefinition(bundleRange.getName(), bundleRange.getVersionRange().getFrom().getVersion()));
BundleFile _bf = improveFileName(factory.getBundleDirectory(), BundleFile.getInstance(f));
resetJarsFromBundleDirectory(factory);
b = _loadBundle(bc, _bf);
}
else {
// MUST find out why this breaks at startup with commandbox if version exists
Resource r = downloadBundle(factory, bundleRange.getName(), null, id);
BundleFile src = BundleFile.getInstance(r);
BundleFile trg = improveFileName(factory.getBundleDirectory(), src);
Expand Down Expand Up @@ -832,9 +830,12 @@ private static String parentBundleText(String parentBundle) {
return "for [" + parentBundle + "] ";
}

private static Resource downloadBundle(CFMLEngineFactory factory, final String symbolicName, String symbolicVersion, Identification id) throws IOException, BundleException {
private static Resource downloadBundle(CFMLEngineFactory factory, final String symbolicName, String symbolicVersion, Identification id)
throws IOException, BundleException, PageException {
resetJarsFromBundleDirectory(factory);
if (!Caster.toBooleanValue(SystemUtil.getSystemPropOrEnvVar("lucee.enable.bundle.download", null), true)) {

String strDownload = SystemUtil.getSystemPropOrEnvVar("lucee.enable.bundle.download", null);
if (!Caster.toBooleanValue(strDownload, true)) {
boolean printExceptions = Caster.toBooleanValue(SystemUtil.getSystemPropOrEnvVar("lucee.cli.printExceptions", null), false);
String bundleError = "Lucee is missing the Bundle jar [" + (symbolicVersion != null ? symbolicName + ":" + symbolicVersion : symbolicName)
+ "], and has been prevented from downloading it. If this jar is not a core jar,"
Expand All @@ -848,20 +849,11 @@ private static Resource downloadBundle(CFMLEngineFactory factory, final String s
}
}
final Resource jarDir = ResourceUtil.toResource(factory.getBundleDirectory());
final URL updateProvider;
if (ThreadLocalPageContext.insideServerNewInstance()) {
ConfigServer cs = ThreadLocalConfigServer.get();
updateProvider = cs != null ? cs.getUpdateLocation() : factory.getUpdateLocation();
}
else {
updateProvider = factory.getUpdateLocation();
}

if (symbolicVersion == null) symbolicVersion = "latest";
final URL updateUrl = new URL(updateProvider, "/rest/update/provider/download/" + symbolicName + "/" + symbolicVersion + "/" + (id != null ? id.toQueryString() : "")
+ (id == null ? "?" : "&") + "allowRedirect=true"

);
final URL updateUrl = BundleProvider.getInstance().getBundleAsURL(new BundleDefinition(symbolicName, symbolicVersion), true);

log(Logger.LOG_INFO, "Downloading bundle [" + symbolicName + ":" + symbolicVersion + "] from [" + updateUrl + "]");

int code;
Expand Down Expand Up @@ -965,7 +957,7 @@ public static BundleFile getBundleFile(String name, Version version, Identificat
if (downloadIfNecessary && version != null) {
try {
resetJarsFromBundleDirectory(factory);
bf = BundleFile.getInstance(factory.downloadBundle(name, version.toString(), id));
bf = BundleFile.getInstance(BundleProvider.getInstance().downloadBundle(new BundleDefinition(name, version)));
if (bf.isBundle()) return bf;
}
catch (Throwable t) {
Expand Down Expand Up @@ -1064,7 +1056,7 @@ public static BundleFile getBundleFile(String name, Version version, Identificat
if (downloadIfNecessary && version != null) {
try {
resetJarsFromBundleDirectory(factory);
bf = BundleFile.getInstance(factory.downloadBundle(name, version.toString(), id));
bf = BundleFile.getInstance(BundleProvider.getInstance().downloadBundle(new BundleDefinition(name, version)));
if (bf.isBundle()) return bf;
}
catch (Throwable t) {
Expand Down
2 changes: 1 addition & 1 deletion loader/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project default="core" basedir="." name="Lucee"
xmlns:resolver="antlib:org.apache.maven.resolver.ant">

<property name="version" value="6.1.0.20-ALPHA"/>
<property name="version" value="6.1.0.21-ALPHA"/>

<taskdef uri="antlib:org.apache.maven.resolver.ant" resource="org/apache/maven/resolver/ant/antlib.xml">
<classpath>
Expand Down
2 changes: 1 addition & 1 deletion loader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.lucee</groupId>
<artifactId>lucee</artifactId>
<version>6.1.0.20-ALPHA</version>
<version>6.1.0.21-ALPHA</version>
<packaging>jar</packaging>

<name>Lucee Loader Build</name>
Expand Down
Loading

0 comments on commit 2a5f1eb

Please sign in to comment.