Skip to content
Draft

Mqtt #1732

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
fc86b6a
Add a shared lib for use between BELY and CDB for MQTT integration an…
iTerminate Oct 2, 2026
5077539
Add scripts to create and deploy mqtt connection configuration
iTerminate Oct 2, 2026
b15f007
Add libs required for mqtt connection.
iTerminate Oct 2, 2026
b3b5498
the shared lib also contains the base mqttEvent.
iTerminate Oct 2, 2026
373eb84
Refactor rename the shared lib to base-cdb-mqtt
iTerminate Oct 2, 2026
719e160
Refactor rename the shared lib to base-cdb-mqtt
iTerminate Oct 2, 2026
fc2a49a
Initial MQTT integration base
iTerminate Oct 2, 2026
0136ccd
Run tests upon changes to the lib.
iTerminate Oct 2, 2026
ed435e4
Run tests in CI upon changes to the lib.
iTerminate Oct 2, 2026
deb9f0e
Merge branch 'master' into mqtt
iTerminate Nov 5, 2026
a0523d9
Add support for adding "specailized" specific change events.
iTerminate Nov 5, 2026
49e325a
Add new property changes events.
iTerminate Nov 5, 2026
6ca76f0
Refactor textOmmitted for clarity
iTerminate Nov 5, 2026
4c17757
Hook property value changes into generation of property value history.
iTerminate Nov 5, 2026
76dbddb
Add appropriate events based on changes that have been populated by p…
iTerminate Nov 5, 2026
688592c
Extend the test framework for the property events.
iTerminate Nov 5, 2026
d2fba9f
Add a base class for all cdb mqtt events.
iTerminate Nov 6, 2026
56aa8e2
Add a mqtt event classes for representing the machien design assigned…
iTerminate Nov 6, 2026
55bfc8b
Add hooks for adding event when changes to the assigned item in the m…
iTerminate Nov 6, 2026
7d097a9
Add unit tests for the new machine design assignment events.
iTerminate Nov 6, 2026
e3a37fa
Refactor to add PropertyValueChange into the new mqtt metadata package.
iTerminate Nov 6, 2026
a842d30
Add a new mqtt model for machine design move events.
iTerminate Nov 6, 2026
1ed3d61
Integrate event after the move update was performed.
iTerminate Nov 6, 2026
6bf3c99
Add unit tests
iTerminate Nov 6, 2026
0486730
Extend the model to expose the item entity type this contains informa…
iTerminate Nov 6, 2026
c7122ed
Add models to support the new machine design represented element chan…
iTerminate Nov 6, 2026
0523b9a
Hook the change into the assigned item history check.
iTerminate Nov 6, 2026
67b1aab
Add unit tests for the new functionality.
iTerminate Nov 6, 2026
064762e
Add a template metadata if a reprented element is updated via template.
iTerminate Nov 6, 2026
c6ceda2
Integrate propagation of item element representation to template mqtt…
iTerminate Nov 6, 2026
890b425
Add tests for represetned item elements
iTerminate Nov 6, 2026
df50326
Add enum for operation to keep the options consistent accross the app…
iTerminate Nov 6, 2026
54dcdf0
Add model to support trash mqtt eventss
iTerminate Nov 6, 2026
e4c036a
Hook the trash events into the standard workflows.
iTerminate Nov 6, 2026
e85d866
Add unit tests for new trash events
iTerminate Nov 6, 2026
5fbb916
Add location change mqtt event model
iTerminate Nov 6, 2026
ecc471b
Add location change mqtt event model
iTerminate Nov 6, 2026
74c9a7b
Hook location change into the location change workflow.
iTerminate Nov 6, 2026
9539199
Add tests for new location change workflow
iTerminate Nov 6, 2026
4facd5b
Add events for assembly element changes.
iTerminate Nov 6, 2026
ed0fadb
Hook assembly change into function where it gets updated.
iTerminate Nov 6, 2026
f7c6b1d
Add tests for updating assembly element mqtt events.
iTerminate Nov 6, 2026
ecacbc2
Resolve issue with delete event not being published
iTerminate Nov 6, 2026
42708e1
Move the detection of assembly changes to top level. Resolve assembly…
iTerminate Nov 6, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/cdb-base-mqtt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: CDB Base MQTT

