Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #10437 - Unify Deployer ContextProvider #12583

Draft
wants to merge 52 commits into
base: jetty-12.1.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
8878567
Initial pass at implementation of EnvironmentContextProvider
joakime Nov 22, 2024
3a46e37
Fixing javadoc errors
joakime Nov 22, 2024
c5c07c2
Moving things around
joakime Nov 25, 2024
e0bdeb3
Moving changes back into ContextProvider
joakime Nov 25, 2024
7588d5f
Introducing ContextProvider.configureEnvironment(String name)
joakime Nov 25, 2024
42015b3
Fixing <env>[-zzz].properties sorting
joakime Nov 26, 2024
f9c90ce
Allow an Environment to be removed (needed for testing with Environment)
joakime Nov 26, 2024
83fc5f1
Fixing test cases
joakime Nov 26, 2024
a0c9058
Merge remote-tracking branch 'origin/jetty-12.1.x' into fix/12.1.x/un…
joakime Nov 27, 2024
249679f
Fix javadoc
joakime Nov 27, 2024
bef04d9
Fix method names
joakime Nov 27, 2024
add337a
Fixing Environment contextClass loading
joakime Nov 27, 2024
2e9660d
Fixing test cases
joakime Nov 27, 2024
9bfab80
Fixing quickstart XML references to provider
joakime Nov 27, 2024
2c651ea
Merge remote-tracking branch 'origin/jetty-12.1.x' into fix/12.1.x/un…
joakime Dec 2, 2024
0e534f7
Fixing quickstart XML
joakime Dec 2, 2024
43eb679
Fixing deploy containerScanJarPattern for ee9/ee8
joakime Dec 2, 2024
c5a00b8
Merge remote-tracking branch 'origin/jetty-12.1.x' into fix/12.1.x/un…
joakime Dec 2, 2024
229e358
Merge remote-tracking branch 'origin/jetty-12.1.x' into fix/12.1.x/un…
joakime Dec 18, 2024
a363189
Changes from reviews. Preparing for BulkListener impl.
joakime Dec 18, 2024
5f6d504
Using BulkListener with sorted paths for alphabetical deployment.
joakime Dec 18, 2024
77c34c2
Changes from review
joakime Dec 18, 2024
5306c3d
More changes from review
joakime Dec 18, 2024
96d5bec
Simplify else
joakime Dec 19, 2024
ee18845
Reworking deploy.createContextHandler to be easier to follow
joakime Dec 20, 2024
e498f2c
Fixing WebAppContext default-context-path mistake
joakime Dec 20, 2024
2b0741b
Merge remote-tracking branch 'origin/jetty-12.1.x' into fix/12.1.x/un…
joakime Jan 2, 2025
9d9267d
Merge remote-tracking branch 'origin/jetty-12.1.x' into fix/12.1.x/un…
joakime Jan 14, 2025
cf69f26
Introducing DeploymentUnit to simplify added/changed/removed update b…
joakime Jan 15, 2025
4fd255b
Merge remote-tracking branch 'origin/jetty-12.1.x' into fix/12.1.x/un…
joakime Jan 15, 2025
1ebdd10
Fix deprecation warnings
joakime Jan 16, 2025
d5def4c
Introduce ChangeSetListener in Scanner
joakime Jan 16, 2025
54960bd
Changes from review
joakime Jan 16, 2025
c16fdf7
Changes from review
joakime Jan 16, 2025
bc1b50f
Adding environment configuration hotreload ability
joakime Jan 17, 2025
24eb791
Correct syntax
joakime Jan 17, 2025
4d286d7
Updating Unit.calcState javadoc and unit tests.
joakime Jan 20, 2025
40052bd
Use new Unit.getLivePaths() impl
joakime Jan 20, 2025
6806b58
Isolate and cleanup deploy test that manipulate the Environment singl…
joakime Jan 21, 2025
8f32176
Merge remote-tracking branch 'origin/jetty-12.1.x' into fix/12.1.x/un…
joakime Jan 21, 2025
f92901d
Correct XML from merge
joakime Jan 21, 2025
c7fdc92
Debug for failing `JettyWebSocketTest` on CI
joakime Jan 21, 2025
745f4fe
Issue warning for overlap on reserved env configuration names in the …
joakime Jan 22, 2025
456132f
Rollback DEBUG logging
joakime Jan 22, 2025
dfd741b
Use new war filenames properly
joakime Jan 22, 2025
72c7304
Overhaul based on last PR review
joakime Jan 23, 2025
fbedd51
Fixing compilation on OSGI modules
joakime Jan 23, 2025
4bb0850
Fixing deployer XML id
joakime Jan 23, 2025
1e29659
Fixing null OSGiApp.properties
joakime Jan 23, 2025
2acf58e
More work on test stability
joakime Jan 23, 2025
7b5cd4e
Fix directory deployment issue
joakime Jan 23, 2025
318ab9e
Fixing "core" deployments
joakime Jan 24, 2025
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
38 changes: 7 additions & 31 deletions jetty-core/jetty-deploy/src/main/config/etc/jetty-core-deploy.xml
Original file line number Diff line number Diff line change
@@ -1,37 +1,13 @@
<?xml version="1.0"?><!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://jetty.org/configure_10_0.dtd">

