Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

MMC REST API: Step by Step Guide to Application Deployment

DZone's Guide to

MMC REST API: Step by Step Guide to Application Deployment

Learn to create and deploy an application on the Mule Management Console REST API, a popular deployment API, using Postman.

· Integration Zone
Free Resource

Share, secure, distribute, control, and monetize your APIs with the platform built with performance, time-to-value, and growth in mind. Free 90-day trial of 3Scale by Red Hat

This article assumes that you have your Mule Management Console (MMC) setup on your server.

For details on how to install MMC, click here.

Deploying an Application Through MMC REST API

MMC Setup Assumptions

This article assumes that you already have an existing server inside MMC.

Let's take the following details as example:

Host: myconsole.mysite.com

Port: 8585

Username: admin

Password: admin

Creating an Application Inside Repository

Creating an application via MMC REST API is simple.

In this article, we are going to use the Chrome extension Postman.

Image title

1. To create an application inside the repository, we will set our Postman request as following:

Request URL: http://myconsole.mysite.com:8585/api/repository

Method: POST

Path: /api/repository

Image title

2. Set Authorization to Basic and enter username/password. In this case, we are going to use admin/admin.

Image title

3. Then click Update Request. 

Once you click Update Request, you will notice that the header has changed.

Image title

4. Using form-data inside the Body tab, set the following keys and values:

Image title

Note that in this request, we only used two keys - name and file.

This request can have three keys.

name - the name of the application inside MMC. This is a simple Text.

file - The deployable mule archive of your application. In this case, the name of our is deployable mule archive is sampleapp.zip 

version - This is key is OPTIONAL. This is your application version. If version is not provided, MMC will automatically set a timestamp with the following format: yyyyMMdd-HH:mm

For more details on creating an application inside the repository using REST API, click here.

5. Click Send.

You will get the following response from the sent request:

Image title

Take note of the versionId as this will be important for deploying the application.

6. Let's check if our application has been successfully added into our repository.

    6.1 Inside Mule Management Console, click on Deployments tab

    6.2 Once you are in Deployments tab, click on Repository located on the left menu.

Image title


As you can see, we have successfully added our application SampleApp inside the repository.

Creating a New Deployment

Now that we have created an application inside our MMC repository, it is time for us to create a new deployment for our new application.

1. Check for Server Id.

Before we could start creating a new deployment, it is very important for us to figure out the id of the server we are deploying to. We won't be able to use the server name for our API request.

You can find the list of servers inside MMC using the following request:

Request URL: http://myconsole.mysite.com:8585/api/servers

Method: GET

Path: /api/servers

Just like our example above, we will set Authorization to Basic and provide the username / password.

Once the request is sent, you will get a JSON response similar to this:

Image title

In this case, our MMC has only 1 server named MULE-EE-3.8.4-DEV-SERVER.

Take note of the server id, we are going to use this later on for creating a new deployment. In this case, our server id is local$2497da58-bcaa-4ed7-a28f-299a01259540

2. Create a new deployment.

Now that we have our server id and application version id, we can start creating a new deployment for our application via MMC REST API.

To create a new deployment, use the following request:

Request URL: http://myconsole.mysite.com:8585/api/deployments

Method: POST

Path: /api/deployments

Set the Authentication to Basic and provide the username/password.

The REST API request we are going to use for this example to create a new deployment would need the following details:

name - the deployment name. This should be unique.

servers - List of servers or server

applications - Version ids of the application/s

Our request would look like this:

Image title

For more details on MMC deployment API, click here.

3. Click Send.

Once the request is sent, you will get a response similar to this:

Image title

Take note of the deployment id as we are going to use it later on for deployment.

Also, you might have noticed that the status of our newly created deployment is UNDEPLOYED.

Let's go to our Mule Management Console and check the status of our deployment.

Image title


The color yellow denotes that the deployment has yet to be deployed.

Now, let's go to our next step which is deployment.

Deploying the Application

Deploying the application via MMC REST API is simple.

We will just have to provide the deployment id of our application.

1. Deploy the application.

Create another Postman request with the following details:

Request URL: http://myconsole.mysite.com:8585/api/deployments/local$4a345cde-93b6-4c28-b097-d63e7ce7621d/deploy

Method: GET

Path: /api/deployments/{deploymentId}/deploy

Just like in our earlier requests, we will need to set the Authentication to Basic and provide the username / password.

Our request would look like this:

Image title

2. Click Send.

3. Check if the application has been successfully deployed.

Let's go back to our Mule Management Console and check if our application has successfully been deployed.

Image title

SampleApp deployment is now in green which means the application has successfully been deployed.

Testing the Deployed Application

Let's test our newly deployed application.

Image title

The newly deployed application has successfully run.

Note that the port number will depend on the ports you have defined on your server or application. In this case, we used port number 30012.

Undeploying the Application

Just like deploying an application, we can also undeploy our application using MMC REST API.

1. Undeploy the application.

Create another Postman request with the following details:

Request URL: http://myconsole.mysite.com:8585/api/deployments/local$4a345cde-93b6-4c28-b097-d63e7ce7621d/undeploy

Method: GET

Path: /api/deployments/{deploymentId}/undeploy

Just like in our earlier requests, we will need to set the Authentication to Basic and provide the username / password.

Our request would look like this:

Image title

2. Click Send.

3. Check if application has been successfully undeployed.

Let's go back to our Mule Management Console and check if our application has successfully been undeployed.

Image title

As you can see, our SampleApp deployment has reverted its status back to yellow.

Other Features

There are many other features you can do using the MMC REST API besides deployment, such as removing an application, deleting deployment, etc. which are not going to be tackled on this article.

If you would like to know more, you can find the complete reference of Mule Management Console REST API here.

If you have any comments or suggestions that you would like to get tackled that were not mentioned in this article, please comment down below.

Explore the core elements of owning an API strategy and best practices for effective API programs. Download the API Owner's Manual, brought to you by 3Scale by Red Hat

Topics:
mule ,mmc ,integration ,tutorial ,rest api

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}