on:
push:
paths:
- "tools/developer_tools/cdb-base-mqtt/**"
- ".github/workflows/cdb-base-mqtt.yml"
pull_request:
paths:
- "tools/developer_tools/cdb-base-mqtt/**"
- ".github/workflows/cdb-base-mqtt.yml"
workflow_dispatch:

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: tools/developer_tools/cdb-base-mqtt

steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Set up Java 8 and Maven cache
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "8"
cache: maven
cache-dependency-path: tools/developer_tools/cdb-base-mqtt/pom.xml

- name: Run tests
run: mvn --batch-mode --no-transfer-progress verify

- name: Publish test results
if: always()
uses: actions/upload-artifact@v4
with:
name: cdb-base-mqtt-test-results
path: tools/developer_tools/cdb-base-mqtt/target/surefire-reports/
if-no-files-found: warn
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ TOP = .
SUBDIRS = src

.PHONY: support support-mysql dev-config prepare-release release-python-client
.PHONY: mqtt-configuration configure-mqtt mqtt-configuration-dev configure-mqtt-dev
.PHONY: db backup db-dev deploy-web-portal undeploy-web-portal deploy-web-service undeploy-web-service
.PHONY: db-dev backup-dev deploy-web-portal-dev undeploy-web-portal-dev deploy-web-service-dev undeploy-web-service-dev

Expand All @@ -28,6 +29,12 @@ release-python-client:
configuration:
$(TOP)/sbin/cdb_create_configuration.sh

mqtt-configuration:
$(TOP)/sbin/cdb_create_mqtt_configuration.sh cdb

configure-mqtt:
$(TOP)/sbin/cdb_configure_mqtt_service.sh cdb

support:
$(TOP)/sbin/cdb_install_support.sh

Expand Down Expand Up @@ -79,6 +86,12 @@ undeploy-web-service:
configuration-dev:
$(TOP)/sbin/cdb_create_configuration.sh cdb_dev

mqtt-configuration-dev:
$(TOP)/sbin/cdb_create_mqtt_configuration.sh cdb_dev

configure-mqtt-dev:
$(TOP)/sbin/cdb_configure_mqtt_service.sh cdb_dev

db-dev:
$(TOP)/sbin/cdb_create_db.sh cdb_dev

Expand Down
170 changes: 170 additions & 0 deletions sbin/cdb_configure_mqtt_service.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
#!/bin/bash

# Copyright (c) UChicago Argonne, LLC. All rights reserved.
# See LICENSE file.


#
# Script used for configuring MQTT connector for CDB webapp
# Deploys MQTT Resource Adapter and creates connection pool/resource
#
# Usage:
#
# $0 [CDB_DB_NAME] [mqtt_config_file]
#
# If no config file is specified, defaults to $CDB_INSTALL_DIR/etc/<CDB_DB_NAME>.mqtt.conf
#
# Sample MQTT configuration file contents (mqtt.conf):
# MQTT_HOST=localhost # MQTT broker hostname (default: localhost)
# MQTT_PORT=1883 # MQTT broker port (default: 1883)
# MQTT_USERNAME=admin # MQTT username (optional)
# MQTT_PASSWORD=admin # MQTT password (optional)
# MQTT_CLEAN_SESSION=true # Clean session flag (optional)
# MQTT_QOS=1 # Quality of Service level (optional)
# MQTT_KEEP_ALIVE_INTERVAL=60 # Keep alive interval in seconds (optional)
# MQTT_CONNECTION_TIMEOUT=30 # Connection timeout in seconds (optional)
# MQTT_MAX_INFLIGHT=10 # Maximum number of messages in flight (optional)
# MQTT_AUTOMATIC_RECONNECT=true # Automatic reconnection on disconnect (optional)
# MQTT_FILE_PERSISTANCE=false # Enable file-based message persistence (optional)
# MQTT_PERSISTENCE_DIRECTORY=. # Directory for persistent message storage (optional)
# MQTT_TOPIC_FILTER # MQTT topic filter for subscriptions (optional)

MY_DIR=`dirname $0` && cd $MY_DIR && MY_DIR=`pwd`
if [ -z "${CDB_ROOT_DIR}" ]; then
CDB_ROOT_DIR=$MY_DIR/..
fi
CDB_ENV_FILE=${CDB_ROOT_DIR}/setup.sh
if [ ! -f ${CDB_ENV_FILE} ]; then
echo "Environment file ${CDB_ENV_FILE} does not exist."
exit 2
fi
. ${CDB_ENV_FILE} > /dev/null