<!-- =============================================================== -->
<!-- Attach the "core" environment app deployment provider -->
<!-- Configure the "core" environment deployment defaults -->
<!-- =============================================================== -->
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Call id="DeploymentManager" name="getBean">
<Arg><Call class="java.lang.Class" name="forName"><Arg>org.eclipse.jetty.deploy.DeploymentManager</Arg></Call></Arg>
<Configure id="contextProvider" class="org.eclipse.jetty.deploy.providers.ContextProvider">
<Call name="configureEnvironment">
<Arg>core</Arg>
<Set name="contextHandlerClass">
<Property name="contextHandlerClass" default="org.eclipse.jetty.server.handler.ResourceHandler$ResourceContext" />
</Set>
</Call>
<Ref refid="Environment">
<Call name="setAttribute">
<Arg>contextHandlerClass</Arg>
<Arg><Property name="contextHandlerClass"/></Arg>
</Call>
</Ref>
<Ref refid="DeploymentManager">
<Call name="addAppProvider">
<Arg>
<New id="WebAppProvider-core" class="org.eclipse.jetty.deploy.providers.ContextProvider">
<Set name="EnvironmentName">core</Set>
<Set name="monitoredDirName">
<Call name="resolvePath" class="org.eclipse.jetty.xml.XmlConfiguration">
<Arg>
<Property name="jetty.base" />
</Arg>
<Arg>
<Property name="jetty.deploy.monitoredDir" default="webapps" />
</Arg>
</Call>
</Set>
<Set name="deferInitialScan" property="jetty.deploy.deferInitialScan"/>
<Set name="scanInterval" property="jetty.deploy.scanInterval"/>
</New>
</Arg>
</Call>
</Ref>
</Configure>
49 changes: 25 additions & 24 deletions jetty-core/jetty-deploy/src/main/config/etc/jetty-deploy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,31 @@
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://jetty.org/configure_10_0.dtd">

<!-- =============================================================== -->
<!-- Create the deployment manager -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- The deplyment manager handles the lifecycle of deploying web -->
<!-- applications. Apps are provided by instances of the -->
<!-- AppProvider interface. -->
<!-- Create the monitored directory Context Provider -->
<!-- -->
<!-- The Context Provider is responsible for monitoring a provided -->
<!-- directory for web applications and hot deploying -->
<!-- through the DeploymentManager. -->
<!-- =============================================================== -->
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Call name="addBean">
<Arg>
<New id="DeploymentManager" class="org.eclipse.jetty.deploy.DeploymentManager">
<Set name="contexts">
<Ref refid="Contexts" />
</Set>
<Configure id="contextProvider" class="org.eclipse.jetty.deploy.providers.ContextProvider">
<Set name="monitoredDirName">
<Call name="resolvePath" class="org.eclipse.jetty.xml.XmlConfiguration">
<Arg>
<Property name="jetty.base" />
</Arg>
<Arg>
<Property name="jetty.deploy.monitoredDir" default="webapps" />
</Arg>
</Call>
</Set>
<Set name="deferInitialScan" property="jetty.deploy.deferInitialScan" />
<Set name="scanInterval" property="jetty.deploy.scanInterval" />

