Monday, May 12, 2014

Rules on BlueMix

I saw lots of service provided by BlueMix platforms.Some of them are enterprise service can meet some business needs like rules,Elastic MQ service,CastIronLive,Single Sign-On (SSO) etc.Today I will introduce rule service on BlueMix.The Rules service provides managed execution of business rules for your applications.The service is based on the IBM Operational Decision Manager (IBM ODM) product, version 8.5.1.I  follow the sample and successfully deploy the application to the BlueMix.Below I will write some key steps when I deploy my rule application.

Below is the whole structure of rule service on the BlueMix.




1.When you apply for a rule service,it will provide the rule res server url to you.You will use that url to deploy your ruleApp.


2.Open the rule desginer and import the  miniloan-rules-materials.zip ,use RuleApp > Deploy. to deploy your ruleApp to previous server.


3.Enter the res console use step 1 provided link and login credential,you can see the ruleApp is deployed.There are two ways to invoke rule service in the BlueMix,one is used Rest API,another is useing HTDS.If you choose soap and click the view button you can get this ruleset wsdl .Otherwisde you can choose rest type and then click the view button to get rest url.






4.If you choose the saop type,you get can the wsdl link like

 https://ds-xxxx.ng.bluemix.net/DecisionService/ws/miniloanApp/1.0/miniloanRules/1.0?WSDL
So you can use any web service client tool to invoke this webservice.Here we recommended to use Apach Axis2.
5.If you use rest type ,you need to download  WADL file.You can get the rest url from resources base file.

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://wadl.dev.java.net/2009/02" xmlns:param="http://www.ibm.com/rules/decisionservice/MiniloanApp/MiniloanRules/param" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://wadl.dev.java.net/2009/02 wadl.xsd">
  <doc title="miniloan$45$rules"/>
  <grammars>
    <include href="MiniloanAppMiniloanRulesParameters.xsd"/>
  </grammars>
  <resources base="https://ds-XXX..ng.bluemix.net/DecisionService/rest/v1/miniloanApp/1.0/miniloanRules/1.0">
    <resource path="">
      <method name="POST">
        <doc title="execute"/>
        .................................................
The rest url  format will be :https://{host}:port}/DecisionService/rest/v1/{rulesetPath}?{options}
Also you can use the test button to test rule rest API.

6.In order to avoid hard coded these url,we can use java api to get rule service url.The below is part of code in the VCAPServiceParser.java
public VCAPServiceParser() {
parse(System.getenv(ENV_VCAP_NAME));
}