# Constants
MQTT_POOL_NAME="cdb/MQTT/pool"
MQTT_RESOURCE_NAME="cdb/MQTT/resource"
MQTT_RAR_NAME="mqtt-rar-0.8.0"
MQTT_CONNECTOR_RAR_DEPLOYMENT_NAME="cdb-mqtt-rar-deployment"
MQTT_RAR_PATH=$CDB_ROOT_DIR/src/lib/${MQTT_RAR_NAME}.rar

# Look for the deployment-specific MQTT configuration file
CDB_DB_NAME=${1:-${CDB_DB_NAME:-cdb}}
if [ ! -z "$2" ]; then
mqttConfigFile=$2
else
mqttConfigFile=$CDB_INSTALL_DIR/etc/${CDB_DB_NAME}.mqtt.conf
fi

if [ -f $mqttConfigFile ]; then
echo "Using MQTT config file: $mqttConfigFile"
. $mqttConfigFile
else
echo "Error: MQTT config file $mqttConfigFile not found."
echo "You can create one using cdb_create_mqtt_configuration.sh ${CDB_DB_NAME}"
exit 1
fi

CDB_HOST_ARCH=$(uname -sm | tr -s '[:upper:][:blank:]' '[:lower:][\-]')
GLASSFISH_DIR=$CDB_SUPPORT_DIR/payara/$CDB_HOST_ARCH

ASADMIN_CMD=$GLASSFISH_DIR/bin/asadmin

# MQTT Configuration defaults
MQTT_HOST=${MQTT_HOST:=localhost}
MQTT_PORT=${MQTT_PORT:=1883}

# Build properties string for connection pool
PROPERTIES="serverURIs=tcp\\://${MQTT_HOST}\\:${MQTT_PORT}"

if [ ! -z "$MQTT_USERNAME" ]; then
PROPERTIES="${PROPERTIES}:userName=${MQTT_USERNAME}"
fi

if [ ! -z "$MQTT_PASSWORD" ]; then
PROPERTIES="${PROPERTIES}:password=${MQTT_PASSWORD}"
fi

if [ ! -z "$MQTT_CLEAN_SESSION" ]; then
PROPERTIES="${PROPERTIES}:cleanSession=${MQTT_CLEAN_SESSION}"
fi

if [ ! -z "$MQTT_KEEP_ALIVE_INTERVAL" ]; then
PROPERTIES="${PROPERTIES}:keepAliveInterval=${MQTT_KEEP_ALIVE_INTERVAL}"
fi

if [ ! -z "$MQTT_CONNECTION_TIMEOUT" ]; then
PROPERTIES="${PROPERTIES}:connectionTimeout=${MQTT_CONNECTION_TIMEOUT}"
fi

if [ ! -z "$MQTT_MAX_INFLIGHT" ]; then
PROPERTIES="${PROPERTIES}:maxInflight=${MQTT_MAX_INFLIGHT}"
fi

if [ ! -z "$MQTT_AUTOMATIC_RECONNECT" ]; then
PROPERTIES="${PROPERTIES}:automaticReconnect=${MQTT_AUTOMATIC_RECONNECT}"
fi

if [ ! -z "$MQTT_FILE_PERSISTANCE" ]; then
PROPERTIES="${PROPERTIES}:filePersistance=${MQTT_FILE_PERSISTANCE}"
fi

if [ ! -z "$MQTT_PERSISTENCE_DIRECTORY" ]; then
PROPERTIES="${PROPERTIES}:persistenceDirectory=${MQTT_PERSISTENCE_DIRECTORY}"
fi

if [ ! -z "$MQTT_QOS" ]; then
PROPERTIES="${PROPERTIES}:qos=${MQTT_QOS}"
fi

if [ ! -z "$MQTT_TOPIC_FILTER" ]; then
PROPERTIES="${PROPERTIES}:topicFilter=${MQTT_TOPIC_FILTER}"
fi

