Tutorial: Accessing MySQL Data Service on Cloud Foundry through Tunneling

Cloud Foundry is an Open PaaS supporting many languages, runtimes, frameworks and services. Cloud Foundry exposes MySQL, PostgreSQL, MongoDB, RabbitMQ and Redis as services that offer the database and messaging capabilities. Developers can easily bind the applications to one of these services during the deployment.

For a detailed walkthrough on getting started with Cloud Foundry, you can refer to the tutorial that we published (Part 1, Part 2 and Part 3) on CloudStory.in a while ago.

After you point vmc to a specific Cloud Foundry target, typing vmc services will show you the available services. For example, after targeting http://api.cloudfoundry.com, vmc services will show the following.

[crayon language="shell"]
vmc services
[/crayon]

During the deployment, Cloud Foundry asks if you want to bind the application to any of the services. Once you choose a specific service, it can be accessed during the runtime through the VCAP_SERVICES environment variable. But many times, developers need to access the services like MySQL, PostgreSQL and MongoDB directly to manage the database. This is where Cloud Foundry tunneling comes into the picture. In this tutorial, we will access MySQL from the local machine through the popular MySQL Workbench.

First, let us make sure that the MySQL data service is provisioned for us. We can check this by typing vmc services and looking under the provisioned services.

Now, let’s install the Caldecott gem to enable tunneling. Caldecott is a simple Ruby gem that enables port forwarding on the local machine.

[crayon language="shell"]
gem install caldecott
[/crayon]

With Caldecott in place, it’s time for us to create the tunnel. We do this by typing vmc tunnel.

[crayon language="shell"]
vmc tunnel
[/crayon]

Note that this command shows the provisioned services. After we select that, the next step is to choose the mysql tool that can be invoked directly by the tool.
If the mysql command line is in path, choosing option 2 will launch it with appropriate parameters. But by choosing 1, we will able to use any tool that can connect to MySQL In this case, we will use MySQL Workbench.

Launch MySQL Workbench and click on New Server Instance under Server Administration.

Select Remote Host and enter 127.0.0.1. Do not enter the port number at this point.

In the next step, enter the port number that vmc tunnel has shown followed by the username and password.

Click continue to see the confirmation.

Finally, double clicking on the server will launch the query editor.

Now, you can run queries and perform any operations on the database provisioned at CloudFoundry.com.

- Janakiram MSV, Chief Editor, CloudStory.in

Tutorial: Adding a Custom Domain Name to Windows Azure Web Site

One of the recently added features to Windows Azure is the Web Sites. It gives developers a chance to deploy ASP, ASP.NET, Node.js and PHP web sites with no friction. Typically, the deployed websites are accessible through http://yourwebsitename.azurewebsites.net. While the free threshold doesn’t support attaching a custom domain name, moving the web site to the reserved mode enables us to point a custom domain to it. This tutorial shows you how to configure an external DNS service for a website deployed to Windows Azure Web Sites.

This tutorial assumes that you have a valid domain already registered with a registrar like Go Daddy. To separate the DNS management from the domain registrar, we will sign up with DNSMadeEasy.com. This will let us manage the DNS independent of the domain registrar and the hosting platform. The other advantage of DNSMadeEasy.com is the programmability of the DNS through the REST API.

There are three steps involved in adding a domain name –

  1. Configuring Go Daddy to point the Nameservers to DNSMadeEasy
  2. Adding the URL of the Azure Web Site to DNSMadeEasy to the CNAME
  3. Updating the hostname at the Windows Azure Management Portal

Prerequisites

  • A registered domain
  • Trial account at DNSMadeEasy.com
  • Web Site successfully deployed at Windows Azure listening at http://yourwebsitename.azurewebsites.net

Step 1 – Configuring Go Daddy to point the Nameservers to DNSMadeEasy

Login to DNSMadeEasy.com and click on the DNS menu at the top to select Managed DNS

Click on Add Domains button and type the domain name that is already registered with Go Daddy

After a few minutes, click on the domain name that is just added. Click on the Name Servers tab you see the list of Name Servers assigned to this domain.

Make a note of the Name Servers listed here. Notice that the FQDN reflects the Name Servers currently assigned by Go Daddy. We will change it by logging on to Go Daddy control panel. Launch the Domain Manager for the domain you want to configure in Go Daddy and click on Set Nameservers link.