<!-- Add a customize step to the deployment lifecycle -->
<!-- uncomment and replace DebugBinding with your extended AppLifeCycle.Binding class
<Call name="insertLifeCycleNode">
<Arg>deployed</Arg>
<Arg>starting</Arg>
<Arg>customise</Arg>
</Call>
-->

</New>
</Arg>
</Call>
<Ref refid="DeploymentManager">
<Call name="addAppProvider">
<Arg>
<Ref refid="contextProvider" />
joakime marked this conversation as resolved.
Show resolved Hide resolved
</Arg>
</Call>
</Ref>
</Configure>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0"?><!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://jetty.org/configure_10_0.dtd">

<!-- =============================================================== -->
<!-- Create the deployment manager -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- The deployment manager handles the lifecycle of deploying web -->
<!-- applications. Apps are provided by instances of the -->
<!-- AppProvider interface. -->
<!-- =============================================================== -->
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Call name="addBean">
<Arg>
<New id="DeploymentManager" class="org.eclipse.jetty.deploy.DeploymentManager">
joakime marked this conversation as resolved.
Show resolved Hide resolved
<Set name="contexts">
<Ref refid="Contexts" />
</Set>

<!-- Add a customize step to the deployment lifecycle -->
<!-- uncomment and replace DebugBinding with your extended AppLifeCycle.Binding class
<Call name="insertLifeCycleNode">
<Arg>deployed</Arg>
<Arg>starting</Arg>
<Arg>customise</Arg>
</Call>
-->
</New>
</Arg>
</Call>
</Configure>
17 changes: 1 addition & 16 deletions jetty-core/jetty-deploy/src/main/config/modules/core-deploy.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,6 @@ webapps/
[xml]
etc/jetty-core-deploy.xml

[ini]
contextHandlerClass?=org.eclipse.jetty.server.handler.ResourceHandler$ResourceContext

[ini-template]
## Monitored directory name (relative to $jetty.base)
# jetty.deploy.monitoredDir=webapps

# Defer Initial Scan
# true to have the initial scan deferred until the Server component is started.
# Note: deploy failures do not fail server startup in a deferred initial scan mode.
# false (default) to have initial scan occur as normal.
# jetty.deploy.deferInitialScan=false

## Monitored directory scan period (seconds)
# jetty.deploy.scanInterval=0

## Default ContextHandler class for core deployments
## Default ContextHandler class for "core" environment deployments
# contextHandlerClass=org.eclipse.jetty.server.handler.ResourceHandler$ResourceContext
15 changes: 14 additions & 1 deletion jetty-core/jetty-deploy/src/main/config/modules/deploy.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[description]
This module enables web application deployment from the `$JETTY_BASE/webapps` directory.
This module enables web application context deployment from the `$JETTY_BASE/webapps` directory.

[depend]
server
deployment-manager

[lib]
lib/jetty-deploy-${jetty.version}.jar
Expand All @@ -13,3 +14,15 @@ webapps/
[xml]
etc/jetty-deploy.xml

[ini-template]
## Monitored directory name (relative to $jetty.base)
# jetty.deploy.monitoredDir=webapps

# Defer Initial Scan
# true to have the initial scan deferred until the Server component is started.
# Note: deploy failures do not fail server startup in a deferred initial scan mode.
# false (default) to have initial scan occur as normal.
# jetty.deploy.deferInitialScan=false

## Monitored directory scan period (seconds)
# jetty.deploy.scanInterval=0
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[description]
joakime marked this conversation as resolved.
Show resolved Hide resolved
This module enables the DeploymentManager

[depend]
server

[lib]
lib/jetty-deploy-${jetty.version}.jar

[xml]
etc/jetty-deployment-manager.xml

Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ public interface AppProvider extends LifeCycle
ContextHandler createContextHandler(App app) throws Exception;

