IBM Mono2Micro overview

IBM® Mono2Micro™ is an AI-based, semi-automated, utility for refactoring Java® monolithic applications into microservices that you run on WebSphere® Application Server Liberty or Open Liberty. You can use IBM Mono2Micro and the recommendations that it provides to automatically generate a significant portion of code that you need to build and deploy your microservices.

Through static and dynamic analysis, IBM Mono2Micro uses its machine learning engine and an analysis of the Java monolithic application code to generate partition recommendations. Partition recommendations are groupings of classes in the monolith that can serve as starting points for microservices. The recommended partitions along with other pertinent information are displayed in an intuitive workbench UI. Based on its built-in knowledge about the Java programming language, IBM Mono2Micro also provides a deep semantic analysis of class-to-class invocations. By using the workbench UI and the detailed analysis, you get a clear picture of the partitioning recommendations, which you can iteratively fine-tune to suit your business needs. After you decide on a specific partitioning recommendation, you can run IBM Mono2Micro to automatically generate a significant portion of code that you need to build and deploy the recommended partitions along with your existing monolith code. After you review the generated code, you can continue to iteratively fine-tune recommendations and generate code until you have the microservices that you want. You can then run the microservices on WebSphere Application Server Liberty or Open Liberty.

IBM Mono2Micro is available as part of IBM WebSphere Hybrid Edition and IBM Cloud Pak® for Applications.

The IBM Mono2Micro journey

IBM Mono2Micro commands provide the following capabilities.

Data collection

For IBM Mono2Micro to analyze your application, first run the mono2micro analyze command on its code and then run your application with instrumentation to collect all the data to be analyzed.

  1. Run the mono2micro analyze command on your application archive to produce table JSON files that contain information about the code such as full class names, method signatures, state variables, and inheritance relationships.
  2. (Optional) Deploy your application with the binary instrumenter enabled.
  3. (Optional) Run the mono2micro usecase command with your business use cases to produce one or more context JSON files and log files for analysis.
AI analysis for partition recommendations

To get the two refactoring options from IBM Mono2Micro, run the mono2micro recommend command on your previously collected files to get reports and graph JSON with the partition recommendations.

  1. Place files in locations within the input directory to get recommendations from static code analysis and, optionally, code generation.
    • For static code analysis only, place table JSON files (from mono2micro analyze) in the proper location within the input directory.
    • For static code analysis and code generation, place table JSON files (from mono2micro analyze), log files (from application server during run of business use cases), and the context JSON file (from mono2micro usecase during run of business use cases) in the proper locations within the input directory.
  2. Run the mono2micro recommend command to produce reports and a graph JSON with the refactoring approaches.
Partition refactoring

Run the mono2micro workbench command to launch the workbench UI where you can gain a deeper understanding of your application and its classes by examining the two refactoring approaches that are created for your application. The two refactoring approaches by IBM Mono2Micro are business logic and natural seams. These recommendations were created from analyzing your application's runtime calls and detected data dependencies. If neither approach is quite what you want, create and save a plan for your own custom partitioning solution.

  1. Launch the workbench UI container image with the mono2micro workbench command.
  2. Access the UI in your browser and load the JSON file that is produced from the mono2micro recommend command.
  3. Explore refactoring approaches.
  4. (Optional) Create and save the custom refactoring option JSON file.
Code generation

Run the mono2micro transform command to automatically produce starter code for creating your microservices.

  1. (Optional) If you choose to use the natural seams or custom refactoring approach, then run the mono2micro refine command.
  2. Run the mono2micro transform command to produce code.
  3. Edit and deploy code in the test environments.

How it works

The following figure displays the workflow through IBM Mono2Micro. The blue boxes, which begin with the term (Action), represent user actions. The unfilled boxes, which begin with the term (File), represent files. The solid lines point to the next steps. The dashed lines show the uses of files and point to the next user actions or files in the workflow. The workflow starts with application code and, after analysis and code generation, ends with generated starter code for partitions.

IBM Mono2Micro components, containers, and workflow