Select I have specific nameservers for my domain option and enter the Nameserver addresses provided by DNSMadeEasy

Give it a few minutes for the DNS to propagate. This will point the domain to the Nameservers of DNSMadeEasy. Go Daddy control panel will confirm this after by showing the new DNS Nameservers.

Step 2- Adding the URL of the Azure Web Site to DNSMadeEasy

Currently, the website deployed at Windows Azure is available at http://cloudreadydemo.azurewebsites.net/

Switch to DNSMadeEasy and click on the domain that was created in the last step. Under the CNAME Records, click the + sign and add the endpoint of the Windows Azure Web Site. Enter www for the Name and the URL of the Windows Azure Web Site with a trailing period (.) at the end. This will instruct DNSMadeEasy to point the domain to the complete URL instead of creating a sub-domain. Finally, click on Submit.

Step 3 – Updating the hostname at the Windows Azure Management Portal

Since we can only add the domain to the websites running in the reserved mode, we will first move the website from the shared mode to reserved mode. To do this, login to Windows Azure Management Portal and select the website that you want to configure. Click on Scale and switch to reserved mode.

After that is done, click on configure, enter the custom domain name under the hostnames section and click on save button at the bottom.

Windows Azure will check if the CNAME records are already configured for this URL and if it finds, it will accept the hostname.

Now our website is accessible through the custom domain.

Hope this helps you to easily configure a custom domain for your Windows Azure Web Sites.

- Janakiram MSV, Chief Editor, CloudStory.in

Tutorial: Getting Started with Cloud Foundry – Part 3/3

Part 1 of this article introduced Cloud Foundry and walked you through the configuration of Micro Cloud Foundry for the offline deployment. In part 2, we reconfigured Micro Cloud Foundry to go online and expose the deployed application on the public internet. In the final part, we will move the application to the Public Cloud running at CloudFoundry.com.

CloudFoundry.com is the Public Cloud that hosts Cloud Foundry. We can deploy applications to run on this environment just by targeting the endpoint, http://api.cloudfoundry.com. Let’s repeat a few steps to run our simple Ruby application on CloudFoundry.com. Now that we are familiar with the vmc tool, just run the following commands in the same sequence.

[crayon lang="shell"]
vmc target http://api.cloudfoundry.com
[/crayon]

Let’s login to the Public Cloud by entering the credentials that we provided during the signup process.

[crayon lang="shell"]
vmc login
[/crayon]

Finally, we push the application to CloudFoundry.com. Give a unique name to the app as it may be turned into a DNS name for our application.

[crayon lang="shell"]
vmc push
[/crayon]

We can access the application by typing the url http://hello-cf-jani.cloudfoundry.com/.

Note that the subdomain is a part of Cloudfoundry.com which is an indication that our app is running on the Public Cloud.

In this tutorial we have seen how to deploy applications running on Cloud Foundry in 3 different modes – 1) Micro Cloud Foundry in the offline mode, 2) Micro Cloud Foundry in the online mode and, 3) Public Cloud running at CloudFoundry.com.

- Janakiram MSV, Chief Editor, CloudStory.in

Tutorial: Getting Started with Cloud Foundry – Part 2/3

Part 1 of this article introduced Cloud Foundry and walked you through the configuration of Micro Cloud Foundry for the offline deployment. In this part, we will reconfigure Micro Cloud Foundry to go online and expose the deployed application on the public internet.

Login to CloudFoundry.com and generate a token to initialize the Micro Cloud Foundry. Enter a unique name and click the create button. This will create a unique domain which will act as the endpoint for vmc. Make a note of the token that is generated. We need this to configure the Micro Cloud Foundry.

Switch to Micro Cloud Foundry and select option 6 to disable the offline mode.

Make sure that the Micro Cloud Foundry is online.

Now, select option 4 to reconfigure the domain. Enter the token generated at Cloudfoundry.com.

After restarting all the services, Micro Cloud Foundry should now be wired to the domain that was created for us at CloudFoundry.com.

We notice that the identify URL and API endpoint are now reflecting the new domain name.

It’s time for us to point vmc to the new URL and login with the user that we created earlier.