/**
* Parses the VCAP_SERVICES
*            environment variable.
* 
* @param VCAP_SERVICES
*            environment variable.
* */
private void parse(String vcapenv) {
if (vcapenv != null) {
ObjectMapper mapper = new ObjectMapper();
try {
JsonNode rootNode = mapper.readTree(vcapenv);
Iterator<String> fields = rootNode.getFieldNames();
while (fields.hasNext()) {
String element = fields.next();
if (element.startsWith(RULESSERVICE_PREFIX)) {
ArrayNode dsService = (ArrayNode) rootNode
.path(element);
// Get the First Rules Service Found in the
// VCAP_SERVICES env variable
JsonNode firstDsService = dsService.get(0);
JsonNode credentials = firstDsService
.path(VCAP_CREDENTIAL_TAG);

setExecutionEndPoint(credentials.path(VCAP_DMS_URL_TAG)
.getTextValue());
break;
}
}
} catch (Exception e) {
LOG.severe("Unable to parse VCAP_SERVICES environment variable");
}
}  .

The application deployment procedure  you can reference below link. https://www.ng.bluemix.net/docs/Services/Rules/rulov008.html

When you launch the application,you need to change some values based on some conditions.

After you click the Submit Approval button,you can see the rule execution result.



Sunday, May 11, 2014

How to use eclipse to develop liberty java application to BlueMix Part Two

Before you begin, make sure you have installed the Liberty and BlueMix plug-in in the  previous blog.

1.Create a HelloWorld Web project from Eclipse and make sure you have choose the traget runtime with was liberty profile.

2.Create a servlet named  HelloWolrd ,and generate get and set method.Write the below code to the doGet method.

/**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        PrintWriter p = response.getWriter();
        p.println("<BODY>");
        p.println("<H2>This a blueMix demo");
        p.println("</BODY>");
    }

3.Start the WebSphere Application Server Liberty Profile at localhost ,choose the server and add your hellow world project to the runtime server,so you can do the local testing for that.

Notes:Sometimes your liberty default 9080 might be occupied,so you might need to change httpPort in the server.xml

<server description="new server">

    <!-- Enable features -->
    <featureManager>
        <feature>jsp-2.2</feature>
        <feature>localConnector-1.0</feature>
    </featureManager>

    <!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
    <httpEndpoint httpPort="9085" httpsPort="9443" id="defaultHttpEndpoint"/>


    <applicationMonitor updateTrigger="mbean"/>

    <webApplication id="HelloWorld" location="HelloWorld.war" name="HelloWorld"/>
</server>

 4. Launch the url in the web console ,open the browser to do the testing

5.Once you liberty application is ready on local side, you can deploy it to the BlueMix,The step is very simple.Choose the IBM  BlueMix server and add your project into it.
6.During the deployment,it will let you change the application detail info,deployment detail,service selection info.

Pls make sure the deploy url is not used by others,otherwise the deployment will be failed

If you don;t use other service,just click  to next.
If the deployment is sucessful,you can see your liberty application is already deployed in the BlueMix.

7.Visit the BlueMix url http://helloworld001.ng.bluemix.net/HelloWorld

Now our first HelloWorld Liberty demo is completed,enjoy it.



How to use eclipse to develop liberty java application to BlueMix Part One

This blog I wrote in  my company blog,since I think it is useful for newbie to learn.So I share the content here.

Recently I am fascinated by the BlueMix.provides a list of runtime environments as containers for different types of applications.Such as Liberty for Java™,NodeJs,Ruby on Rails.If in future it support .Net ,it will be a perfect plartform for developers to develop their application on the plartform.



Today I just want to write some experience of writing and deploying a "HelloWorld" liberty demo for the BlueMix.



Before we write code,we need to install eclipse on the local side and install two plugin based on that.

1.Install liberty plug-in tools in the eclipse
a. Start the Eclipse integrated development environment (IDE) for Java EE
Developers workbench.
b. Click Help Eclipse Marketplace
c. type websephere
d.Click install ,when you finish it pls restart the eclipse.

2.Install the BlueMix for Eclipse Kelper Beta or Cloud Foundry Plug-in .

3.After restart the eclipse ,you can add liberty runtime enviroment to your eclipse,choose eclipse menu windows-preference-Server-Runtime Enviorment

You can add liberty , bluemix two runtimes.

Notes:When you define your blueMix server,you can switch different url for that


After finish the setting,you can see your deployed BlueMix project.

How you you setup WordPress on BlueMix?

WordPress is a free and open source blogging tool and a content management system (CMS) based on PHP and MySQL.Today I just have successfully installed wordPress on the BlueMix Platform. I will write the detail steps so you can follow me to create your blog on the BlueMix.

Firstly I will try to install wordPress on the my local machine based on Microsoft operation system.

1.Download the wordpress from the http://wordpress.org/download/,the latest version is the 3.9.1.Unzip zip file to you local drive disk.For example e:\wordpress.
2.In order to setup your php and mysql environment,here I recommended the wampserver.It is a web development platform on Windows allowing you to create dynamic web applications with Apache2, PHP and MySQL.You can download it from http://www.wampserver.com/en/.It support 32 bit and 64 bit installation based on your computer.
Notes:
If you don;t install Visual Studio 2012,you need to install Visual Studio 2012 VC 11 vcredist_x64/86.exe .http://www.microsoft.com/en-us/download/details.aspx?id=30679

3.If your installation complete,Click the tray icon of  wampserver.You can see below menu.

4.Copy the wordpress folder all files to the wamp server www folder.

5.Make your WAMP server Online and start all service.Click the phpMyAdmin link to create wordpress db.Here I create a  wordpress db.

6.When you launch the url http://localhost/wordpress you can find below error.It means we need to change some configuration.

7.Make a file copy from the wp-config-sample.php,named the wp-config.php.Change the db setting like below.The default mysql username root and empty password.

8.Also you need setup WordPress Authentication Unique Keys and Salts .You need to visit the https://api.wordpress.org/secret-key/1.1/salt/  and copy all the content to replace below lines.You can know the detail reason based on this link.

define('AUTH_KEY',         'put your unique phrase here');
define('SECURE_AUTH_KEY',  'put your unique phrase here');
define('LOGGED_IN_KEY',    'put your unique phrase here');
define('NONCE_KEY',        'put your unique phrase here');
define('AUTH_SALT',        'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT',   'put your unique phrase here');
define('NONCE_SALT',       'put your unique phrase here');

9.Now we can visit our local wordPress blog.You can set the blog site title and user name and password.


10.You can setup other(Plug-in,template etc) from below link.After you login into the wordPress,So now our local setting is completed.


How can I deploy it to BlueMix >

So the left work is how do I deploy it the BlueMix.Since you need to create mysql on BluxMix,the db  credentials will be different when you create mysqlservice on the Cloud.So we might need to change the wp-config.php code to support that.See below code changes.

 $services = getenv("VCAP_SERVICES");
 $services_json = json_decode($services,true);
 $mysql_config = $services_json["mysql-5.5"][0]["credentials"];

        // ** MySQL settings from resource descriptor ** //

error_log($mysql_config["name"], 0);
error_log($mysql_config["user"], 0);
error_log($mysql_config["password"], 0);
error_log($mysql_config["host"], 0);
error_log($mysql_config["port"], 0);

    define('DB_NAME', $mysql_config["name"]);
    define('DB_USER', $mysql_config["user"]);
    define('DB_PASSWORD', $mysql_config["password"]);
    define('DB_HOST', $mysql_config["host"].":".$mysql_config["port"]);
Using the cloud foundry v6 cli, login to BlueMix and deploy your modified WordPress files using a PHP buildpack runtime. 
Run the below command step by step
$ cf login -a https://api.ng.bluemix.net
# Step 1: cf create-service <service name> <service plan type> <unique service instance name>

$ cf create-service mysql 100 mysql-wordpress-service
$ cf push mysql-wordpress -b https://github.com/dmikusa-pivotal/cf-php-build-pack.git --no-manifest --no-start
$ cf bind-service mysql-wordpress mysql-wordpress-service
$ cf start mysql-wordpress

When you see the below info on the console it means your deployment is successful.
Uploading mysql-wordpress...
Uploading app files from: E:\wamp\www\wordpress
Uploading 9.9M, 1206 files
OK

Stopping app mysql-wordpress in org XXX@ibm.com / space dev as XXX@cn.i
bm.com...
OK
websocket: bad handshake
Starting app mysql-wordpress in org XX@cn.ibm.com / space dev as XXX@cn.i
bm.com...
OK

1 of 1 instances running

Launch the url http://mysql-wordpress.ng.bluemix.net/wp-admin/install.php,you can install wordPress now.



So if you have any installation issue,pls let me know.

Friday, May 9, 2014

How let BlueMix support PHP?

Default BlueMix support the below four run time environment.So if you want to run some other environment,you might need to use customize buildpack to do this.
Today I will introduce how to run PHP in the BlueMix.
What you need to prepare before building and runing the app ?

a)A BlueMix account
b)Familiarity with the Cloud Foundry cf command-line interface, which you can download directly from the BlueMix site

c)Elementary knowledge of the PHP programming language

1.Write the php code
<html>
 <head>
  <title>PHP Test</title>
 </head>
 <body>
 <?php echo '<p>Hello World</p>'; ?>
 </body>
</html>
2.Choose the php buildpack,actually there are many php buildpack provided.The most popular php buildpack is heroku-buildpack-php.You can also try others as well.
3. Use cf command to login into the bluemix,it will let you enter the email and password
cf login -a https://api.ng.bluemix.net
4.After log in to your BlueMix account and run this command from the root folder of your application, where appname represents a unique name for your BlueMix-hosted app.I have tested below three buildpack,they both support php,you can pick anyone of three to test it.

cf push myphptest -b https://github.com/dmikusa-pivotal/cf-php-build-pack.git --no-manifest --no-start
cf push myphptest -b https://github.com/cyberdelia/heroku-buildpack-php.git --no-manifest --no-start
cf push myphptest -bhttps://github.com/zendtech/zend-server-php-buildpack.git --no-manifest --no-start

Note:you can also write a  manifest.yml to include the BlueMix deploy information.For example:
---
applications:
- name: myphptest
  memory: 256M
  instances: 1
  host: myphptest
  buildpack: https://github.com/zendtech/zend-server-php-buildpack.git

So you can use only cf push command to do that.

5.When you deploy sucessfully,you can launch the url  myphptest.bluemix.net/hello.php,when you see the hello world page,it means your deployment is sucessfully.




BlueMix Let's started

This blog will demonstrate the feature of IBM blueMix .The postings on this site are my own and don't necessarily represent IBM's positions, strategies or opinions.

What is Codename: BlueMix?

BlueMix is an implementation of IBM’s Open Cloud Architecture, leveraging Cloud Foundryto 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.Now BlueMix is in the beta status.You can join it open beta.
http://www.bluemix.net