# Deploy MQTT RAR
echo "Deploying MQTT RAR"
if [ -f "$MQTT_RAR_PATH" ]; then
# Check if already deployed and undeploy if needed
$ASADMIN_CMD list-applications | grep -q ${MQTT_CONNECTOR_RAR_DEPLOYMENT_NAME} && {
echo "Undeploying existing MQTT RAR"
# Check if resource exists and delete it
$ASADMIN_CMD list-connector-resources | grep -q ${MQTT_RESOURCE_NAME} && {
echo "Deleting existing MQTT resource"
$ASADMIN_CMD delete-connector-resource ${MQTT_RESOURCE_NAME} || exit 1
}

# Check if connection pool exists and delete it
$ASADMIN_CMD list-connector-connection-pools | grep -q ${MQTT_POOL_NAME} && {
echo "Deleting existing MQTT connection pool"
$ASADMIN_CMD delete-connector-connection-pool ${MQTT_POOL_NAME} || exit 1
}

echo "Undeploying existing MQTT RAR"
$ASADMIN_CMD undeploy ${MQTT_CONNECTOR_RAR_DEPLOYMENT_NAME} || exit 1
}
$ASADMIN_CMD deploy --name ${MQTT_CONNECTOR_RAR_DEPLOYMENT_NAME} $MQTT_RAR_PATH || exit 1
else
echo "Warning: MQTT RAR file not found at $MQTT_RAR_PATH"
exit 1
fi

# Create MQTT connection pool
echo "Creating MQTT connection pool ${MQTT_POOL_NAME}"
$ASADMIN_CMD create-connector-connection-pool \
--raname ${MQTT_CONNECTOR_RAR_DEPLOYMENT_NAME} \
--connectiondefinition fish.payara.cloud.connectors.mqtt.api.MQTTConnectionFactory \
--property "${PROPERTIES}" \
${MQTT_POOL_NAME} || exit 1
# Create MQTT resource
echo "Creating MQTT resource ${MQTT_RESOURCE_NAME}"
$ASADMIN_CMD create-connector-resource \
--poolname ${MQTT_POOL_NAME} \
${MQTT_RESOURCE_NAME} || exit 1

# The connector logs allocation failures with a full stack trace before returning null.
$ASADMIN_CMD set-log-levels fish.payara.cloud.connectors.mqtt.api.outbound.MQTTConnectionFactoryImpl=OFF || exit 1

# Test MQTT connection pool
echo "Testing MQTT connection pool"
$ASADMIN_CMD ping-connection-pool ${MQTT_POOL_NAME} || { echo "Warning: MQTT connection pool ping failed"; exit 1; }

echo "Restart or redeploy CDB."
135 changes: 135 additions & 0 deletions sbin/cdb_create_mqtt_configuration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#!/bin/bash

# Script to create MQTT configuration file for CDB service
# Usage: $0 [CDB_DB_NAME]

MY_DIR=`dirname $0` && cd $MY_DIR && MY_DIR=`pwd`
if [ -z "${CDB_ROOT_DIR}" ]; then
CDB_ROOT_DIR=$MY_DIR/..
fi
CDB_ENV_FILE=${CDB_ROOT_DIR}/setup.sh
if [ ! -f ${CDB_ENV_FILE} ]; then
echo "Environment file ${CDB_ENV_FILE} does not exist."
exit 2
fi
. ${CDB_ENV_FILE} > /dev/null

# Default configuration file location
CDB_DB_NAME=${1:-${CDB_DB_NAME:-cdb}}
MQTT_CONFIG_FILE=${CDB_INSTALL_DIR}/etc/${CDB_DB_NAME}.mqtt.conf

echo "==================================="
echo "MQTT Configuration Setup for CDB"
echo "==================================="
echo ""
echo "This script will help you create an MQTT configuration file."
echo "Configuration will be saved to: $MQTT_CONFIG_FILE"
echo ""

# Check if config file already exists
if [ -f "$MQTT_CONFIG_FILE" ]; then
read -p "Configuration file already exists. Overwrite? (y/n): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Exiting without changes."
exit 0
fi
fi

echo ""
echo "Configuration Details:"
echo "- cleanSession: Whether client and server should remember state across reconnects"
echo "- automaticReconnect: Whether client will automatically reconnect if connection is lost"
echo "- filePersistance: Whether to use file persistence for un-acknowledged messages"
echo "- persistenceDirectory: Directory to use for file persistence"
echo "- connectionTimeout: Connection timeout value in seconds"
echo "- maxInflight: Maximum messages that can be sent without acknowledgements"
echo "- keepAliveInterval: Keep alive interval in seconds"
echo "- userName/password: Authentication credentials"
# Disable MDB only variables.
# echo "- topicFilter: Topic Filter (For MDBs only)"
# echo "- qos: Quality of Service for the subscription (For MDBs only)"
echo ""

