Refactoring code with Code Migrator
Code Migrator is an AI agent that refactors Spark and Airflow source code in a Git repository for a target version. It builds and validates the code, repeats until the checks pass or it reaches its iteration limit, and writes the result to a new branch.
You can start a refactor job yourself on the Refactor page, or a plan execution starts one in its Migrate Code using AI step. Both kinds of job are displayed on the Refactor page.
How refactor jobs work
- Code Migrator clones the repository at the branch or commit that you enter.
- For a repository in the built-in Git server, it works on that repository.
- For any other repository, it copies the repository into the
CMA-Workspaceorganization of the built-in Git server, and works on the copy. It never pushes to your own repository.
- It creates a work branch named
code-agent-branch-[***JOB-ID***]from that branch or commit, where [***JOB-ID***] is the ID of the job. It never changes the branch or commit that you started from. - It checks that it can push to the work branch before it changes any code.
- It plans the changes, refactors the code, builds it, and validates it. It repeats these steps until the build and validation pass, for at most 20 iterations. The limit is fixed.
- It commits its changes to the work branch, and pushes the branch.
At the cleanup step after a migration completes, the built-in Git server keeps the record of the work and the source code and the target code. The code stays there until Cloudera Migration Assistant is decommissioned or until you remove the code from the built-in Git server.
You choose how much Code Migrator changes. In Minimal mode, it makes only the changes that the target version needs, and keeps the original formatting. In Improve mode, it also modernizes the code, improves its readability, and applies best practices.
Where Code Migrator runs
Code Migrator runs in its own container in the Cloudera Migration Assistant engine, as a non-root user. It reads and writes files only in the working directory of the job, and the LLM has no shell access.
The build and the validation run in a separate sandbox pod for each job, under the gVisor container runtime. The pod holds no secrets, and can connect only to DNS and to the network destinations set on the Code Executor Sandbox tab of the Settings page. The sandbox limits what the code can do, but the build still runs the plugins and the tests of the project, so start refactor jobs only on code that you trust.
Turning on Code Migrator
Code Migrator has no flag that you can change. Anywhere Cloud turns on Code Migrator when Enable LLM is on in the engine configuration of the Cloudera Migration Assistant engine. When Enable LLM is off, Code Migrator is not deployed, and the Code Migrator item is not displayed in the navigation pane. The Code Migrator item opens the Refactor page.
To set up the LLM connection, see Configuring LLM connection.
