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.
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.
Your Virtual Machine will start up and it boots up using the ISO file, your screen will look something like this -
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.
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.
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.
On the next screen, again select Done and hit Enter. A prompt will ask for confirmation. Select Continue and hit Enter.
Next is profile setup, use the following screenshot as reference to fill up the fields. Once filled, select Done and hit Enter.
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.
That's it, if the top orange bar has the text - Install complete! then you can safely select Cancel update and reboot.
As the VM reboots, you may receive Failed unmounting /cdrom error. It is alright, just hit Enter.
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 -
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 -
First of all, let's update the package information using the following command -
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.
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 -
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 -
You should see active (running) in the result.
Next, we install ufw and open port 22 using the following commands -
Now, we find the IP address of our VM using this command -
You will find the IP address here and now everything is set-up for the remote access.
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.
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.
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.
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.
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.
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-
Execute these commands one-by-one after modification.
Don't worry if running the 4th Step command doesn't return anything. Instead of that you can use the following command -
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.
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 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.
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.
On the Review page, just click on Save & Deploy.
Now, wait for the API to become Active.
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 -
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.
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 -
Comments
Post a Comment