Code Migrator reference
Defines the components, agents, data flow, and security controls of Code Migrator, the AI agent of Cloudera Migration Assistant that refactors Spark and Airflow source code for a target version.
What Code Migrator does
Code Migrator refactors Spark and Airflow projects written in Java, Python, or Scala, so that they run on a target version. You start a refactor job on the Refactor page, or a plan execution starts one in its Migrate Code using AI step. Code Migrator is available when Enable LLM is on in the engine configuration of Cloudera Migration Assistant.
For the intended use, the data use, the output checks, and the limits of Code Migrator, see Code Migrator system card.
Architecture
| Component | Role in Code Migrator |
|---|---|
| Cloudera Migration Assistant server | Provides the Refactor page and the REST API for refactor jobs. It passes each job to the Code Migrator service, and stores the jobs, their iterations, their plans, and their conversation history in its database. |
| Code Migrator service | Runs the refactor jobs. It gets the code, calls the LLM, builds and validates the code, and commits and pushes each iteration. It is deployed only when Enable LLM is on. |
| Documentation search service | Searches the migration documentation of the target frameworks for migration guidance. It runs inside the cluster, and is deployed only when Enable LLM is on. |
| Built-in Git server | Holds the repositories that Code Migrator works on, and the work branch of each job. |
| Build sandbox | A separate pod for each job, where Code Migrator builds, tests, and validates the code. It holds no secrets of Cloudera Migration Assistant. |
| LLM endpoint | The endpoint, compatible with the OpenAI API, that your administrator configures. It is not part of Cloudera Migration Assistant. |
Agents
Code Migrator runs each job with several agents. Each agent is a conversation with the LLM that has its own instructions and its own set of tools. An agent can use only the tools that it is given.
| Agent | What it does | What it can use |
|---|---|---|
| Orchestrator | Runs the job. It calls the other agents in turn, checks the progress of the job, and ends the job. | The other agents, the status of the job, and the tool that ends the job |
| Planning agent | Explores the original project, and writes a migration plan for the job. | The files of the job (to list, read, and search them), the plan (to write it), the documentation search service, and a dry run of the Airflow rules of the ruff linter, which lists the Airflow 3 changes to make |
| Migration agent | Changes the code to the target version, as the plan describes, including the Airflow 3 changes that the ruff dry run found, and fixes build errors. | Reading and editing the files of the job |
| Build agent | Builds the migrated project after each change, and reports the result. | A build of the migrated project with Maven, Gradle, sbt, or Python |
| Validation agent | Validates the migrated project, and reports the result. For an Airflow 3 target, it runs the Airflow rules of the ruff linter, and can apply their automatic fixes. For a Maven, Gradle, or sbt project, it runs the tests of the project. It does not run pytest tests. | The validation of the migrated project, and automatic ruff fixes |
| Spark job collector | After an Airflow project is migrated, lists the Airflow tasks in each DAG file that run Spark jobs. | Listing, reading, and searching the files of the job |
Code Migrator in the Spark migration flow
A CDE Spark Migration execution runs these steps. Three of them start, review, or merge the work of Code Migrator:
- Export from CDE copies the jobs and their resources to the intermediate Git repository, and creates the plan branch. This step does not use Code Migrator.
- Migrate Code using AI starts one Code Migrator job for each pair of source and target virtual clusters. Each job works on the files for the target Spark version on the plan branch, and writes its changes to its own work branch.
- Review code changes is a manual step. You review the changes of each job, and then mark the step as completed.
- Finalize changes merges the work branches of the jobs into the plan branch.
- The later steps import the resources and the Spark jobs into Cloudera Data Engineering on Anywhere Cloud, and clean up. These steps do not use Code Migrator.
An Airflow migration execution has the same Migrate Code using AI, Review code changes, and Finalize changes steps. For all the steps of an execution, see Migrating Cloudera Data Engineering Spark jobs.
Data flow
A refactor job runs in these steps:
- You create a refactor job. Cloudera Migration Assistant stores the job, with the additional context that you enter.
- Code Migrator gets the code into the built-in Git server and works there.
- The planning agent reads the project, searches the documentation search service, and writes the migration plan.
- The migration agent changes the code as the plan describes. It sends the files that it reads, the plan, the target settings, the additional context, the notes from earlier jobs of the same kind, and the conversation history of the job to the LLM, and writes the changes to the working directory of the job.
- The build agent and the validation agent build and test the code in the build sandbox of the job. Build and validation errors go to the LLM in the next request.
- Code Migrator commits each iteration to the work branch of the job in the built-in Git server. Cloudera Migration Assistant stores the iterations, the plan, and the conversation history of the agents in its database.
For the steps of a job, the work branch, and how Code Migrator works with repositories outside the built-in Git server, see Refactoring code with Code Migrator.
Code Migrator does not put Git credentials or the LLM API key in its requests to the LLM. Before each request, it replaces values that look like secrets with placeholders. The detection is based on patterns, so a secret that matches no pattern is sent. Searches of the documentation search service stay inside the cluster. If the LLM endpoint is outside your network, the data that Code Migrator sends to the LLM leaves your network.
Security controls
Code Migrator applies these security controls:
- Files – Code Migrator reads and writes files only inside the working directory of the job. It blocks any path that points outside that directory. It does not write to Git metadata or to the configuration files of the build tools, such as .git, .mvn, and Maven settings files.
- Tools – Each agent can use only the tools that it is given. The LLM has no shell access. The build and validation tools run fixed commands. An agent can choose only their arguments, and Code Migrator refuses arguments with special characters and options that change the repository settings of the build tool.
- Build files – Before a build, Code Migrator checks the build files of the project. It refuses a project whose build runs arbitrary commands, such as the Maven exec or antrun plugins, Gradle exec tasks, or sbt process calls, a project with a .mvn directory, and build files larger than 2 MB. It uses the Gradle of the build sandbox, not the Gradle wrapper of the project.
- Build sandbox – Builds, tests, and validation run in a separate pod for each job, under the gVisor container runtime. The pod holds no secrets and no service account token, accepts no incoming connections, and can connect only to DNS and to the network destinations set on the Code Executor Sandbox tab of the Settings page. Code Migrator treats the files that come back from the pod as untrusted. It skips links and protected paths, and limits their size.
- Git – Code Migrator writes only to a new work branch. It never changes the branch or commit that you started from, never merges the work branch, and never pushes to a repository outside the built-in Git server. It checks that it can push to the work branch before it changes any code. It turns off the Git hooks of the repository.
- Secrets in requests – Before each request to the LLM, Code Migrator replaces values that look like secrets with placeholders. The detection is based on patterns, and can miss a secret.
- Iterations – A job runs at most 20 iterations. The limit is fixed. A Code Migrator step in a plan also stops at its total timeout, which you set on the Code Migrator tab of the Settings page.
- Cancel – You can cancel a job at any time. Code Migrator notices the cancel request within about two seconds and stops the job. A build or validation that is running ends immediately, and the job makes no further LLM request, commit, or push. A push or LLM request that is in progress when you cancel completes, but Code Migrator does not use its result.
- Container – Code Migrator runs as a non-root user, with a read-only root filesystem, under the restricted Pod Security Standard of Kubernetes.
- Credentials – Cloudera Migration Assistant stores the LLM API key in a Kubernetes Secret, and never writes it to its database.
- Errors and audit – For authentication, permission, and rate limit errors from the LLM endpoint, the job shows a fixed message, not the response of the provider. Each request to the LLM writes an audit record with the model, the size of the prompt, the outcome, and the job ID, but no prompt text and no code.