IBM Mono2Micro components

IBM Mono2Micro consists of the following six components, which are displayed in the previous figure.

Code analyzer (mono2micro-bluejay container or binary analyzer .jar)
The mono2micro analyze command that analyzes and optionally instruments the Java code of monolithic applications.
Binary instrumenter (minerva-agent-1.0.jar)
A Java agent that instruments a running application deployed on the application server.
Use case recorder (Flicker)
Run with the mono2micro usecase command, a Java program that records use case names and times. Use it when you run test suites or test cases corresponding to various business use cases of a Java monolithic application.
The AI engine for partition recommendations (mono2micro-aipl container)
The mono2micro recommend command runs the AI engine of IBM Mono2Micro. It uses machine learning techniques on the user supplied runtime traces and metadata that is obtained from the source code analyzer. It uses the resulting information to generate partition recommendations that eventually can become microservices. This command also produces a detailed report for the recommended partitions.
IBM Mono2Micro workbench UI
The mono2micro-ui container that displays the recommendations from the AI engine when launched with the mono2micro workbench command. The recommendations that are obtained from the IBM Mono2Micro AI engine are kept in your local storage. You can load the recommendations in the workbench UI to display them in a graphical visualizer. With the UI, you can modify the AI-generated partition recommendations.
Code generator (mono2micro-cardinal container)

The mono2micro transform command invokes the code generator, which has deep knowledge of the semantics of the Java programming language. The code generator uses the recommendations from the AI engine to do the following things:

  • Provide detailed invocation analyses of the recommended partitions that can eventually be implemented as microservices.
  • Generate detailed inheritance analyses of the recommended partitions.
  • Generate a significant portion of the code needed to realize the recommended partitions in containers.

You can download the Mono2Micro tools and run them on your local computer.

Steps for refactoring a Java monolithic application

The following steps describe how to refactor a Java monolithic application by using IBM Mono2Micro. They are a more detailed version of the previous figure.

  1. Analyze the Java code of a monolithic application by using the code analyzer.

  2. Choose whether to get recommendations based on application static code analysis only or to get code generation too. For static code analysis only, skip to step 3. For static code analysis and code generation, complete the following steps to add code generation:

    1. Deploy the Java monolithic application in nonproduction but representative environments along with the binary instrumenter Java agent. Use the JSON files that are generated by the code analyzer as input.

      The JSON files are symTable.json, refTable.json, and instrumenter-config.json.

    2. Run test cases corresponding to various business use cases on the deployed Java monolithic application.

      Run the use case recorder to name and record the start and stop times of individual test cases that correspond to the various business use cases.

    3. Arrange the log files that contain the traces along with the JSON files (symTable.json and refTable.json) that are produced by the code analyzer and use case recorder (one or more context .json files) in the appropriate subdirectories.

    4. Run the AI engine on the directory where the log files and JSON files are kept.

      The AI engine analyzes the contents of the directory and generates the partition recommendations in the final_graph.json file along with reports in HTML format.

      The AI engine creates a directory that contains all the necessary artifacts that are needed for code generation. It also produces the partitions and inheritance reports in HTML format in the directory. The partitions report contains the detailed invocation analysis for the partition recommendations which can be the beginnings of microservices. The inheritance report details any existing inheritance chains in the application under consideration.

  3. View the partition recommendations by loading the final_graph.json file.

    In the workbench UI, you can adjust and fine-tune the recommendations and save the changes to a JSON file. You can view the partitions and inheritance reports in any browser.

  4. If you added code generation in step 2, run other commands to produce artifacts and starter code.

    1. If you adjusted partitioning recommendations in a previous step, run the mono2micro refine command to produce the new artifacts for code generation along with new reports.
    2. Run the mono2micro transform command to automatically generate the starter code for realizing the microservice recommendations.
  5. You can iterate through the steps again, beginning with the step that runs the mono2micro recommend command, to arrive at the microservices of your choice.

Some of the previous steps are explained in detail in other IBM Mono2Micro topics.