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.



2 comments:

  1. BlueHost is definitely the best web-hosting company for any hosting plans you might need.

    ReplyDelete