[crayon lang="shell"]
vmc target http://api.janakiramm.cloudfoundry.me
vmc login
[/crayon]

Let’s deploy the Ruby application to the new configuration. Let’s call this hello-mcf!

[crayon lang="shell"]
vmc push
[/crayon]

t is time for us to open the browser and access the application through the Internet. We type hello-mcf.cloudfoundry.me to access the app.

Notice that the application is now accessible through the public DNS name.

In the next part, we will target cloudfoundry.com to deploy the same application. Stay tuned!

- Janakiram MSV, Chief Editor, CloudStory.in

Tutorial: Getting Started with Cloud Foundry – Part 1/3

We take you on an interesting journey of deploying an application on the new PaaS environment, Cloud Foundry. Part 1 will introduce Cloud Foundry and setting up the Micro Cloud Foundry. In Part 2 and Part 3, we will see how to configure Micro Cloud Foundry to expose the deployed applications on the public Internet and go live with deployments on CloudFoundry.com.

Why Cloud Foundry?

Cloud Foundry is an interesting choice for developers targeting the Cloud. As an Open PaaS, Cloud Foundry offers the flexibility to run it on a VM, Private Cloud or the Public Cloud. This makes it easy for the businesses to unify its development environment across the enterprise, 3rd party hosting and Public Clouds. Developers can package the application for Cloud Foundry and run it in a single VM, Private Cloud running behind the firewall of an organization or a Public Cloud like Amazon EC2 without worrying about the scalability of the infrastructure. The other benefit of Cloud Foundry is the choice of available runtimes, frameworks and languages. Cloud Foundry supports Java, Ruby and Node.js runtimes along with grails, spring, rack, sinatra, rails, node, lift and play frameworks. Developers using any of these environments can easily deploy the applications to Cloud Foundry. Contemporary applications rely on relational databases, NoSQL databases and messaging infrastructure for achieving the internet scale. Cloud Foundry exposes MySQL, PostgreSQL, MongoDB, RabbitMQ and Redis as services that offer the database and messaging capabilities. Developers can easily bind the applications to one of these services during the deployment. Apart from these core services, various language, platform and hosting partners extended Cloud Foundry to support additional languages, frameworks, services and deployment options.

Cloud Foundry

What to Expect from this tutorial?

There are many tutorials and getting started guides including the official documentation of Cloud Foundry. This tutorial is focused on understanding the deployment choices of Cloud Foundryby targeting the VMware hosted CloudFoundry.com and Micro Cloud Foundry that runs as a VM. We will learn how to setup and configure Micro Cloud Foundry in two modes – 1) Offline and, 2) Online. Offline mode enables developers to easily deploy applications on the Micro Cloud Foundry without the internet connection. Online mode is primarily meant to expose the applications deployed on the Micro Cloud Foundry through a publicly accessible URL while still running it within the VM. Finally, we will deploy the application on the Public Cloud running at CloudFoundry.com. Since the core objective of the tutorial is to understand the deployment options, we will keep the code simple by writing a Ruby application with just a few lines. While the tutorial is helpful in setting up Cloud Foundry environment on any OS, it shows how to configure Micro Cloud Foundry specifically on Windows 7.

Prerequisites for the Tutorial

1) Active account created at www.cloudfoundry.com – Signing up is easy and you should get your credentials in just a few minutes.

2) Download and install VMware Player – This is required to run the Micro Cloud Foundry VM. VMware makes it available for free.

3) Download Micro Cloud Foundry – Once you have an active account, you can login to download the VM that is configured to run the Micro Cloud Foundry.

4) Download Ruby for Windows – We need this for the VMC client and also to write the sample application to deploy on Cloud Foundry. Install and configure it to make sure you are able to run Ruby code on your machine.

Step 1 – Configure Micro Cloud Foundry for Offline Deployment

Before you get started, make sure that you have downloaded, installed the VMware Player and unzipped the Micro Cloud Foundry VM on your machine.

Launch VMware Player and click on Open a Virtual Machine. Point to the path where you expanded the Micro Cloud Foundry zip file.

Cloud Foundry

Cloud Foundry

Once the VM is opened within the VMware player, click on the Play Virtual Machine

Cloud Foundry

