To perform a policy migration, this example uses the Mule Migration Assistant (MMA), an open source project on GitHub. The procedure requires that you meet the Prerequisites for the tool. For complete user documentation on MMA, see Migration to Mule 4 (on GitHub).
Command-line Invocation:
$ java -jar mule-migration-assistant-runner-0.5.1.jar \
-projectBasePath /Users/me/AnypointStudio/workspace-studio/my-mule3-policy/src/main/policy \
-muleVersion 4.1.5 \
-destinationProjectBasePath /Users/me/my-dir/my-migrated-policy
Note that the MMA creates the directory for the migrated project through
the -destinationProjectBasePath option. The my-migrated-policy must not
exist before you invoke the command. If you point to a folder that exists
already, the migration fails with an error like this:
Exception: Destination folder already exists.
When the migrator runs successfully, you see a message like this:
Successful Migration
Executing migration...
...
========================================================
MIGRATION SUCCESS
========================================================
Total time: 11.335 s
Migration report:
/Users/me/my-dir/my-migrated-policy/report/summary.html
After migration completes successfully, the destination folder contains:
-
A policy POM file.
-
The policy YAML file, renamed to the artifactId value found in the POM file.
-
The report directory containing the
Mule Migration Report (on GitHub) (summary.html).
Note that the same information provided in the report can be found as comments
in the policy XML file.
-
The mule-artifact.json file, with a minMuleVersion value that matches the
-muleVersion value set in the MMA command.
-
The src directory, which contains the migrated content.
The src directory contains directories main and test. Inside main, the
mule directory contains the policy XML file, renamed to template.xml. At
the same level as the mule directory, MMA might create a resources directory
that contains DataWeave files or other files that the migrated policy needs.
The test directory contains test configuration files.
After a successful migration, you need to modify the POM file as explained in
POM Migration. Once the POM file has the correct organization ID, you can
compile with mvn clean install. If the compilation is successful, you can
upload the migrated policy to Exchange using maven clean deploy. You can find
a more detailed explanation of uploading a custom policy in
Uploading a Custom Policy to Exchange.
POM Migration
The POM file migration modifies the file to include the elements necessary for
uploading the custom policy to Exchange.
Replace the {orgId} value in the <groupId/> and <exchange.url/> elements with the organization ID found in Anypoint Platform.
By default, the Exchange URL is set to the production environment.
<groupId>{orgId}</groupId>
<properties>
<exchange.url>https://maven.anypoint.mulesoft.com/api/v1/organizations/{orgId}/maven</exchange.url>
</properties>
Note that for the EU version of the URL, you need to set the URL manually
after the migration:
If the MMA does not find a POM file for the policy, MMA will create a new POM
file. In this file, the artifactId for the policy will be the name of the
parent directory for the policy XML file. For example, for a policy in
src/main/mytestpolicy/policy.xml, the artifactId is mytestpolicy.
Dependency and Plugin Versions
Dependency and plugin versions are set by default by the MMA, and you can change
manually, as needed.
Un-Migrated Elements
Several elements are not migrated from Mule 3 to Mule 4:
| Element |
Reason |
policy:before-exception
|
Unable to recreate the behavior in Mule 4. |
policy:pointcut
|
Resource and API pointcuts are resolved by the Mule runtime engine automatically. App and Endpoint pointcuts do not have an equivalent in Mule 4. |
policy:data
|
The behavior is resolved by the Mule runtime engine automatically. |
For each of these elements, the child elements are removed, as well.
Elements Migrated to Other Structures
The throttling element fixed-time-frame-algorithm is migrated to the
Rate Limit format if multiple rate-limit elements are found as child elements
of the delay-response element.
In addition, because Throttling SLA policy is no longer supported, if a
delay-response element is found as a child of a sla-based-algorithm element,
the policy is migrated to Rate Limit SLA format.
Common Migration Issues
If policy files are not found during the migration, the MMA prints a message
like this one:
Unsuccessful Migration
Executing migration...
...
===============================================================================
MIGRATION FAILED
===============================================================================
Total time: 3.008 s
Exception: Cannot read mule project. Is it a Mule Studio project?
com.mulesoft.tools.migration.engine.exception.MigrationJobException: Cannot read mule project. Is it a Mule Studio project?
at com.mulesoft.tools.migration.engine.project.MuleProjectFactory.getMuleProject(MuleProjectFactory.java:50)
at com.mulesoft.tools.migration.engine.MigrationJob.generateSourceApplicationModel(MigrationJob.java:116)
at com.mulesoft.tools.migration.engine.MigrationJob.execute(MigrationJob.java:80)
at com.mulesoft.tools.migration.MigrationRunner.main(MigrationRunner.java:83)
===============================================================================
POM Migration Issues
If the MMA does not find the POM model for the policy, the MMA will
either generate the model from an existing POM in Mule 3, or if there is no
Mule 3 POM, the MMA will create the model. If MMA uses an existing POM, any
incorrect POM definition that the MMA encounters will cause POM model creation
process to fail. For information about a POM model failure, you need to
check for any preceding error messages regarding MMA steps on modifying the
POM model.
YAML Migration Issues
The following issues can occur:
| Case |
Reason |
Error editing YAML |
Use stack trace in the MMA for more information. |
Multiple YAMLs found |
MMA expects only one YAML file in the project base
path, which is interpreted as the policy YAML.
If you need more than one YAML in the project, the
extra YAML files must be stored in another directory. |
No YAML found |
MMA expects a YAML file in the project base path
when migration starts. If none is found, it is
possible that a separate error occurred earlier in
the migration process. |
Threat Protection Migration Issues
The following issues can occur:
| Case |
Reason |
Could not determine if policy is XML or JSON threat protection type |
In threat protection policies, the elements xml-policy and json-policy
determine which type of threat protection to migrate. Only one of them must
be present. If none are present, the error message will appear in the
migration report. |
Element structure could not be found |
In threat protection policies, the xml-policy element needs to have child
element, structure. |
Element values could not be found |
In threat protection policies, the xml-policy element needs to have child
element, values. |
Client Id Enforcement Migration Issue
The following issue is possible:
| Case |
Reason |
Client Id Enforcement invalid migration element |
If the basicAuthEnabled attribute in the validate-client element is
absent or equal to false, MMA expects clientSecret or clientId attributes
to be present in the validate-client element. |
Spring Limitations
You must perform a manual migration of your Spring Beans even though MMA migrates spring:bean elements in Mule 3 policies to a template-beans.xml file in the resources directory and even though it adds to the custom policy a spring-module:config element that references template-beans.xml. Declaring the beans in a policy is unsupported in Mule 4 and causes the policy to fail to deploy.
Known Issues
Known issues for MMA are:
-
Policies that have policy YAML files with the .yml extension are not detected.
-
Policy YAML files are not autocompleted with mandatory fields.
-
mule:processor element is not migrated.
-
byte-array-to-string-transformer element is not migrated.
-
expression-component element is not migrated.
-
mulexml:object-to-xml-transformer element is not migrated.
-
The migrated element ee:transform does not add a schema location URI.
-
DataWeave expressions that start with an underscore are not quoted, which causes the policy to fail.