Nowadays, it’s easy to get up and running WildFly standalone server in a container. But what if you need to enable clustering in Managed Domain mode, which is one of the key features of Jakarta EE in general? That is not an easy task. Some people claim it’s nearly impossible in the cloud-native world, because Jakarta EE clustering was designed before the containers era. The old question on the official developers portal is still not answered with any adequate instruction that just proves the presence of the issue.
As a result, developers go with standalone nodes as the only available production-ready option in containers, integrating clustering and management features from third-party solutions. Or they just keep running applications in VMs, facing complexity that makes migration nearly impossible.
But what developers should do if they are looking for a solution to migrate from VMs to containers already existing and nicely working Jakarta EE clusters in managed domain mode?
Till this time, there were very few examples (e.g., for GlassFish and WebLogic) on how to run and scale Java application servers in managed domain mode within containers correctly. In most cases, a lack of knowledge or even the absence of a working solution for the domain mode in containers leads to the loss of integrated Jakarta EE clustering features that just become obsolete.
But managed domain mode is still awesome! A vast portion of mission-critical and large-scale applications, such as banking and billing, are still running on Jakarta EE in VMs. Integrated Jakarta EE clustering provides functionality that people are interested in, including high-availability and automated deployment among distributed Java application servers regardless of underlying infrastructure, and, of course, Admin Panel to manage your cluster using a nice UI. 

When, What, and Why Managed Domain Mode?
Every WildFly standalone server has its own admin console and is managed independently. At the same time, WildFly multiple instances running in the domain mode share the same management interface called the domain controller. So you can issue commands and deploy applications to all running WildFly servers from one place. The official documentation suggests considering the domain mode for:
- Multi-server production environments with the ability to use centralized management capabilities that a managed domain provides.
- For advanced development scenarios, i.e., those involving interaction between multiple WildFly instances.
We can easily run one big service or several small interrelated services per cluster running in managed domain mode. Deployment to such a cluster is automated, so applications running in VMs can be lifted and shifted to containers without re-architecturing. It provides a very convenient way for replicating on-premise applications in the cloud while avoiding costly and time-consuming re-design. As a result, the legacy applications can benefit from the cost-efficiency of cloud-native features such as elastic compute and auto-scaling.
Complexity of Managed Domain Topology
Let’s have a look at the topology of the WildFly cluster in managed domain mode, which is illustrated in the official documentation. The illustration below provides a sense of the complexity of managed domain architecture. This scheme is considered a classical Jakarta EE topology in VMs, or the so-called “legacy dragon,” which should be tamed and decomposed properly into containers. 



- Worker Server is a JVM process where the enterprise Jakarta EE applications are deployed and handle requests.
- Host Controller is a JVM process that is responsible for configuring Worker Servers and synchronization between the Servers and Domain Controller.
- Process Controller is a JVM process that is responsible for the lifecycle (start/stop/restart) of Worker Servers. It is absent in the original scheme, but it is important to take into account while decomposition.
- Domain Controller is a type of Host Controller that is designated to act as master admin server (or orchestrator) at the cluster running in managed domain mode and provides a single pane for managing distributed Worker Servers.
Running Multiple Processes in an Application Container
As we can see from the illustration above, the VM1 contains two Java processes inside: Process Controller and Domain Controller. And every other VM contains at least three Java processes (or more, depending on how many server instances you want to run inside every host): Process Controller, Host Controllers, and Worker Server(s).
That’s not easy to run it in containers. Such topology conflicts with the anti-pattern in the application containers world. The official Docker documentation warns us about running multiple Java processes inside the same container:
“It’s ok to have multiple processes, but to get the most benefit out of Docker, avoid one container being responsible for multiple aspects of your overall application.”
So users feel confused when they get the message to perform this “seems-unreliable” action. Previous bad experience led to loss of trust, and it is rather reasonable.
Running Multiple Processes in a System Container
However, the situation is not so bad. If configured properly, the domain mode works perfectly inside system containers. They can handle as many processes as required inside one container. This kind of container drastically simplifies migration from heavy VMs to a much lightweight virtualization. And there are two well-known options on the market LXD and OpenVZ. Moreover, system containers and application containers are complementary; the combination of both provides VM characteristics for dockerized applications.
Virtuozzo PaaS implemented support of system containers in early days of 2011 and can confirm that many customers are happy with running multiple processes inside the same container in production when it’s required.
Moreover, system containers provide better resource and security isolation compared to the application containers, so cloud providers can safely host applications of different projects on the same infrastructure, reducing the cost of ownership and complexity of management. As a side effect, system containers are starting up a little bit slower compared to the application containers, but they are still much slimmer and faster than VMs.
Decomposition and Building Modified Topology
We are ready to start our decomposition journey. The first rule is in the spirit of microservices - it is always better to put only one Worker Server per container. Also, we create only one server group per domain for all containers inside the cluster. Such simple adjustments will give tremendous and desired flexibility for scaling each Worker Server vertically, gaining resource usage efficiency, and scaling the group of containers horizontally by adding new instances on demand. 

