How to control the order of deployed applications on JBoss EAP 8 / 7 / 6
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 8.x
- 7.x
- 6.x
Issue
- On JBoss Enterprise Application Platform 6 it difficult to control the order in which applications, packed in different ear-files, are deployed when the server is started.
- We have multiple ear archives that need to be deployed in strict order, and the deployment order need to be remembered after a restart. How could this be done ?
- How to deploy the application from the
admin-consolewhen one application is dependent on other application? - Can EAP6 handle multiple deployments simultaneously? Or would deployment requests be queued and executed serially?
- A "war" file should be deployed after the two "ear" files.
- We have around 13 services that we are deploying to JBoss. All of these services are WAR's. We need to define an order of startup for these services. Additionally, all of these services are dependent on a resource adapter starting first. Can this be done?
- How to put the order of deployment on different file types ?
- We have got an application (abc.ear) that depends on a third party resource adapter (XYZ.rar).
How to reliably configure class loading dependency from abc.ear to XYZ.rar ?
We have other EARs depending on "abc.ear". Those do already use "ejb-ref" in their deployment descriptors and deployment activation is deferred until "abc.ear" is ready.
Within "abc.ear!abc-ejb.jar" we have "resource-ref"s pointing to connection factories set up and served by "XYZ.rar", hence the module dependency for being able to use those classes. - In one of our application (A ), It has dependency on another application (B). So B application must be deployed in the JBOSS container before application A. But sometime, the contextpath for Application B is not loaded before Application A. In this case, our jboss server fails.
- Is it possible to control the order of the deploying the application on different JBoss nodes?
Node1 has the applications A and B.
Node2 has the applications C and D.
Application C depends on A and application D depends on B.
Resolution
- Services that have
@EJB,@Resourceorenv-entryconfigured in the components deployment descriptor, will start after the injected resources have been started. If you need ordering that JBoss cannot determine via analyzing the metadata, then you will need to do one of the options below to explicitly control the top level deployment starting order. If the order is needed just to have visibility of classes in an application that can be fixed by declaring a module dependency on the deployment's module whose classes you need via thejboss-deployment-structure.xmlor in theMANIFEST.MFas described in this article1. For service dependencies such as EJBs see this article2. If you want to control the initialization order of an EAR's subdeployments / modules, see this article3.
JBoss EAP 6.0.x
-
Create CLI scripts that will (un)deploy the applications in sequential order when the server is started/stopped.
-
EAP 6 CLI also supports the concept of batch mode which allows one to group commands and operations and execute them together as an atomic unit, i.e., if at least one of the commands or operations fails, all the other successfully executed commands and operations in the batch are rolled back.
Note: Using this approach will require that the applications will be undeployed via CLI before server shutdown and deployed each time the server is started.
JBoss EAP 6.1.x
- There is a new feature where you can declare dependencies between top level deployments:
AS7-5410 - Support inter deployment dependencies
Content from issues.jboss.org is not included.Content from issues.jboss.org is not included.https://issues.jboss.org/browse/AS7-5410
Example if you have a framework.ear and an app.ear and then app.ear depends on the framework.ear being deployed / started before it is deployed you can create a jboss-all.xml such as:
app.ear/META-INF/jboss-all.xml:
<jboss umlns="urn:jboss:1.0">
<jboss-deployment-dependencies xmlns="urn:jboss:deployment-dependencies:1.0">
<dependency name="framework.ear" />
</jboss-deployment-dependencies>
</jboss>
See attached jboss-all-dependency-demonstration.zip which shows the jboss-all.xml usage.
Note: This example was for ears, but as mentioned above this works for top level deployments, so if your top level deployment was a war or a jar you could put a jboss-all.xml inside of them and declare a dependency on another top level deployment. The jboss-all.xml goes in WEB-INF/ if the top level deployment is a war else it goes in META-INF/ for all other deployment types.
Note: If redeploying the application which is a dependent of others without deploying the others in JBoss EAP 6.2 CP 4 and prior versions may encounter this issue: Redeploying deployment that has a dependent throws IllegalStateException in JBoss EAP 6.2
Note: This jboss-deployment-dependencies configuration can be used by EAP 7 too.
To define dependency on a RAR, add like below in the EAR :
Created "abc.ear!META-INF/jboss-all.xml", containing:
<?xml version="1.0" encoding="utf-8"?>
<jboss xmlns="urn:jboss:1.0">
<jboss-deployment-dependencies xmlns="urn:jboss:deployment-dependencies:1.0">
<dependency name="BeanConnect.rar"/>
</jboss-deployment-dependencies>
</jboss>
Note: Controlling the order of deploying the application on different JBoss nodes are not possible because the application which are deployed on Node1 are not aware of the application deployed on Node2.
References:
How to declare classloading dependencies between deployments in JBoss EAP 6
https://access.redhat.com/site/solutions/308003
2: How to declare service lifecycle dependencies (such as EJB) between deployments in JBoss EAP 6
https://access.redhat.com/site/solutions/308013
3: How to control the initialization order of an EAR's subdeployments / modules in JBoss Enterprise Application 6
https://access.redhat.com/site/solutions/524873
Root Cause
- EAP 6 runs most of its start-up tasks in parallel , and it also loads services and classes on demand.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.