Run Flex Gateway in Linux VM for Non-Mule API

This document covers steps to setup Anypoint Flex Gateway as a Service in a Linux virtual machine. The Linux distribution being used here is Ubuntu Server. It will be running inside a virtual machine using VMware Workstation Player in the local Windows environment. The API being used will be a Non-Mule API from SampleAPIs.com called Coffee. You'll find a RAML for it in pre-requisites section. We'll publish it to the Anypoint Exchange and then use our Flex Gateway as an API Gateway for it.

We'll also briefly cover installation of Ubuntu Server in VMware Workstation Player.

Let’s begin...

Pre-requisites

  • Installed VMware Workstation Player - Link
  • Ubuntu Server ISO (LTS Version Recommended) - Link
  • Installed OpenSSH Client in your Windows System - Link
  • Mulesoft Anypoint Platform Account
  • Coffee SampleAPI RAML File - Link
  • Postman

Setup Ubuntu Server in VMware

Open VMware Workstation Player and click on Create a New Virtual Machine link on the right side.

In the New Virtual Machine Wizard, select the 2nd option - Installer disc image (iso) and use the Browse button to select the Ubuntu Server ISO file. The wizard will automatically detect the OS.

Click Next, then name your virtual machine and provide a location to store its files.

Click Next, you can leave the maximum disk size field unchanged and if you prefer you can select Store virtual disk as a single file option.

VM Configuration | Ubuntu Server

Click Next, you will see your virtual machine's OS and virtualized hardware configuration. You can customize them if you know what you are doing or else just leave it unchanged. If you are working on a laptop or smaller screen then I recommend that you click on Customize Hardware button and in the Display section change display resolution to something like 800 x 600 (You don't really need high resolution to work in a Command Line Interface OS like Ubuntu Server). After that is done, click Finish.

VM Display Configuration | Ubuntu Server

Your Virtual Machine will start up and it boots up using the ISO file, your screen will look something like this -

Try or Install | Ubuntu Server

Select Try or Install Ubuntu Server option and hit Enter.

Through out the Ubuntu Server Setup, you can use Arrow keys to navigate between options and Space Bar key to mark or unmark options.

As the setup loads, the first screen will ask you to select your language. Choose English and then hit Enter.

In the next screen, you may be asked to update the installer, you can do that if you wish or just select Continue without updating and hit Enter.

Next, you'll be asked to select Keyboard configuration. Leave it unchanged (English - US) and hit Enter on the Done selection.

After that, you'll have to select the installation base. Select the first option - Ubuntu Server and hit Enter on the Done selection.

Installation Base | Ubuntu Server

Next is Network connections, this one is very important. You should see an IP address automatically assigned to this VM. This VM should be able to access the Internet, we can't proceed without it. Select Done and hit Enter.

Network Connections | Ubuntu Server

Next is proxy configuration. Fill it up if applicable in your case or just simply select Done and hit Enter.

After that, setup will ask you to provide alternative mirror for Ubuntu. Leave it unchanged, select Done and hit Enter.

Next, disk configuration, select Use an entire disk and leave the rest of the options unchanged. Select Done and hit Enter.

Storage Configuration | Ubuntu Server

On the next screen, again select Done and hit Enter. A prompt will ask for confirmation. Select Continue and hit Enter.

Storage Configuration Confirmation | Ubuntu Server

Next is profile setup, use the following screenshot as reference to fill up the fields. Once filled, select Done and hit Enter.

Profile Setup | Ubuntu Server

Next, you'll be asked to upgrade to Ubuntu Pro. You can select Skip for now and continue ahead.

After that, the setup will offer Open SSH server package. You don't have to install this now. We'll do it after Ubuntu is installed. So, leave the box unmarked, select Done and hit Enter.

Next, the setup will offer popular server snaps. You don't have to select any of these, just select Done and hit Enter.

Featured Server Snaps | Ubuntu Server

That's it, if the top orange bar has the text - Install complete! then you can safely select Cancel update and reboot.

Install Complete | Ubuntu Server

As the VM reboots, you may receive Failed unmounting /cdrom error. It is alright, just hit Enter.

Failed Unmounting | Ubuntu Server

Wait for the system to boot up. You will be shown some secret keys for safekeeping on this first-time boot. Take screenshot of it if you wish and then hit Enter.

Then the system will ask for login -

Login | Ubuntu Server

Enter your login - ubuntu and password - abc123 (These values are from the Ubuntu Server installation profile setup section). Now, you are logged into your Ubuntu Server VM.

You can type following command and hit Enter to clear the screen anytime you want -

clear

First of all, let's update the package information using the following command -

sudo apt update

Note that whenever you execute a sudo command, the system will ask you to Enter the password for security reasons. So just type in the password and hit Enter.

If you want to update your Ubuntu Server at this point, use the command below to do that. It can take some time depending on the number of updates available and their size. You can skip this if you want.

sudo apt upgrade