/**
*
* @return The name of the {@link org.eclipse.jetty.util.component.Environment} this provider is for.
* @deprecated not used by all AppProviders, no generic replacement provided.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this interface is not named exactly accurately, and the class javadoc is misleading. According to its api, it isn't creating or providing any App instances to the DeploymentManager at all. Looking at it's api, it's function is really to create a ContextHandler instance - after some other class passes in an already created instance of App.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Unit a way that ScanningAppProvider tracks its collection of Path objects to an App via it's basename. (as long as the basename exists, this Unit exist)
  • App the fundamental unit used to track the App through the deployment lifecycle. (created as part of new deployment, used as reference for moving through lifecycle: undeploy/remove steps)
  • ContextHandler the feature of the Jetty Server that represents the instantiated and live App

While all of these seem like the same "thing" to track as a single place, it is really 3 levels of abstraction, each with its own life cycle. The Unit has the longest lifecycle, followed by App with a shorter lifecycle, and finally ContextHandler with the shortest (from the point of view of a deployment manager).

A Unit exists for as long as there are Paths with a basename being tracked. (only lives in ScanningAppProvider)
An App only exists if there is an AppProvider that creates it. (note that ScanningAppProvider can have a Unit with no App if there is no main deployment path present for that Unit)
A ContextHandler only exists if there is a need for it in the lifecycle binding. (If a step in the lifecycle needs a ContextHandler then that's when it gets created or accessed. Our standard lifecycle bindings will use the ContextHandler for deploy/start/stop/undeploy, but not the other bindings)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ContextHandler can even change as the App moves through the registered lifecycle bindings.
For example, a custom binding could wrap the ContextHandler to add an auditing layer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lifecycle relationships are such that neither an App nor a ContextHandler (in the sense of deployer) can exist without a Unit. Sure, ContextHandler and App have their own lifecycles, but they ultimately depend on the existence or otherwise of the Unit.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ContextHandlerFactory would be a better name for this interface

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another feature of Unit is that it represents a group of paths that influence the deployment process.

One aspect not made clear is that the environment configuration files (webapps/<env>.xml, webapps/<env>-<name>.xml, webapps/<env>.properties, and webapps/<env>-<name>.properties) are also considered a Unit (with basename <env>) that is tracked by the Scanner. (this is a feature that's been in Jetty 12.0.x since its inception). If one of those files in the unit are changed, then that triggers all associated Apps on that environment to also hot-redeploy.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting a good simple description of what a Unit is would be good. Then perhaps a better name would come from that.

*/
String getEnvironmentName();
@Deprecated(forRemoval = true, since = "12.1.0")
default String getEnvironmentName()
{
return "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.eclipse.jetty.deploy.graph.Edge;
import org.eclipse.jetty.deploy.graph.Node;
import org.eclipse.jetty.deploy.graph.Route;
import org.eclipse.jetty.deploy.providers.ContextProvider;
import org.eclipse.jetty.server.Deployable;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
Expand Down Expand Up @@ -132,7 +133,9 @@ void setLifeCycleNode(Node node)
* Get the default {@link Environment} name for deployed applications, which is
* the maximal name when using the {@link Deployable#ENVIRONMENT_COMPARATOR}.
* @return The default {@link Environment} name or null.
* @deprecated not used, replacement at {@link ContextProvider#getDefaultEnvironmentName()}
*/
@Deprecated(since = "12.1.0", forRemoval = true)
public String getDefaultEnvironmentName()
{
return _providers.stream()
Expand All @@ -150,7 +153,8 @@ public String getDefaultEnvironmentName()
*/
public void addApp(App app)
{
LOG.info("addApp: {}", app);
if (LOG.isDebugEnabled())
LOG.debug("addApp: {}", app);
AppEntry entry = new AppEntry();
entry.app = app;
entry.setLifeCycleNode(_lifecycle.getNodeByName("undeployed"));
Expand Down Expand Up @@ -184,6 +188,10 @@ public void setAppProviders(Collection<AppProvider> providers)
}
}

/**
* @deprecated No replacement. AppProvider interface no longer has getEnvironmentName.
*/
@Deprecated(since = "12.1.0", forRemoval = true)
public boolean hasAppProviderFor(String environmentName)
{
return environmentName != null && getAppProviders().stream()
Expand Down
Loading
Loading