This application demonstrates how to use the Workload Scheduler service, with the 'Liberty for Java™' runtime and Cloudant No-SQL database on Bluemix Cloud.
The Java Workload Scheduler Web Starter application contains the following:
- javaCloudantWorkloadSchedulerApp.war
This WAR file is actually the application itself. It is the only file that is be pushed to, and run on, the Bluemix cloud. Every time your application code is updated, you need to regenerate this WAR file and push it to Bluemix again. See the Build section for detailed steps. - src/main/webapp
This directory contains the client side code (HTML/CSS/JavaScript) of your application. - src/main/java
This directory contains the server side code (JAVA) of your application. - pom.xml
This file allows you to easily build your application using Apache Maven. - lib/
This directory contains external libraries that you need to compile the app.
This section explains how to compile the app and manually generate a deployable artifact. If you just wish to try it using the precompiled war, skip to the Deploy section.
- Make sure you have an installed and working instance of Apache Maven, using Java 1.7 or above. You also need git.
- Clone this project:
git clone https://github.com/WAdev0/WAProjects.git
- Move to the newly created folder:
cd WAProjects/javacloudantworkschedbp/app
- Build the app
mvn package
You can find the deployable war javaCloudantWorkloadSchedulerApp.war under the target folder.
This section explains how to run the application on the Bluemix environment.
- Create a new app using the Java Workload Scheduler Web Starter boilerplate.
- Download the precompiled javaCloudantWorkloadSchedulerApp.war from this repo or, if you want to build the application manually, follow the Build section instructions and go to the target directory
cd target
- Follow the instructions in the Start Coding section to install and setup the command line tools for Bluemix.
- Using the ad-hoc commands in the same page, authenticate to the service and push your application to the cloud.
- Optionally, modify the push command to only upload the war and save bandwidth:
cf push <YourAppName> -p javaCloudantWorkloadSchedulerApp.war
If you wish to receive an email confirmation for every order processed by the app, you need a Unix/Linux machine connected to the internet, with the mailx command installed and configured.
- under Services, click the Workload Scheduler section
- Click Downloads
- Download the agent for your linux architecture on your linux machine
- Unzip the agent:
unzip /tmp/SCWA-SaaS_LINUX_X86_64.zip
- Move to the new folder:
cd SCWA-SaaS/
- Create a user for the agent:
useradd -m iws
- Install the agent using the command:
./installAgent.sh -new -acceptlicense yes -uname iws -displayname hybrid
- While waiting for the Application Lab to discover the newly installed agent, set the environment variables for the sender and recipient email:
- Click the Runtime tab
- Click the Environment Variables tab
- Scroll to the USER-DEFINED section
- Add a FROM and a TO variable containing the sender and recipient email address, respectively.
- Note: for some specific services, like Gmail, additional configurations may be needed on the agent machine.
Once the deployed app is online, click its link and select some beers, then click the Checkout button. During the waiting time, what happens under the curtains is the following:
- By using the official Cloudant Java Library, the app creates a document with the order information in a database called orders.
- With the help of the Java Application Lab library, the app creates (if it does not exist) a Library and a Process inside it
- If the FROM and TO environment variables are defined, a step using the hybrid agent is created to send a notification with the order information.
- The app runs the OrderProcess process asynchronously:
- A Cloudant READ DOCUMENT step is run on the Bluemix order database, to read the ALL_DOCS document and get the doc_id of the first order to be processed.
- A Cloudant READ DOCUMENT step is run, to read the first order to be processed.
- If enabled, an executable step is run on the retail premises warehouse, to start the delivery of the goods and the payment process, and to finally send a confirmation email to customers.
- A Cloudant DELETE DOCUMENT step is run on the Bluemix order database, to delete the order just processed.