From 0599b3494f6c6b43ff3232cc4575d08cb6620d68 Mon Sep 17 00:00:00 2001 From: Andrew Block Date: Sun, 11 Sep 2016 23:16:39 -0400 Subject: [PATCH] Initial Commit --- .gitignore | 11 + README.md | 68 ++++ init.sh | 59 +++ iot-ose-businessrules-service/pom.xml | 16 + .../redhat/demo/businessRules/DataSet.java | 149 ++++++++ .../src/main/resources/META-INF/kmodule.xml | 7 + .../demo/iot/datacenter/monitor/sample.drl | 30 ++ .../resources/decisiontable/DecisionTable.xls | Bin 0 -> 24064 bytes .../configuration/settings.xml | 121 +++++++ iot-ose-routing-service/pom.xml | 236 ++++++++++++ .../redhat/demo/businessRules/DataSet.java | 165 +++++++++ .../routingService/BusinessRulesBean.java | 80 +++++ .../demo/iotdemo/routingService/DataSet.java | 152 ++++++++ .../demo/iotdemo/routingService/MyHelper.java | 87 +++++ .../META-INF/spring/camel-context.xml | 57 +++ .../demo/iotdemo/routingService/jaxb.index | 1 + iot-ose-software-sensor/pom.xml | 66 ++++ .../com/redhat/demo/DummyDataGenerator.java | 118 ++++++ .../java/com/redhat/demo/MqttProducer.java | 60 ++++ .../main/java/com/redhat/demo/MqttTester.java | 60 ++++ .../java/com/redhat/demo/TestDataSet.java | 125 +++++++ support/templates/amq62-basic.json | 321 +++++++++++++++++ .../templates/decisionserver63-basic-s2i.json | 339 ++++++++++++++++++ .../templates/fis-generic-template-build.json | 297 +++++++++++++++ support/templates/fis-image-streams.json | 76 ++++ support/templates/jboss-image-streams.json | 79 ++++ 26 files changed, 2780 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100755 init.sh create mode 100644 iot-ose-businessrules-service/pom.xml create mode 100644 iot-ose-businessrules-service/src/main/java/com/redhat/demo/businessRules/DataSet.java create mode 100644 iot-ose-businessrules-service/src/main/resources/META-INF/kmodule.xml create mode 100644 iot-ose-businessrules-service/src/main/resources/com/redhat/demo/iot/datacenter/monitor/sample.drl create mode 100644 iot-ose-businessrules-service/src/main/resources/decisiontable/DecisionTable.xls create mode 100644 iot-ose-routing-service/configuration/settings.xml create mode 100644 iot-ose-routing-service/pom.xml create mode 100644 iot-ose-routing-service/src/main/java/com/redhat/demo/businessRules/DataSet.java create mode 100644 iot-ose-routing-service/src/main/java/com/redhat/demo/iotdemo/routingService/BusinessRulesBean.java create mode 100644 iot-ose-routing-service/src/main/java/com/redhat/demo/iotdemo/routingService/DataSet.java create mode 100644 iot-ose-routing-service/src/main/java/com/redhat/demo/iotdemo/routingService/MyHelper.java create mode 100644 iot-ose-routing-service/src/main/resources/META-INF/spring/camel-context.xml create mode 100644 iot-ose-routing-service/src/main/resources/com/redhat/demo/iotdemo/routingService/jaxb.index create mode 100644 iot-ose-software-sensor/pom.xml create mode 100644 iot-ose-software-sensor/src/main/java/com/redhat/demo/DummyDataGenerator.java create mode 100644 iot-ose-software-sensor/src/main/java/com/redhat/demo/MqttProducer.java create mode 100644 iot-ose-software-sensor/src/main/java/com/redhat/demo/MqttTester.java create mode 100644 iot-ose-software-sensor/src/main/java/com/redhat/demo/TestDataSet.java create mode 100644 support/templates/amq62-basic.json create mode 100644 support/templates/decisionserver63-basic-s2i.json create mode 100644 support/templates/fis-generic-template-build.json create mode 100644 support/templates/fis-image-streams.json create mode 100644 support/templates/jboss-image-streams.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9413859 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +target/ +*.m4v +.DS_Store +RemoteSystemsTempFiles/ +.index/ +*.zip +repository/ +*.tar +.classpath +.project +.settings diff --git a/README.md b/README.md new file mode 100644 index 0000000..7fc3eaa --- /dev/null +++ b/README.md @@ -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 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 +``` \ No newline at end of file diff --git a/init.sh b/init.sh new file mode 100755 index 0000000..46bbc06 --- /dev/null +++ b/init.sh @@ -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 \ No newline at end of file diff --git a/iot-ose-businessrules-service/pom.xml b/iot-ose-businessrules-service/pom.xml new file mode 100644 index 0000000..97d3ed4 --- /dev/null +++ b/iot-ose-businessrules-service/pom.xml @@ -0,0 +1,16 @@ + + 4.0.0 + com.redhat.demo.iotdemo + iot-ose-businessrules-service + 0.0.1-SNAPSHOT + + + + + UTF-8 + + 1.8 + 1.8 + + + \ No newline at end of file diff --git a/iot-ose-businessrules-service/src/main/java/com/redhat/demo/businessRules/DataSet.java b/iot-ose-businessrules-service/src/main/java/com/redhat/demo/businessRules/DataSet.java new file mode 100644 index 0000000..84b3110 --- /dev/null +++ b/iot-ose-businessrules-service/src/main/java/com/redhat/demo/businessRules/DataSet.java @@ -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; + } + +} + \ No newline at end of file diff --git a/iot-ose-businessrules-service/src/main/resources/META-INF/kmodule.xml b/iot-ose-businessrules-service/src/main/resources/META-INF/kmodule.xml new file mode 100644 index 0000000..c099fcc --- /dev/null +++ b/iot-ose-businessrules-service/src/main/resources/META-INF/kmodule.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/iot-ose-businessrules-service/src/main/resources/com/redhat/demo/iot/datacenter/monitor/sample.drl b/iot-ose-businessrules-service/src/main/resources/com/redhat/demo/iot/datacenter/monitor/sample.drl new file mode 100644 index 0000000..4c84dc8 --- /dev/null +++ b/iot-ose-businessrules-service/src/main/resources/com/redhat/demo/iot/datacenter/monitor/sample.drl @@ -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 \ No newline at end of file diff --git a/iot-ose-businessrules-service/src/main/resources/decisiontable/DecisionTable.xls b/iot-ose-businessrules-service/src/main/resources/decisiontable/DecisionTable.xls new file mode 100644 index 0000000000000000000000000000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~9&JFUJ+IUUS^+8&|*xvEr?Ou`Bs7 zoaysnXeY)nTxB3VN4nDFazeLhg^~&_My)SA%`<&u1su{L*6NLR~^gH zT$3Th#bKfa8geL6GJVe@CK_5Yow0K{#B2x{RiMe|@Er!x3;aBQRU@u!q5%eT7`j5C z!w1Y0S2h6vf9I7A)IoXaK!R_g8#46K{6L}u2=#_mf;|dnh(PiSlD7;ITH` + + + + + + fusesource.repo + + + fusesource.m2 + FuseSource Community Release Repository + https://repo.fusesource.com/nexus/content/groups/public + + false + + + true + never + + + + fusesource.ea + FuseSource Community Early Access Release Repository + https://repo.fusesource.com/nexus/content/groups/ea + + false + + + true + never + + + + redhat.ga + Red Hat General Availability Repository + https://maven.repository.redhat.com/ga + + false + + + true + never + + + + paho-mqtt-client + Paho MQTT Client + https://repo.eclipse.org/content/repositories/paho-releases + + false + + + true + never + + + + + + fusesource.m2 + FuseSource Community Release Repository + https://repo.fusesource.com/nexus/content/groups/public + + false + + + true + never + + + + fusesource.ea + FuseSource Community Early Access Release Repository + https://repo.fusesource.com/nexus/content/groups/ea + + false + + + true + never + + + + redhat.ga + Red Hat General Availability Repository + https://maven.repository.redhat.com/ga + + false + + + true + never + + + + + + + + fusesource.repo + + + diff --git a/iot-ose-routing-service/pom.xml b/iot-ose-routing-service/pom.xml new file mode 100644 index 0000000..c03304e --- /dev/null +++ b/iot-ose-routing-service/pom.xml @@ -0,0 +1,236 @@ + + 4.0.0 + com.redhat.demo.iot + iot-ose-routing-service + 0.0.1-SNAPSHOT + bundle + + + + + UTF-8 + + 1.7 + 1.7 + 3.2 + 2.3.7 + 2.5.3 + 2.7 + 3.0.4 + + + 2.15.1.redhat-621084 + 1.7.10 + 2.2.0.redhat-079 + 6.2.1.redhat-084 + 5.11.0.redhat-621084 + 2.4.0.redhat-621084 + 4.0.2.redhat-621079 + 6.4.0.Final-redhat-3 + + + + + + + org.apache.camel + camel-core + ${camel.version} + + + org.apache.camel + camel-spring + ${camel.version} + + + org.apache.camel + camel-test-spring + ${camel.version} + test + + + + org.apache.camel + camel-test + ${camel.version} + test + + + + + + org.apache.camel + camel-bindy + ${camel.version} + + + + org.apache.camel + camel-mqtt + ${camel.version} + + + + org.apache.camel + camel-jaxb + ${camel.version} + + + + org.kie.server + kie-server-client + ${brms.version} + + + + + + + org.jboss.fuse + fuse-karaf-framework + ${fuse.version} + kar + + + + * + * + + + + + org.apache.karaf.assemblies.features + standard + ${karaf.version} + features + xml + + + org.apache.karaf.assemblies.features + enterprise + ${karaf.version} + features + xml + + + org.apache.camel.karaf + apache-camel + ${camel.version} + features + xml + + + org.apache.activemq + activemq-karaf + ${activemq-version} + features + xml + + + org.apache.karaf.features + spring + ${spring.features.version} + features + xml + + + + org.drools + drools-karaf-features + xml + ${brms.version} + features + + + + + install + + + + + org.apache.karaf.tooling + karaf-maven-plugin + ${karaf.plugin.version} + true + + + karaf-assembly + + assembly + + install + + + karaf-archive + + archive + + install + + + + v24 + 1.8 + true + + false + + + karaf-framework + shell + jaas + spring + activemq-client + activemq-camel + camel-spring + camel-bindy + camel-mqtt + kie-server-client + camel-jaxb + + + + mvn:org.apache.karaf.bundle/org.apache.karaf.bundle.core/3.0.4 + mvn:io.fabric8.mq/mq-client/2.2.0.redhat-079 + mvn:io.fabric8/fabric8-utils/2.2.0.redhat-079 + mvn:${project.groupId}/${project.artifactId}/${project.version} + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven.compiler.plugin.version} + + ${maven.compiler.source} + ${maven.compiler.target} + + + + + org.apache.felix + maven-bundle-plugin + ${maven.bundle.plugin.version} + true + + + * + + + + + + org.apache.maven.plugins + maven-resources-plugin + ${maven.resources.plugin.version} + + + + + + + \ No newline at end of file diff --git a/iot-ose-routing-service/src/main/java/com/redhat/demo/businessRules/DataSet.java b/iot-ose-routing-service/src/main/java/com/redhat/demo/businessRules/DataSet.java new file mode 100644 index 0000000..6038386 --- /dev/null +++ b/iot-ose-routing-service/src/main/java/com/redhat/demo/businessRules/DataSet.java @@ -0,0 +1,165 @@ +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; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("===== Dataset ======"); + sb.append("\nTimeStamp: "+ timestamp); + sb.append("\nDevice Type: "+ deviceType); + sb.append("\nDevice ID: "+ deviceID); + sb.append("\nPayload: "+ payload); + sb.append("\nRequired: "+ required); + sb.append("\nAverage: "+ average); + sb.append("\nError Message: "+ errorMessage); + sb.append("\nError Code: "+ errorCode); + + return sb.toString(); + } + +} + diff --git a/iot-ose-routing-service/src/main/java/com/redhat/demo/iotdemo/routingService/BusinessRulesBean.java b/iot-ose-routing-service/src/main/java/com/redhat/demo/iotdemo/routingService/BusinessRulesBean.java new file mode 100644 index 0000000..d770937 --- /dev/null +++ b/iot-ose-routing-service/src/main/java/com/redhat/demo/iotdemo/routingService/BusinessRulesBean.java @@ -0,0 +1,80 @@ +package com.redhat.demo.iotdemo.routingService; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.apache.camel.Body; +import org.drools.core.command.runtime.rule.GetObjectsCommand; +import org.kie.api.KieServices; +import org.kie.api.command.BatchExecutionCommand; +import org.kie.api.command.Command; +import org.kie.api.command.KieCommands; +import org.kie.api.runtime.ExecutionResults; +import org.kie.internal.command.CommandFactory; +import org.kie.server.api.marshalling.MarshallingFormat; +import org.kie.server.api.model.ServiceResponse; +import org.kie.server.client.KieServicesConfiguration; +import org.kie.server.client.KieServicesFactory; +import org.kie.server.client.RuleServicesClient; + +import com.redhat.demo.businessRules.DataSet; + +public class BusinessRulesBean { + + private String kieHost; + private String kieUser; + private String kiePassword; + + private static final String SERVICE_CONTEXT = "kie-server/services/rest/server"; + + public com.redhat.demo.businessRules.DataSet processRules(@Body com.redhat.demo.businessRules.DataSet dataSet) { + + KieServicesConfiguration config = KieServicesFactory.newRestConfiguration( + kieHost, kieUser, + kiePassword); + + Set> jaxBClasses = new HashSet>(); + jaxBClasses.add(DataSet.class); + + config.addJaxbClasses(jaxBClasses); + config.setMarshallingFormat(MarshallingFormat.JAXB); + RuleServicesClient client = KieServicesFactory.newKieServicesClient(config) + .getServicesClient(RuleServicesClient.class); + + List> cmds = new ArrayList>(); + KieCommands commands = KieServices.Factory.get().getCommands(); + cmds.add(commands.newInsert(dataSet)); + + GetObjectsCommand getObjectsCommand = new GetObjectsCommand(); + getObjectsCommand.setOutIdentifier("objects"); + + + cmds.add(commands.newFireAllRules()); + cmds.add(getObjectsCommand); + BatchExecutionCommand myCommands = CommandFactory.newBatchExecution(cmds, + "DecisionTableKS"); + ServiceResponse response = client.executeCommandsWithResults("iot-ose-businessrules-service", myCommands); + + List responseList = (List) response.getResult().getValue("objects"); + + com.redhat.demo.businessRules.DataSet responseDataSet = (com.redhat.demo.businessRules.DataSet) responseList.get(0); + + return responseDataSet; + + } + + public void init() { + + String kieAppName = (System.getenv("KIE_APP_NAME") == null) ? "kie-app" : System.getenv("KIE_APP_NAME"); + String kiePort = (System.getenv("KIE_APP_SERVICE_PORT") == null) ? "8080" : System.getenv("KIE_APP_SERVICE_PORT"); + + kieUser = (System.getenv("KIE_APP_USER") == null) ? "iotuser" : System.getenv("KIE_APP_USER"); + kiePassword = (System.getenv("KIE_APP_PASSWORD") == null) ? "iotuser1!" : System.getenv("KIE_APP_PASSWORD"); + + kieHost = String.format("http://%s:%s/%s", kieAppName, kiePort, SERVICE_CONTEXT); + + } + +} diff --git a/iot-ose-routing-service/src/main/java/com/redhat/demo/iotdemo/routingService/DataSet.java b/iot-ose-routing-service/src/main/java/com/redhat/demo/iotdemo/routingService/DataSet.java new file mode 100644 index 0000000..7bb649c --- /dev/null +++ b/iot-ose-routing-service/src/main/java/com/redhat/demo/iotdemo/routingService/DataSet.java @@ -0,0 +1,152 @@ +package com.redhat.demo.iotdemo.routingService; + +import java.io.Serializable; + +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +import org.apache.camel.dataformat.bindy.annotation.CsvRecord; +import org.apache.camel.dataformat.bindy.annotation.DataField; + +@XmlRootElement(name = "dataSet") +@XmlType(propOrder = { "timestamp", "deviceType", "deviceID","count", "payload","required","average" }) +@CsvRecord(separator = ",") +public class DataSet implements Serializable { + @DataField(pos = 1, required = true) + private String deviceType; + + @DataField(pos = 2, required = true) + private String deviceID; + + @DataField(pos = 3, required = true) + private String payload; + + @DataField(pos = 4, required = true) + private String count; + + @DataField(pos = 5, required = true) + private String timestamp; + + @DataField(pos = 6, required = false) + private int required; + + @DataField(pos = 7, required = false) + private float average; + + public DataSet() + { + this.timestamp = ""; + this.deviceType = ""; + this.deviceID = ""; + this.count = ""; + this.payload = ""; + this.required = 0; + this.average = 0; + } + + public DataSet(String time, String devType, String devID, String count, String pay, int req, float av ) + { + this.timestamp = time; + this.deviceType = devType; + this.deviceID = devID; + this.count = count; + this.payload = pay; + this.required = req; + this.average = av; + } + + + /** + * @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 String getDeviceID() { + return deviceID; + } + + /** + * @param deviceID the deviceID to set + */ + public void setDeviceID(String deviceID) { + this.deviceID = deviceID; + } + + /** + * @return the payload + */ + public String getPayload() { + return payload; + } + + /** + * @param payload the payload to set + */ + public void setPayload(String payload) { + this.payload = payload; + } + + public String getCount() { + return count; + } + + public void setCount(String count) { + this.count = count; + } + + /** + * @return the required + */ + public int getRequired() { + return required; + } + + /** + * @param required the required to set + */ + public void setRequired(int required) { + this.required = required; + } + + /** + * @return the average + */ + public float getAverage() { + return average; + } + + /** + * @param average the average to set + */ + public void setAverage(float average) { + this.average = average; + } + + +} \ No newline at end of file diff --git a/iot-ose-routing-service/src/main/java/com/redhat/demo/iotdemo/routingService/MyHelper.java b/iot-ose-routing-service/src/main/java/com/redhat/demo/iotdemo/routingService/MyHelper.java new file mode 100644 index 0000000..f1f3675 --- /dev/null +++ b/iot-ose-routing-service/src/main/java/com/redhat/demo/iotdemo/routingService/MyHelper.java @@ -0,0 +1,87 @@ + +package com.redhat.demo.iotdemo.routingService; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.camel.Body; +import org.apache.camel.Exchange; +import org.apache.camel.Handler; + +public class MyHelper { + + @Handler + public String enhanceMessage( String body, Exchange exchange ) { + String res = null; + + res = addDeviceID(body, exchange); + res = addDeviceType(res, exchange); + res = appendTimestamp(res, exchange); + + return res; + } + + @Handler + public String appendTimestamp( String body, Exchange exchange ) { + + SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyy HH:mm:ss SSS"); + Date timeNow = new Date(); + + body = body +","+format.format(timeNow); + + return body; + + } + + + @Handler + public String addDeviceType(String body, Exchange exchange) { + + String result=null; + + Pattern pattern = Pattern.compile("(?<=\\/)(.*?)(?=\\/)"); + Matcher matcher = pattern.matcher((String)exchange.getIn().getHeader("CamelMQTTSubscribeTopic")); + if (matcher.find()) + { + result = matcher.group(0); + } + + return result + ", " + body; + + } + + + @Handler + public String addDeviceID(String body, Exchange exchange) { + + String result=null; + + Pattern pattern = Pattern.compile("([^\\/]*)$"); + Matcher matcher = pattern.matcher((String)exchange.getIn().getHeader("CamelMQTTSubscribeTopic")); + if (matcher.find()) + { + result = matcher.group(0); + } + + return result + ", " + body; + } + + + public com.redhat.demo.businessRules.DataSet transform(@Body DataSet dataSet) { + + com.redhat.demo.businessRules.DataSet businessDataSet = new com.redhat.demo.businessRules.DataSet(); + businessDataSet.setAverage(dataSet.getAverage()); + businessDataSet.setDeviceID(Integer.parseInt(dataSet.getDeviceID().trim())); + businessDataSet.setDeviceType(dataSet.getDeviceType()); + businessDataSet.setPayload(Integer.parseInt(dataSet.getPayload().trim())); + businessDataSet.setRequired(dataSet.getRequired()); + businessDataSet.setTimestamp(dataSet.getTimestamp()); + + return businessDataSet; + + } + +} + diff --git a/iot-ose-routing-service/src/main/resources/META-INF/spring/camel-context.xml b/iot-ose-routing-service/src/main/resources/META-INF/spring/camel-context.xml new file mode 100644 index 0000000..b8a1c09 --- /dev/null +++ b/iot-ose-routing-service/src/main/resources/META-INF/spring/camel-context.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${body.errorCode} == 0 + + + + + + + + \ No newline at end of file diff --git a/iot-ose-routing-service/src/main/resources/com/redhat/demo/iotdemo/routingService/jaxb.index b/iot-ose-routing-service/src/main/resources/com/redhat/demo/iotdemo/routingService/jaxb.index new file mode 100644 index 0000000..0e8d10a --- /dev/null +++ b/iot-ose-routing-service/src/main/resources/com/redhat/demo/iotdemo/routingService/jaxb.index @@ -0,0 +1 @@ +DataSet \ No newline at end of file diff --git a/iot-ose-software-sensor/pom.xml b/iot-ose-software-sensor/pom.xml new file mode 100644 index 0000000..d3096da --- /dev/null +++ b/iot-ose-software-sensor/pom.xml @@ -0,0 +1,66 @@ + + 4.0.0 + com.redhat.demo.iot + iot-ose-software-sensor + 0.0.1-SNAPSHOT + + + + + UTF-8 + + 1.8 + 1.8 + + + + + org.eclipse.paho + mqtt-client + 0.4.0 + + + + + + + paho-mqtt-client + Paho MQTT Client + https://repo.eclipse.org/content/repositories/paho-releases/ + + + + + iot-ose-software-sensor + + + maven-assembly-plugin + + + package + + single + + + + + + + + true + com.redhat.demo.MqttTester + + + + + jar-with-dependencies + + + + + + + + + + \ No newline at end of file diff --git a/iot-ose-software-sensor/src/main/java/com/redhat/demo/DummyDataGenerator.java b/iot-ose-software-sensor/src/main/java/com/redhat/demo/DummyDataGenerator.java new file mode 100644 index 0000000..8585690 --- /dev/null +++ b/iot-ose-software-sensor/src/main/java/com/redhat/demo/DummyDataGenerator.java @@ -0,0 +1,118 @@ +package com.redhat.demo; + +import java.io.StringWriter; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Random; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; + +public class DummyDataGenerator { + + private TestDataSet tempSet; + private int lowWaterThreshold; + private int highWaterThreshold; + + public void createInitialDataSet(String devType, String devID, int pay, String unit, int highWater, int lowWater ) { + tempSet = new TestDataSet(); + + SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyy HH:mm:ss SSS"); + Date timeNow = new Date(); + + tempSet.setTimestamp( format.format(timeNow) ); + tempSet.setDeviceType(devType); + tempSet.setDeviceID(devID); + tempSet.setPayload(pay); + tempSet.setUnit(unit); + tempSet.setCount(0); + setLowWaterThreshold(lowWater); + setHighWaterThreshold(highWater); + } + + public void updateDataSet() { + Random random = new Random(); + + SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyy HH:mm:ss SSS"); + Date timeNow = new Date(); + + tempSet.setTimestamp( format.format(timeNow) ); + + int randValue = random.nextInt(1000); + + tempSet.setCount( tempSet.getCount() + 1 ); + + if ( randValue <= getLowWaterThreshold() ) + tempSet.setPayload(tempSet.getPayload()-1); + else if ( randValue >= getHighWaterThreshold() ) + tempSet.setPayload(tempSet.getPayload()+1); + } + + public TestDataSet getDataSet(){ + return tempSet; + } + + public String getDataSetXML() { + return jaxbObjectToXML(); + } + + public String getDataSetCSV() { + StringBuilder sb = new StringBuilder(); + + sb.append( tempSet.getPayload() ).append(","); + sb.append( tempSet.getCount() ); + + return sb.toString(); + } + + private String jaxbObjectToXML( ) { + + StringWriter writer = new StringWriter(); + + try { + JAXBContext context = JAXBContext.newInstance(TestDataSet.class); + + Marshaller m = context.createMarshaller(); + + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); + + m.marshal(this.getDataSet(), writer); + + } catch (JAXBException e) { + e.printStackTrace(); + } + + return writer.toString(); + } + + /** + * @return the lowWaterThreshold + */ + public int getLowWaterThreshold() { + return lowWaterThreshold; + } + + /** + * @param lowWaterThreshold the lowWaterThreshold to set + */ + public void setLowWaterThreshold(int lowWaterThreshold) { + this.lowWaterThreshold = lowWaterThreshold; + } + + /** + * @return the highWaterThreshold + */ + public int getHighWaterThreshold() { + return highWaterThreshold; + } + + /** + * @param highWaterThreshold the highWaterThreshold to set + */ + public void setHighWaterThreshold(int highWaterThreshold) { + this.highWaterThreshold = highWaterThreshold; + } + + +} diff --git a/iot-ose-software-sensor/src/main/java/com/redhat/demo/MqttProducer.java b/iot-ose-software-sensor/src/main/java/com/redhat/demo/MqttProducer.java new file mode 100644 index 0000000..78cb81e --- /dev/null +++ b/iot-ose-software-sensor/src/main/java/com/redhat/demo/MqttProducer.java @@ -0,0 +1,60 @@ +package com.redhat.demo; + +import org.eclipse.paho.client.mqttv3.MqttClient; +import org.eclipse.paho.client.mqttv3.MqttConnectOptions; +import org.eclipse.paho.client.mqttv3.MqttException; +import org.eclipse.paho.client.mqttv3.MqttMessage; +import org.eclipse.paho.client.mqttv3.MqttPersistenceException; +import org.eclipse.paho.client.mqttv3.MqttSecurityException; +import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; + +public class MqttProducer { + + MqttClient client; + MqttConnectOptions options; + MemoryPersistence persistence; + + public MqttProducer(String brokerURL, String user, String password, String queueName) { + + // MemoryPersistence persistence = new MemoryPersistence(); + + try { + client = new MqttClient(brokerURL, "mqtt.temp.receiver"); + } catch (MqttException e) { + // TODO Auto-generated catch block + e.printStackTrace(System.out); + } + + options = new MqttConnectOptions (); + options.setUserName(user); + options.setPassword(password.toCharArray()); + + try { + client.connect(options); + } catch (MqttSecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (MqttException e) { + // TODO Auto-generated catch block + e.printStackTrace(System.out); + } + + } + + public void run(String data, String deviceType, String deviceID) throws MqttPersistenceException, MqttException { + + MqttMessage message = new MqttMessage(); + + message.setPayload(data.getBytes()); + + client.publish("iotdemo/"+deviceType+"/"+deviceID, message); + + } + + public void close() throws MqttException{ + + client.disconnect(); + client.close(); + + } +} \ No newline at end of file diff --git a/iot-ose-software-sensor/src/main/java/com/redhat/demo/MqttTester.java b/iot-ose-software-sensor/src/main/java/com/redhat/demo/MqttTester.java new file mode 100644 index 0000000..64114b1 --- /dev/null +++ b/iot-ose-software-sensor/src/main/java/com/redhat/demo/MqttTester.java @@ -0,0 +1,60 @@ +package com.redhat.demo; + +import org.eclipse.paho.client.mqttv3.MqttException; +import org.eclipse.paho.client.mqttv3.MqttPersistenceException; + +public class MqttTester { + + // Default Values for message producer + private static final String DEFAULT_DEVICETYPE = "temperature"; + private static final String DEFAULT_DEVICEID = "1"; + private static final String DEFAULT_INITIALVALUE = "70"; + private static final String DEFAULT_COUNT = "1"; + private static final String DEFAULT_UNIT = "C"; + private static final String DEFAULT_WAIT = "1"; + private static final String DEFAULT_RECEIVER = "localhost"; + private static final String DEFAULT_BROKER_UID = "iotuser"; + private static final String DEFAULT_BROKER_PASSWD = "iotuser"; + private static final String DEFAULT_HIGHWATER_MARK = "800"; + private static final String DEFAULT_LOWWATER_MARK = "200"; + + + public static void main(String args[]) throws MqttPersistenceException, MqttException, InterruptedException { + DummyDataGenerator dummy = new DummyDataGenerator(); + MqttProducer producer; + + String devType = System.getProperty("deviceType", DEFAULT_DEVICETYPE); + String devID = System.getProperty("deviceID", DEFAULT_DEVICEID); + int initialValue = Integer.parseInt(System.getProperty("initialValue", DEFAULT_INITIALVALUE)); + int count = Integer.parseInt(System.getProperty("count", DEFAULT_COUNT)); + int waitTime = Integer.parseInt(System.getProperty("waitTime", DEFAULT_WAIT)); + String unit = System.getProperty("payloadUnit", DEFAULT_UNIT); + String brokerURLMQTT = "tcp://" + System.getProperty("receiverURL",DEFAULT_RECEIVER) + ":1883"; + String brokerUID = System.getProperty("brokerUID", DEFAULT_BROKER_UID); + String brokerPassword = System.getProperty("brokerPassword", DEFAULT_BROKER_PASSWD); + + int highWater = Integer.parseInt(System.getProperty("highWater", DEFAULT_HIGHWATER_MARK)); + int lowWater = Integer.parseInt(System.getProperty("lowWater", DEFAULT_LOWWATER_MARK)); + + dummy.createInitialDataSet(devType, devID, initialValue, unit, highWater, lowWater); + + producer = new MqttProducer(brokerURLMQTT, brokerUID, brokerPassword, "mqtt.receiver"); + + int counter = 0; + while ( counter < count ) { + + System.out.println("Sending '"+dummy.getDataSetCSV()+"'"); + producer.run( dummy.getDataSetCSV(), dummy.getDataSet().getDeviceType(), dummy.getDataSet().getDeviceID() ); + + dummy.updateDataSet(); + + counter++; + + Thread.sleep ( waitTime * 1000 ); + } + + producer.close(); + + } + +} diff --git a/iot-ose-software-sensor/src/main/java/com/redhat/demo/TestDataSet.java b/iot-ose-software-sensor/src/main/java/com/redhat/demo/TestDataSet.java new file mode 100644 index 0000000..d4d64c9 --- /dev/null +++ b/iot-ose-software-sensor/src/main/java/com/redhat/demo/TestDataSet.java @@ -0,0 +1,125 @@ +package com.redhat.demo; + +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +@XmlRootElement(name = "dataSet") +@XmlType(propOrder = { "timestamp", "deviceType", "deviceID", "count", "payload", "unit", "required"}) +public class TestDataSet { + private String timestamp; + private String deviceType; + private String deviceID; + private int count; + private int payload; + private int required; + private String unit; + + public TestDataSet() + { + this.timestamp = ""; + this.deviceType = ""; + this.deviceID = ""; + this.count = 0; + this.payload = 0; + this.required = 0; + this.unit = ""; + } + + public TestDataSet(String time, String devType, String devID, int count, String unit, int pay ) + { + this.timestamp = time; + this.deviceType = devType; + this.deviceID = devID; + this.count = count; + this.payload = pay; + this.unit = unit; + this.required = 0; + } + + /** + * @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 String getDeviceID() { + return deviceID; + } + + /** + * @param deviceID the deviceID to set + */ + public void setDeviceID(String 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 int getCount() { + return count; + } + + public void setCount(int count) { + this.count = count; + } + + public String getUnit() { + return unit; + } + + public void setUnit(String unit) { + this.unit = unit; + } + +} diff --git a/support/templates/amq62-basic.json b/support/templates/amq62-basic.json new file mode 100644 index 0000000..2d589f3 --- /dev/null +++ b/support/templates/amq62-basic.json @@ -0,0 +1,321 @@ +{ + "kind": "Template", + "apiVersion": "v1", + "metadata": { + "annotations": { + "description": "Application template for JBoss A-MQ brokers. These can be deployed as standalone or in a mesh. This template doesn't feature SSL support.", + "iconClass": "icon-jboss", + "tags": "messaging,amq,jboss,xpaas", + "version": "1.3.1" + }, + "name": "amq62-basic" + }, + "labels": { + "template": "amq62-basic", + "xpaas": "1.3.1" + }, + "parameters": [ + { + "description": "The name for the application.", + "name": "APPLICATION_NAME", + "value": "broker", + "required": true + }, + { + "description": "Protocols to configure, separated by commas. Allowed values are: `openwire`, `amqp`, `stomp` and `mqtt`.", + "name": "MQ_PROTOCOL", + "value": "openwire,mqtt", + "required": false + }, + { + "description": "Queue names, separated by commas. These queues will be automatically created when the broker starts. If left empty, queues will be still created dynamically.", + "name": "MQ_QUEUES", + "value": "", + "required": false + }, + { + "description": "Topic names, separated by commas. These topics will be automatically created when the broker starts. If left empty, topics will be still created dynamically.", + "name": "MQ_TOPICS", + "value": "", + "required": false + }, + { + "description": "List of packages that are allowed to be serialized for use in ObjectMessage, separated by commas. If your app doesn't use ObjectMessages, leave this blank. This is a security enforcement. For the rationale, see http://activemq.apache.org/objectmessage.html", + "name": "MQ_SERIALIZABLE_PACKAGES", + "value": "", + "required": false + }, + { + "description": "User name for standard broker user. It is required for connecting to the broker. If left empty, it will be generated.", + "name": "MQ_USERNAME", + "from": "user[a-zA-Z0-9]{3}", + "generate": "expression", + "required": false + }, + { + "description": "Password for standard broker user. It is required for connecting to the broker. If left empty, it will be generated.", + "name": "MQ_PASSWORD", + "from": "[a-zA-Z0-9]{8}", + "generate": "expression", + "required": false + }, + { + "description": "The discovery agent type to use for discovering mesh endpoints. 'dns' will use OpenShift's DNS service to resolve endpoints. 'kube' will use Kubernetes REST API to resolve service endpoints. If using 'kube' the service account for the pod must have the 'view' role, which can be added via 'oc policy add-role-to-user view system:serviceaccount::default' where is the project namespace.", + "name": "AMQ_MESH_DISCOVERY_TYPE", + "value": "kube", + "required": false + }, + { + "description": "The A-MQ storage usage limit", + "name": "AMQ_STORAGE_USAGE_LIMIT", + "value": "100 gb", + "required": false + }, + { + "description": "Namespace in which the ImageStreams for Red Hat Middleware images are installed. These ImageStreams are normally installed in the openshift namespace. You should only need to modify this if you've installed the ImageStreams in a different namespace/project.", + "name": "IMAGE_STREAM_NAMESPACE", + "value": "openshift", + "required": true + } + ], + "objects": [ + { + "kind": "Service", + "apiVersion": "v1", + "spec": { + "ports": [ + { + "port": 5672, + "targetPort": 5672 + } + ], + "selector": { + "deploymentConfig": "${APPLICATION_NAME}-amq" + } + }, + "metadata": { + "name": "${APPLICATION_NAME}-amq-amqp", + "labels": { + "application": "${APPLICATION_NAME}" + }, + "annotations": { + "description": "The broker's AMQP port." + } + } + }, + { + "kind": "Service", + "apiVersion": "v1", + "spec": { + "ports": [ + { + "port": 1883, + "targetPort": 1883 + } + ], + "selector": { + "deploymentConfig": "${APPLICATION_NAME}-amq" + } + }, + "metadata": { + "name": "${APPLICATION_NAME}-amq-mqtt", + "labels": { + "application": "${APPLICATION_NAME}" + }, + "annotations": { + "description": "The broker's MQTT port." + } + } + }, + { + "kind": "Service", + "apiVersion": "v1", + "spec": { + "ports": [ + { + "port": 61613, + "targetPort": 61613 + } + ], + "selector": { + "deploymentConfig": "${APPLICATION_NAME}-amq" + } + }, + "metadata": { + "name": "${APPLICATION_NAME}-amq-stomp", + "labels": { + "application": "${APPLICATION_NAME}" + }, + "annotations": { + "description": "The broker's STOMP port." + } + } + }, + { + "kind": "Service", + "apiVersion": "v1", + "spec": { + "ports": [ + { + "port": 61616, + "targetPort": 61616 + } + ], + "selector": { + "deploymentConfig": "${APPLICATION_NAME}-amq" + } + }, + "metadata": { + "name": "${APPLICATION_NAME}-amq-tcp", + "labels": { + "application": "${APPLICATION_NAME}" + }, + "annotations": { + "description": "The broker's OpenWire port." + } + } + }, + { + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "${APPLICATION_NAME}-amq", + "labels": { + "application": "${APPLICATION_NAME}" + } + }, + "spec": { + "strategy": { + "type": "Rolling", + "rollingParams": { + "maxSurge": 0 + } + }, + "triggers": [ + { + "type": "ImageChange", + "imageChangeParams": { + "automatic": true, + "containerNames": [ + "${APPLICATION_NAME}-amq" + ], + "from": { + "kind": "ImageStreamTag", + "namespace": "${IMAGE_STREAM_NAMESPACE}", + "name": "jboss-amq-62:1.3" + } + } + }, + { + "type": "ConfigChange" + } + ], + "replicas": 1, + "selector": { + "deploymentConfig": "${APPLICATION_NAME}-amq" + }, + "template": { + "metadata": { + "name": "${APPLICATION_NAME}-amq", + "labels": { + "deploymentConfig": "${APPLICATION_NAME}-amq", + "application": "${APPLICATION_NAME}" + } + }, + "spec": { + "terminationGracePeriodSeconds": 60, + "containers": [ + { + "name": "${APPLICATION_NAME}-amq", + "image": "jboss-amq-62", + "imagePullPolicy": "Always", + "readinessProbe": { + "exec": { + "command": [ + "/bin/bash", + "-c", + "/opt/amq/bin/readinessProbe.sh" + ] + } + }, + "ports": [ + { + "name": "jolokia", + "containerPort": 8778, + "protocol": "TCP" + }, + { + "name": "amqp", + "containerPort": 5672, + "protocol": "TCP" + }, + { + "name": "mqtt", + "containerPort": 1883, + "protocol": "TCP" + }, + { + "name": "stomp", + "containerPort": 61613, + "protocol": "TCP" + }, + { + "name": "tcp", + "containerPort": 61616, + "protocol": "TCP" + } + ], + "env": [ + { + "name": "AMQ_USER", + "value": "${MQ_USERNAME}" + }, + { + "name": "AMQ_PASSWORD", + "value": "${MQ_PASSWORD}" + }, + { + "name": "AMQ_TRANSPORTS", + "value": "${MQ_PROTOCOL}" + }, + { + "name": "AMQ_QUEUES", + "value": "${MQ_QUEUES}" + }, + { + "name": "AMQ_TOPICS", + "value": "${MQ_TOPICS}" + }, + { + "name": "MQ_SERIALIZABLE_PACKAGES", + "value": "${MQ_SERIALIZABLE_PACKAGES}" + }, + { + "name": "AMQ_MESH_DISCOVERY_TYPE", + "value": "${AMQ_MESH_DISCOVERY_TYPE}" + }, + { + "name": "AMQ_MESH_SERVICE_NAME", + "value": "${APPLICATION_NAME}-amq-tcp" + }, + { + "name": "AMQ_MESH_SERVICE_NAMESPACE", + "valueFrom": { + "fieldRef": { + "fieldPath": "metadata.namespace" + } + } + }, + { + "name": "AMQ_STORAGE_USAGE_LIMIT", + "value": "${AMQ_STORAGE_USAGE_LIMIT}" + } + ] + } + ] + } + } + } + } + ] +} diff --git a/support/templates/decisionserver63-basic-s2i.json b/support/templates/decisionserver63-basic-s2i.json new file mode 100644 index 0000000..807837d --- /dev/null +++ b/support/templates/decisionserver63-basic-s2i.json @@ -0,0 +1,339 @@ +{ + "kind": "Template", + "apiVersion": "v1", + "metadata": { + "annotations": { + "description": "Application template for Red Hat JBoss BRMS 6.3 decision server applications built using S2I.", + "iconClass": "icon-jboss", + "tags": "decisionserver,java,jboss,xpaas", + "version": "1.3.3" + }, + "name": "decisionserver63-basic-s2i" + }, + "labels": { + "template": "decisionserver63-basic-s2i", + "xpaas": "1.3.3" + }, + "parameters": [ + { + "description": "The KIE Container deployment configuration in format: containerId=groupId:artifactId:version|c2=g2:a2:v2", + "name": "KIE_CONTAINER_DEPLOYMENT", + "value": "iot-ose-businessrules-service=com.redhat.demo.iotdemo:iot-ose-businessrules-service:0.0.1-SNAPSHOT", + "required": false + }, + { + "description": "The user name to access the KIE Server REST or JMS interface.", + "name": "KIE_SERVER_USER", + "value": "kieserver", + "required": false + }, + { + "description": "The password to access the KIE Server REST or JMS interface. Must be different than username; must not be root, admin, or administrator; must contain at least 8 characters, 1 alphabetic character(s), 1 digit(s), and 1 non-alphanumeric symbol(s).", + "name": "KIE_SERVER_PASSWORD", + "from": "[a-zA-Z]{6}[0-9]{1}!", + "generate": "expression", + "required": false + }, + { + "description": "The name for the application.", + "name": "APPLICATION_NAME", + "value": "kie-app", + "required": true + }, + { + "description": "Custom hostname for http service route. Leave blank for default hostname, e.g.: -.", + "name": "HOSTNAME_HTTP", + "value": "", + "required": false + }, + { + "description": "Git source URI for application", + "name": "SOURCE_REPOSITORY_URL", + "value": "https://github.com/sabre1041/iot-ose.git", + "required": true + }, + { + "description": "Git branch/tag reference", + "name": "SOURCE_REPOSITORY_REF", + "value": "master", + "required": false + }, + { + "description": "Path within Git project to build; empty for root project directory.", + "name": "CONTEXT_DIR", + "value": "iot-ose-businessrules-service", + "required": false + }, + { + "description": "Queue names", + "name": "HORNETQ_QUEUES", + "value": "", + "required": false + }, + { + "description": "Topic names", + "name": "HORNETQ_TOPICS", + "value": "", + "required": false + }, + { + "description": "HornetQ cluster admin password", + "name": "HORNETQ_CLUSTER_PASSWORD", + "from": "[a-zA-Z0-9]{8}", + "generate": "expression", + "required": true + }, + { + "description": "GitHub trigger secret", + "name": "GITHUB_WEBHOOK_SECRET", + "from": "[a-zA-Z0-9]{8}", + "generate": "expression", + "required": true + }, + { + "description": "Generic build trigger secret", + "name": "GENERIC_WEBHOOK_SECRET", + "from": "[a-zA-Z0-9]{8}", + "generate": "expression", + "required": true + }, + { + "description": "Namespace in which the ImageStreams for Red Hat Middleware images are installed. These ImageStreams are normally installed in the openshift namespace. You should only need to modify this if you've installed the ImageStreams in a different namespace/project.", + "name": "IMAGE_STREAM_NAMESPACE", + "value": "openshift", + "required": true + } + ], + "objects": [ + { + "kind": "Service", + "apiVersion": "v1", + "spec": { + "ports": [ + { + "port": 8080, + "targetPort": 8080 + } + ], + "selector": { + "deploymentConfig": "${APPLICATION_NAME}" + } + }, + "metadata": { + "name": "${APPLICATION_NAME}", + "labels": { + "application": "${APPLICATION_NAME}" + }, + "annotations": { + "description": "The web server's http port." + } + } + }, + { + "kind": "Route", + "apiVersion": "v1", + "id": "${APPLICATION_NAME}-http", + "metadata": { + "name": "${APPLICATION_NAME}", + "labels": { + "application": "${APPLICATION_NAME}" + }, + "annotations": { + "description": "Route for application's http service." + } + }, + "spec": { + "host": "${HOSTNAME_HTTP}", + "to": { + "name": "${APPLICATION_NAME}" + } + } + }, + { + "kind": "ImageStream", + "apiVersion": "v1", + "metadata": { + "name": "${APPLICATION_NAME}", + "labels": { + "application": "${APPLICATION_NAME}" + } + } + }, + { + "kind": "BuildConfig", + "apiVersion": "v1", + "metadata": { + "name": "${APPLICATION_NAME}", + "labels": { + "application": "${APPLICATION_NAME}" + } + }, + "spec": { + "source": { + "type": "Git", + "git": { + "uri": "${SOURCE_REPOSITORY_URL}", + "ref": "${SOURCE_REPOSITORY_REF}" + }, + "contextDir": "${CONTEXT_DIR}" + }, + "strategy": { + "type": "Source", + "sourceStrategy": { + "env": [ + { + "name": "KIE_CONTAINER_DEPLOYMENT", + "value": "${KIE_CONTAINER_DEPLOYMENT}" + } + ], + "forcePull": true, + "from": { + "kind": "ImageStreamTag", + "namespace": "${IMAGE_STREAM_NAMESPACE}", + "name": "jboss-decisionserver63-openshift:1.3" + } + } + }, + "output": { + "to": { + "kind": "ImageStreamTag", + "name": "${APPLICATION_NAME}:latest" + } + }, + "triggers": [ + { + "type": "GitHub", + "github": { + "secret": "${GITHUB_WEBHOOK_SECRET}" + } + }, + { + "type": "Generic", + "generic": { + "secret": "${GENERIC_WEBHOOK_SECRET}" + } + }, + { + "type": "ImageChange", + "imageChange": {} + }, + { + "type": "ConfigChange" + } + ] + } + }, + { + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "${APPLICATION_NAME}", + "labels": { + "application": "${APPLICATION_NAME}" + } + }, + "spec": { + "strategy": { + "type": "Recreate" + }, + "triggers": [ + { + "type": "ImageChange", + "imageChangeParams": { + "automatic": true, + "containerNames": [ + "${APPLICATION_NAME}" + ], + "from": { + "kind": "ImageStream", + "name": "${APPLICATION_NAME}" + } + } + }, + { + "type": "ConfigChange" + } + ], + "replicas": 1, + "selector": { + "deploymentConfig": "${APPLICATION_NAME}" + }, + "template": { + "metadata": { + "name": "${APPLICATION_NAME}", + "labels": { + "deploymentConfig": "${APPLICATION_NAME}", + "application": "${APPLICATION_NAME}" + } + }, + "spec": { + "terminationGracePeriodSeconds": 60, + "containers": [ + { + "name": "${APPLICATION_NAME}", + "image": "${APPLICATION_NAME}", + "imagePullPolicy": "Always", + "livenessProbe": { + "exec": { + "command": [ + "/bin/bash", + "-c", + "/opt/eap/bin/livenessProbe.sh" + ] + } + }, + "readinessProbe": { + "exec": { + "command": [ + "/bin/bash", + "-c", + "/opt/eap/bin/readinessProbe.sh" + ] + } + }, + "ports": [ + { + "name": "jolokia", + "containerPort": 8778, + "protocol": "TCP" + }, + { + "name": "http", + "containerPort": 8080, + "protocol": "TCP" + } + ], + "env": [ + { + "name": "KIE_CONTAINER_DEPLOYMENT", + "value": "${KIE_CONTAINER_DEPLOYMENT}" + }, + { + "name": "KIE_SERVER_USER", + "value": "${KIE_SERVER_USER}" + }, + { + "name": "KIE_SERVER_PASSWORD", + "value": "${KIE_SERVER_PASSWORD}" + }, + { + "name": "HORNETQ_CLUSTER_PASSWORD", + "value": "${HORNETQ_CLUSTER_PASSWORD}" + }, + { + "name": "HORNETQ_QUEUES", + "value": "${HORNETQ_QUEUES}" + }, + { + "name": "HORNETQ_TOPICS", + "value": "${HORNETQ_TOPICS}" + } + ] + } + ] + } + } + } + } + ] +} diff --git a/support/templates/fis-generic-template-build.json b/support/templates/fis-generic-template-build.json new file mode 100644 index 0000000..2571cde --- /dev/null +++ b/support/templates/fis-generic-template-build.json @@ -0,0 +1,297 @@ +{ + "apiVersion": "v1", + "kind": "Template", + "labels": {}, + "metadata": { + "annotations": { + "description": "FIS Generic Template", + "iconClass": "icon-java" + }, + "labels": {}, + "name": "fis-generic-build" + }, + "parameters": [ + { + "name": "APP_NAME", + "value": "fis-app", + "description": "Application Name" + }, + { + "name": "GIT_REPO", + "required": true, + "value": "https://github.com/sabre1041/iot-ose.git", + "description": "Git repository, required" + }, + { + "name": "GIT_REF", + "value": "master", + "description": "Git ref to build" + }, + { + "name": "GIT_CONTEXT_DIR", + "value": "iot-ose-routing-service", + "description": "Git context directory" + }, + { + "name": "BUILDER_VERSION", + "value": "1.0", + "description": "Builder version" + }, + { + "name": "MAVEN_ARGS", + "value": "clean install -DskipTests", + "description": "Arguments passed to mvn in the build" + }, + { + "name": "MAVEN_ARGS_APPEND", + "description": "Extra arguments passed to mvn, e.g. for multi-module builds" + }, + { + "name": "ARTIFACT_DIR", + "description": "Directory containing build artifacts." + }, + { + "description": "Namespace in which the Fuse ImageStreams are installed. These ImageStreams are normally installed in the openshift namespace. You should only need to modify this if you've installed the ImageStreams in a different namespace/project.", + "name": "IMAGE_STREAM_NAMESPACE", + "value": "openshift", + "required": true + }, + { + "description": "The user name to access the KIE Server.", + "name": "KIE_APP_USER", + "value": "kieserver", + "required": false + }, + { + "description": "The password to access the KIE Server REST. Must be different than username; must not be root, admin, or administrator; must contain at least 8 characters, 1 alphabetic character(s), 1 digit(s), and 1 non-alphanumeric symbol(s).", + "name": "KIE_APP_PASSWORD", + "from": "[a-zA-Z]{6}[0-9]{1}!", + "generate": "expression", + "required": false + }, + { + "description": "The user name to access the AMQ Server.", + "name": "BROKER_AMQ_USERNAME", + "value": "kieserver", + "required": false + }, + { + "description": "The password to access the AMQ awecwe. Must be different than username; must not be root, admin, or administrator; must contain at least 8 characters, 1 alphabetic character(s), 1 digit(s), and 1 non-alphanumeric symbol(s).", + "name": "BROKER_AMQ_PASSWORD", + "from": "[a-zA-Z]{6}[0-9]{1}!", + "generate": "expression", + "required": false + } + ], + "objects": [ + { + "apiVersion": "v1", + "kind": "Service", + "metadata": { + "annotations": { + }, + "labels": { + "container": "karaf", + "component": "${APP_NAME}" + }, + "name": "${APP_NAME}" + }, + "spec": { + "clusterIP": "None", + "deprecatedPublicIPs": [], + "ports": [ + { + "port": 9412, + "protocol": "TCP", + "targetPort": 8181 + } + ], + "selector": { + "container": "karaf", + "component": "${APP_NAME}" + } + } + }, + { + "kind": "ImageStream", + "apiVersion": "v1", + "metadata": { + "name": "${APP_NAME}", + "creationTimestamp": null, + "labels": { + "component": "${APP_NAME}", + "container": "karaf" + } + }, + "spec": {}, + "status": { + "dockerImageRepository": "" + } + }, + { + "kind": "BuildConfig", + "apiVersion": "v1", + "metadata": { + "name": "${APP_NAME}", + "creationTimestamp": null, + "labels": { + "component": "${APP_NAME}", + "container": "karaf" + } + }, + "spec": { + "triggers": [ + { + "type": "ConfigChange" + }, + { + "type": "ImageChange", + "imageChange": {} + } + ], + "source": { + "type": "Git", + "git": { + "uri": "${GIT_REPO}", + "ref": "${GIT_REF}" + }, + "contextDir": "${GIT_CONTEXT_DIR}" + }, + "strategy": { + "type": "Source", + "sourceStrategy": { + "from": { + "kind": "ImageStreamTag", + "namespace": "${IMAGE_STREAM_NAMESPACE}", + "name": "fis-karaf-openshift:${BUILDER_VERSION}" + }, + "forcePull": true, + "env": [ + { + "name": "ARTIFACT_DIR", + "value": "${ARTIFACT_DIR}" + }, + { + "name": "MAVEN_ARGS", + "value": "${MAVEN_ARGS}" + }, + { + "name": "MAVEN_ARGS_APPEND", + "value": "${MAVEN_ARGS_APPEND}" + } + ] + } + }, + "output": { + "to": { + "kind": "ImageStreamTag", + "name": "${APP_NAME}:latest" + } + }, + "resources": {} + }, + "status": { + "lastVersion": 0 + } + }, + { + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "${APP_NAME}", + "creationTimestamp": null, + "labels": { + "component": "${APP_NAME}", + "container": "karaf" + } + }, + "spec": { + "strategy": { + "resources": {} + }, + "triggers": [ + { + "type": "ConfigChange" + }, + { + "type": "ImageChange", + "imageChangeParams": { + "automatic": true, + "containerNames": [ + "${APP_NAME}" + ], + "from": { + "kind": "ImageStreamTag", + "name": "${APP_NAME}:latest" + } + } + } + ], + "replicas": 1, + "selector": { + "component": "${APP_NAME}", + "container": "karaf", + "deploymentconfig": "${APP_NAME}" + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "component": "${APP_NAME}", + "container": "karaf", + "deploymentconfig": "${APP_NAME}" + } + }, + "spec": { + "containers": [ + { + "name": "${APP_NAME}", + "image": "${APP_NAME}", + "readinessProbe": { + "exec": { + "command": [ + "/bin/bash", + "-c", + "(curl -f 127.0.0.1:8778) >/dev/null 2>&1; test $? != 7" + ] + }, + "initialDelaySeconds": 30, + "timeoutSeconds": 5 + }, + "ports": [ + { + "containerPort": 8181, + "name": "http" + }, + { + "containerPort": 8778, + "name": "jolokia" + } + ], + "env": [ + { + "name": "KIE_APP_USER", + "value": "${KIE_APP_USER}" + }, + { + "name": "KIE_APP_PASSWORD", + "value": "${KIE_APP_PASSWORD}" + }, + { + "name": "BROKER_AMQ_USERNAME", + "value": "${BROKER_AMQ_USERNAME}" + }, + { + "name": "BROKER_AMQ_PASSWORD", + "value": "${BROKER_AMQ_PASSWORD}" + } + ] + } + ] + } + } + }, + "status": {} + } + ] +} diff --git a/support/templates/fis-image-streams.json b/support/templates/fis-image-streams.json new file mode 100644 index 0000000..65060cc --- /dev/null +++ b/support/templates/fis-image-streams.json @@ -0,0 +1,76 @@ +{ + "kind": "List", + "apiVersion": "v1", + "metadata": { + "name": "fis-image-streams", + "annotations": { + "description": "ImageStream definitions for JBoss Fuse Integration Services." + } + }, + "items": [ + { + "kind": "ImageStream", + "apiVersion": "v1", + "metadata": { + "name": "fis-java-openshift" + }, + "spec": { + "dockerImageRepository": "registry.access.redhat.com/jboss-fuse-6/fis-java-openshift", + "tags": [ + { + "name": "1.0", + "annotations": { + "description": "JBoss Fuse Integration Services 1.0 Java S2I images.", + "iconClass": "icon-jboss", + "tags": "builder,jboss-fuse,java,xpaas", + "supports":"jboss-fuse:6.2.1,java:8,xpaas:1.2", + "version": "1.0" + } + }, + { + "name": "2.0", + "annotations": { + "description": "JBoss Fuse Integration Services 2.0 Java S2I images.", + "iconClass": "icon-jboss", + "tags": "builder,jboss-fuse,java,xpaas", + "supports":"jboss-fuse:6.3.0,java:8,xpaas:1.2", + "version": "2.0" + } + } + ] + } + }, + { + "kind": "ImageStream", + "apiVersion": "v1", + "metadata": { + "name": "fis-karaf-openshift" + }, + "spec": { + "dockerImageRepository": "registry.access.redhat.com/jboss-fuse-6/fis-karaf-openshift", + "tags": [ + { + "name": "1.0", + "annotations": { + "description": "JBoss Fuse Integration Services 1.0 Karaf S2I images.", + "iconClass": "icon-jboss", + "tags": "builder,jboss-fuse,java,karaf,xpaas", + "supports":"jboss-fuse:6.2.1,java:8,xpaas:1.2", + "version": "1.0" + } + }, + { + "name": "2.0", + "annotations": { + "description": "JBoss Fuse Integration Services 2.0 Karaf S2I images.", + "iconClass": "icon-jboss", + "tags": "builder,jboss-fuse,java,karaf,xpaas", + "supports":"jboss-fuse:6.3.0,java:8,xpaas:1.2", + "version": "2.0" + } + } + ] + } + } + ] +} diff --git a/support/templates/jboss-image-streams.json b/support/templates/jboss-image-streams.json new file mode 100644 index 0000000..6c828db --- /dev/null +++ b/support/templates/jboss-image-streams.json @@ -0,0 +1,79 @@ +{ + "kind": "List", + "apiVersion": "v1", + "metadata": { + "name": "jboss-image-streams", + "annotations": { + "description": "ImageStream definitions for JBoss Middleware products." + } + }, + "items": [ + { + "kind": "ImageStream", + "apiVersion": "v1", + "metadata": { + "name": "jboss-decisionserver63-openshift" + }, + "spec": { + "dockerImageRepository": "registry.access.redhat.com/jboss-decisionserver-6/decisionserver63-openshift", + "tags": [ + { + "name": "1.3", + "annotations": { + "description": "Red Hat JBoss BRMS 6.3 decision server S2I images.", + "iconClass": "icon-jboss", + "tags": "builder,decisionserver,java,xpaas", + "supports":"decisionserver:6.3,java:8,xpaas:1.3", + "sampleRepo": "https://github.com/jboss-openshift/openshift-quickstarts.git", + "sampleContextDir": "decisionserver/hellorules", + "sampleRef": "1.3", + "version": "1.3" + } + } + ] + } + }, + { + "kind": "ImageStream", + "apiVersion": "v1", + "metadata": { + "name": "jboss-amq-62" + }, + "spec": { + "dockerImageRepository": "registry.access.redhat.com/jboss-amq-6/amq62-openshift", + "tags": [ + { + "name": "1.1", + "annotations": { + "description": "JBoss A-MQ 6.2 broker image.", + "iconClass": "icon-jboss", + "tags": "messaging,amq,jboss,xpaas", + "supports":"amq:6.2,messaging,xpaas:1.1", + "version": "1.1" + } + }, + { + "name": "1.2", + "annotations": { + "description": "JBoss A-MQ 6.2 broker image.", + "iconClass": "icon-jboss", + "tags": "messaging,amq,jboss,xpaas", + "supports":"amq:6.2,messaging,xpaas:1.2", + "version": "1.2" + } + }, + { + "name": "1.3", + "annotations": { + "description": "JBoss A-MQ 6.2 broker image.", + "iconClass": "icon-jboss", + "tags": "messaging,amq,jboss,xpaas", + "supports":"amq:6.2,messaging,xpaas:1.3", + "version": "1.3" + } + } + ] + } + } + ] +}