IBM App Connect Enterprise Shared Classes and Containers
This article describes two categories of solution which show how shared classes can be migrated to containers without being rewritten.
Join the DZone community and get the full member experience.Join For Free
IBM App Connect Enterprise (ACE) has provided support for the concept of “shared classes” for many releases, enabling various use cases including providing supporting Java classes for JMS providers and also for caching data in Java static variables to make it available across whole servers (plus other scenarios). Some of these scenarios are less critical in a containerized server, and others might be handled by using shared libraries instead, but for the remaining scenarios there is still a need for the shared classes capability in containers.
What Is the Equivalent of
/var/mqsi/shared-classes in Containers?
Adding JARs to shared classes is relatively simple when running ACE in a virtual machine: copying the JAR files into a specific directory such as
/var/mqsi/shared-classes allows all flows in all servers to make use of the Java code. There are other locations that apply only to certain integration nodes or servers, but the basic principle is the same, and only needs to be performed once for a given version of supporting JAR as the copy action is persistent across redeploys and reboots.
The container world is different, in that it starts with a fixed image every time, so copying files into a specific location must either be done when building the container image, or else done every time the container starts (because changes to running containers are generally non-persistent). Further complicating matters is the way flow redeploy works with containers: the new flow is run in a new container, and the old container with the old flow is deleted, so any changes to the old container are lost.
Two main categories of solution exist in the container world:
- Copy the shared classes JARs into the container image during the container build, and
- Deploy the shared classes JARs in a BAR file or configuration in IBM Cloud Pak for Integration (CP4i) and configure the server to look for them.
There is also a modified form of the second category that uses persistent volumes to hold the supporting JARs, but from an ACE point of view it is very similar to the CP4i configuration method.
The following discussion uses an example application from the GitHub repo at https://github.com/trevor-dolby-at-ibm-com/ace-shared-classes to illustrate the question and some of the answers.
Original Behavior With ACE in a Virtual Machine
Copying the supporting JAR file into
/var/mqsi/shared-classes was sufficient when running in a virtual machine, as the application would be able to use the classes without further configuration:
The application would start and run successfully, and other applications would also be able to use the same shared classes across all servers.
Container Solution 1: Copy the Shared Classes JARs in While Building the Container Image
This solution has several variants, but they all result in the container starting up with the support JAR already in place. ACE servers will automatically look in the “
shared-classes” directory within the work directory, and so it is possible to simply copy the JARs into the correct location; the following example from the Dockerfile in the repo mentioned above shows this:
# Copy the pre-built shared JAR file into place
RUN mkdir /home/aceuser/ace-server/shared-classes
COPY SharedJava.jar /home/aceuser/ace-server/shared-classes/
and the server in the container will load the JAR into the shared classloader:
Note that this solution also works for servers running locally during development in a virtual machine. It also means that any change to the supporting JAR requires a rebuild of the container image, but this may not be a problem if a CI/CD pipeline is used to build application-specific container images.
The server may also be configured to look elsewhere for shared classes by setting the
additionalSharedClassesDirectories parameter in server.conf.yaml. This parameter can be set to a list of directories to use, and then the supporting JAR files can be placed anywhere in the container. The following example shows the JAR file in the “
This solution would be most useful for cases where the needed JAR files are already present in the image, possibly as part of another application installation.
Container Solution 2: Deploy the Shared Classes JARs in a BAR File or Configuration in CP4i
For many CP4i use cases, the certified container image will be used unmodified, so the previous solution will not work as it requires modification of the container image. In these cases, the supporting JAR files can be deployed either as a BAR file or else as a “generic files” configuration. In both cases, the server must be configured to look for shared classes in the desired location.
If the JAR files are small enough or if the shared artifacts are just properties files, then using a “generic files” configuration is a possible solution, as that type of configuration is a ZIP file that can contain arbitrary contents. The repo linked above shows an example of this, where the supporting JAR file is placed in a ZIP file in a subdirectory called “
additionalSharedClassesDirectories is set to “
(If a persistent volume is used instead, then the “generic files” configuration is not needed and the
additionalSharedClassesDirectories setting should point to the PV location; note that this requires the PV to be populated separately and managed appropriately (including allowing multiple simultaneous versions of the JARs in many cases)).
The JAR file can also be placed in a shared library and deployed in a BAR file, which allows the supporting JARs to be any size and also allows a specific version of the supporting JARs to be used with a given application. In this case, the supporting JARs must be copied into a shared library and then
additionalSharedClassesDirectories must be set to point the server at the shared library to tell it to use it as shared classes.
This example uses a shared library called SharedJavaLibrary and so
additionalSharedClassesDirectories is set to “
Shared libraries used this way cannot also be used by applications in the server.
Existing solutions that require the use of shared classes can be migrated to containers without needing to be rewritten, with two categories of solution that allow this. The first category would be preferred if building container images is possible, while the second would be preferred if a certified container image is used as-is.
For further reading on container image deployment strategies, see Comparing Styles of Container-Based Deployment for IBM App Connect Enterprise; ACE servers can be configured to work with shared classes regardless of which strategy is chosen.
Published at DZone with permission of Trevor Dolby. See the original article here.
Opinions expressed by DZone contributors are their own.