Running the code generator
You use the code generator to generate the API services and related code needed to implement the recommended partitions.
Before you begin
Ensure to meet the system requirements and the following code generator requirements.
Also, customize the code generation process as needed. The app.config.txt file in the cardinal directory has two customizable parameters.
- ApplicationName
- The name of the refactored application. The value is used as the prefix for the generated code, URL and annotations.
- CardinalOutPath
- The location in the source code tree where utility class code is generated.
Procedure
Run the code generator to generate refactoring code for the recommended partitions.
Results
A successful completion of the code generator results in a directory structure similar to the following Daytrader directory structure.
transform-input ├── cardinal │ ├── app_config.txt │ ├── cardinal-codegen │ │ ├── Cardinal-Utility-report.txt │ │ ├── Cardinal-partition0-report.txt │ │ ├── Cardinal-partition1-report.txt │ │ ├── Cardinal-partition2-report.txt │ │ ├── Cardinal-partition3-report.txt │ │ ├── Cardinal-partition4-report.txt │ │ ├── CardinalFileSummary.json │ │ ├── CardinalFileSummary.txt │ │ └── CardinalSings.json │ ├── cardinal_graph.json │ ├── class_run.json │ ├── instrumenter-config.json │ ├── partition.txt │ ├── refTable.json │ └── symTable.json ├── daytrader7-source ├── daytrader7-source-Utility ├── daytrader7-source-partition0 ├── daytrader7-source-partition1 ├── daytrader7-source-partition2 ├── daytrader7-source-partition3 └── daytrader7-source-partition4
In this example, the daytrader-source-Utility partition contains Java monolithic application classes identified as potential utility classes. You can treat this partition as any other partition along with the IBM Mono2Micro generated code, or you can package these application classes as a utility .jar file with all other partitions that depend on the classes.
The highlighted directories are created by the code generator. The cardinal-codegen directory contains various reports, and various partitions are written in the xxx-partition_n directories, where xxx is the ApplicationName value and n is the partition number. For the example, the partitions are named daytrader7-source-partition_n (where 0 <= n <= 4). For more information, see Creating custom views.
Each of these xxx-partition_n directories contains the appropriate portions of the source code that is taken from the monolith under consideration. The output includes, but is not limited to, transformational wrappers, API services, code for distributed object management, and garbage collection. All of the code movement and generation is done automatically by the code generation component of Mono2Micro. At present the code generator only considers .java source files; it does not copy or generate any configuration or deployment information from the monolith. For actual deployment of the partitions as microservices, you must provide the appropriate configuration information.
The contents of the generated inner cardinal-codegen folder are various reports. The Cardinal-partition_n-report.txt (where 0 <= n <= 4) files are the Java invocation analysis reports for individual partitions in text form, as shown in figure for the partition_3 partition. You can specify the html option while running the code generator to generate a consolidated HTML version of the report. For more information, see Cardinal-Report.

The code generation component of Mono2Micro generates the CardinalFileSummary.txt file, which details all of the steps taken for generating the code. You use the report for debugging, for a deeper understanding of the code generation process, and for looking at the generated code. The report is for reference use only and is not used by any component of Mono2Micro.
For each partition, there are five categories of reports in the CardinalFileSummary.txt report. An abbreviated sample report is shown in the next figure.

Proxy- A report that contains stub classes for each partition that needs to access objects which are not local and belong to other partitions.
Service- A report that contains the APIs created for the objects of the partitions which are accessed from outside the partition.
Original- A report that contains the original intact Java files from monolith. These files are only accessed locally within the partition.
Dummy- A report that contains the files picked up during static source code analysis which are not used in runtime.
Cardinal Exceptionsare added to these files to ensure that appropriate runtime exceptions are generated if they are run. This category of report also informs the developers about potential dependencies on these files. Helper- A report that contains generated code that handles such functions as serialization and exceptions for the recommended partitions and their corresponding interfaces.
Copied- A report that contains classes that have no programming logic but are needed for compiling the partitions, such as interfaces and abstract classes.
The final report under the cardinal-codegen directory is CardinalSings.json. This file is intended for use by developers. This report lists the following content:
- Lists the locations where code needs to be altered or where detailed inspection is necessary to implement partitions as potential microservices.
- Lists action items for developers, keyed as
CARDINAL_TODO_T<number>, which either must be addressed, or which are of theWARNvariety. These warnings advise that developers to inspect and update code as necessary. Tasks are grouped into class and file levels. The following report shows theWARN TODOswhile refactoring the sample Daytrader application. Detailed self-explanatory comments are provided by the code generator for eachCARDINAL_TODO_T<number>task.