Now, we'll install/upgrade net-tools and openssh-server in this VM. We need net-tools for finding the IP address of our VM and openssh-server to SSH into this VM from our host Windows OS. Use the following 2 commands one-by-one -

sudo apt install net-tools
sudo apt install openssh-server

Your VM may or may not have openssh-server already installed on it. But the point of installing openssh-server is that so you don't have to type long commands in it. Instead we will use the host OS's powershell/terminal/command prompt to remote into the VM using SSH and then just copy & paste our commands.

After you install/upgrade the openssh-server, we use the following command to check the ssh service status -

service ssh status

You should see active (running) in the result.

SSH Service Status | Ubuntu Server

Next, we install ufw and open port 22 using the following commands -

sudo apt install ufw
sudo ufw allow 22

Now, we find the IP address of our VM using this command -

sudo ifconfig

You will find the IP address here and now everything is set-up for the remote access.

IP Address | Ubuntu Server

Let's minimize the VMware Workstation Player window and open your Windows Command Prompt.

In the following command, replace <username> with your Linux username (in our case, it will be ubuntu) and <IP_address> with the IP from the previous step.

Format: ssh <username>@<IP_address> -p 22
Example: ssh ubuntu@192.XXX.XX.XXX -p 22

You will be asked - are you sure you want to continue? just type yes and hit Enter. Next type your VM's password and you will successfully remote into your VM from your Host OS's Command Prompt. We'll do rest of the work from this Command Prompt window only.

SSH | Ubuntu Server | Command Prompt

Anypoint Platform API & Flex Gateway Setup

Login to your Anypoint Platform and head over to the Design Center. Next, click on Create button and select Import from File option. Name the project and browse the RAML file you downloaded from the pre-requisites section. After that, publish this API to Exchange.

Coffee Sample API | Anypoint Exchange

Next, head over to the API Manager. Click on Add API button and select Add new API. In the wizard, select Flex Gateway and click on Add a new gateway button.

Add a Flex Gateway | API Manager

A new tab will open, here select the Linux OS and Ubuntu Distribution. If you scroll down, you will see all the commands that you have to execute in our Ubuntu VM.

Flex Gateway Setup Commands | Runtime Manager

Flex Gateway Setup Commands | Runtime Manager

DO NOT COPY AND RUN THESE COMMANDS DIRECTLY INTO THE VM!. Instead, copy the commands into Notepad first (Notepad++ Preferably) and make the edits (Remove "\" symbol and the next line character just after it). Then copy and paste them into your Windows Command Prompt one-by-one where we have taken remote of our Linux VM.

Check the example below-

Flex Gateway Setup Commands | Editing Example

Execute these commands one-by-one after modification.

Flex Gateway Setup Commands | Running in Ubuntu Server | SSH Command Prompt
Flex Gateway Setup Commands | Running in Ubuntu Server | SSH Command Prompt
Flex Gateway Setup Commands | Running in Ubuntu Server | SSH Command Prompt

Don't worry if running the 4th Step command doesn't return anything. Instead of that you can use the following command -

top

This will open Linux's task manager and if you find flex-agent is running then you are all set. Press Ctrl + C to exit out of it.

Ubuntu Server Task Manager | Flex Agent Process

Now on your browser, if you refresh the API Manager - Add a new API wizard page, you'll see your Flex Gateway in the Gateway Selection section with CONNECTED status -

Select Gateway | API Manager

Select the gateway you just created and click Next.

In the next screen, select the API Spec you published to the Exchange previously and click Next.

Select API from Exchange | API Manager

Here on the Endpoint page, you don't have to change anything. You will also notice that the Implementation URI is auto populated from the RAML file. Click Next.

API Endpoint | API Manager

On the Review page, just click on Save & Deploy.

Now, wait for the API to become Active.

API Activation | API Manager

As it goes active, you can now test your gateway using Postman.

As per the API Spec and the Gateway Configuration, try sending GET request to the following endpoints -

Format: http://<IP_address>:8081/hot OR /iced
Example: http://192.XXX.XX.XXX:8081/hot OR /iced

You'll get the response and that's it for this Flex Gateway demo.

You can try applying policies to it, everything will work just fine.

Troubleshooting Common Issues

Known Issue #1

When you SSH into the VM, you may or may not receive the error - WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!. If you do, fix that by going over to this location - %UserProfile%/.ssh and remove the entry of your VM's IP address from known_hosts file (You can open that file using Notepad). Save that file and then try the SSH command again.

SSH Error | Ubuntu Server | Command Prompt

Known Issue #2

Please note that, if you sleep or shutdown this Ubuntu Server VM, the IP Address assigned to it will change and you'll now have to make requests to the new IP Address. But rest assured, you don't have to change anything on the Anypoint Platform or in the VM. You can find the current IP Address anytime in Linux using ifconfig command.

P.S. Ubuntu Server Shutdown & Restart Commands -

sudo poweroff
sudo reboot

Comments