Forums/Knowledge Bases/Micro Cloud Foundry Knowledge Base

Introduction to Using Micro Cloud Foundry

Dave McCrory
posted this on July 31, 2011 10:06

This document assumes that you have successfully completed the Micro Cloud Foundry Installation & Setup and that your Micro Cloud FoundryTM instance is currently powered on without showing any errors.  If you go into VMware Workstation, Fusion, or Player you should see a screen similar to the one shown below:

Complete.png

Micro Cloud Foundry requires either the vmc client or the Spring STS plug-in to be installed on the client environment.  

Installation instructions for the vmc client can be found here

Installation instructions for the Spring STS plug-in can be found here

 Default Resource Limitations for Micro Cloud Foundry can be found here

 

Using Micro Cloud Foundry

If you want to use Spring STS please go here.

The first thing that must be done to use Micro Cloud Foundry is to target the Micro Cloud Foundry instance.  

Using vmc this is done by typing:

vmc target http://api.YOURMICROCLOUDNAME.cloudfoundry.me

You will then need to register a user on the Micro Cloud Foundry instance.  This is done by typing:

vmc register

You will then be prompted to input a username (e-mail address) and a password

Register.png

Next you will need to login to the Micro Cloud Foundry instance.  To do this, type:

vmc login

You will then be prompted for the e-mail address and password that you just registered with.

Login.png

After successfully logging in, you should be able to push a test application.  

Deploying a Hello World Application

Save the following code in a directory by itself as "hello.rb"

require 'rubygems' 
require 'sinatra' 
 
get '/' do 
 "Hello from your Micro Cloud Foundry instance" 
end

To deploy this onto your Micro Cloud Foundry instance type the following from a terminal window/command prompt

inside of the directory where "hello.rb" was saved:

vmc push hello

Press enter 

(this takes the default answer "Yes")

Push.png

Press enter 

(this determines the URL your application will be mapped to)

In this case it is "hello.demo.cloudfoundry.me".

DeployURL.png

Press enter

(the vmc client has detected that hello.rb uses the Sinatra Framework)

Sinatra.png

Press enter

(this is the Memory allocation, the default for Sinatra is 128M for a Java Application it would be 512M)

Memory.png

Press enter

(This answers the default "No" we do not want to bind a service to the Application.)

Using services are covered later in the document.

Services.png

After the application has been successfully deployed, you should see the screen below:

Success.png

To see the application running, open a web browser and go the Application Deployed URL:

Hello.png

 

Using Service with Micro Cloud Foundry

Micro Cloud Foundry allows the creation and binding of services to Applications the same way the Cloud Foundry does.

Supported Micro Cloud Foundry Services include:

 

Creating a Service in Micro Cloud Foundry is done by using the following command:

vmc create-service redis

ServiceCreate.png

In the above example, an instance of Redis was created, this could be substituted with mongodb or mysql.

 

Once a service is provisioned, it can be bound to an Application.

In the example below we will create a more complex version of the Hello World Application by adding

Redis support to read and write data from two additional Sinatra Routes (URLs). 

First create a new directory and create a file named "helloredis.rb" with the following contents:

require 'rubygems'
require 'sinatra'
require 'thin'
require 'json'
require 'redis'

configure do
  services = JSON.parse(ENV['VCAP_SERVICES'])
  redis_key = services.keys.select { |svc| svc =~ /redis/i }.first
  redis = services[redis_key].first['credentials']
  redis_conf = {:host => redis['hostname'], :port => redis['port'], :password => redis['password']}
  @@redis = Redis.new redis_conf
end

get '/' do
 "Hello from your Micro Cloud Foundry instance"
end

get '/write/*/*' do
  key=params[:splat][0]
  value=params[:splat][1]
  @@redis.set key, value
end

get '/read/:key' do |k|
  @@redis.get k
end

We will now do a vmc push that will include binding the application to the redis instance that was created earlier. 

In the example below the application name is redis, you can name it whatever you like (just remember this name

is also the name for the URL that you will use to access the application).

vmc push redis

Press enter (this assumes you are pushing from the directory where you saved the "helloredis.rb" file.

PushRedis.png

Press enter (this assumes that you want the URL to use redis - the default)

DeployRedisURL.png

Press enter (Sinatra should be the detected Framework)

SinatraRedis.png

Press enter (Default Memory Allocation is 128M)

MemoryRedis.png

Type Y, then Press enter (This is so that the redis Service can be bound to the redis Application)

Bind.png

Type Y, then Press enter (This is to choose the redis Service previously created)

PreviousRedisService.png

Select the Number assigned to the Redis service previously created, (3 in this case)

then Press enter

RedisSelection.png

The application should now successfully push and be bound.

RedisPushComplete.png

Testing the redis Application

First open a browser and go to the Deployed URL

(http://redis.demo.cloudfoundry.me in this example)

 RedisBrowser.png

To add keys to the redis Application, add write/key/value to the URL

http://redis.demo.cloudfoundry.me/write/somekey/somevalue

 WriteSomeKey.png

To read keys from the redis Application, add read/key to the URL

http://redis.demo.cloudfoundry.me/read/somekey

 ReadSomeKey.png

 This demonstrates that you can successfully read and write keys to the Redis Service.

Additional Information

The Micro Cloud Foundry instance should work identically to Cloud Foundry.com (with the exceptions mentioned previously).  For additional information, please review the Cloud Foundry Knowledge base located at http://support.cloudfoundry.com/forums/373015 

Support

For support and additional resources please visit : http://support.cloudfoundry.com

 
Topic is closed for comments