Contents


Automate operational business decisions with Weather Data and Business Rules services on Bluemix, Part 1

Get started with a sample weather cancellation service

Comments

Content series:

This content is part # of # in 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.

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.

Overview of the Acme Bus Weather Cancellation service
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:

To build the sample Acme Bus Weather Cancellation service you need the following accounts and software set up:

Step 1. Create a Node-RED starter app

Create a new Node-RED Starter application from the Boilerplates section of the Bluemix service catalog.

  1. Go to www.bluemix.net.
  2. Click Log in and enter your IBM Bluemix user name and password.
  3. On the IBM Bluemix Dashboard, click Create App.
  4. Scroll down to the list of Boilerplates and click Node-RED Starter.
  5. On the Create a Cloud Foundry App window, enter a unique name for the App Name field. For this tutorial, type Weather and Business Rules App.
  6. Leave the rest of the default values as is and click Create.
  7. Wait for your app to be created and started. The status changes to Running, as shown in the following screen capture. Weather and Business Rules Node-RED Bluemix                 App
    Weather and Business Rules Node-RED Bluemix App

    To open the Node-RED flow editor, click the starter application link, which is Weather-and-Business-Rules-App.mybluemix.net in this tutorial.

  8. 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

  1. 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.)
  2. Select the Connections tab and click the Connect new button. The IBM Bluemix catalog opens.
  3. In the catalog, search for and select the Business Rules service.
  4. 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.
  5. 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.
  6. 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.
  7. From the catalog, search for and select the Weather Company Data service.
  8. 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.
  9. 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.

The Execution Object Model (XOM) is a set of Java classes that the business rules engine uses to run rules. To build the application, you need access to a sample Java XOM that corresponds to the JavaScript Object Notation (JSON) object models from data returned by the Weather Data service API.

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.

  1. Open Rule Designer and create a workspace.
  2. Click Rule to switch to that perspective.
  3. Download and import the sample Java XOM code for the weather data that the Acme Bus Weather Cancellation service uses from BluemixWeatherAndBusinessRules.
    1. Extract the sample code into a directory you want to use. Notice the root directory of the extracted archive contains a WeatherDataXOM subdirectory that you use later.
    2. From the Rule Explorer view, right-click the project area and click Import.
    3. Select General > Existing Projects Into Workspace and click Next.
    4. Click Browse and navigate to the directory that contains the WeatherDataXOM subdirectory from step a.
    5. 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.

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.

  1. 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. Decision Service Map
    Decision Service Map
  2. From the New Rule Project window, select Main Rule Project and click Next.
  3. Give the Rule Project a name and click Finish. Now you should see the new empty rule project in the Rule Explorer view.
  4. 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.
  5. Select Java execution object model and click OK.
  6. Select the WeatherDataXOM check box in the Properties for WeatherDataRuleProject window, and click OK.
  7. 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.
  8. Select the default values in the first screen of the New BOM Entry window and click Next.
  9. Click Browse XOM and under Choose a XOM Element, select platform:/WeatherDataProject and click OK.
  10. 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.
  11. 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.
  12. In the Class Verbalization section, next to the Term text box, click Edit.
  13. 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.

  1. Go to the Rule Project Map view. In the Decision Service Map, click Add decision operation in the Define decision operation node.
  2. In the New Decision Operation window, enter WeatherDataDecision in the Name field and click Finish.
  3. 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: Decision Operation Overview Properties                 window
    Decision Operation Overview Properties window
  4. 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.
  5. Click OK in the Select an operation window.
  6. 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. Decision Operation Map
    Decision Operation Map
  7. Enter WeatherDataRuleVariables for the name for the variable set and click Finish.
  8. 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. Variable Set Defined in the Business Rules                 Project
    Variable Set Defined in the Business Rules Project
  9. 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.
  10. Add the ruleset variables as either Input - Output Parameters or Output Parameters, as shown in the following screen capture. Input / Output Parameter Definition for the Decision                 Operations
    Input / Output Parameter Definition for the Decision Operations

    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.

Conclusion

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.

Acknowledgements

The authors would like to thank Uzma Siddiqui for her detailed review and thoughtful suggestions to improve this article.


Downloadable resources


Comments

Sign in or register to add and subscribe to comments.

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Middleware, Cloud computing
ArticleID=1049440
ArticleTitle=Automate operational business decisions with Weather Data and Business Rules services on Bluemix, Part 1: Get started with a sample weather cancellation service
publish-date=09202017