WildFly Managed Domain in Virtuozzo
To facilitate the migration of legacy Jakarta EE applications from VMs to containers, we created a special embedded Auto-Clustering mode for WildFly that can be enabled for new instances.
The main advantage of this solution is an automatic interconnection of multiple application servers upon the environment topology change, which implements the commonly used clustering configuration in managed domain mode.
Below you’ll see how standalone WildFly transforms into the cluster by means of the Auto-Clustering feature and a simple horizontal scaling with no manual configurations required. Also, we’ll describe infrastructure topology specifics and the way to get the appropriate development and production environments up and running inside Virtuozzo PaaS.
Create Standalone WildFly
With Virtuozzo, the required topology can be built using a convenient wizard:
1. Create a new environment 

- Choose a proper version of WildFly
- Set up vertical scaling limits
- Change the name of the environment if needed (e.g., wildfly)




In the Deployment manager, click Deploy to… button. 







Get Clustered WildFly with Managed Domain Mode
WildFly clustering with domain mode is configured automatically by means of the Auto-Clustering feature. Once it was enabled, the servers can be scaled manually or automatically.
- Manually
Add new servers via wizard while creating the environment or by changing its topology. 



- Automatically
The number of servers can be changed automatically by setting up scaling triggers based on the resource consumption within Settings > Auto Horizontal Scaling. 

- During the initial transformation from standalone to domain mode, your application will be down for about 1 minute
- All further scaling changes happen with no downtime
- If you enable Auto-Clustering and start from two instances at once, the domain mode will be created from the beginning, so no downtime will happen during the scaling
Afterwards, as the scaling is completed (manual or automatic), all WildFly instances will join the cluster, working in the operation mode of WildFly Managed Domain. Domain Controller and Load Balancer are added automatically as required components of the cluster.
Upon this scaling, the previously deployed application is also automatically redeployed to the rest of WildFly instances of the cluster. Also, database connection pool configurations and other config customizations, previously made via WildFly admin console, are replicated across the whole application server layer.
You can check how WildFly topology is changed from standalone mode to managed domain cluster: 

- Server:worker
- Process Controller
- Host Controller


And Domain Controller node has two processes running:
- Process Controller
- Host Controller


Also, the topology changes are synchronized and shown within WildFly Admin Panel. 

Application Availability among Workers
The application deployed to the standalone server is redeployed to all server instances during transformation to the cluster. To check this you can click Open in browser at each Worker. 



Cloning Cluster in Domain Mode
When releasing a new application version or just applying some essential adjustments, it’s a good practice to check how the newly implemented changes could affect the service work. The Virtuozzo PaaS allows you to accomplish such testing ‘on-fly’ (i.e., without service downtime and implicitly for your customers) with the Clone Environment option. 



Summary
This instruction proves that there is no need to rebuild the whole application architecture in order to gain the required outcome from both managed domain mode and container technology. Migration of legacy projects from VMs to micro clusters with system containers is not that painful at all. It brings a “rich taste” of flexibility and efficiency for increasing competitive advantage.
Want to see how it works for you?
Give it a try with a free trial from a local Virtuozzo Application Platform provider — and see how easy cloud can be.
Want to offer powerful cloud services under your brand?
Get in touch with Virtuozzo to learn how to install the Application Platform on your own infrastructure.





