- A sample Acme Bus Weather Cancellation service
- What you need to build your application
- Step 1. Create a Node-RED starter app
- Step 2. Create the Weather Data and Business Rules services and bind them to your app
- Step 3. Set up Rule Designer and create a Java XOM project
- Step 4. Create a rule project, import the XOM, and create the BOM
- Step 5. Create a decision operation and define its signature
- Downloadable resources
Automate operational business decisions with Weather Data and Business Rules services on Bluemix, Part 1
Get started with a sample weather cancellation service
This content is part # of # in the series: Automate operational business decisions with Weather Data and Business Rules services on Bluemix, Part 1
This content is part of the series:Automate operational business decisions with Weather Data and Business Rules services on Bluemix, Part 1
Stay tuned for additional content in this series.
Weather events affect business operations. When weather events occur or are likely to occur, businesses take actions to mitigate the effects on their operations. Now businesses can make their operations smarter by reacting to weather events and automating operational decisions that factor in weather data.
Organizations can find an emerging number of services available on Bluemix, the IBM Cloud Platform, to use together to help automate decision-making by taking actions such as invoking a business process based on big data analytics in response to events like weather alerts.
Applications can analyze current weather information for a specific location the Weather Company Data service. Applications can get help automating operational decision logic with the Business Rules service. And, you can use a Node-RED visual tool to wire together the services and devices with the Node-RED Starter boilerplate.
This two-part series describes the steps to combine these Bluemix services to automate decisions that consider weather data by executing business rules. These business decisions could result in any number of actions such as sending notifications, adjusting prices, generating promotions, triggering Internet of Things (IoT) devices, or initiating business processes.
In Part 1, you set up the Bluemix services and create the Business Rules project, the business object model, and the main weather decision operation.
In Part 2, you define the rules and the rule flow, deploy the rules onto Bluemix, and use Node Red to orchestrate the weather data service, the business rules services, and the notification service.
A sample Acme Bus Weather Cancellation service
This article provides a step-by-step explanation of how to build the sample Acme Bus Weather Cancellation service. The sample demonstrates how to use weather data in operational decisions. The service you assemble in this tutorial series simulates a bus transportation system that relies on short-term weather forecasts to determine if road conditions become unsafe. The service runs business logic to determine if a bus tour needs to be cancelled.
You use the Node-RED service to orchestrate the Bluemix services. The business process requests weather data from the Weather Data service for a particular geographical location, which represents the start location of a planned bus tour route. The weather data feeds into the Business Rules service, which makes a decision to either proceed or cancel the planned bus tour. The following screen capture shows an overview of the Acme Bus Weather Cancellation service.
What you need to build your application
You should be familiar with the following technologies and software:
- Node-RED and the Node-RED Starter boilerplate on Bluemix
- The Business Rules service on Bluemix
- The Weather Company Data service on Bluemix
- The Rule Designer Eclipse-based tool, including how to develop business rule projects and author business rules
To build the sample Acme Bus Weather Cancellation service you need the following accounts and software set up:
- An IBM Bluemix account. If you do not have an existing Bluemix account, start your free trial.
- A working installation of Rule Designer to author business rules. Follow the steps in Using Rule Designer to develop business rules applications to install Rule Designer.
- Sample code from GitHub at BluemixWeatherAndBusinessRules.
Step 1. Create a Node-RED starter app
Create a new Node-RED Starter application from the Boilerplates section of the Bluemix service catalog.
- Go to www.bluemix.net.
- Click Log in and enter your IBM Bluemix user name and password.
- On the IBM Bluemix Dashboard, click Create App.
- Scroll down to the list of Boilerplates and click Node-RED Starter.
- On the Create a Cloud Foundry App window, enter a
unique name for the App Name field. For this
Weather and Business Rules App.
- Leave the rest of the default values as is and click Create.
- Wait for your app to be created and started. The status changes to
Running, as shown in the following screen
To open the Node-RED flow editor, click the starter application link, which is Weather-and-Business-Rules-App.mybluemix.net in this tutorial.
- OPTIONAL: From your new Node-RED app home page in Bluemix, click Learn how to password-protect your instance and follow the steps to protect your Node-RED application instance with a password.
Step 2. Create the Weather Data and Business Rules services and bind them to your app
- From the IBM Bluemix dashboard, select the Weather and Business Rules App application. (You can click anywhere on the row, except the hyperlink, which opens the Node-RED editor.)
- Select the Connections tab and click the Connect new button. The IBM Bluemix catalog opens.
- In the catalog, search for and select the Business Rules service.
- On the Business Rules service page, click the Create button to create an instance of the Business Rules service and bind it to the Node-RED starter app.
- Click Restage on the Restage app window to allow the Weather and Business Rules App to restage and restart with the newly bound Business Rules service.
- After the restaging is complete and the Weather and Business Rules App is listed as Running, click the Connect new button again. The IBM Bluemix catalog opens.
- From the catalog, search for and select the Weather Company Data service.
- On the Weather Company Data service page, under the Pricing Plans section, leave the default value Free Plan selected and click the Create button to create an instance of the Weather Company Data service and bind it to the Node-RED starter app.
- Click Restage on the Restage app window to allow the Weather and Business Rules App to restage and restart with the newly bound Weather Company Data service. Make sure the status of the Weather and Business Rules App is listed as Running.
Step 3. Set up Rule Designer and create a Java XOM project
The Weather Data service on Bluemix has a Representational State Transfer (REST) API that retrieves daily, hourly and intraday forecasts. It can also retrieve current weather conditions and historical data.
You have two choices. You can manually create the Java XOM by referencing the attributes and objects in the JSON schemas of the Weather Data service and creating the corresponding classes with attributes and getters and setters. Or, you can use a JSON-to-Java converter to convert JSON objects returned by the APIs to Java objects.
- Open Rule Designer and create a workspace.
- Click Rule to switch to that perspective.
- Download and import the sample Java XOM code for the weather data that
the Acme Bus Weather Cancellation service uses from BluemixWeatherAndBusinessRules.
- Extract the sample code into a directory you want to use.
Notice the root directory of the extracted archive contains a
WeatherDataXOMsubdirectory that you use later.
- From the Rule Explorer view, right-click the project area and click Import.
- Select General > Existing Projects Into Workspace and click Next.
- Click Browse and navigate to the directory
that contains the
WeatherDataXOMsubdirectory from step a.
- You should see the WeatherDataXOM project show up in the list of projects. Select the check box next to it and click Finish to import the project.
- Extract the sample code into a directory you want to use. Notice the root directory of the extracted archive contains a
Step 4. Create a rule project, import the XOM, and create the BOM
Now you create a Business Rule project, and you import the XOM that you created in the previous step. Then, you create the BOM from the XOM.
- From the Rule Project Map view of the Rule perspective in Rule Designer, open the the Decision Service Map. Then click Create main rule project in the Set up a Decision Service node, as shown in the following screen capture.
- From the New Rule Project window, select Main Rule Project and click Next.
- Give the Rule Project a name and click Finish. Now you should see the new empty rule project in the Rule Explorer view.
- To import the weather data Java project as the XOM for this rule project, click Import XOM in the Set up a Decision Service node of the Decision Service Map.
- Select Java execution object model and click OK.
- Select the WeatherDataXOM check box in the Properties for WeatherDataRuleProject window, and click OK.
- In the Decision Service Map, create a BOM from the Weather Data Java XOM. Click Create BOM in the Set up a Decision Service node.
- Select the default values in the first screen of the New BOM Entry window and click Next.
- Click Browse XOM and under Choose a XOM Element, select platform:/WeatherDataProject and click OK.
- Select all available packages and click Finish. This step creates a default BOM with getters and setters for each attribute from the XOM and default verbalization of the attributes from each XOM class. You can customize the BOM and the verbalization if you want.
- Go to the Problems view. You see an error that indicates a duplication of the term forecast. Double-click the error message to open the corresponding BOM class editor where you can change the verbalization of the term.
- In the Class Verbalization section, next to the Term text box, click Edit.
- In the Edit Term window, change the value for the Singular field from forecast to Hourly Weather and click OK. Save the contents of the open editor.
Step 5. Create a decision operation and define its signature
In this section, you create a decision operation and define its signature. The signature includes the input and output parameters that the decision uses. For the Acme Bus Weather Cancellation service, the set of input parameters are the BOM classes that are returned from the weather data service.
The output of the decision is the result of executing rules, which in the Acme service are a Boolean flag and a message. To add inputs and outputs to the signature of the decision operation, you create a variable set and add variables, which represent the information returned by weather data APIs.
- Go to the Rule Project Map view. In the Decision Service Map, click Add decision operation in the Define decision operation node.
- In the New Decision Operation window, enter WeatherDataDecision in the Name field and click Finish.
- After the new decision operation is created, it opens, and you can specify the main ruleflow and the input and output parameters that form the signature, as shown in the following screen capture:
- Go back to the Rule Project Map view. In the Decision Service Map, add a variable set. Click Go to operation map in the Define decision operation node.
- Click OK in the Select an operation window.
- To create a variable set and add variables, click the Add variable set link in the Design Signature node of the WeatherDataDecision Operation Map, as shown in the following screen capture.
WeatherDataRuleVariablesfor the name for the variable set and click Finish.
- In the new variable set that opens, use the Add button to add the following variables that representing inputs and outputs to the decision operation, as shown in the following screen capture. Make sure to save the changes.
- To bind the variable set as input and output parameters for the decision operation, click Bind variables in the Design Signature node of the WeatherDataDecision operation map. The Signature tab opens in the Decision Operation editor.
- Add the ruleset variables as either Input -
Output Parameters or Output
Parameters, as shown in the following screen capture.
Select each variable in the Eligible variables section, right-click, and select either Use as input and output or Use as output. Make sure to save the changes.
So far, in Part 1 of the Augment and automate operational business decisions with Weather Data and Business Rules services on Bluemix series, you completed steps to get started with the sample Acme Bus Weather Cancellation service. You created a Node-RED starter application on Bluemix and bound it to a new Weather Data service and a new Business Rules service. After creating a Java XOM project and importing some starter code into Rule Designer, you created a Rule project, the BOM, including weather data object models and the beginnings of a corresponding weather related decision operation. Finally, you defined its parameters.
In Part 2, you further define the decision operation, create simple business rules that use weather data and a rule flow, and you deploy the decision operation to Bluemix. Then you define a Node-RED flow that orchestrates a call to the weather data, the business rules service, and a HTTP notification service. You expose this flow as the HTTP Acme Bus Weather Cancellation service to notify stakeholders of decisions made to cancel bus trips based on weather conditions from the Weather Data service.
The authors would like to thank Uzma Siddiqui for her detailed review and thoughtful suggestions to improve this article.