Migrating the Liberty version

Content series:

This content is part # of # in the series: Refactor existing monolithic applications to microservices one bite at a time, Part 1

https://www.ibm.com/developerworks/library/?series_title_by=**auto**

Stay tuned for additional content in this series.

This content is part of the series:Refactor existing monolithic applications to microservices one bite at a time, Part 1

Stay tuned for additional content in this series.

For most new applications, microservices is the architecture of choice of
many organizations. These organizations are starting to examine how they
can refactor their existing monolithic Java applications into
microservices to make them more flexible and agile without starting from
scratch. Monoliths were designed not just for single tasks, but also to
perform every step that is needed to complete a particular function. The
size and complexity of monolithic applications are the result of numerous
inter-related pieces of code and data models, which can be overwhelming to
developers when they start refactoring. They might dive straight into
changing code, where one monolith becomes 10 or 20 smaller monoliths. As a
result, the developer can't be sure whether the issues in testing are
related to the migration to the cloud or the refactoring process.

This article series breaks down the complex problem of refactoring
monoliths into microservices step-by-step. You learn how to implement a
systematic approach to refactor your monolithic applications and how to
use the tools and techniques to help you along that journey. You see how
to migrate the monolith to microservices and then run that monolith in the
cloud. The target cloud platforms are Docker Containers in IBM Cloud Private on-premises and Cloud
Foundry in the IBM Cloud Public.

In Part 1 of this series, you migrate the Daytrader3 application from
IBM® WebSphere® Application Server Liberty 8.5.5.0 to Liberty
17.0.0.2. After you migrate the application, you then deploy and run it on
premises. This step is important to ensure that your application is at the
latest version before you move it to the cloud. During this step, you
might also want to eliminate other areas of technical debt, such as
upgrading your open source libraries or upgrading your Java Enterprise
Edition (Java EE) specification levels. Keep these changes to a minimum so
that you do not introduce too much risk. By doing so, you can move your
workloads to the cloud and benefit from cloud economics sooner, rather
than later.

Prerequisites

Downloadable files. To view the original monolith and
the refactored monolith at each stage of refactoring, go to this repository
on GitHub.

Set up the development environment

To set up the development environment, you must complete the following
steps:

Download and install the Liberty kernel.

Download and install the Daytrader3 application.

Configure Eclipse IDE for Java EE Developers.

1a

Download and install the Liberty kernel

The Liberty server process comprises a single Java virtual machine
(JVM)--the Liberty kernel--and various optional features. The kernel does
not provide any features by itself, but you can add features to it. By
using the installUtility command of the Liberty kernel, you
can use the bin/installUtility command to create your own
server from the kernel with the features that you need.

The Daytrader3Sample.jar file contains the
Daytrader3Sample server that is configured with the features that
are required to run the Daytrader3 application. The JAR file also
contains the Daytrader3 application (daytrader3-ee6.ear file),
which includes the source code. In addition, the JAR file includes
the externaldependencies.xml file, which is used to download the
Derby database that the application uses.

Install the Daytrader3Sample.jar file from the command line by using
the installUtility command.

At a command prompt, go to the Liberty/bin directory, for
example: %HOMEPATH%\wlp\bin.

Enter the following
command:installUtility install
DayTrader3Sample

When prompted, accept the terms of the license agreement, and
click Yes to download the Derby prerequisite
dependencies.

Import the code into the Web Tools Platform
(Eclipse) projects

The daytrader3-ee6.ear file contains the source and binary files for the
application. To import it into Eclipse to establish the application
projects:

In Eclipse, click File -> Import -> Java EE -> EAR
file.

Enter the daytrader3-ee6.ear file. You can find the file
in the
%HOMEPATH%\wlp\usr\servers\Daytrader3Sample\dropins
directory. Then, click Finish.

By having an enterprise archive (EAR) file with source code, you can easily
import the code into Web Tools Platform projects. If you don't have this
file, you can modify your build system to create this EAR file.
Alternatively, you can import the code from your source code repository
that was used to create the EAR file.

