Service Extraction
Overview
Code-Copy is a tool to extract code for services corresponding to domains specified in the analysis. Currently it is only supported in Java, since Code-Copy relies on the relationship between packages and folders and between public classes and files to find and copy the source code from the monolith code repository.
Most of the procedure is done on a development workstation which has the application code and an up-to-date maven/gradle/ivy local dependency repository cache. The source code must match the app version analyzed in AO Manager.
Code-Copy Procedure
The Code-Copy procedure starts by specifying configuration parameters for Code-Copy in the vFunction Server UI’s SERVICE CREATION tab. These configuration parameters, such as the Java version to be used and the target platform the service should run on (e.g., SPRINGBOOT 3 or QUARKUS 2), impact the build and main files Code-Copy generates for the service.
vFunction Server version 3.4 introduced an integration with Open ReWrite: you can select relevant Recipes in the configuration dialog to perform automatic refactoring by running the Recipes from the Code-Copy -generated gradle and maven files. For example, migrating to a newer Java version or a more modern platform such as Springboot 3 or Quarkus.
After setting the configuration, download the Service Specification file corresponding to a domain from the vFunction server - this file contains all the necessary information required to create the baseline code for the corresponding service.
The Code-Copy tool itself should be downloaded from the vFunction Server UI’s SERVICE CREATION tab. Please note that Code-Copy requires Java 17 to run.
In addition to the Service Specification file, an Open API specification (yaml file) is also downloaded corresponding to the entry points defined in the domain. This can be used for testing and documenting the APIs.
After the Service Specification files are downloaded, the developer runs Code-Copy which creates the code baseline for the services. Code-Copy copies relevant source code files from the original application code (including tests), copies minimized configuration files, creates maven and gradle build files with the appropriate dependencies based on the jar files located in the local repository and generates wrapper code for the REST APIs that realize the domain entry points. If you configured OpenReWrite Recipes, then you can run these recipes after running Code-Copy using the commands: mvn rewrite:run or gradle rewriteRun.
The created code is just a baseline, and the developer will need to refine and configure the code. As the coding operations are done, the developer may need to go back to the AO Manager Analysis either to get some insights or to adjust the baseline (for example, mark a class as dead-code in a context of a domain). vFunction has IDE plugins to streamline the workflow.