You should see the below screen after booting the VM. Press ‘1’ to select configure.

Cloud Foundry

Register a password by entering it twice.

Cloud Foundry

Select DHCP in the next option and choose none for the HTTP proxy. Enter an offline domain name that will uniquely identify the offline endpoint to deploy applications. This can be anything but it is a good idea to have a domain name that looks like your-firstname.cloudfoundry.offline.

Cloud Foundry

In the next step, enter your email id and accept the Terms of Service.

Cloud Foundry

Micro Cloud Foundry may take a while to get installed and configured. Give it a few minutes.

Cloud Foundry

Cloud Foundry

Cloud Foundry

If everything goes well, the installation should get completed to show the following screen

Cloud Foundry

We have one more step to go before we are done. Open Network Connections in Control Panel on Windows 7 to change the DNS settings of VMware Network Adapter VMnet8. Set the Preferred DNS server address to the IP address that the Micro Cloud Foundry is currently listening on. In my case it was 192.168.190.130.

Cloud Foundry

Cloud Foundry

Let’s test if the DNS name is accessible to the host machine by pinging the DNS name of the Micro Cloud Foundry VM.

Cloud Foundry

Congratulations! Micro Cloud Foundry is all set for the deployments.

Step 2 – Creating and deploying a simple Ruby Application

Open your favorite editor and write the following code. Create a directory called hello and save the file as hello.rb.
[crayon lang="ruby"]
require ‘rubygems’
require ‘sinatra’
get ‘/’ do

“Hello from Cloud Foundry”

end
[/crayon]

Cloud Foundry

Now that we have the code and the platform ready, it is time for us to configure the tools to deploy our first application on Cloud Foundry. To do this, we need to install the vmc gem on our machine. Open Command Prompt and run

[crayon lang="shell"]
gem install vmc
[/crayon]

Cloud Foundry

Let’s test the VMC installation by running the vmc –v command. This should show the version of the client.

[crayon lang="shell"]
vmc –v
[/crayon]

Cloud Foundry

Now, it is time for us to deploy our application to the Micro Cloud Foundry. We start this process by pointing vmc to the Micro Cloud Foundry. Let’s run the following command. Don’t forget to replace this with the actual endpoint that the Micro Cloud Foundry is listening on. You can refer to the console to get the URI.

[crayon lang="shell"]
vmc target http://api.janakiramm.cloudfoundry.offline
[/crayon]

Cloud Foundry

If everything is fine, you should see a message that vmc is successfully targeting the Micro Cloud Foundry.

We need to register a new user who can deploy applications. This is different from the VCAP user that was created on the VM. The user is identified by the email address and password.

Let’s run the following command to create a new user. Do remember the password you enter during the creation.

[crayon lang="shell"]
vmc register
[/crayon]

Cloud Foundry

VMC has created a new user and automatically logged him into the Micro Cloud Foundry environment. With all the prerequisites met, it is time for us to push the code. We will do this by running the following command. Make sure you are in the hello directory that contains the hello.rb file.

[crayon lang="shell"]
vmc push
[/crayon]

Give a name to your application and accept the defaults where possible.

Cloud Foundry

Congratulations! You have successfully deployed your first application on Cloud Foundry! Let’s go ahead and access this application. Open browser and type the URL of the Micro Cloud Foundry.

Cloud Foundry

In the next part, we will see how to take Micro Cloud Foundry online to access the deployed applications from a publicly accessible URL. Stay tuned!

- Janakiram MSV, Chief Editor, CloudStory.in

Suresh Sambandam, Founder & CEO, OrangeScape

Suresh Sambandam, Founder & CEO, OrangeScapeSuresh Sambandam is the Founder and CEO of OrangeScape a global top 10 Platform as a Service Company. OrangeScape’s Visual PaaS helps creating business applications quickly and easily. OrangeScape is also the world’s only cross cloud platform. OrangeScape is featured in multiple research reports of Gartner and Forrester. OrangeScape has a marquee customers like Citibank, Unilever, Pfizer, AstraZeneca, Fullerton and the likes. OrangeScape has partnered with Tier 1 Services providers like TCS, Cognizant, Wipro and 5 others to support enterprise implementations. Read Suresh’s guest articles on PaaS on CloudStory.in here