Skip to content

Commit

Permalink
bugfix: EAR deployment bugs found
Browse files Browse the repository at this point in the history
- fixed current deployment context - made it a regular thread local, not queue
- only add CDI bundles that are not UNKNOWN
- disable injection on EAR-root context (wrong context mode)
- actually destroy deployment ClassLoader shareableTemp correctly
  • Loading branch information
lprimak committed Feb 28, 2025
1 parent 383526a commit 39f8f2e
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 33 deletions.
2 changes: 1 addition & 1 deletion appserver/extras/docker-images/tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.12.0</version>
<version>5.11.4</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
4 changes: 2 additions & 2 deletions appserver/tests/payara-samples/samples/concurrency/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<failOnMissingWebXml>false</failOnMissingWebXml>
<arquillian-bom.version>1.9.1.Final</arquillian-bom.version>
<junit-jupiter.version>5.12.0</junit-jupiter.version>
<junit-jupiter.version>5.11.4</junit-jupiter.version>
<arquillian-payara.version>3.0.alpha4</arquillian-payara.version>
<jakarta-concurrent.version>3.0.4</jakarta-concurrent.version>
<shrinkwrap.version>3.3.3</shrinkwrap.version>
Expand Down Expand Up @@ -133,7 +133,7 @@
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.14.0</version>
<version>3.13.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public DeploymentImpl(ReadableArchive archive,
this.archiveFactory = archiveFactory;
this.context = context;
this.injectionManager = injectionManager;
this.contextId = moduleName != null? moduleName : archive.getName();

// Collect /lib Jar BDAs (if any) from the parent module.
// If we've produced BDA(s) from any /lib jars, <code>return</code> as
Expand All @@ -177,7 +178,6 @@ public DeploymentImpl(ReadableArchive archive,
this.appName = "CDIApp";
}

this.contextId = moduleName != null? moduleName : archive.getName();
createModuleBda(archive, ejbs, context, contextId);
}

Expand Down Expand Up @@ -274,7 +274,9 @@ private <TT extends BeanDeploymentArchive> Set<TT> filterBDAs(Set<TT> bdas, List
}

private void addBeanDeploymentArchives(RootBeanDeploymentArchive bda) {
rootBDAs(bda).add(bda);
if (bda.getModuleBDAType() != BDAType.UNKNOWN) {
rootBDAs(bda).add(bda);
}
}

private Set<RootBeanDeploymentArchive> rootBDAs(RootBeanDeploymentArchive bda) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,12 @@ public WeldApplicationContainer load(WeldContainer container, DeploymentContext
beanDeploymentArchive.getServices().add(EEModuleDescriptor.class, eeModuleDescriptor);
}
}
if (beanDeploymentArchive instanceof BeanDeploymentArchiveImpl
&& ((BeanDeploymentArchiveImpl) beanDeploymentArchive)
.getBDAType() != WeldUtils.BDAType.UNKNOWN) {
bundleToBeanDeploymentArchive.put(bundle, beanDeploymentArchive);
}
}

bundleToBeanDeploymentArchive.put(bundle, beanDeploymentArchive);
}

