Loading

Deploy a Mule 4 application on CloudHub 2.0 using REST APIs

Publish Date: Mar 2, 2024
Task
Content

GOAL

Deploy a Mule 4 application on CloudHub 2.0 using Exchange REST API and AMC Application Manager REST API
Steps

Step1. In order to use any of following APIs to deploy an asset to the Exchange or deploy CloudHub 2.0 app via AMC Application Manager, you will need to obtain Anypoint platform Environment Id and Anypoint platform Organization Id. 
a) Organization ID: How to know my Organization ID (Org ID) on the Anypoint Platform
b) Environment ID: How to get the Environment ID

Step 2. Please refer to KB "Creating connected app and getting the bearer token example" or "How to generate your Authorization Bearer token for Anypoint Platform" to get a bearer token.
Example:

curl --location --request POST https://anypoint.mulesoft.com/accounts/api/v2/oauth2/token \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'client_id=<connected_app_clientID>' \
--data-urlencode 'client_secret=<connected_app_secret>' \
--data-urlencode 'grant_type=client_credentials'

Step 3. Modify the pom.xml to define the right groupId, artifactId, version as requested in Exchange REST API here
Example:

    <groupId>18a04ea1-3b84-42fb-837a-bbcbe964f394</groupId>
	<artifactId>demo-ch2-helloworld</artifactId>
	<version>1.0.4</version>
	<packaging>mule-application</packaging>
	<name>demo-ch2-helloworld</name>

Step 4. Publish the asset to Exchange with the info collected in the steps above. Please replace the values in the angle brackets with the values collected in the previous steps.
Please keep in mind that the "path_to_app_jar_name.jar" refers to the location of the executable Mule application jar file. 
You can find more information about packing a mule app by referring to this document here.  Alternatively, you can use Anypoint Studio to export the application by following the steps
outlined in the document.

curl -X POST \
  https://anypoint.mulesoft.com/exchange/api/v2/organizations/<orgID>/assets/<groupId>/<artifactId>/<version> \
  -H 'Accept: application/json, text/plain, */*' \
  -H 'Authorization: Bearer <token>' \
  -H 'X-ANYPNT-ENV-ID: <envID>' \
  -H 'X-ANYPNT-ORG-ID: <orgID>' \
  -F 'files.mule-application.jar=@<path_to_app_jar_name.jar>' \
  -F 'files.pom=@<path_to_pom.xml>'

Example:

curl -X POST \
  https://anypoint.mulesoft.com/exchange/api/v2/organizations/18a04ea1-3b84-42fb-837a-bbcbe964f394/assets/18a04ea1-3b84-42fb-837a-bbcbe964f394/demo-ch2-helloworld/1.0.4 \
  -H 'Accept: application/json, text/plain, */*' \
  -H 'Authorization: Bearer <token>' \
  -H 'X-ANYPNT-ENV-ID: 7d1a0de5-8c49-4cc3-a21d-2566312469d2' \
  -H 'X-ANYPNT-ORG-ID: 18a04ea1-3b84-42fb-837a-bbcbe964f394' \
-F 'files.mule-application.jar=@/Users/<user_name>/demo-ch2-helloworld.jar' \
-F 'files.pom=@/Users/<user_name>/pom.xml'

Step 5. Deploy a CloudHub 2.0 app via AMC Application Manager REST API
Below is an example of deploying a mule app "demo-helloworld2" to Shared Private Space (Sydney Region) with asset version 1.0.4 that got published in step 4.
Example:

curl --location 'https://anypoint.mulesoft.com/amc/application-manager/api/v2/organizations/<orgID>/environments/<envID>/deployments' \
--header 'X-ANYPNT-ENV-ID: <envID>' \
--header 'X-ANYPNT-ORG-ID: <orgID>' \
--header 'Content-Type: application/json;charset=UTF-8' \
--header 'Authorization: Bearer <token>' \
--data '{
    "name": "demo-helloworld2",
    "labels": [
        "beta"
    ],
    "target": {
        "provider": "MC",
        "targetId": "cloudhub-ap-southeast-2",
        "deploymentSettings": {
            "clustered": false,
            "enforceDeployingReplicasAcrossNodes": false,
            "http": {
                "inbound": {
                    "publicUrl": null,
                    "pathRewrite": null,
                    "lastMileSecurity": false,
                    "forwardSslSession": false
                }
            },
            "jvm": {},
            "runtimeVersion": "4.4.0:20230320-2",
            "updateStrategy": "rolling",
            "disableAmLogForwarding": false,
            "persistentObjectStore": false,
            "generateDefaultPublicUrl": false
        },
        "replicas": 1
    },
    "application": {
        "ref": {
            "groupId": "18a04ea1-3b84-42fb-837a-bbcbe964f394",
            "artifactId": "demo-ch2-helloworld",
            "version": "1.0.4",
            "packaging": "jar"
        },
        "assets": [],
        "desiredState": "STARTED",
        "configuration": {
            "mule.agent.application.properties.service": {
                "applicationName": "demo-helloworld2",
                "properties": {},
                "secureProperties": {}
            },
            "mule.agent.logging.service": {
                "scopeLoggingConfigurations": []
            }
        },
        "integrations": {
            "services": {
                "objectStoreV2": {
                    "enabled": true
                }
            }
        },
        "vCores": "0.1"
    }
}'


Disclaimer: This solution provides a suggestion that should be considered in conjunction with your specific use-case and requirements and does not represent a complete solution for all circumstances.

Knowledge Article Number

001117108

 
Loading
Salesforce Help | Article