# Ensure directory exists
mkdir -p $(dirname "$MQTT_CONFIG_FILE")

# Prompt for configuration values
read -p "MQTT Host [localhost]: " MQTT_HOST
MQTT_HOST=${MQTT_HOST:-localhost}

read -p "MQTT Port [1883]: " MQTT_PORT
MQTT_PORT=${MQTT_PORT:-1883}

read -p "MQTT Username (leave empty for no auth): " MQTT_USERNAME

if [ ! -z "$MQTT_USERNAME" ]; then
read -s -p "MQTT Password: " MQTT_PASSWORD
echo
fi

read -p "Clean Session (true/false) [false]: " CLEAN_SESSION
CLEAN_SESSION=${CLEAN_SESSION:-false}

read -p "Automatic Reconnect (true/false) [true]: " AUTOMATIC_RECONNECT
AUTOMATIC_RECONNECT=${AUTOMATIC_RECONNECT:-true}

read -p "File Persistance (true/false) [false]: " FILE_PERSISTANCE
FILE_PERSISTANCE=${FILE_PERSISTANCE:-false}

read -p "Persistence Directory [.]: " PERSISTENCE_DIRECTORY
PERSISTENCE_DIRECTORY=${PERSISTENCE_DIRECTORY:-.}

read -p "Connection Timeout (seconds) [30]: " CONNECTION_TIMEOUT
CONNECTION_TIMEOUT=${CONNECTION_TIMEOUT:-30}

read -p "Max Inflight [10]: " MAX_INFLIGHT
MAX_INFLIGHT=${MAX_INFLIGHT:-10}

read -p "Keep Alive Interval (seconds) [60]: " KEEP_ALIVE_INTERVAL
KEEP_ALIVE_INTERVAL=${KEEP_ALIVE_INTERVAL:-60}

# MDB only variables
# read -p "Topic Filter (leave empty if not using MDB): " TOPIC_FILTER
# read -p "QoS (0/1/2) [0]: " QOS
# QOS=${QOS:-0}

# Write configuration file
cat > "$MQTT_CONFIG_FILE" << EOF
# MQTT Configuration for CDB Service
# Generated on $(date)

MQTT_HOST=$MQTT_HOST
MQTT_PORT=$MQTT_PORT
EOF

if [ ! -z "$MQTT_USERNAME" ]; then
echo "MQTT_USERNAME=$MQTT_USERNAME" >> "$MQTT_CONFIG_FILE"
fi

if [ ! -z "$MQTT_PASSWORD" ]; then
echo "MQTT_PASSWORD=$MQTT_PASSWORD" >> "$MQTT_CONFIG_FILE"
fi

cat >> "$MQTT_CONFIG_FILE" << EOF
MQTT_CLEAN_SESSION=$CLEAN_SESSION
MQTT_AUTOMATIC_RECONNECT=$AUTOMATIC_RECONNECT
MQTT_FILE_PERSISTANCE=$FILE_PERSISTANCE
MQTT_PERSISTENCE_DIRECTORY=$PERSISTENCE_DIRECTORY
MQTT_CONNECTION_TIMEOUT=$CONNECTION_TIMEOUT
MQTT_MAX_INFLIGHT=$MAX_INFLIGHT
MQTT_KEEP_ALIVE_INTERVAL=$KEEP_ALIVE_INTERVAL
EOF

if [ ! -z "$TOPIC_FILTER" ]; then
echo "MQTT_TOPIC_FILTER=$TOPIC_FILTER" >> "$MQTT_CONFIG_FILE"
fi

if [ ! -z "$QOS" ]; then
echo "MQTT_QOS=$QOS" >> "$MQTT_CONFIG_FILE"
fi

echo ""
echo "Configuration file created successfully at: $MQTT_CONFIG_FILE"
echo ""
echo "You can now run cdb_configure_mqtt_service.sh ${CDB_DB_NAME} to apply this configuration."
Binary file added src/java/CdbWebPortal/lib/cdb-base-mqtt-1.0.0.jar
Binary file not shown.
Binary file not shown.
Loading
Loading