applicationInfo.addTransientAppMetaData(WELD_DEPLOYMENT, deploymentImpl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

package org.glassfish.weld.services;

import com.sun.enterprise.deployment.Application;
import com.sun.enterprise.deployment.BundleDescriptor;
import com.sun.enterprise.deployment.EjbBundleDescriptor;
import com.sun.enterprise.deployment.EjbDescriptor;
Expand Down Expand Up @@ -155,7 +156,7 @@ public <T> void aroundInject(InjectionContext<T> injectionContext) {
String targetClassName = targetClass.getName();
Object target = injectionContext.getTarget();

if ( isInterceptor( targetClass )
if ( isInterceptor( targetClass ) && !(bundleContext instanceof Application)
&& (componentEnv != null && !componentEnv.equals(injectionEnv)) ) {
// Resources injected into interceptors must come from the environment in which the interceptor is
// intercepting, not the environment in which the interceptor resides (for everything else!)
Expand Down Expand Up @@ -214,7 +215,7 @@ public <T> void aroundInject(InjectionContext<T> injectionContext) {
} else {
injectionManager.injectInstance(target, compEnvManager.getComponentEnvId(injectionEnv),false);
}
} else {
} else if (!(bundleContext instanceof Application)){
if ( target == null ) {
injectionManager.injectClass(targetClass, injectionEnv, false);
} else {
Expand All @@ -234,7 +235,7 @@ public <T> void aroundInject(InjectionContext<T> injectionContext) {

@Override
public <T> void registerInjectionTarget(InjectionTarget<T> injectionTarget, AnnotatedType<T> annotatedType) {
if ( bundleContext instanceof EjbBundleDescriptor ) {
if ( bundleContext instanceof EjbBundleDescriptor || bundleContext instanceof Application ) {
// we can't handle validting producer fields for ejb bundles because the JNDI environment is not setup
// yet for ejbs and so we can't get the correct JndiNameEnvironment to call getInjectionInfoByClass.
// getInjectionInfoByClass caches the results and so causes subsequent calls to return invalid information.
Expand Down
4 changes: 2 additions & 2 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
<command.security.maven.plugin.isFailureFatal>false</command.security.maven.plugin.isFailureFatal>
<maven.jar.plugin.version>3.4.2</maven.jar.plugin.version>
<maven.clean.plugin.version>3.4.1</maven.clean.plugin.version>
<maven.compiler.plugin.version>3.14.0</maven.compiler.plugin.version>
<maven.compiler.plugin.version>3.13.0</maven.compiler.plugin.version>
<maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>
<maven.surefire.plugin.version>3.5.2</maven.surefire.plugin.version>
<maven.resources.plugin.version>3.3.1</maven.resources.plugin.version>
Expand Down Expand Up @@ -198,7 +198,7 @@
<payara.deployment.transformer.version>1.3</payara.deployment.transformer.version>
<payara.transformer.version>0.2.12</payara.transformer.version>

<awaitility.version>4.3.0</awaitility.version>
<awaitility.version>4.2.2</awaitility.version>
</properties>

<issueManagement>
Expand Down
11 changes: 10 additions & 1 deletion nucleus/admin/template/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,16 @@
<configuration>
<artifactItems>
<!-- The index.html for the "docroot" application,
saying Payara is running etc when nothing is deployed to root. -->+--
saying Payara is running etc when nothing is deployed to root. -->
<artifactItem>
<groupId>org.glassfish.docs</groupId>
<artifactId>basedocs</artifactId>
<version>4.1.payara-p3</version>
<type>zip</type>
<overWrite>false</overWrite>
<includes>glassfish/lib/templates/**</includes>
</artifactItem>

<artifactItem>
<groupId>fish.payara.server.internal.ejb</groupId>
<artifactId>ejb-http-endpoint</artifactId>
Expand Down
14 changes: 7 additions & 7 deletions nucleus/admin/template/src/main/resources/docroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ <h1>Hello from Payara - your server is now running!</h1>
<main>
<div class="container">
<p>To replace this page, overwrite the file index.html in the document root folder of this server. The document root folder for this server is the docroot subdirectory of this server's domain directory.</p>
<p>To manage a server on the <strong>local host</strong> with the <b>default administration port</b><a href="http://localhost:4848" rel="nofollow" target="_blank">go to the Administration Console.</a></p>
<p>To manage a server on the <strong>local host</strong> with the <b>default administration port</b><a href="http://localhost:4848" target="_blank">go to the Administration Console.</a></p>
<h2>Payara Server Documentation</h2>
<p>For more information about Payara Server, documentation and additional resources see the <a href="https://docs.payara.fish/?utm_source=Payara+Community+Project&utm_medium=referral&utm_campaign=html+page+installed+with+payara+community" rel="nofollow" target="_blank">Payara documentation</a></p>
<p>For more information about Payara Server, documentation and additional resources see the <a href="https://docs.payara.fish" target="_blank">Payara documentation</a></p>
<h2>Welcome to the Payara Community</h2>
<p>As a member of the continuously growing and evolving open source community, you can benefit from some great support offered by other Payara Server users, and get involved yourself by posting feedback on the latest features and enhancements - or by making suggestions for future releases! And if you want to take it one step further, you can also become an official Payara Contributor. If you’d like to be a part of Payara Server's development, or simply get some help and advice from the community, <a href="https://www.payara.fish/community?utm_source=Payara+Community+Project&utm_medium=referral&utm_campaign=html+page+installed+with+payara+community" rel="nofollow" target="_blank">check out our Community page</a> for some useful information and links.</p>
<p>As a member of the continuously growing and evolving open source community, you can benefit from some great support offered by other Payara Server users, and get involved yourself by posting feedback on the latest features and enhancements - or by making suggestions for future releases! And if you want to take it one step further, you can also become an official Payara Contributor. If you’d like to be a part of Payara Server's development, or simply get some help and advice from the community, <a href="https://www.payara.fish/about/community/" target="_blank">check out our Community page</a> for some useful information and links.</p>

<h2>Subscribe to the Payara Tech Blog</h2>
<p>The Payara Tech Blog is packed with technical articles on Payara Server, Payara Micro, GlassFish, Java EE, Jakarta EE, microservices and more. For some expert hints and tips, demos, overviews and news delivered directly to your inbox, <a href="https://blog.payara.fish/?utm_source=Payara+Community+Project&utm_medium=referral&utm_campaign=html+page+installed+with+payara+community" rel="nofollow" target="_blank">subscribe to the Payara Blog here.</a></p>
<p>The Payara Tech Blog is packed with technical articles on Payara Server, Payara Micro, GlassFish, Java EE, Jakarta EE, microservices and more. For some expert hints and tips, demos, overviews and news delivered directly to your inbox, <a href="https://blog.payara.fish" target="_blank">subscribe to the Payara Blog here.</a></p>
<h2>Are You Running Payara Server in Mission Critical Production Environments?</h2>
<p>Payara Server Enterprise supports reliable and secure deployments of Jakarta EE (Java EE) applications in any environment: on premise in the cloud, or hybrid.</p>
<p>Our 10-year software lifecycle ensures longevity of your Payara Server investment. </p>
Expand All @@ -51,12 +51,12 @@ <h2>Are You Running Payara Server in Mission Critical Production Environments?</
<li>Migration &amp; Project Support, 24x7, or 10x5 support options included in your Enterprise subscription</li>
<li>Delivered by the experienced and dedicated team</li>
</ul>
<p>Learn More About <a href="https://www.payara.fish/enterprise/?utm_source=Payara+Community+Project&utm_medium=referral&utm_campaign=html+page+installed+with+payara+community" rel="nofollow" target="_blank">Payara Enterprise</a> or<a href="https://www.payara.fish/contact-us-sales-request/?utm_source=Payara+Community+Project&utm_medium=referral&utm_campaign=html+page+installed+with+payara+community" rel="nofollow" target="_blank"> contact the team.</a></p>
<p>Learn More About <a href="https://www.payara.fish/enterprise/" target="_blank">Payara Enterprise</a> or<a href="https://www.payara.fish/contact-us-sales-request/" target="_blank"> contact the team.</a></p>
</div>
<footer>
<div class="container">
<p class="links"><a href="https://www.payara.fish/about/?utm_source=Payara+Community+Project&utm_medium=referral&utm_campaign=html+page+installed+with+payara+community" rel="nofollow" target="_blank">Company Info</a>   |   <a href="https://www.payara.fish/about/contact-us/?utm_source=Payara+Community+Project&utm_medium=referral&utm_campaign=html+page+installed+with+payara+community" rel="nofollow" target="_blank">Contact</a>   | <a href="https://github.com/payara?utm_source=Payara+Community+Project&utm_medium=referral&utm_campaign=html+page+installed+with+payara+community" rel="nofollow">GitHub</a></p>
<p class="signoff">Copyright 2025 Payara Services Ltd and/or its affiliates.</p>
<p class="links"><a href="https://www.payara.fish/about/" target="_blank">Company Info</a>   |   <a href="https://www.payara.fish/about/contact-us/" target="_blank">Contact</a>   | <a href="https://github.com/payara">GitHub</a></p>
<p class="signoff">Copyright 2024 Payara Services Ltd and/or its affiliates.</p>
</div>
</footer>
</main>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,7 @@ public class ApplicationLifecycle implements Deployment, PostConstruct {
protected Logger logger = KernelLoggerInfo.getLogger();
final private static LocalStringManagerImpl localStrings = new LocalStringManagerImpl(ApplicationLifecycle.class);

private final ThreadLocal<Deque<ExtendedDeploymentContext>> currentDeploymentContext //
= new ThreadLocal<Deque<ExtendedDeploymentContext>>() {

@Override
protected Deque<ExtendedDeploymentContext> initialValue() {
return new ArrayDeque<>(5);
}
};
private final ThreadLocal<ExtendedDeploymentContext> currentDeploymentContext = new ThreadLocal<>();

protected DeploymentLifecycleProbeProvider
deploymentLifecycleProbeProvider = null;
Expand Down Expand Up @@ -291,7 +284,6 @@ public ApplicationDeployment prepare(Collection<? extends Sniffer> sniffers, fin
events.send(new Event<>(Deployment.DEPLOYMENT_START, context), false);
eventSpan.close();

currentDeploymentContext.get().push(context);
final ActionReport report = context.getActionReport();
final DeployCommandParameters commandParams = context.getCommandParameters(DeployCommandParameters.class);
final String appName = commandParams.name();
Expand Down Expand Up @@ -358,6 +350,7 @@ public void actOn(Logger logger) {
}
};

currentDeploymentContext.set(context);
try (DeploymentSpan topSpan = tracing.startSpan(DeploymentTracing.AppStage.PREPARE);
SpanSequence span = tracing.startSequence(DeploymentTracing.AppStage.PREPARE, "ArchiveMetadata")) {
if (commandParams.origin == OpsParams.Origin.deploy
Expand Down Expand Up @@ -604,7 +597,7 @@ public void actOn(Logger logger) {
if (report.getActionExitCode() != ActionReport.ExitCode.SUCCESS) {
context.postDeployClean(false /* not final clean-up yet */);
events.send(new Event<>(Deployment.DEPLOYMENT_FAILURE, context));
currentDeploymentContext.get().pop();
currentDeploymentContext.remove();
}
}
ApplicationDeployment depl = new ApplicationDeployment(appInfo, context);
Expand All @@ -625,6 +618,7 @@ public void initialize(ApplicationInfo appInfo, Collection<? extends Sniffer> sn
// time the containers are set up, all the modules have been prepared in their
// associated engines and the application info is created and registered
if (loadOnCurrentInstance(context)) {
currentDeploymentContext.set(context);
try (SpanSequence span = tracing.startSequence(DeploymentTracing.AppStage.INITIALIZE)){
notifyLifecycleInterceptorsBefore(ExtendedDeploymentContext.Phase.START, context);
appInfo.initialize();
Expand All @@ -646,9 +640,9 @@ public void initialize(ApplicationInfo appInfo, Collection<? extends Sniffer> sn
} else {
events.send(new Event<>(Deployment.DEPLOYMENT_SUCCESS, appInfo));
}
currentDeploymentContext.remove();
}
}
currentDeploymentContext.get().pop();
}

@Override
Expand Down Expand Up @@ -2713,6 +2707,6 @@ public Thread newThread(Runnable r) {

@Override
public ExtendedDeploymentContext getCurrentDeploymentContext() {
return currentDeploymentContext.get().peek();
return currentDeploymentContext.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public synchronized ClassLoader getClassLoader(boolean sharable) {
// return the final classloader
if (sharableTemp != null && sharableTemp.get() != cloader) {
try {
PreDestroy.class.cast(sharableTemp).preDestroy();
PreDestroy.class.cast(sharableTemp.get()).preDestroy();
} catch (Exception e) {
// ignore, the classloader does not need to be destroyed
}
Expand Down

0 comments on commit 39f8f2e

Please sign in to comment.