This case study is specifically prepared for IBM tutorial in Serverless NYC, A serverless reality check - October 30 2018, New York
What is BAI?
IBM® Business Automation Insights (BAI) is a platform-level component that provides visualization insights to business owners and that feeds a data lake to infuse artificial intelligence into IBM Digital Business Automation. More in docs
This case study is designed to show how to use Apache OpenWhisk with IBM Cloud Functions to add custom behavior to BAI.
We simplify several aspects of BAI:
- emitter is not connected to a real system but is hardcoded to send sample task events
- analytics is simplified and modified to group task summaries by actions
- summaries are stored as JSON objects in Elasticsearch
- dashboards are a simplified version of BAI dashboards
Share Feedback - we would apprecate if you take one minute to fill very short google form: https://ibm.biz/BdY3B8
Adn feel free to reach out with any questions! Twitter @aslom https://twitter.com/aslom
IBM Cloud Functions is based on the Apache OpenWhisk project. We'll be using IBM Cloud Functions for today's lab, but the concepts could apply to any managed Serverless offering.
- Sign up for an IBM Cloud Account [https://ibm.biz/BdY3BT]
- This should redirect you to IBM Cloud as a part of the sign up process, but if not you can go directly there at https://bluemix.net
- Sign in to confirm your account was created.
In this section, you will install the IBM Cloud CLI and the IBM Cloud Functions Plugin to the CLI, as well as do some account set up and configuration. This will enable you to interact with IBM Cloud Functions from a command line interface.
-
Install the IBM Cloud CLI
-
From Shell:
- Mac/Linux: In your terminal window, run
curl -sL https://ibm.biz/idt-installer | bash
- Windows 10 Pro, run
Set-ExecutionPolicy Unrestricted; iex(New-Object Net.WebClient).DownloadString('http://ibm.biz/idt-win-installer')
- Mac/Linux: In your terminal window, run
-
Alternatively, you can use an installer:
- Link to installer: Link to installer
-
-
Configure your environment
- Select your API:
ibmcloud api https://api.ng.bluemix.net
- Login:
ibmcloud login
- You should have an org created already. Target your org with the command
ibmcloud target --cf
- You should have a space that was created automatically for you as well, called dev. If it was, then the
ibmcloud target --cf
command would show that this space was targeted, and you can skip the steps for creating a space.- If you do not have a space; let's create one. In this example, we'll call our space dev, but you can choose anything you want:
ibmcloud cf create-space dev
- Ensure your org & space is correctly targeted using
ibmcloud target --cf
- If you do not have a space; let's create one. In this example, we'll call our space dev, but you can choose anything you want:
- Confirm cloud-functions plugin is installed:
ibmcloud fn
should return some help information.- If the plugin is not installed, install it:
ibmcloud plugin install cloud-functions
- If the plugin is not installed, install it:
- Select your API:
Your first goal is to create a simple hello world action. This action will return the string 'Hello World' when it is in invoked.
-
Create a folder for your action to live in:
mkdir myFolder && cd myFolder
-
Create a file called helloworld.js:
touch helloworld.js
-
Use your favorite editor to paste the following code into helloworld.js:
function main(params) { if (params.name) { return { greeting: `Hello ${params.name}` }; } return { greeting: 'Hello stranger!' }; }
-
This code will return "Hello stranger" if no name parameter is given, otherwise it will say hello to the supplied name. Let's create a new action using this file:
ibmcloud fn action create helloWorld helloworld.js
-
Let's invoke the action hosted on IBM Cloud Functions, using -r to wait for a result:
ibmcloud fn action invoke helloWorld -r
-
You should see a response like:
{ "greeting": "Hello stranger!" }
-
Let's invoke the action with a parameter of your name:
ibmcloud fn action invoke helloWorld -p name Belinda -r
-
You should see a response like:
{ "greeting": "Hello Belinda" }
Now that you have a basic hello action working, you are ready to go to the main part of our tutorial: let's move to BAI Case study.
It is not required for this lab due to time constraints, but in the future you could use your own Kafka or Elasticsearch.
To use your own Kafka, update JSON with Kafka configuration.
To use your own Elasticsearch, update JSON with Elasticsearch installation or use the one provided (should be valid during lab).