3

Resolve Java problems

Now that you imported the source for the DayTrader application, you must
resolve Java problems so that you can compile the application as ready for
deployment.

In Eclipse, select Project -> Clean -> Clean all
projects.

Open the Markers view, and expand Java
problems.

The web project uses types and interfaces
from the dt-ejb project, which results in several "The import XXX
cannot be resolved" Java problems. You can find the important
problems to fix by searching for
"The import XXX cannot be
resolved."

The following sections examine two of the problems and their solutions.

The import com.ibm.websphere.samples.daytrader cannot be
resolved

To resolve this Java problem, add the dt-ejb project to the Java build path
of the web project:

The import org.apache.commons cannot be resolved

The dt-ejb project uses classes and interfaces from the Apache commons
logging library (apache.commons.logging V1.0.3). The application does not
provide this library. Although this same library is available in Liberty
17.0.0.2, it is not visible to the application. Regardless, an application
should not rely on open source libraries from the application server.

The Apache commons logging library has dependencies on the Log4J file,
which create runtime issues if not resolved. You will find these
dependencies in the manifest.mf file that is inside the
commons-logging.jar file. To resolve this problem, download the log4j-1.2.6.jar and log4j-core-2.8.2.jar files to the
%HOMEPATH%\downloads directory.

Copy the log4j.jar and log4j-core.jar
files into the daytrader3-ee6\lib
directory.

4

Run the WebSphere Application Server Migration
Toolkit

The WebSphere Application Server Migration Toolkit Eclipse plug-in analyzes
source code and configuration files for known migration issues. In this
step, you use the Migration Toolkit to look for known issues when you
migrate from Liberty that is running Java 6 to Liberty that is running
Java 8.

In Eclipse, run the WebSphere Application Server Migration Toolkit.
Click Run -> Analysis. In the left pane, click
Software Analyzer, and then click
New.

In the Create, manage, and configurations window:

Enter a suitable name for the configuration.

On the Scope tab, select Analyze
entire workspace.

On the Rules tab, for Rule Sets, select
WebSphere Application Server Version
Migration.

Deploy the DayTrader application
on-premises

Click Browse, go to the
%HOMEPATH%\wlp\usr\servers\Daytrader3Sample\dropins
directory, and select the existing daytrader3-ee6.ear
file. Select Overwrite existing file, and click
Finish. This step replaces the provided EAR file
with the file that you just created.

Click the (Re)-create DayTrader Database Tables and
Indexes link. A window opens that shows the
progress. When the database is created successfully, close the
window, and return to the DayTrader Configuration page.

Click the (Re)-populate DayTrader Database
link to generate the sample data. A window opens that shows
the progress. In this example, you see that the DayTrader
Database is populated with 15,000 user accounts and 10,000
stock quotes. You can update these values by using the
Configure DayTrader run-time parameters
link on the Configuration tab. When the
database is populated, close the window, and return to the
DayTrader Configuration page.

Click the Trading & Portfolios link.
Accept the default user ID and password, and click
Login. You now see a window like the
following example that you can use to begin trading.

You can download a completed Eclipse workspace for Part 1 from GitHub.

Conclusion

You now migrated the Daytrader3 application from Liberty 8.5.5.0 to Liberty
17.0.0.2 and are ready for Part 2 in this series to migrate the application to the cloud. If
your monolith is already running on the latest Java and application server
containers, you can skip this step and go directly to Part 2. Conversely, if you are lifting and shifting your Java
workloads to the cloud, you can install the earlier version of your
software on an infrastructure as a service platform, such as SoftLayer,
Amazon Web Services, or Google Cloud Services. But, this series assumes
that you want to do more than a simple lift and shift.

The following resources also provide information about refactoring
monoliths to microservices, but they do not define a systematic
approach nor show how to do it as this series shows: