-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0599b34
Showing
26 changed files
with
2,780 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
target/ | ||
*.m4v | ||
.DS_Store | ||
RemoteSystemsTempFiles/ | ||
.index/ | ||
*.zip | ||
repository/ | ||
*.tar | ||
.classpath | ||
.project | ||
.settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
IoT OpenShift Demo | ||
=============== | ||
|
||
This project demonstrates the use of Internet of Things (IoT) and OpenShift | ||
|
||
## Prerequisites | ||
|
||
The following prerequisites must be satisfied prior to running the demo | ||
|
||
* Git client | ||
* Access to an OpenShift environment | ||
* OpenShift Command Line Interface (CLI) | ||
|
||
## Setup | ||
|
||
An [init.sh](init.sh) script is available to quickly configure an OpenShift environment for the demo | ||
|
||
Execute the script to setup the demo | ||
|
||
``` | ||
./init.sh | ||
``` | ||
|
||
## Validation | ||
|
||
The execution of the script in the previous section will trigger asynchronous builds and deployments of AMQ, Decision Server, and Fuse Integration Service components. Validate the following sections: | ||
|
||
* Validate KIE and FIS builds completed successfully | ||
|
||
``` | ||
oc get builds | ||
``` | ||
|
||
* Validate AMQ, KIE and FIS pods are running | ||
|
||
``` | ||
oc get pods | grep Running | ||
``` | ||
|
||
## Send a Test Message | ||
|
||
The *iot-ose-software-sensor* project is configured with a testing application to send messages to AMQ via the *mqtt* protocol. | ||
|
||
To avoid communicating with the OpenShift routing layer, the OpenShift CLI can be used to communicate directly with the pod network by forwarding a local port to a container port. | ||
|
||
First, locate the name of the AMQ pod | ||
|
||
``` | ||
oc get pods | grep amq.*Running | awk '{ print $1 }' | ||
``` | ||
|
||
Forward the mqtt port using the name of the pod retrieved in the previous command | ||
|
||
``` | ||
oc port-forward -p <AMQ_POD> 1883:1883 | ||
``` | ||
|
||
Build the *iot-ose-software-sensor* project using maven by navigating to the *iot-ose-software-sensor* folder and executing a build | ||
|
||
``` | ||
mvn clean install | ||
``` | ||
|
||
The build produces an executable jar with the necessary dependencies to send a test message. Execute the following command to execute the jar and send a message | ||
|
||
``` | ||
java -jar target/iot-ose-software-sensor-jar-with-dependencies.jar | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/bin/bash | ||
|
||
|
||
SCRIPT_BASE_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) | ||
IOT_OSE_PROJECT="iot-ose" | ||
MQ_USER="iotuser" | ||
MQ_PASSWORD="iotuser" | ||
KIE_USER="kieuser" | ||
KIE_PASSWORD="kieuser1!" | ||
|
||
echo "Setting up OpenShift IoT Demo" | ||
|
||
echo | ||
echo "Creating Project: ${IOT_OSE_PROJECT}..." | ||
echo | ||
oc new-project ${IOT_OSE_PROJECT} >/dev/null 2>&1 | ||
|
||
echo | ||
echo "Creating ImageStreams..." | ||
echo | ||
oc create -n ${IOT_OSE_PROJECT} -f ${SCRIPT_BASE_DIR}/support/templates/jboss-image-streams.json | ||
oc create -n ${IOT_OSE_PROJECT} -f ${SCRIPT_BASE_DIR}/support/templates/fis-image-streams.json | ||
|
||
echo | ||
echo "Pausing 10 Seconds..." | ||
echo | ||
sleep 10 | ||
|
||
echo | ||
echo "Importing ImageStreams..." | ||
echo | ||
oc import-image -n ${IOT_OSE_PROJECT} jboss-decisionserver63-openshift --all=true | ||
oc import-image -n ${IOT_OSE_PROJECT} jboss-amq-62 --all=true | ||
oc import-image -n ${IOT_OSE_PROJECT} fis-karaf-openshift --all=true | ||
|
||
echo | ||
echo "Deploying AMQ..." | ||
echo | ||
oc process -v=MQ_USERNAME=${MQ_USER},MQ_PASSWORD=${MQ_PASSWORD},IMAGE_STREAM_NAMESPACE=${IOT_OSE_PROJECT} -f ${SCRIPT_BASE_DIR}/support/templates/amq62-basic.json | oc create -n ${IOT_OSE_PROJECT} -f- | ||
|
||
echo | ||
echo "Exposing MQTT Route..." | ||
echo | ||
oc expose svc -n ${IOT_OSE_PROJECT} broker-amq-mqtt | ||
|
||
echo | ||
echo "Deploying Decision Server..." | ||
echo | ||
oc process -v=KIE_SERVER_USER="${KIE_USER}",KIE_SERVER_PASSWORD="${KIE_PASSWORD}",IMAGE_STREAM_NAMESPACE=${IOT_OSE_PROJECT} -f ${SCRIPT_BASE_DIR}/support/templates/decisionserver63-basic-s2i.json | oc create -n ${IOT_OSE_PROJECT} -f- | ||
|
||
echo | ||
echo "Deploying FIS Application..." | ||
echo | ||
oc process -v=KIE_APP_USER="${KIE_USER}",KIE_APP_PASSWORD="${KIE_PASSWORD}",BROKER_AMQ_USERNAME="${MQ_USER}",BROKER_AMQ_PASSWORD="${MQ_PASSWORD}",IMAGE_STREAM_NAMESPACE=${IOT_OSE_PROJECT} -f ${SCRIPT_BASE_DIR}/support/templates/fis-generic-template-build.json | oc create -n ${IOT_OSE_PROJECT} -f- | ||
|
||
|
||
echo | ||
echo "OpenShift IoT Demo Setup Complete." | ||
echo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.redhat.demo.iotdemo</groupId> | ||
<artifactId>iot-ose-businessrules-service</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
|
||
<properties> | ||
<!-- Explicitly declaring the source encoding eliminates the following message: --> | ||
<!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! --> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<!-- maven-compiler-plugin --> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
</properties> | ||
|
||
</project> |
149 changes: 149 additions & 0 deletions
149
iot-ose-businessrules-service/src/main/java/com/redhat/demo/businessRules/DataSet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
package com.redhat.demo.businessRules; | ||
|
||
import java.io.StringWriter; | ||
|
||
import javax.xml.bind.JAXBContext; | ||
import javax.xml.bind.JAXBException; | ||
import javax.xml.bind.annotation.XmlRootElement; | ||
import javax.xml.bind.annotation.XmlType; | ||
import javax.xml.bind.Marshaller; | ||
|
||
@XmlRootElement(name = "dataSet") | ||
@XmlType(propOrder = { "timestamp", "deviceType", "deviceID", "payload","required","average", "errorCode", "errorMessage" }) | ||
public class DataSet { | ||
private String timestamp; | ||
private String deviceType; | ||
private int deviceID; | ||
private int payload; | ||
private int required; | ||
private float average; | ||
private String errorMessage; | ||
private int errorCode; | ||
|
||
public DataSet() | ||
{ | ||
this.timestamp = ""; | ||
this.deviceType = ""; | ||
this.deviceID = 0; | ||
this.payload = 0; | ||
this.required = 0; | ||
this.average = 0; | ||
} | ||
|
||
public DataSet(String time, String devType, int devID, int pay, int required, float average) | ||
{ | ||
this.timestamp = time; | ||
this.deviceType = devType; | ||
this.deviceID = devID; | ||
this.payload = pay; | ||
this.required = required; | ||
this.average = average; | ||
} | ||
|
||
public String asString( ) throws JAXBException { | ||
StringWriter sw = new StringWriter(); | ||
|
||
JAXBContext context = JAXBContext.newInstance("com.redhat.demo.businessRules"); | ||
Marshaller marshaller = context.createMarshaller(); | ||
marshaller.marshal(this, sw ); | ||
|
||
return sw.toString(); | ||
|
||
} | ||
|
||
/** | ||
* @return the required | ||
*/ | ||
public int getRequired() { | ||
return required; | ||
} | ||
|
||
/** | ||
* @param required the required to set | ||
*/ | ||
public void setRequired(int required) { | ||
this.required = required; | ||
} | ||
|
||
/** | ||
* @return the timestamp | ||
*/ | ||
public String getTimestamp() { | ||
return timestamp; | ||
} | ||
|
||
/** | ||
* @param timestamp the timestamp to set | ||
*/ | ||
public void setTimestamp(String timestamp) { | ||
this.timestamp = timestamp; | ||
} | ||
|
||
/** | ||
* @return the deviceType | ||
*/ | ||
public String getDeviceType() { | ||
return deviceType; | ||
} | ||
|
||
/** | ||
* @param deviceType the deviceType to set | ||
*/ | ||
public void setDeviceType(String deviceType) { | ||
this.deviceType = deviceType; | ||
} | ||
|
||
/** | ||
* @return the deviceID | ||
*/ | ||
public int getDeviceID() { | ||
return deviceID; | ||
} | ||
|
||
/** | ||
* @param deviceID the deviceID to set | ||
*/ | ||
public void setDeviceID(int deviceID) { | ||
this.deviceID = deviceID; | ||
} | ||
|
||
/** | ||
* @return the payload | ||
*/ | ||
public int getPayload() { | ||
return payload; | ||
} | ||
|
||
/** | ||
* @param payload the payload to set | ||
*/ | ||
public void setPayload(int payload) { | ||
this.payload = payload; | ||
} | ||
|
||
public String getErrorMessage() { | ||
return errorMessage; | ||
} | ||
|
||
public void setErrorMessage(String errorMessage) { | ||
this.errorMessage = errorMessage; | ||
} | ||
|
||
public int getErrorCode() { | ||
return errorCode; | ||
} | ||
|
||
public void setErrorCode(int errorCode) { | ||
this.errorCode = errorCode; | ||
} | ||
|
||
public float getAverage() { | ||
return average; | ||
} | ||
|
||
public void setAverage(float average) { | ||
this.average = average; | ||
} | ||
|
||
} | ||
|
7 changes: 7 additions & 0 deletions
7
iot-ose-businessrules-service/src/main/resources/META-INF/kmodule.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule"> | ||
<kbase name="DecisionTableKB" packages="*" default="true"> | ||
<ksession name="DecisionTableKS" type="stateless" | ||
default="true"/> | ||
</kbase> | ||
</kmodule> |
30 changes: 30 additions & 0 deletions
30
...usinessrules-service/src/main/resources/com/redhat/demo/iot/datacenter/monitor/sample.drl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.redhat.demo.iot.datacenter.monitor | ||
|
||
import com.redhat.demo.businessRules.DataSet; | ||
|
||
rule "VoltageTooLow" | ||
lock-on-active true | ||
when | ||
$t : DataSet( deviceType == "voltage", payload < 2000 ) | ||
then | ||
System.out.println("Rule 'low voltage' fired as voltage is " + $t.getPayload() + " with clipping at 2000"); | ||
$t.setRequired(0); | ||
$t.setErrorCode(1); | ||
$t.setErrorMessage("Voltage too low"); | ||
update( $t ); | ||
|
||
end | ||
|
||
rule "TemperatureTooHigh" | ||
lock-on-active true | ||
when | ||
$t : DataSet( deviceType == "temperature", payload > 27 ) | ||
then | ||
System.out.println("Rule 'high temperature' fired as temperature is " + $t.getPayload() + " with clipping at 27"); | ||
$t.setRequired(0); | ||
$t.setErrorCode(2); | ||
$t.setErrorMessage("Temperature too high"); | ||
System.out.println("Temperature too high"); | ||
update( $t ); | ||
|
||
end |
Binary file added
BIN
+23.5 KB
iot-ose-businessrules-service/src/main/resources/decisiontable/DecisionTable.xls
Binary file not shown.
Oops, something went wrong.