If you are a newbie,you might not be clearly all three ways to deploy your applications on BlueMix. Today I will talk about these three tools a little bit.
Developers have the freedom to choose the development tools that work best for them. Developers don’t always want to work with the same tool sets and BlueMix provides several options, including the following:
• Command line: The Cloud Foundry (CF) command line provides integration for developers that prefer coding without an integrated development environment (IDE). This is also helpful for developing automation scripts with BlueMix. The CF application programming interfaces (APIs) can be integrated with multiple languages, frameworks and services.
• BlueMix for Eclipse Kepler Beta: Since Eclipse is widely used by developers, they can continue to use the tools with which they are comfortable.This plug-in expose some of the unique features of the Liberty buildpack such as
deploying a Liberty packaged server. In addition, support for deploying
node.js applications allows you to target your JavaScript project, and
then deploy and run your server side JavaScript application in the
Cloud.
•IDS(IBM DevOps Services): The cloud-based software development service(the former name is jazz hub) is based on IBM's software development tool Rational Team Concert.Developers can work with the IDS using web IDE to edit the code online and provide automatically deployment to BlueMix . It also provide integration to several source control management (SCM) systems like Git, GitHub and Jazz SCM.
I will blog three tools details in the next few days.
Monday, May 19, 2014
Sunday, May 18, 2014
How do you choose your PaaS?
Platform as a Service (PaaS) is a cloud model designed for software developers that streamlines the development process by shifting specific aspects of systems management to the service provider. PaaS is used to develop web and mobile applications using components that are pre-configured and maintained by the service provider, including programming languages, application servers and databases.
Today I will list some popular PAAS vendors for your reference.
BlueMix
BlueMix is an implementation of IBM’s Open Cloud Architecture, leveraging Cloud Foundry to enable developers to rapidly build, deploy, and manage their cloud applications, while tapping a growing ecosystem of available services and runtime frameworks. IBM will provide services and runtimes into the ecosystem based on our extensive software portfolio.It offically support Liberty for Java™,Node.js,Ruby on Rails,Ruby Sinatra.Since itis built on top of Cloud Foundry and you can add support for languages or frameworks not supported in Cloud Foundry by default.Now it is in beta
Heroku
Heroku was acquired by Salesforce.com in 2010. one of the first cloud platforms, has been in development since June 2007, when it supported only the Ruby programming language, but has since added support for Java, Node.js, Scala, Clojure and Python and (undocumented) PHP and Perl. The base operating system is Debian or, in the newest stack, the Debian-based UbuntuHeroku is the leading platform as a service in the world and supports Ruby, Java, Python, Scala, Clojure, and Node.js. Deploying an app is simple and easy.
Red Hat OpenShift
Red Hat OpenShift is based on open source applications and offers a wide variety of languages, databases and components. The PaaS is highly customizable and offered in three forms: OpenShift Online (a cloud-based hosting service), OpenShift Enterprise (a private PaaS that runs in your data center) and OpenShift Origin (the open source application hosting platform). OpenShift automates system administration tasks such as virtual server provisioning, configuration and scaling and supports git repositories for code management.
Google App Engine
Google App Engine is designed for distributed web applications and developers using Java, Python, PHP and Go. The Java environment supports other languages that make use of the JRE and there is a SDK for each of the four main supported languages as well as a plugin for Eclipse. The PaaS offers managed infrastructure and runtime environments that are guaranteed to scale, but only if the applications fit the restrictions of Google App Engine. The Datastore, a transactional, schema-less data store based on key-value pairs, handles the complex management of data that's accessible to multiple machine instances. Programming languages are limited to Java, Python, Go and PHP.
AppFog
AppFog is a multi-language, multi-framework PaaS that's a good option for multi-cloud deployments, including private clouds. AppFog supports Java, Ruby, PHP, Python, Node, Scala and Erlang and offers MySQL, PostgreSQL, Redis and RabbitMQ along with third party add-on services. It can be used as a DaaS with ClearDB, MongoHQ, MongoLab, Redis Cloud and Xeround. AppFog is based on the open source Cloud Foundry platform and supports Git, SVN and Mercurial for code management.
Windows Azure Cloud Services
Within Windows Azure, Microsoft is blurring the lines between IaaS and PaaS. Windows Azure Cloud Services supports .NET, Node.js, PHP, Python, Java and Ruby. In addition to software development kits, developers can use Visual Studio for creating and deploying applications. Developers can choose between a SQL Database, Tables and Blobs when it comes to persistent storage. Applications are administered through the Windows Azure dashboard or through a command line interface.
Amazon AWS
Although Amazon Web Services is primarily an IaaS, many of the services available in AWS are comparable to PaaS offerings. You can use the platform services available in AWS without having to create or maintain your own application servers. AWS readily supports Java, Python, Ruby, Perl and other languages. Oracle, MySQL and SQL Server can be set up and managed, but AWS offers RDS web service as well, which eliminates database administration tasks. Developers can take advantage of Amazon Elastic Beanstalk for automatic load balancing, auto-scaling, and application health monitoring
force.com
Force.com is a Platform as a Service (PaaS) product designed to simplify the development and deployment of cloud-based applications and websites. Developers can create apps and websites through the cloud IDE (integrated development environment) and deploy them quickly to Force.com’s multi-tenant servers.
Also there is a good site http://www.paasify.it/vendors ,you can choose your PAAS based on the predefined search condition.
Also it is very cool to know all kinds of PAAS feature and status.Enjoy it.
Today I will list some popular PAAS vendors for your reference.
BlueMix
BlueMix is an implementation of IBM’s Open Cloud Architecture, leveraging Cloud Foundry to enable developers to rapidly build, deploy, and manage their cloud applications, while tapping a growing ecosystem of available services and runtime frameworks. IBM will provide services and runtimes into the ecosystem based on our extensive software portfolio.It offically support Liberty for Java™,Node.js,Ruby on Rails,Ruby Sinatra.Since itis built on top of Cloud Foundry and you can add support for languages or frameworks not supported in Cloud Foundry by default.Now it is in beta
Heroku
Heroku was acquired by Salesforce.com in 2010. one of the first cloud platforms, has been in development since June 2007, when it supported only the Ruby programming language, but has since added support for Java, Node.js, Scala, Clojure and Python and (undocumented) PHP and Perl. The base operating system is Debian or, in the newest stack, the Debian-based UbuntuHeroku is the leading platform as a service in the world and supports Ruby, Java, Python, Scala, Clojure, and Node.js. Deploying an app is simple and easy.
Red Hat OpenShift
Red Hat OpenShift is based on open source applications and offers a wide variety of languages, databases and components. The PaaS is highly customizable and offered in three forms: OpenShift Online (a cloud-based hosting service), OpenShift Enterprise (a private PaaS that runs in your data center) and OpenShift Origin (the open source application hosting platform). OpenShift automates system administration tasks such as virtual server provisioning, configuration and scaling and supports git repositories for code management.
Google App Engine
Google App Engine is designed for distributed web applications and developers using Java, Python, PHP and Go. The Java environment supports other languages that make use of the JRE and there is a SDK for each of the four main supported languages as well as a plugin for Eclipse. The PaaS offers managed infrastructure and runtime environments that are guaranteed to scale, but only if the applications fit the restrictions of Google App Engine. The Datastore, a transactional, schema-less data store based on key-value pairs, handles the complex management of data that's accessible to multiple machine instances. Programming languages are limited to Java, Python, Go and PHP.
AppFog
AppFog is a multi-language, multi-framework PaaS that's a good option for multi-cloud deployments, including private clouds. AppFog supports Java, Ruby, PHP, Python, Node, Scala and Erlang and offers MySQL, PostgreSQL, Redis and RabbitMQ along with third party add-on services. It can be used as a DaaS with ClearDB, MongoHQ, MongoLab, Redis Cloud and Xeround. AppFog is based on the open source Cloud Foundry platform and supports Git, SVN and Mercurial for code management.
Windows Azure Cloud Services
Within Windows Azure, Microsoft is blurring the lines between IaaS and PaaS. Windows Azure Cloud Services supports .NET, Node.js, PHP, Python, Java and Ruby. In addition to software development kits, developers can use Visual Studio for creating and deploying applications. Developers can choose between a SQL Database, Tables and Blobs when it comes to persistent storage. Applications are administered through the Windows Azure dashboard or through a command line interface.
Amazon AWS
Although Amazon Web Services is primarily an IaaS, many of the services available in AWS are comparable to PaaS offerings. You can use the platform services available in AWS without having to create or maintain your own application servers. AWS readily supports Java, Python, Ruby, Perl and other languages. Oracle, MySQL and SQL Server can be set up and managed, but AWS offers RDS web service as well, which eliminates database administration tasks. Developers can take advantage of Amazon Elastic Beanstalk for automatic load balancing, auto-scaling, and application health monitoring
force.com
Force.com is a Platform as a Service (PaaS) product designed to simplify the development and deployment of cloud-based applications and websites. Developers can create apps and websites through the cloud IDE (integrated development environment) and deploy them quickly to Force.com’s multi-tenant servers.
Also there is a good site http://www.paasify.it/vendors ,you can choose your PAAS based on the predefined search condition.
Also it is very cool to know all kinds of PAAS feature and status.Enjoy it.
RabbitMQ deployment on BlueMix
RabbitMQ is open source message broker software (sometimes called message-oriented middleware) that implements the Advanced Message Queuing Protocol (AMQP). The RabbitMQ server is written in the Erlang programming language and is built on the Open Telecom Platform framework for clustering and failover. Client libraries to interface with the broker are available for all major programming languages.RabbitMQ can run all major operation systems (for example, Windows, Linux, MacOS) and supports a huge number of developer platforms (for example, Java, Ruby, Python, .NET, Node.JS, and etc).
Today I will talk about how to use node.js or jave to send message using RabbitMQ on the BlueMix.Let's get started.
1.Node.js
a)Firstly, you need to create a new RabbitMQ service instance with the cf create-service command. Type the following command at terminal:
cf create-service rabbitmq 100 rabbitmq-test
b)Create a manifest.yml,it will describe the deployment strcture on BlueMix.The service name should be "rabbitmq-test" you created before.
applications:
- services:
- rabbitmq-test
host: RabbitMQ
disk: 1024M
name: RabbitMQ
command: node app.js
path: .
domain: ng.bluemix.net
instances: 1
memory: 128M
Notes: Pls make sure the host name is not taken by others,otherwise the deployment will report error.You have to change other name to instead of it.
c) Since our command point the start node from app.js,so we need to create app.js file.You can copy below content into your files.
var http = require('http');
var amqp = require('amqp');
if (process.env.VCAP_SERVICES) {
var env = JSON.parse(process.env.VCAP_SERVICES);
var credentials = env['rabbitmq-2.8'][0]['credentials'];
} else {
var credentials = {"url": "amqp://user1:secret@localhost:5672/vhost"}
}
var port = (process.env.VCAP_APP_PORT || 1337);
var host = (process.env.VCAP_APP_HOST || '0.0.0.0');
http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
var conn = amqp.createConnection({url: credentials.url});
conn.on('ready', function() {
var exchange = conn.exchange('test-event', {type: 'fanout'});
conn.queue('test-event-queue', function(q) {
q.bind(exchange, '');
q.subscribe(function(json) {
res.end("Fetched message: " + json.body);
conn.end();
});
exchange.publish('test-event-queue', {'body': 'Hello, world!'} );
});
});
}).listen(port, host);
d) Create a package.json.
This text file contains all the information about the project, like project path, dependencies, author name, tags, bug tracking info etc.. To create a package.json run npm init command from the root folder. It will ask series of questions and finally it will create package.json file.
Our package.json file will look like this.
{
"version":"1.0.0",
"scripts":{"start":"node app.js"},
"dependencies":{"amqp":"*"},
"name":"hellorabbitmq",
"description":"This is a Bluemix demo"
}
Notes:
You need to add dependencies amqp,it will automatic download the node module when you deploy to the BlueMix.
e) use cf push command to deploy Node application to the BlueMix.You can see below sucessfule info.
1 of 1 instances running
App started
Showing health and status for app RabbitMQ in org gyyuan@cn.ibm.com / space dev
as XXX@XXX...
OK
requested state: started
instances: 1/1
usage: 128M x 1 instances
urls: RabbitMQ..ng.bluemix.net
state since cpu memory disk
#0 running 2014-05-18 11:26:27 PM 0.0% 30.6M of 128M 21.8M of 1G
f) Open the browser and luanch the url http://rabbitmq.ng.bluemix.net ,you can see the below screenshot.It means your deployment sucessfule.
b) Create a java package named com.ibm.bluemix,and create a servlet class named RabbitMq.The detail code you can see below
package com.ibm.bluemix;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.cloudfoundry.runtime.env.CloudEnvironment;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
/**
* Servlet implementation class RabbitMq
*/
@WebServlet("/RabbitMq")
public class RabbitMq extends HttpServlet {
private static final long serialVersionUID = 1L;
private final static String QUEUE_NAME = "hello";
/**
* @see HttpServlet#HttpServlet()
*/
public RabbitMq() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
try{
String connURL = getServiceInfo();
ConnectionFactory factory = new ConnectionFactory();
factory.setUri(connURL);
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
String message = "Hello World!";
channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
out.println(" [x] Sent '" + message + "'");
channel.close();
connection.close();
out.println( "Successful" );
}catch(Exception e){
out.println( "Error running query: " + e.getMessage() );
e.printStackTrace();
}
}
public String getServiceInfo() throws Exception {
CloudEnvironment environment = new CloudEnvironment();
List<Map<String, Object>> services= environment.getServices();
List<Map<String, Object>> matchedServices = new ArrayList();
List<String> listlabels=new ArrayList();
listlabels.add("rabbitmq-2.8");
for (Map service : services) {
if ( listlabels.contains(service.get("label"))) {
System.out.println("we get match service");
matchedServices.add(service);
}else{
System.out.println("service name"+service.get("label"));
}
}
if ( matchedServices.size() == 0 ) {
throw new Exception( "No RabbitMQ service is bund to this app!!" );
}
Map credential = (Map)( matchedServices.get(0)).get( "credentials" );
return (String)credential.get( "url" );
}
}
Notes:
Here getServiceInfo() method will include all the service deployed on the BlueMix,so we need to filter the service which only used the rabbitmq-2.8.You can use this way to filter other service. The service detail parameter you can check your application run time enviroment variable.
c)Create an IBM BlueMix server like below screenshot.
d) Fill the credential info and use validate account to connect remote BlueMix env,
e)When your BlueMix server is started,you can add the RabbitMQTest project to the server,in the launch deployment wizard,you need to enter the deploy host name and application name etc info.
f) Choose the rabbitMQ service "rabbitmq-test"we created before .
g)You should see the console some logs.If you see below logs,it means your deployment is successful.
Checking application - RabbitMQTest
Generating application archive
Creating application in Cloud Foundry server
Pushing application to Cloud Foundry server
Application successfully pushed to Cloud Foundry server
h) Login into the BlueMix website and click the Dashboard tab and you can see your application is not started.Click the start button to start the application.
i) After started and launch the browser and open the url rabbitmqtest.ng.bluemix.net/RabbitMq, you should see the below screenshot.
Notes: /RabbitMq part url is defined in the RabbitMq servlet annations.
@WebServlet("/RabbitMq")
Now all are done.Enjoy the node.js and java integration with RabbitMQ.
Today I will talk about how to use node.js or jave to send message using RabbitMQ on the BlueMix.Let's get started.
1.Node.js
a)Firstly, you need to create a new RabbitMQ service instance with the cf create-service command. Type the following command at terminal:
cf login -a https://api.ng.bluemix.netcf create-service rabbitmq 100 rabbitmq-test
b)Create a manifest.yml,it will describe the deployment strcture on BlueMix.The service name should be "rabbitmq-test" you created before.
applications:
- services:
- rabbitmq-test
host: RabbitMQ
disk: 1024M
name: RabbitMQ
command: node app.js
path: .
domain: ng.bluemix.net
instances: 1
memory: 128M
Notes: Pls make sure the host name is not taken by others,otherwise the deployment will report error.You have to change other name to instead of it.
c) Since our command point the start node from app.js,so we need to create app.js file.You can copy below content into your files.
var http = require('http');
var amqp = require('amqp');
if (process.env.VCAP_SERVICES) {
var env = JSON.parse(process.env.VCAP_SERVICES);
var credentials = env['rabbitmq-2.8'][0]['credentials'];
} else {
var credentials = {"url": "amqp://user1:secret@localhost:5672/vhost"}
}
var port = (process.env.VCAP_APP_PORT || 1337);
var host = (process.env.VCAP_APP_HOST || '0.0.0.0');
http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
var conn = amqp.createConnection({url: credentials.url});
conn.on('ready', function() {
var exchange = conn.exchange('test-event', {type: 'fanout'});
conn.queue('test-event-queue', function(q) {
q.bind(exchange, '');
q.subscribe(function(json) {
res.end("Fetched message: " + json.body);
conn.end();
});
exchange.publish('test-event-queue', {'body': 'Hello, world!'} );
});
});
}).listen(port, host);
d) Create a package.json.
This text file contains all the information about the project, like project path, dependencies, author name, tags, bug tracking info etc.. To create a package.json run npm init command from the root folder. It will ask series of questions and finally it will create package.json file.
Our package.json file will look like this.
{
"version":"1.0.0",
"scripts":{"start":"node app.js"},
"dependencies":{"amqp":"*"},
"name":"hellorabbitmq",
"description":"This is a Bluemix demo"
}
Notes:
You need to add dependencies amqp,it will automatic download the node module when you deploy to the BlueMix.
e) use cf push command to deploy Node application to the BlueMix.You can see below sucessfule info.
1 of 1 instances running
App started
Showing health and status for app RabbitMQ in org gyyuan@cn.ibm.com / space dev
as XXX@XXX...
OK
requested state: started
instances: 1/1
usage: 128M x 1 instances
urls: RabbitMQ..ng.bluemix.net
state since cpu memory disk
#0 running 2014-05-18 11:26:27 PM 0.0% 30.6M of 128M 21.8M of 1G
f) Open the browser and luanch the url http://rabbitmq.ng.bluemix.net ,you can see the below screenshot.It means your deployment sucessfule.
2. Java
In ordet to quick to demostrate the java ability, I decied to use servlet to show the sending message to RabbitMQ result .Also I will use java liberty as my runtime enviorment.If you have no experience for that you should read my previous post "How to use eclipse to develop liberty java application to BlueMix"
a.Create a dynamic web project named RabbitMQTest. Download below two libs and copy to WEB_inf lib folder.
rabbitmq-client.jar
cloudfoundry-runtime-0.7.1.jar
get it from http://www.java2s.com/Code/Jar/c/Downloadcloudfoundryruntime071jar.htm
package com.ibm.bluemix;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.cloudfoundry.runtime.env.CloudEnvironment;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
/**
* Servlet implementation class RabbitMq
*/
@WebServlet("/RabbitMq")
public class RabbitMq extends HttpServlet {
private static final long serialVersionUID = 1L;
private final static String QUEUE_NAME = "hello";
/**
* @see HttpServlet#HttpServlet()
*/
public RabbitMq() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
try{
String connURL = getServiceInfo();
ConnectionFactory factory = new ConnectionFactory();
factory.setUri(connURL);
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
String message = "Hello World!";
channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
out.println(" [x] Sent '" + message + "'");
channel.close();
connection.close();
out.println( "Successful" );
}catch(Exception e){
out.println( "Error running query: " + e.getMessage() );
e.printStackTrace();
}
}
public String getServiceInfo() throws Exception {
CloudEnvironment environment = new CloudEnvironment();
List<Map<String, Object>> services= environment.getServices();
List<Map<String, Object>> matchedServices = new ArrayList();
List<String> listlabels=new ArrayList();
listlabels.add("rabbitmq-2.8");
for (Map service : services) {
if ( listlabels.contains(service.get("label"))) {
System.out.println("we get match service");
matchedServices.add(service);
}else{
System.out.println("service name"+service.get("label"));
}
}
if ( matchedServices.size() == 0 ) {
throw new Exception( "No RabbitMQ service is bund to this app!!" );
}
Map credential = (Map)( matchedServices.get(0)).get( "credentials" );
return (String)credential.get( "url" );
}
}
Notes:
Here getServiceInfo() method will include all the service deployed on the BlueMix,so we need to filter the service which only used the rabbitmq-2.8.You can use this way to filter other service. The service detail parameter you can check your application run time enviroment variable.
c)Create an IBM BlueMix server like below screenshot.
d) Fill the credential info and use validate account to connect remote BlueMix env,
e)When your BlueMix server is started,you can add the RabbitMQTest project to the server,in the launch deployment wizard,you need to enter the deploy host name and application name etc info.
f) Choose the rabbitMQ service "rabbitmq-test"we created before .
g)You should see the console some logs.If you see below logs,it means your deployment is successful.
Checking application - RabbitMQTest
Generating application archive
Creating application in Cloud Foundry server
Pushing application to Cloud Foundry server
Application successfully pushed to Cloud Foundry server
i) After started and launch the browser and open the url rabbitmqtest.ng.bluemix.net/RabbitMq, you should see the below screenshot.
Notes: /RabbitMq part url is defined in the RabbitMq servlet annations.
@WebServlet("/RabbitMq")
Now all are done.Enjoy the node.js and java integration with RabbitMQ.
Friday, May 16, 2014
Ten minutes to create a node.js based album on BlueMix (Part Two)
This part I will step by step to show how to write my album application.You can download my code from here.If you don;t have jazz hub account,pls register one and use your IBM id to login on .
1.Create a project album use the express project as the template to generate project structure.Also create image folder under the public folder.Create a car folder under the image folder.
2.In order to control my UI easily,I decide to use the bootstrap.Download it from the official site.Unzip the package and put all the css,js folder including files under the public folder. You should see the below structure generated.
3.Modify layout.jade under the views folder.You can copy the below code to this file.
doctype html
html
head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
link(rel='stylesheet', href='/stylesheets/bootstrap.min.css')
link(rel="stylesheet" href="http://blueimp.github.io/Gallery/css/blueimp-gallery.min.css")
link(rel="stylesheet" href="/stylesheets/bootstrap-image-gallery.min.css")
body(style='background:black')
div(class="navbar navbar-inverse navbar-fixed-top" )
div(class='container')
div(class='navbar-header')
span(class='sr-only')='Toggle navigation'
span(class='icon-bar')
span(class='icon-bar')
span(class='icon-bar')
a(class='navbar-brand' href='#')='My tesla'
div(class='collapse navbar-collapse' style='height: 1px;')
block content
script(src='http://cdn.bootcss.com/jquery/1.10.2/jquery.min.js')
script(src='/bootstrap.js')
script(src="http://blueimp.github.io/Gallery/js/jquery.blueimp-gallery.min.js")
script(src="/bootstrap-image-gallery.min.js")
4.Change index.js under the routes folder.Copy below code to this file.
var fs = require('fs');
exports.index = function(req, res){
var files = fs.readdirSync('public/images/car');
res.render('index', { title: 'My car',imgs:files });
};
5.Change index.jade under the views folder.Copy below code to this file
7.In order to deploy to the BlueMix,I need to create two files manifest.yml,package.json.
8. Deploy to the BlueMix
After review the project,I found some files/folder are not necessary when you deploy to the BlueMix.Like .settings,node_modules. We can delete these two folders.
After login into the bluemix,you can directly use cf push command.Pls make sure the application host name is not occupied by others.
Now our node.js demo is completed deployed on to the BlueMix.
1.Create a project album use the express project as the template to generate project structure.Also create image folder under the public folder.Create a car folder under the image folder.
2.In order to control my UI easily,I decide to use the bootstrap.Download it from the official site.Unzip the package and put all the css,js folder including files under the public folder. You should see the below structure generated.
3.Modify layout.jade under the views folder.You can copy the below code to this file.
doctype html
html
head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
link(rel='stylesheet', href='/stylesheets/bootstrap.min.css')
link(rel="stylesheet" href="http://blueimp.github.io/Gallery/css/blueimp-gallery.min.css")
link(rel="stylesheet" href="/stylesheets/bootstrap-image-gallery.min.css")
body(style='background:black')
div(class="navbar navbar-inverse navbar-fixed-top" )
div(class='container')
div(class='navbar-header')
span(class='sr-only')='Toggle navigation'
span(class='icon-bar')
span(class='icon-bar')
span(class='icon-bar')
a(class='navbar-brand' href='#')='My tesla'
div(class='collapse navbar-collapse' style='height: 1px;')
block content
script(src='http://cdn.bootcss.com/jquery/1.10.2/jquery.min.js')
script(src='/bootstrap.js')
script(src="http://blueimp.github.io/Gallery/js/jquery.blueimp-gallery.min.js")
script(src="/bootstrap-image-gallery.min.js")
4.Change index.js under the routes folder.Copy below code to this file.
var fs = require('fs');
exports.index = function(req, res){
var files = fs.readdirSync('public/images/car');
res.render('index', { title: 'My car',imgs:files });
};
5.Change index.jade under the views folder.Copy below code to this file
extends layout
block content
div(style='height:210px')
for img in imgs
a(href='images/car/'+img title=img data-gallery)
img(src='images/baby/'+img class="img-thumbnail" style='width:140px;height:140px;margin:5px' )
6.put some car pictures in the car folders.Run the app.js in the eclipse and open the browser and use http://localhost:3000 to visit my application,you can see my album is generated.
a)manifest.yml it defines the deploy settings on BlueMix.
applications: - host: node-album disk: 1024M name: node-album command: node app.js path: . domain: ng.bluemix.net instances: 1 memory: 128M
Notes:
If you don;t know how to write the manifest.yml,you can create a sample node.js application on the BlueMix, download the sample package,it will ship this file.
b)package.json It defines the node dependencies module,so when you deploy node.js application,the buildpack will automatic download the node module from this file.
{
"name": "NodeAlbum",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node app.js"
},
"dependencies": {
"express": "3.2.6",
"jade": "*"
}
}
After review the project,I found some files/folder are not necessary when you deploy to the BlueMix.Like .settings,node_modules. We can delete these two folders.
Next we can use below cf command to deploy it on the BlueMix.
cf api https://api.ng.bluemix.net
cf push
Now our node.js demo is completed deployed on to the BlueMix.
Ten minutes to create a node.js based album on BlueMix (Part One)
Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications.Now most paas support Node.js runtime env.Node.js has now became the most popular choice for building Real-time Web Applications since it’s first release on May 27, 2009.Now BlueMix host nodejs for developer to use.Today I will talk about how to write my albumn application based on node.js and deploy on the bluemix.
Setup Node.js IDE
If you are a java developer, I recommend you to use Eclipse. Nodeclipse plug-in is free open-source software released every month and it became #1 in Eclipse Top 10 NEW Plugins for 2013.You can install it through the eclipse(http://www.nodeclipse.org/updates).You can also download the node.js eclipse version from this link.When you finish the plug-in installation,you should see the below screenshot.
Setup Node.js IDE
If you are a java developer, I recommend you to use Eclipse. Nodeclipse plug-in is free open-source software released every month and it became #1 in Eclipse Top 10 NEW Plugins for 2013.You can install it through the eclipse(http://www.nodeclipse.org/updates).You can also download the node.js eclipse version from this link.When you finish the plug-in installation,you should see the below screenshot.
Now we will build the app, we'll use the Express.js framework ,use nodeeclipse we can easily to create a sample project for that.Here we choose jade as our template engine.
When you click the finish button,it will automatic download the express,jade module and also create express project structure.
Choose the app.js and right click the menu and run as node application.You will see below screenshot.
Notes: there is a issue in layout.jade.You need to manually change it.
doctype 5 //you need to change doctype htnl
html
head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
body
block content
Next part I will focus on how to write a node.js application with bootstrap to create my Album.
Wednesday, May 14, 2014
Is that possible to manage the Mongo data on BlueMix ?
Most applications need db support.Sometimes people we need client tools to maintain these db structure and data.In local environment,we can install db client tools to control these db,but how about BlueMix ? After some research I found IBM only provide SQLDB(DB2) Console to manage SQLDB. For other db we might have use own way to provide it.The next part I will introduce how to maintain the mongo db on the BlueMix.
After some research,I decide to use RockMongo.It is a MongoDB administration tool, written in PHP5, is Best in PHP world, more like PHPMyAdmin.You can download it from http://rockmongo.com/downloads.
Since it used PHP and Mongo db,when we deploy this app to the BlueMix,there are some steps we need to do.
1.Unzip the download package to specified folder. For exmaple c:\rockmongo
2.Create a manifest.yml in the c:\rockmongo.The manifest document has captured all of the configuration that we entered above for the application push into a description of the application deployment. Once you have a manifest.yml file, you can modify it however you would like.Copy the below content to this manifest.yml
---
applications:
- name: php-mongoAdmin
memory: 128M
instances: 1
path: .
buildpack: https://github.com/dmikusa-pivotal/cf-php-build-pack
3.Since this php application need to use mongo module,so you need to included php_mongo in the list of extensions in the buildpack options file. This is documented here:
https://github.com/dmikusa-pivotal/cf-php-build-pack/blob/master/docs/config.md#php-extensions
So we need to create a folder named .bp-config under your project and create a options.json file which will include php extension ,so when you install php buildpack it will install the dependency based on this options.json file.
4.Copy the below content to the options.json
5.When we config rockmongo db info we need to know the mongo db name,ip ,user name ,password etc info.In order to get this kind of info,we double click the mongo db service,choose the application used this service then find the env log under the Files and Logs directory.You can get db credential info.
6.Open the config,php change the setting value based on the step5.You can add multiple server in this configuration file.
$MONGO["servers"][$i]["mongo_name"] = "192.155.236.166";//mongo server name
$MONGO["servers"][$i]["mongo_host"] = "192.155.236.166";//mongo host
$MONGO["servers"][$i]["mongo_port"] = "10014";//mongo port
$MONGO["servers"][$i]["mongo_timeout"] = 0;//mongo connection timeout
$MONGO["servers"][$i]["mongo_db"] = "db";//default mongo db to connect, works only if mongo_auth=false
$MONGO["servers"][$i]["mongo_user"] = "430f4c04-9ab0-49b2-95c8-226a3db5386f";//mongo authentication user name, works only if mongo_auth=false
$MONGO["servers"][$i]["mongo_pass"] = "a30d54be-2159-48ee-ae33-ca50d1ecc3ef";//mongo authentication password, works only if mongo_auth=false
$MONGO["servers"][$i]["mongo_auth"] = true;//enable mongo authentication?
7.Create a composer.json empty file. This file describes the dependencies of your project and may contain other metadata as well.
So by now all the configuration changes are done.The next step just deploy the app to the BlueMix.
Using the cloud foundry v6 cli, login to BlueMix and deploy your modified files using a PHP buildpack runtime.
# Step 0: cf login -a <api target url>
$ cf login -a https://api.ng.bluemix.net
# Step 1: under the rockmongo project folder
$ cf push
After some research,I decide to use RockMongo.It is a MongoDB administration tool, written in PHP5, is Best in PHP world, more like PHPMyAdmin.You can download it from http://rockmongo.com/downloads.
Since it used PHP and Mongo db,when we deploy this app to the BlueMix,there are some steps we need to do.
1.Unzip the download package to specified folder. For exmaple c:\rockmongo
2.Create a manifest.yml in the c:\rockmongo.The manifest document has captured all of the configuration that we entered above for the application push into a description of the application deployment. Once you have a manifest.yml file, you can modify it however you would like.Copy the below content to this manifest.yml
---
applications:
- name: php-mongoAdmin
memory: 128M
instances: 1
path: .
buildpack: https://github.com/dmikusa-pivotal/cf-php-build-pack
3.Since this php application need to use mongo module,so you need to included php_mongo in the list of extensions in the buildpack options file. This is documented here:
https://github.com/dmikusa-pivotal/cf-php-build-pack/blob/master/docs/config.md#php-extensions
So we need to create a folder named .bp-config under your project and create a options.json file which will include php extension ,so when you install php buildpack it will install the dependency based on this options.json file.
4.Copy the below content to the options.json
{
"WEB_SERVER": "httpd",
"PHP_EXTENSIONS": ["bz2", "zlib", "curl", "mcrypt", "mongo"]
}
5.When we config rockmongo db info we need to know the mongo db name,ip ,user name ,password etc info.In order to get this kind of info,we double click the mongo db service,choose the application used this service then find the env log under the Files and Logs directory.You can get db credential info.
6.Open the config,php change the setting value based on the step5.You can add multiple server in this configuration file.
$MONGO["servers"][$i]["mongo_name"] = "192.155.236.166";//mongo server name
$MONGO["servers"][$i]["mongo_host"] = "192.155.236.166";//mongo host
$MONGO["servers"][$i]["mongo_port"] = "10014";//mongo port
$MONGO["servers"][$i]["mongo_timeout"] = 0;//mongo connection timeout
$MONGO["servers"][$i]["mongo_db"] = "db";//default mongo db to connect, works only if mongo_auth=false
$MONGO["servers"][$i]["mongo_user"] = "430f4c04-9ab0-49b2-95c8-226a3db5386f";//mongo authentication user name, works only if mongo_auth=false
$MONGO["servers"][$i]["mongo_pass"] = "a30d54be-2159-48ee-ae33-ca50d1ecc3ef";//mongo authentication password, works only if mongo_auth=false
$MONGO["servers"][$i]["mongo_auth"] = true;//enable mongo authentication?
7.Create a composer.json empty file. This file describes the dependencies of your project and may contain other metadata as well.
So by now all the configuration changes are done.The next step just deploy the app to the BlueMix.
Using the cloud foundry v6 cli, login to BlueMix and deploy your modified files using a PHP buildpack runtime.
# Step 0: cf login -a <api target url>
$ cf login -a https://api.ng.bluemix.net
# Step 1: under the rockmongo project folder
$ cf push
After successfully deployment,open the browser and visit the http://php-mongoadmin.ng.bluemix.net/,you will see below login screen
After input the db credential ,you can see Mongo db management UI.Now we can totally control our db in the cloud.
During my research ,I find some technical difficulty,so I post some questions on dw bluemix fourm and got my answers.It is a place to ask BlueMix usage questions since lots of IBM experts there.
Tuesday, May 13, 2014
Deploy HelloWorld Ruby Sinatra web application on BlueMix
Today I will share my step-by-step process to build and deploy a Ruby-based Sinatra application on BlueMix.Sinatra is a free and open source software web application library and domain-specific language written in Ruby. It is an alternative to other Ruby web application frameworks such as Ruby on Rails, Merb, Nitro and Camping. I am a newbie for Ruby,I thought it might take me lots effort to do this,but after trial,it is beyond my expectation,the whole operation is less five minutes.
1.Visit https://ace.ng.bluemix.net/ and setup an IBM account.After login into the BlueMix site, Click the catalog link,you will see below screen.
2.Double Click the Ruby Sinatra,it will popup a dialog for you to create your Ruby Sinatra name and host name. For example I create the app name to HelloWordlRuby,the domain name is also HelloWorld.ng.bluemix.net.After click the "Create" Button,it will automatic create this app into the DashBoard.
3.You can double click the HelloWorldRuby app link http://hellowordlruby.ng.bluemix.net to see the actual result.
4.Actually the web UI show the most variable of the Ruby(version 1.9.3) Sinatra environment info.I want to make some changes on the UI. Just click on the settings(gear) icon next to your application name and select view guide to download the whole package.
5.Unzip the package to my local machine to c:\sinatra, open the helloWorld.rb and change the content to below screen.
6.Visit this CLI link and download the installer for your OS.Use below command to connect your bluemix
cf api https://api.ng.bluemix.net
Setting api endpint to https://api.ng.bluemix.net... OK
Notes:
Since the package already shipped with manifest.yml file,so we can directly use cf push command to deploy it.
applications:
- host: HelloWordlRuby
disk: 1024M
name: HelloWordlRuby
path: .
domain: ng.bluemix.net
instances: 1
memory: 128M
After authentication, we can use cf push command to deploy our application(make sure you execute command under the application fold) to BlueMix again.After successful deployment and re-visit the url you can see the below new UI,
1.Visit https://ace.ng.bluemix.net/ and setup an IBM account.After login into the BlueMix site, Click the catalog link,you will see below screen.
2.Double Click the Ruby Sinatra,it will popup a dialog for you to create your Ruby Sinatra name and host name. For example I create the app name to HelloWordlRuby,the domain name is also HelloWorld.ng.bluemix.net.After click the "Create" Button,it will automatic create this app into the DashBoard.
3.You can double click the HelloWorldRuby app link http://hellowordlruby.ng.bluemix.net to see the actual result.
4.Actually the web UI show the most variable of the Ruby(version 1.9.3) Sinatra environment info.I want to make some changes on the UI. Just click on the settings(gear) icon next to your application name and select view guide to download the whole package.
5.Unzip the package to my local machine to c:\sinatra, open the helloWorld.rb and change the content to below screen.
6.Visit this CLI link and download the installer for your OS.Use below command to connect your bluemix
cf api https://api.ng.bluemix.net
Setting api endpint to https://api.ng.bluemix.net... OK
Notes:
Since the package already shipped with manifest.yml file,so we can directly use cf push command to deploy it.
applications:
- host: HelloWordlRuby
disk: 1024M
name: HelloWordlRuby
path: .
domain: ng.bluemix.net
instances: 1
memory: 128M
Subscribe to:
Posts (Atom)


























