100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Logging improvements (#930)
Rich Turner5223a598f8b5
diff --git a/.ci_cd/deploy.sh b/.ci_cd/deploy.shindex cd1cebbd7..be41d8c50 100644--- a/.ci_cd/deploy.sh+++ b/.ci_cd/deploy.sh@@ -265,8 +265,6 @@ fi# Delete any deployment volume so we get the latestecho "Deleting existing deployment data volume"docker volume rm or_deployment-data 1>/dev/null-echo "Deleting existing EFS mount volume"-docker volume rm or_efs-data 1>/dev/null# Start the stackecho "Starting the stack"@@ -306,6 +304,7 @@ if [ "\$STATUSES_OK" == 'true' ]; thenecho "All services are healthy"elseecho "One or more services are unhealthy"+ docker ps -aexit 1fi@@ -334,14 +333,18 @@ EOFif [ $? -ne 0 ]; thenecho "Deployment failed or is unhealthy"- if [ "$ROLLBACK_ON_ERROR" != 'true' ]; then- revoke_ssh- exit 1- else- DO_ROLLBACK=true- fifi+revoke_ssh+exit 1++# ROLLBACK FUNCTIONALITY DISABLED FOR NOW AS WASN'T WORKING AND MANUAL INTERVENTION IS FINE AT THIS POINT++#if [ "$ROLLBACK_ON_ERROR" != 'true' ]; then+#else+# DO_ROLLBACK=true+#fi+if [ "$DO_ROLLBACK" == 'true' ]; thenecho "Attempting rollback"$sshCommandPrefix ${hostStr} << EOF@@ -402,8 +405,6 @@ fi# Delete any deployment volume so we get the latestecho "Deleting existing deployment data volume"docker volume rm or_deployment-data 1>/dev/null-echo "Deleting existing EFS mount volume"-docker volume rm or_efs-data 1>/dev/null# Start the stackecho "Starting the stack"diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.ymlindex 66fdfd52c..0727accbf 100644--- a/.github/workflows/ci_cd.yml+++ b/.github/workflows/ci_cd.yml@@ -177,7 +177,7 @@ jobs:- name: Backend files changedid: backend-files-changedif: github.event_name == 'pull_request'- uses: tj-actions/changed-files@v34+ uses: tj-actions/changed-files@v35with:files_ignore: |.ci_cd/**@@ -193,7 +193,7 @@ jobs:- name: UI files changedid: ui-files-changedif: github.event_name == 'pull_request'- uses: tj-actions/changed-files@v34+ uses: tj-actions/changed-files@v35with:files: |ui/app/manager/**diff --git a/agent/build.gradle b/agent/build.gradleindex 9e7b2a314..96f042ae4 100644--- a/agent/build.gradle+++ b/agent/build.gradle@@ -12,13 +12,10 @@ dependencies {api "com.fazecast:jSerialComm:$jSerialCommVersion"- api("com.github.calimero:calimero-core:$calimeroVersion") {- // Libraries should not depend on a logging implementation and/or alpha versions!- exclude group: "org.slf4j"- }+ api "com.github.calimero:calimero-core:$calimeroVersion"api ("com.github.calimero:calimero-tools:$calimeroVersion") {- // Libraries should not depend on a logging implementation and/or alpha versions!+ // Has a dependency on the SLF4J simple providerexclude group: "org.slf4j"}@@ -34,13 +31,7 @@ dependencies {api "com.hivemq:hivemq-mqtt-client:$hiveMQClientVersion"- api ("com.github.weliem:blessed-bluez:$bluetoothVersion") {- // Libraries should not depend on a logging implementation and/or alpha versions!- exclude group: "org.slf4j"-- // Conflicts with asm version bundled with GWT- exclude group: "org.ow2.asm"- }+ api "com.github.weliem:blessed-bluez:$bluetoothVersion"implementation "dev.failsafe:failsafe:$failsafeVersion"}diff --git a/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.javaindex 877affbca..f4932c621 100644--- a/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java+++ b/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java@@ -283,7 +283,7 @@ public abstract class AbstractProtocol<T extends Agent<T, ?, U>, U extends Agent}AttributeEvent attributeEvent = new AttributeEvent(new AttributeState(state.getRef(), ignoreAndConverted.value), timestamp);- LOG.finer("Sending linked attribute update on sensor queue: " + attributeEvent);+ LOG.finest("Sending linked attribute update on sensor queue: " + attributeEvent);producerTemplate.sendBodyAndHeader(SENSOR_QUEUE, attributeEvent, Protocol.SENSOR_QUEUE_SOURCE_PROTOCOL, getProtocolName());}@@ -296,7 +296,7 @@ public abstract class AbstractProtocol<T extends Agent<T, ?, U>, U extends Agentreturn;}AttributeEvent attributeEvent = new AttributeEvent(state, timerService.getCurrentTimeMillis());- LOG.finer("Sending protocol agent attribute update: " + attributeEvent);+ LOG.finest("Sending protocol agent attribute update: " + attributeEvent);assetService.sendAttributeEvent(attributeEvent);}diff --git a/agent/src/main/java/org/openremote/agent/protocol/controller/Controller.java b/agent/src/main/java/org/openremote/agent/protocol/controller/Controller.javadeleted file mode 100644index 2a1b0345f..000000000--- a/agent/src/main/java/org/openremote/agent/protocol/controller/Controller.java+++ /dev/null@@ -1,73 +0,0 @@-package org.openremote.agent.protocol.controller;--import org.openremote.model.attribute.AttributeRef;--import java.util.*;-import java.util.stream.Collectors;--import static org.openremote.container.concurrent.GlobalLock.withLock;--/**- * Controller class represent a Controller defined in a Manager Agent and store all sensors and commands linked to that Controller agent- */-public class Controller {-- /**- * A unique ID to use for polling (see Controller 2.5 polling HTTP API)- */- public final String DEVICE_ID_BASE = "OR3ControllerProtocol";-- private String controllerConfigName;-- private String deviceId;-- private Map<AttributeRef, ControllerSensor> sensorsList = new HashMap<>();- private Map<AttributeRef, ControllerCommand> commandsList = new HashMap<>();-- public Controller(String agentId) {- this.controllerConfigName = agentId;- this.deviceId = DEVICE_ID_BASE + "_" + agentId;- }-- public void addSensor(AttributeRef attributeRef, ControllerSensor sensor) {- this.sensorsList.put(attributeRef, sensor);- }-- public void addCommand(AttributeRef attributeRef, ControllerCommand command) {- this.commandsList.put(attributeRef, command);- }-- public ControllerCommand getCommand(AttributeRef attributeRef) {- return this.commandsList.get(attributeRef);- }-- public Set<Map.Entry<AttributeRef, ControllerSensor>> getSensorsListForDevice(String deviceName) {- return this.sensorsList.entrySet().stream().filter(entry -> entry.getValue().getDeviceName().equals(deviceName)).collect(Collectors.toSet());- }-- public String getDeviceId() {- return this.deviceId;- }-- public String getControllerConfigName() {- return this.controllerConfigName;- }-- public void removeAttributeRef(AttributeRef attributeRef) {- withLock(ControllerProtocol.PROTOCOL_DISPLAY_NAME + ":Controller::removeAttributeRef", () -> {- this.commandsList.remove(attributeRef);- this.sensorsList.remove(attributeRef);- });- }-- /**- * Collect every sensorName linked to a deviceName. Look into {@link #sensorsList}- */- public List<String> collectSensorNameLinkedToDeviceName(String deviceName) {- return sensorsList.values()- .stream()- .filter(sensor -> sensor.getDeviceName().equals(deviceName)).map(ControllerSensor::getSensorName)- .distinct()- .collect(Collectors.toList());- }-}diff --git a/agent/src/main/java/org/openremote/agent/protocol/controller/ControllerAgent.java b/agent/src/main/java/org/openremote/agent/protocol/controller/ControllerAgent.javadeleted file mode 100644index e9d00b3d7..000000000--- a/agent/src/main/java/org/openremote/agent/protocol/controller/ControllerAgent.java+++ /dev/null@@ -1,64 +0,0 @@-/*- * Copyright 2020, OpenRemote Inc.- *- * See the CONTRIBUTORS.txt file in the distribution for a- * full listing of individual contributors.- *- * This program is free software: you can redistribute it and/or modify- * it under the terms of the GNU Affero General Public License as- * published by the Free Software Foundation, either version 3 of the- * License, or (at your option) any later version.- *- * This program is distributed in the hope that it will be useful,- * but WITHOUT ANY WARRANTY; without even the implied warranty of- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the- * GNU Affero General Public License for more details.- *- * You should have received a copy of the GNU Affero General Public License- * along with this program. If not, see <http://www.gnu.org/licenses/>.- */-package org.openremote.agent.protocol.controller;--import org.openremote.model.asset.agent.Agent;-import org.openremote.model.asset.agent.AgentDescriptor;-import org.openremote.model.util.ModelIgnore;-import org.openremote.model.value.AttributeDescriptor;-import org.openremote.model.value.ValueType;--import javax.persistence.Entity;-import java.util.Optional;--@ModelIgnore-@Entity-public class ControllerAgent extends Agent<ControllerAgent, ControllerProtocol, ControllerAgentLink> {-- public static final AttributeDescriptor<String> CONTROLLER_URI = new AttributeDescriptor<>("controllerURI", ValueType.TEXT);-- public static final AgentDescriptor<ControllerAgent, ControllerProtocol, ControllerAgentLink> DESCRIPTOR = new AgentDescriptor<>(- ControllerAgent.class, ControllerProtocol.class, ControllerAgentLink.class- );-- /**- * For use by hydrators (i.e. JPA/Jackson)- */- protected ControllerAgent() {- }-- public ControllerAgent(String name) {- super(name);- }-- @Override- public ControllerProtocol getProtocolInstance() {- return new ControllerProtocol(this);- }-- public Optional<String> getControllerURI() {- return getAttributes().getValue(CONTROLLER_URI);- }-- public ControllerAgent setControllerURI(String uri) {- getAttributes().getOrCreate(CONTROLLER_URI).setValue(uri);- return this;- }-}diff --git a/agent/src/main/java/org/openremote/agent/protocol/controller/ControllerAgentLink.java b/agent/src/main/java/org/openremote/agent/protocol/controller/ControllerAgentLink.javadeleted file mode 100644index 2ac0bd193..000000000--- a/agent/src/main/java/org/openremote/agent/protocol/controller/ControllerAgentLink.java+++ /dev/null@@ -1,89 +0,0 @@-/*- * Copyright 2021, OpenRemote Inc.- *- * See the CONTRIBUTORS.txt file in the distribution for a- * full listing of individual contributors.- *- * This program is free software: you can redistribute it and/or modify- * it under the terms of the GNU Affero General Public License as- * published by the Free Software Foundation, either version 3 of the- * License, or (at your option) any later version.- *- * This program is distributed in the hope that it will be useful,- * but WITHOUT ANY WARRANTY; without even the implied warranty of- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the- * GNU Affero General Public License for more details.- *- * You should have received a copy of the GNU Affero General Public License- * along with this program. If not, see <http://www.gnu.org/licenses/>.- */-package org.openremote.agent.protocol.controller;--import org.openremote.model.asset.agent.AgentLink;--import java.util.List;-import java.util.Map;-import java.util.Optional;--public class ControllerAgentLink extends AgentLink<ControllerAgentLink> {-- protected String deviceName;- protected String sensorName;- protected String commandDeviceName;- protected String commandName;- protected Map<String, List<String>> commandsMap;-- // For Hydrators- protected ControllerAgentLink() {- }-- public ControllerAgentLink(String id, String deviceName) {- super(id);- this.deviceName = deviceName;- }-- public Optional<String> getDeviceName() {- return Optional.ofNullable(deviceName);- }-- public ControllerAgentLink setDeviceName(String deviceName) {- this.deviceName = deviceName;- return this;- }-- public Optional<String> getSensorName() {- return Optional.ofNullable(sensorName);- }-- public ControllerAgentLink setSensorName(String sensorName) {- this.sensorName = sensorName;- return this;- }-- public Optional<String> getCommandDeviceName() {- return Optional.ofNullable(commandDeviceName);- }-- public ControllerAgentLink setCommandDeviceName(String commandDeviceName) {- this.commandDeviceName = commandDeviceName;- return this;- }-- public Optional<String> getCommandName() {- return Optional.ofNullable(commandName);- }-- public ControllerAgentLink setCommandName(String commandName) {- this.commandName = commandName;- return this;- }-- public Optional<Map<String, List<String>>> getCommandsMap() {- return Optional.ofNullable(commandsMap);- }-- public ControllerAgentLink setCommandsMap(Map<String, List<String>> commandsMap) {- this.commandsMap = commandsMap;- return this;- }-}diff --git a/agent/src/main/java/org/openremote/agent/protocol/controller/ControllerCommand.java b/agent/src/main/java/org/openremote/agent/protocol/controller/ControllerCommand.javadeleted file mode 100644index 9278b62d5..000000000--- a/agent/src/main/java/org/openremote/agent/protocol/controller/ControllerCommand.java+++ /dev/null@@ -1,29 +0,0 @@-package org.openremote.agent.protocol.controller;--/**- * ControllerCommand represent an executable command on the Controller- * <p>- * Depending if the command to send to the Controller is based on META {@link ControllerProtocol#META_ATTRIBUTE_COMMAND_NAME- * } or {@link ControllerProtocol#META_ATTRIBUTE_COMMANDS_MAP}, we'll create an instance of ControllerCommand as {@link- * org.openremote.agent.protocol.controller.command.ControllerCommandBasic} or {@link- * org.openremote.agent.protocol.controller.command.ControllerCommandMapped}- */-public class ControllerCommand {- private String deviceName;-- public ControllerCommand() {- this.deviceName = "";- }-- public ControllerCommand(String deviceName) {- this.deviceName = deviceName;- }-- public String getDeviceName() {- return deviceName;- }-- public void setDeviceName(String deviceName) {- this.deviceName = deviceName;- }-}diff --git a/agent/src/main/java/org/openremote/agent/protocol/controller/ControllerProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/controller/ControllerProtocol.javadeleted file mode 100644index 0ce031eec..000000000--- a/agent/src/main/java/org/openremote/agent/protocol/controller/ControllerProtocol.java+++ /dev/null@@ -1,536 +0,0 @@-/*- * Copyright 2017, OpenRemote Inc.- *- * See the CONTRIBUTORS.txt file in the distribution for a- * full listing of individual contributors.- *- * This program is free software: you can redistribute it and/or modify- * it under the terms of the GNU Affero General Public License as- * published by the Free Software Foundation, either version 3 of the- * License, or (at your option) any later version.- *- * This program is distributed in the hope that it will be useful,- * but WITHOUT ANY WARRANTY; without even the implied warranty of- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the- * GNU Affero General Public License for more details.- *- * You should have received a copy of the GNU Affero General Public License- * along with this program. If not, see <http://www.gnu.org/licenses/>.- */-package org.openremote.agent.protocol.controller;--import com.fasterxml.jackson.databind.node.ArrayNode;-import com.fasterxml.jackson.databind.node.ObjectNode;-import org.apache.http.client.utils.URIBuilder;-import org.apache.http.conn.HttpHostConnectException;-import org.jboss.resteasy.client.jaxrs.ResteasyClient;-import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;-import org.openremote.agent.protocol.AbstractProtocol;-import org.openremote.agent.protocol.controller.command.ControllerCommandBasic;-import org.openremote.agent.protocol.controller.command.ControllerCommandMapped;-import org.openremote.agent.protocol.http.HTTPProtocol;-import org.openremote.container.web.WebTargetBuilder;-import org.openremote.model.Container;-import org.openremote.model.asset.agent.ConnectionStatus;-import org.openremote.model.attribute.Attribute;-import org.openremote.model.attribute.AttributeEvent;-import org.openremote.model.attribute.AttributeRef;-import org.openremote.model.attribute.AttributeState;-import org.openremote.model.syslog.SyslogCategory;-import org.openremote.model.util.ValueUtil;-import org.openremote.model.value.ValueDescriptor;--import javax.ws.rs.ProcessingException;-import javax.ws.rs.core.MultivaluedMap;-import javax.ws.rs.core.Response;-import java.net.ConnectException;-import java.net.URI;-import java.net.URISyntaxException;-import java.net.UnknownHostException;-import java.util.*;-import java.util.concurrent.Future;-import java.util.concurrent.ScheduledFuture;-import java.util.concurrent.TimeUnit;-import java.util.function.Consumer;-import java.util.logging.Level;-import java.util.logging.Logger;--import static org.openremote.container.concurrent.GlobalLock.withLock;-import static org.openremote.container.concurrent.GlobalLock.withLockReturning;-import static org.openremote.container.web.WebTargetBuilder.CONNECTION_POOL_SIZE;-import static org.openremote.container.web.WebTargetBuilder.createClient;-import static org.openremote.model.syslog.SyslogCategory.PROTOCOL;--/**- * This is a Controller 2.5 protocol to communicate with a running Controller 2.5 instance and getting sensor's status- * and executing commands.- * <p>- * The protocol communicate with Controller by using Controller REST API.- * <p>- * The protocol manage two kinds of request :- * <ul>- * <li>A set of polling requests (one by controller/device name couple) {@link #pollingSensorList}. For each request we- * just wait for a response 200 (new status) or 403 (timeout after 60 seconds) and relaunch the same request as soon as we have one of those two responses.</li>- * <li>Executing commands provided by Write Attribute with necessary information. There is different kind of situations explained in- * {@link org.openremote.agent.protocol.controller.ControllerCommand}</li>- * </ul>- * <p>- * <p>- * Two cases are considered:- * <ul>- * <li>A sensor : if we want to link an attribute to a controller 2.5 sensor to get status we should create an Attribute with proper type- * considering the situation (temperature, time,...) and two necessary META {@link ControllerAgent#META_DEVICE_NAME} and- * {@link ControllerAgent#META_SENSOR_NAME}</li>- * <li>A command : if we want to execute a command on a controller 2.5, we create an attribute with the following available META (see details- * in {@link org.openremote.agent.protocol.controller.ControllerCommand}) :- * {@link ControllerAgent#META_DEVICE_NAME} or {@link ControllerAgent#META_COMMAND_DEVICE_NAME}, {@link ControllerAgent#META_COMMAND_NAME} or- * {@link ControllerAgent#META_COMMANDS_MAP}</li>- * </ul>- * <p>- */-// TODO: Fix or remove this protocol - it does polling per device and also futures are not cancelled and NPEs appear etc...nasty-public class ControllerProtocol extends AbstractProtocol<ControllerAgent, ControllerAgentLink> {-- public static final int HEARTBEAT_DELAY_SECONDS = 5;- public static final String PROTOCOL_DISPLAY_NAME = "Controller Client";- private static final Logger LOG = SyslogCategory.getLogger(PROTOCOL, ControllerProtocol.class);- private final Map<String, Future<?>> pollingSensorList = new HashMap<>();- protected ResteasyClient client;- private Controller controller;- private ResteasyWebTarget controllerWebTarget;- private ScheduledFuture<?> controllerHeartbeat;- private final Map<AttributeRef, Boolean> initStatusDone = new HashMap<>();-- public ControllerProtocol(ControllerAgent agent) {- super(agent);- }-- @Override- public void doStart(Container container) throws Exception {-- String baseURL = agent.getControllerURI().orElseThrow(() -> new IllegalArgumentException("Missing or invalid controller URI: " + agent));- URI uri;-- try {- uri = new URIBuilder(baseURL).build();- } catch (URISyntaxException e) {- LOG.log(Level.SEVERE, "Invalid Controller URI", e);- setConnectionStatus(ConnectionStatus.ERROR);- throw e;- }-- client = createClient(executorService, CONNECTION_POOL_SIZE, 70000, null);-- WebTargetBuilder webTargetBuilder = new WebTargetBuilder(client, uri);-- agent.getUsernamePassword().ifPresent(usernamePassword -> {- LOG.info("Setting BASIC auth credentials for controller");- webTargetBuilder.setBasicAuthentication(usernamePassword.getUsername(), usernamePassword.getPassword());- });-- controllerWebTarget = webTargetBuilder.build();- controller = new Controller(agent.getId());-- controllerHeartbeat = this.executorService.scheduleWithFixedDelay(- () -> this.executeHeartbeat(this::onHeartbeatResponse),- 0,- HEARTBEAT_DELAY_SECONDS,- TimeUnit.SECONDS);- }-- @Override- protected void setConnectionStatus(ConnectionStatus connectionStatus) {- super.setConnectionStatus(connectionStatus);-- if (connectionStatus.equals(ConnectionStatus.DISCONNECTED)) {- for (Future<?> task : this.pollingSensorList.values()) {- task.cancel(true);- }- }- }-- @Override- protected void doStop(Container container) throws Exception {-- if (controllerHeartbeat != null) {- controllerHeartbeat.cancel(true);- }-- pollingSensorList.values().forEach(pollingTask -> pollingTask.cancel(true));- pollingSensorList.clear();- initStatusDone.clear();- }-- @Override- protected void doLinkAttribute(String assetId, Attribute<?> attribute, ControllerAgentLink agentLink) {- AttributeRef attributeRef = new AttributeRef(assetId, attribute.getName());- String deviceName = agentLink.getDeviceName().orElse(null);- String sensorName = agentLink.getSensorName().orElse(null);- String commandDeviceName = agentLink.getCommandDeviceName().orElse(null);- String commandName = agentLink.getCommandName().orElse(null);-- Map<String, List<String>> commandsMap = agentLink.getCommandsMap().orElse(null);-- /*- * Build Sensor Status info for polling request- */- if (sensorName != null) {- LOG.finer("### Adding new sensor [" + deviceName + "," + sensorName + "] linked to " + agent.getId() + " (" + agent.getName() + ")");- controller.addSensor(attributeRef, new ControllerSensor(deviceName, sensorName));-- // Properly stop previously existing polling on device name --> use of false parameter- if (pollingSensorList.containsKey(deviceName)) {- pollingSensorList.get(deviceName).cancel(true);- }-- this.initStatusDone.put(attributeRef, false);-- // Get initial status of sensor- collectInitialStatus(attributeRef, deviceName, sensorName);-- //Put new polling on a new device name or update previous- this.schedulePollingTask(deviceName);- }-- /*- * If linked Attribute contains command info, we build {@link org.openremote.agent.protocol.controller.ControllerCommand } depending on- * attribute information.- */- if (commandName != null || commandsMap != null) {- //If no command specific device name is set, then we're using deviceName- if (commandDeviceName == null && deviceName != null) {- commandDeviceName = deviceName;- }-- if (commandName != null) {- controller.addCommand(attributeRef, new ControllerCommandBasic(commandDeviceName, commandName));- } else {- assert commandsMap.size() > 0;- controller.addCommand(attributeRef, new ControllerCommandMapped(commandDeviceName, computeCommandsMapFromMultiValue(commandsMap)));- }- }- }-- /**- * Clearing elements if an attribute is unlinked from Controller Agent We don't have to clear {@link- * #pollingSensorList} as a check is done before scheduling task {@link #schedulePollingTask}- */- @Override- protected void doUnlinkAttribute(String assetId, Attribute<?> attribute, ControllerAgentLink agentLink) {- AttributeRef attributeRef = new AttributeRef(assetId, attribute.getName());- controller.removeAttributeRef(attributeRef);- }-- /**- * Write action on a linked attribute mean we execute a command on the Controller. It induce a HTTP request and- * manage it's return code. (No value is returned from the execution of a command)- */- @Override- protected void doLinkedAttributeWrite(Attribute<?> attribute, ControllerAgentLink agentLink, AttributeEvent event, Object processedValue) {- LOG.finer("### Process Linked Attribute Write");-- AttributeRef attributeRef = event.getAttributeRef();- ControllerCommand controllerCommand = controller.getCommand(attributeRef);- HTTPProtocol.HttpClientRequest request = RequestBuilder.buildCommandRequest(controllerCommand, event, controllerWebTarget);-- String body = null;-- if (controllerCommand instanceof ControllerCommandBasic) {- body = event.getValue().map(v -> {- ObjectNode objectValue = ValueUtil.JSON.createObjectNode();- objectValue.putPOJO("parameter", processedValue);- return objectValue.toString();- }).orElse(null);- }- executeAttributeWriteRequest(request, body, this::onAttributeWriteResponse);- }-- /**- * Convert commands map received as {@link MultivaluedMap} into a simple {@link Map}- */- private Map<String, String> computeCommandsMapFromMultiValue(Map<String, List<String>> multivaluedMap) {- Map<String, String> commandsMap = new HashMap<>();-- for (Map.Entry<String, List<String>> entry : multivaluedMap.entrySet()) {- commandsMap.put(entry.getKey(), entry.getValue().get(0));- }-- return commandsMap;- }-- private void collectInitialStatus(AttributeRef attributeRef, String deviceName, String sensorName) {- this.executorService- .submit(() -> this.executeInitialStatus(attributeRef, deviceName, sensorName, response -> onInitialStatusResponse(attributeRef, deviceName, sensorName, response)));- }-- private void executeInitialStatus(AttributeRef attributeRef, String deviceName, String sensorName, Consumer<Response> responseConsumer) {- withLock(getProtocolName() + "::executeInitialStatus::" + attributeRef, () -> {- LOG.info("### Initial status check for " + attributeRef.getName() + " [" + deviceName + "," + sensorName + "] ...");-- HTTPProtocol.HttpClientRequest checkRequest = RequestBuilder.buildStatusRequest(deviceName, Arrays.asList(sensorName), controllerWebTarget);-- Response response = null;-- try {- response = checkRequest.invoke(null);- responseConsumer.accept(response);- } catch (ProcessingException e) {- LOG.log(Level.SEVERE, "### Initial status for " + attributeRef.getName() + " [" + deviceName + "," + sensorName + "] doesn't succeed", e);- } finally {- if (response != null) {- response.close();- }- }-- });- }-- private void onInitialStatusResponse(AttributeRef attributeRef, String deviceName, String sensorName, Response response) {- if (response != null) {- if (response.getStatusInfo().equals(Response.Status.OK)) {- LOG.finer("### New sensor [" + sensorName + "] status received");- ArrayNode arrayValue = response.readEntity(ArrayNode.class);-- if (arrayValue.isEmpty()) {- LOG.warning("### Status response is empty");- } else {- arrayValue.forEach(status -> {- String name = status.get("name").asText();- String value = status.get("value").asText();-- this.updateAttributeValue(attributeRef, value);- this.initStatusDone.put(attributeRef, true);- });- }- } else {- LOG.severe("### Status code for initial status received error : " + response.getStatus() + " --> " + response.getStatusInfo().getReasonPhrase());- }- } else {- LOG.warning("### Initial status check return a null value for " + attributeRef.getName() + " [" + deviceName + "," + sensorName + "]");- }-- if (!this.initStatusDone.get(attributeRef)) {- collectInitialStatus(attributeRef, deviceName, sensorName);- }- }-- /**- * Compute the polling request for a given deviceName and controller. Method check all registered sensor's (linked- * to the Protocol) and collect all sensor's name to put them into polling request- */- private Future<?> computePollingTask(String deviceName) {- return withLockReturning(getProtocolName() + "::computePollingTask::" + deviceName, () -> {- List<String> sensorNameList = controller.collectSensorNameLinkedToDeviceName(deviceName);-- if (sensorNameList.isEmpty()) {- return null;- }-- return executorService.submit(() -> executePollingRequest(deviceName, sensorNameList,- response -> onPollingResponse(deviceName, sensorNameList, response)));- });- }-- /**- * Polling Request execution if a Connection issue (exception) occurs, we check the nature {@link- * #checkIfConnectionRefused}- */- private void executePollingRequest(String deviceName, List<String> sensorList, Consumer<Response> responseConsumer) {- LOG.info("### Polling Request for device [device=" + deviceName + ", sensors=" + this.formatSensors(sensorList) + "]");-- HTTPProtocol.HttpClientRequest httpClientRequest = RequestBuilder- .buildStatusPollingRequest(deviceName, sensorList, controller.getDeviceId(), controllerWebTarget);-- Response response = null;-- try {- response = httpClientRequest.invoke(null);- setConnectionStatus(ConnectionStatus.CONNECTED);- } catch (Exception e) {- LOG.log(Level.SEVERE,- "### Exception thrown whilst doing polling request [device=" + deviceName + ", sensors=" + this.formatSensors(sensorList) + "]",- e);-- this.checkIfConnectionRefused(e);- }-- responseConsumer.accept(response);- }-- /**- * Polling request should return three different responses :- * <ul>- * <li>OK (200) : new values are available for at least one of the sensor provided in queryParam</li>- * <li>TIMEOUT (408) : during the last 60 seconds following the start of the request, none of the sensors have new values</li>- * <li>Others : error</li>- * </ul>- * <p>- * In every case, we should start a new polling request directly. Only the 200 response induce an update of every linked attribute having a sensor- * status updated.- */- private void onPollingResponse(String deviceName, List<String> sensorNameList, Response response) {- if (response != null) {- if (response.getStatusInfo() == Response.Status.OK) {- String responseBodyAsString = response.readEntity(String.class);-- LOG.info("### New sensors status received");- LOG.finer("### Polling request body response : " + responseBodyAsString);-- ArrayNode statusArray = ValueUtil.convert(responseBodyAsString, ArrayNode.class);-- if (statusArray == null) {- LOG.warning("### Polling response is not a JSON array or empty: " + responseBodyAsString);- } else {- statusArray.forEach(status -> {-- String name = Optional.ofNullable(status.get("name")).flatMap(ValueUtil::getString).orElse(null);- String value = Optional.ofNullable(status.get("value")).flatMap(ValueUtil::getString).orElse(null);-- /**- * For every sensors in the request body, find the linked attributeref and update value by calling {@link #updateAttributeValue}- */- controller.getSensorsListForDevice(deviceName).stream()- .filter(entry -> entry.getValue().getSensorName().equals(name))- .forEach(e -> this.updateAttributeValue(e.getKey(), value));- });- }- } else if (response.getStatusInfo() == Response.Status.REQUEST_TIMEOUT) {- LOG.info("### Timeout from polling no changes on Controller side given sensors [device=" + deviceName + ", sensors=" + this.formatSensors(sensorNameList) + "]");- } else {- LOG.severe("### Status code received error : " + response.getStatus() + " --> " + response.getStatusInfo().getReasonPhrase());- }- } else {- LOG.severe("### Received null response from polling (due to previous exception)");- }-- //No matter status code, we're continuing to poll- this.schedulePollingTask(deviceName);- }-- /**- * Update linked attribute with new value. We should take care of attribute type and format- */- private void updateAttributeValue(AttributeRef attributeRef, String value) {- LOG.finest("### Updating attribute " + attributeRef + " with value " + value);- ValueDescriptor<?> valueType = this.linkedAttributes.get(attributeRef).getType();- Object valueObj = ValueUtil.convert(value, valueType.getType());- this.updateLinkedAttribute(new AttributeState(attributeRef, valueObj));- }-- private void executeAttributeWriteRequest(HTTPProtocol.HttpClientRequest request, String body, Consumer<Response> responseConsumer) {- Response response = null;-- try {- response = request.invoke(body);-- } catch (Exception e) {- LOG.log(Level.SEVERE, "### Exception thrown whilst doing attribute write request", e);- this.checkIfConnectionRefused(e);- }-- responseConsumer.accept(response);- }-- private void onAttributeWriteResponse(Response response) {- if (response != null) {- LOG.finer("### Response from command (204 is a valid and success return) : " + response.getStatus());- if (response.getStatus() != 204) {- LOG.severe("### Linked attribute Write request return with an error (different from 204) : " + response.getStatusInfo().getReasonPhrase());- }- } else {- LOG.warning("### Response set to null on Write");- }- }-- private String formatSensors(List<String> sensorList) {- return String.join(",", sensorList);- }-- /**- * Check the exception received from a request execution to see if it's not a connection issue. If it is the case,- * we'll start a heartbeat task until we get a new signal. Heartbeat is done every {@link #HEARTBEAT_DELAY_SECONDS}- * seconds.- */- private void checkIfConnectionRefused(Exception e) {- if (e.getCause() instanceof HttpHostConnectException) {- HttpHostConnectException e2 = (HttpHostConnectException) e.getCause();-- if (e2.getCause() instanceof ConnectException || e2.getCause() instanceof UnknownHostException) {- ConnectException e3 = (ConnectException) e2.getCause();- LOG.log(Level.SEVERE, "Connection refused: " + e3.getMessage());- setConnectionStatus(ConnectionStatus.DISCONNECTED);-- // Starting a heartbeat Task until connection is OK- if (controllerHeartbeat == null || this.controllerHeartbeat.isCancelled()) {- controllerHeartbeat = this.executorService.scheduleWithFixedDelay(() ->- this.executeHeartbeat(this::onHeartbeatResponse), 0, HEARTBEAT_DELAY_SECONDS, TimeUnit.SECONDS);- }- }- }- }--- /**- * Heartbeat is used when connection with Controller 2.x is lost and is running until connection is back- */- private void executeHeartbeat(Consumer<Response> responseConsumer) {- withLock(getProtocolName() + "::executeHeartbeat", () -> {- LOG.info("Doing heartbeat check for controller: " + controllerWebTarget.getUriBuilder().build());-- HTTPProtocol.HttpClientRequest checkRequest = RequestBuilder.buildCheckRequest(controllerWebTarget);-- Response response = null;-- try {- response = checkRequest.invoke(null);- responseConsumer.accept(response);- } catch (ProcessingException e) {- LOG.log(Level.SEVERE, "Heartbeat check for controller failed: " + controllerWebTarget.getUriBuilder().build(), e);- } finally {- if (response != null) {- response.close();- }- }- });- }-- private void onHeartbeatResponse(Response response) {- //if we don't have any connection issue, we stop the heartbeat check- if (response != null && (response.getStatusInfo().equals(Response.Status.OK) || response.getStatusInfo().equals(Response.Status.FOUND))) {- LOG.info("Heartbeat check for controller success: " + controllerWebTarget.getUriBuilder().build());- setConnectionStatus(ConnectionStatus.CONNECTED);- // cancel has to be the last step- controllerHeartbeat.cancel(true);- controllerHeartbeat = null;- } else {- String responseMsg = "NONE";- if (response != null) {- responseMsg = Integer.toString(response.getStatus());- }- LOG.severe("Heartbeat check for controller failed (Response = " + responseMsg + "): " + controllerWebTarget.getUriBuilder().build());- }- }-- /**- * Scheduling of a polling request- * <p>- * We check if there is sensor to poll for the given device name.- */- private void schedulePollingTask(String deviceName) {- Future<?> scheduledFuture = computePollingTask(deviceName);-- if (scheduledFuture != null) {- pollingSensorList.put(deviceName, scheduledFuture);- }- }-- @Override- public String getProtocolName() {- return PROTOCOL_DISPLAY_NAME;- }-- @Override- public String getProtocolInstanceUri() {- return "or-controller://" + (controllerWebTarget != null ? controllerWebTarget.getUriBuilder().build() : agent.getId());- }-}diff --git a/agent/src/main/java/org/openremote/agent/protocol/controller/ControllerSensor.java b/agent/src/main/java/org/openremote/agent/protocol/controller/ControllerSensor.javadeleted file mode 100644index cd9613ccc..000000000--- a/agent/src/main/java/org/openremote/agent/protocol/controller/ControllerSensor.java+++ /dev/null@@ -1,34 +0,0 @@-package org.openremote.agent.protocol.controller;--/**- * ControllerSensor represents a sensor on a device- */-public class ControllerSensor {- private String deviceName;- private String sensorName;-- public ControllerSensor() {-- }-- public ControllerSensor(String deviceName, String sensorName) {- this.deviceName = deviceName;- this.sensorName = sensorName;- }-- public String getDeviceName() {- return deviceName;- }-- public void setDeviceName(String deviceName) {- this.deviceName = deviceName;- }-- public String getSensorName() {- return sensorName;- }-- public void setSensorName(String sensorName) {- this.sensorName = sensorName;- }-}diff --git a/agent/src/main/java/org/openremote/agent/protocol/controller/RequestBuilder.java b/agent/src/main/java/org/openremote/agent/protocol/controller/RequestBuilder.javadeleted file mode 100644index 32018cf8b..000000000--- a/agent/src/main/java/org/openremote/agent/protocol/controller/RequestBuilder.java+++ /dev/null@@ -1,121 +0,0 @@-/*- * Copyright 2017, OpenRemote Inc.- *- * See the CONTRIBUTORS.txt file in the distribution for a- * full listing of individual contributors.- *- * This program is free software: you can redistribute it and/or modify- * it under the terms of the GNU Affero General Public License as- * published by the Free Software Foundation, either version 3 of the- * License, or (at your option) any later version.- *- * This program is distributed in the hope that it will be useful,- * but WITHOUT ANY WARRANTY; without even the implied warranty of- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the- * GNU Affero General Public License for more details.- *- * You should have received a copy of the GNU Affero General Public License- * along with this program. If not, see <http://www.gnu.org/licenses/>.- */-package org.openremote.agent.protocol.controller;--import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;-import org.openremote.agent.protocol.controller.command.ControllerCommandBasic;-import org.openremote.agent.protocol.controller.command.ControllerCommandMapped;-import org.openremote.agent.protocol.http.HTTPProtocol;-import org.openremote.model.attribute.AttributeEvent;--import javax.ws.rs.core.MediaType;-import javax.ws.rs.core.MultivaluedHashMap;-import javax.ws.rs.core.MultivaluedMap;-import java.util.List;-import java.util.Map;--/**- * Request's builder created for {@link ControllerProtocol}- */-public class RequestBuilder {-- /**- * Default header used for every request.- * We're working with JSON object in response- */- private static MultivaluedMap<String, Object> getDefaultHeaders() {- MultivaluedMap<String, Object> headers = new MultivaluedHashMap<>();-- headers.addAll("Accept", MediaType.APPLICATION_JSON);-- return headers;- }-- public static HTTPProtocol.HttpClientRequest buildCommandRequest(ControllerCommand controllerCommand, AttributeEvent event, ResteasyWebTarget webTarget) {- MultivaluedMap<String, String> queryParam = new MultivaluedHashMap<>();-- //This part could be put in a Wrapper- if(controllerCommand instanceof ControllerCommandBasic) {- String commandName = ((ControllerCommandBasic) controllerCommand).getCommandName();- queryParam.add("name", commandName);--- } else {- Map<String, String> actionCommandLink = ((ControllerCommandMapped) controllerCommand).getActionCommandLink();- String attributeValue = event.getValue().map(Object::toString).orElse(null);- String correspondingCommandName = actionCommandLink.get(attributeValue);- queryParam.add("name", correspondingCommandName);- }-- return new HTTPProtocol.HttpClientRequest(- webTarget,- "/rest/devices/" + controllerCommand.getDeviceName() + "/commands",- "POST",- getDefaultHeaders(),- queryParam,- false,- MediaType.APPLICATION_JSON- );- }-- public static HTTPProtocol.HttpClientRequest buildStatusPollingRequest(String deviceName, List<String> sensorsName, String deviceId, ResteasyWebTarget webTarget) {- MultivaluedMap<String, String> queryParam = new MultivaluedHashMap<>();-- queryParam.addAll("name", sensorsName);-- return new HTTPProtocol.HttpClientRequest(- webTarget,- "/rest/devices/" + deviceName + "/polling/" + deviceId,- "GET",- getDefaultHeaders(),- queryParam,- false,- MediaType.APPLICATION_JSON- );- }-- public static HTTPProtocol.HttpClientRequest buildStatusRequest(String deviceName, List<String> sensorsName, ResteasyWebTarget webTarget) {- MultivaluedMap<String, String> queryParam = new MultivaluedHashMap<>();-- queryParam.addAll("name", sensorsName);-- return new HTTPProtocol.HttpClientRequest(- webTarget,- "/rest/devices/" + deviceName + "/status",- "GET",- getDefaultHeaders(),- queryParam,- false,- MediaType.APPLICATION_JSON- );- }-- public static HTTPProtocol.HttpClientRequest buildCheckRequest(ResteasyWebTarget webTarget) {- return new HTTPProtocol.HttpClientRequest(- webTarget,- "",- "GET",- null,- null,- false,- null- );- }-}diff --git a/agent/src/main/java/org/openremote/agent/protocol/controller/command/ControllerCommandBasic.java b/agent/src/main/java/org/openremote/agent/protocol/controller/command/ControllerCommandBasic.javadeleted file mode 100644index a919d0c5f..000000000--- a/agent/src/main/java/org/openremote/agent/protocol/controller/command/ControllerCommandBasic.java+++ /dev/null@@ -1,35 +0,0 @@-package org.openremote.agent.protocol.controller.command;--import org.openremote.agent.protocol.controller.ControllerCommand;-import org.openremote.agent.protocol.http.HTTPProtocol;-import org.openremote.model.attribute.AttributeRef;--import java.util.function.Consumer;--/**- * A ControllerCommandBasic represent a configuration to execute a Controller 2.5 command with just a command name- * (command parameter is managed at launch depending on linked attribute value {@link- * org.openremote.agent.protocol.controller.ControllerProtocol#executeAttributeWriteRequest(HTTPProtocol.HttpClientRequest,- * AttributeRef, Consumer)}).- */-public class ControllerCommandBasic extends ControllerCommand {- private String commandName;-- public ControllerCommandBasic() {- super();- this.commandName = "";- }-- public ControllerCommandBasic(String deviceName, String commandName) {- super(deviceName);- this.commandName = commandName;- }-- public String getCommandName() {- return commandName;- }-- public void setCommandName(String commandName) {- this.commandName = commandName;- }-}diff --git a/agent/src/main/java/org/openremote/agent/protocol/controller/command/ControllerCommandMapped.java b/agent/src/main/java/org/openremote/agent/protocol/controller/command/ControllerCommandMapped.javadeleted file mode 100644index 678391365..000000000--- a/agent/src/main/java/org/openremote/agent/protocol/controller/command/ControllerCommandMapped.java+++ /dev/null@@ -1,55 +0,0 @@-package org.openremote.agent.protocol.controller.command;--import org.openremote.agent.protocol.controller.ControllerCommand;--import java.util.HashMap;-import java.util.Map;--/**- * A ControllerCommandMapped represent a configuration to execute a Controller 2.5 command where exact command name to execute depend on a linked- * attribute value and the match between linked attribute value and command name is stored in a map where key is attribute value and value is the- * command name to execute- *- * <h2>Example:</h2>- * Control a fan with 3 speeds: low, mid, high- * <ul>- * <li>Controller 2.x: a command to read the state of the fan and a sensor associated with it + commands with no parameter to turn fan off, set it- * to low speed, medium speed or high speed</li>- * <li>Manager 3.0: a read-write attribute (enum if it exists or string). Its value reflects the state of the sensor. If it is written to,- * appropriate command is sent to controller based on written value.</li>- * </ul>- * <h3>Mapping:</h3>- * The end user defines the device_name and sensor_name to read the attribute value + the device_name for command execution and a mapping table for- * the command execution e.g.- * <blockquote><pre>- * {@code- * {- * "off": "cmd1",- * "low": "cmd2",- * "mid": "cmd3",- * "high": "cmd4"- * }- * }- * </pre></blockquote>- */-public class ControllerCommandMapped extends ControllerCommand {- private Map<String, String> actionCommandLink;-- public ControllerCommandMapped() {- super();- this.actionCommandLink = new HashMap<>();- }-- public ControllerCommandMapped(String deviceName, Map<String, String> actionCommandLink) {- super(deviceName);- this.actionCommandLink = actionCommandLink;- }-- public Map<String, String> getActionCommandLink() {- return actionCommandLink;- }-- public void setActionCommandLink(Map<String, String> actionCommandLink) {- this.actionCommandLink = actionCommandLink;- }-}diff --git a/agent/src/main/java/org/openremote/agent/protocol/http/HTTPProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/http/HTTPProtocol.javaindex e812d0997..066bf0e3e 100644--- a/agent/src/main/java/org/openremote/agent/protocol/http/HTTPProtocol.java+++ b/agent/src/main/java/org/openremote/agent/protocol/http/HTTPProtocol.java@@ -59,6 +59,7 @@ import java.net.URISyntaxException;import java.util.*;import java.util.concurrent.ScheduledFuture;import java.util.concurrent.TimeUnit;+import java.util.concurrent.atomic.AtomicReference;import java.util.function.Consumer;import java.util.logging.Level;import java.util.logging.Logger;@@ -278,11 +279,7 @@ public class HTTPProtocol extends AbstractProtocol<HTTPAgent, HTTPAgentLink> {public static final String DEFAULT_CONTENT_TYPE = MediaType.TEXT_PLAIN;protected static final Logger LOG = SyslogCategory.getLogger(PROTOCOL, HTTPProtocol.class);public static int MIN_POLLING_MILLIS = 5000;- protected static ResteasyClient client;-- static {- client = createClient(org.openremote.container.Container.EXECUTOR_SERVICE);- }+ protected static final AtomicReference<ResteasyClient> client = new AtomicReference<>();protected final Map<AttributeRef, HttpClientRequest> requestMap = new HashMap<>();protected final Map<AttributeRef, ScheduledFuture<?>> pollingMap = new HashMap<>();@@ -291,6 +288,8 @@ public class HTTPProtocol extends AbstractProtocol<HTTPAgent, HTTPAgentLink> {public HTTPProtocol(HTTPAgent agent) {super(agent);++ initClient();}@Override@@ -333,7 +332,7 @@ public class HTTPProtocol extends AbstractProtocol<HTTPAgent, HTTPAgentLink> {if (readTimeout != null) {webTargetBuilder = new WebTargetBuilder(WebTargetBuilder.createClient(executorService, WebTargetBuilder.CONNECTION_POOL_SIZE, readTimeout.longValue(), null), uri);} else {- webTargetBuilder = new WebTargetBuilder(client, uri);+ webTargetBuilder = new WebTargetBuilder(client.get(), uri);}if (oAuthGrant.isPresent()) {@@ -453,6 +452,14 @@ public class HTTPProtocol extends AbstractProtocol<HTTPAgent, HTTPAgentLink> {return webTarget != null ? webTarget.getUri().toString() : agent.getBaseURI().orElse("");}+ protected static void initClient() {+ synchronized (client) {+ if (client.get() == null) {+ client.set(createClient(org.openremote.container.Container.EXECUTOR_SERVICE));+ }+ }+ }+protected HttpClientRequest buildClientRequest(String path, String method, MultivaluedMap<String, Object> headers, MultivaluedMap<String, String> queryParams, boolean pagingEnabled, String contentType) {return new HttpClientRequest(webTarget,diff --git a/agent/src/main/java/org/openremote/agent/protocol/io/AbstractIOClientProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/io/AbstractIOClientProtocol.javaindex eae0168e9..9adb105dc 100644--- a/agent/src/main/java/org/openremote/agent/protocol/io/AbstractIOClientProtocol.java+++ b/agent/src/main/java/org/openremote/agent/protocol/io/AbstractIOClientProtocol.java@@ -174,7 +174,7 @@ public abstract class AbstractIOClientProtocol<T extends AbstractIOClientProtocoreturn;}- AbstractIOClientProtocol.LOG.finer("Sending message to IO client: " + client.getClientUri());+ AbstractIOClientProtocol.LOG.finest("Sending message to IO client: " + client.getClientUri());client.sendMessage(message);}diff --git a/agent/src/main/java/org/openremote/agent/protocol/io/AbstractNettyIOClient.java b/agent/src/main/java/org/openremote/agent/protocol/io/AbstractNettyIOClient.javaindex 9a54cd8ac..1f29ea5f7 100644--- a/agent/src/main/java/org/openremote/agent/protocol/io/AbstractNettyIOClient.java+++ b/agent/src/main/java/org/openremote/agent/protocol/io/AbstractNettyIOClient.java@@ -202,7 +202,7 @@ public abstract class AbstractNettyIOClient<T, U extends SocketAddress> implemen}if (connectionStatus != ConnectionStatus.DISCONNECTED) {- LOG.finer("Must be disconnected before calling connect: " + getClientUri());+ LOG.finest("Must be disconnected before calling connect: " + getClientUri());return;}@@ -344,7 +344,7 @@ public abstract class AbstractNettyIOClient<T, U extends SocketAddress> implemen}protected void doDisconnect() {- LOG.finer("Performing disconnect: " + getClientUri());+ LOG.finest("Performing disconnect: " + getClientUri());try {if (channelStartFuture != null) {channelStartFuture.cancel(true);@@ -363,7 +363,7 @@ public abstract class AbstractNettyIOClient<T, U extends SocketAddress> implemenworkerGroup = null;}}- LOG.finer("Disconnect done: " + getClientUri());+ LOG.finest("Disconnect done: " + getClientUri());}@Overridediff --git a/agent/src/main/java/org/openremote/agent/protocol/io/AbstractNettyIOServer.java b/agent/src/main/java/org/openremote/agent/protocol/io/AbstractNettyIOServer.javaindex 78e926411..a6b1e687d 100644--- a/agent/src/main/java/org/openremote/agent/protocol/io/AbstractNettyIOServer.java+++ b/agent/src/main/java/org/openremote/agent/protocol/io/AbstractNettyIOServer.java@@ -249,7 +249,7 @@ public abstract class AbstractNettyIOServer<T, U extends Channel, V extends Abst@Overridepublic void disconnectClient(U client) {- LOG.finer("Disconnecting client: " + getClientDescriptor(client));+ LOG.finest("Disconnecting client: " + getClientDescriptor(client));client.close();}diff --git a/agent/src/main/java/org/openremote/agent/protocol/knx/KNXConnection.java b/agent/src/main/java/org/openremote/agent/protocol/knx/KNXConnection.javaindex 80c4f172d..3534d19da 100644--- a/agent/src/main/java/org/openremote/agent/protocol/knx/KNXConnection.java+++ b/agent/src/main/java/org/openremote/agent/protocol/knx/KNXConnection.java@@ -101,7 +101,7 @@ public class KNXConnection implements NetworkLinkListener, ProcessListener {onConnectionStatusChanged(ConnectionStatus.CONNECTED);// Get the values of all registered group addresses- LOG.finer("Initialising group address values");+ LOG.finest("Initialising group address values");synchronized (groupAddressConsumerMap) {groupAddressConsumerMap.forEach((groupAddress, datapointConsumerList) -> {if (!datapointConsumerList.isEmpty()) {@@ -167,7 +167,7 @@ public class KNXConnection implements NetworkLinkListener, ProcessListener {public void sendCommand(Datapoint datapoint, Optional<Object> value) {try {if (this.connectionStatus == ConnectionStatus.CONNECTED && value.isPresent()) {- LOG.finer("Sending to KNX action datapoint '" + datapoint + "': " + value);+ LOG.finest("Sending to KNX action datapoint '" + datapoint + "': " + value);Object val = value.get();DPTXlator translator = TypeMapper.toDPTXlator(datapoint, val);processCommunicator.write(datapoint.getMainAddress(), translator);@@ -301,12 +301,12 @@ public class KNXConnection implements NetworkLinkListener, ProcessListener {protected void getGroupAddressValue(GroupAddress groupAddress, Priority priority) {if (knxLink == null || !knxLink.isOpen()) {- LOG.finer("Cannot send read request not currently connected: " + groupAddress);+ LOG.finest("Cannot send read request not currently connected: " + groupAddress);return;}try {- LOG.finer("Sending read request to KNX group address: " + groupAddress);+ LOG.finest("Sending read request to KNX group address: " + groupAddress);this.knxLink.sendRequest(groupAddress, priority, DataUnitBuilder.createLengthOptimizedAPDU(0x00, null));} catch (Exception e) {LOG.log(Level.INFO, "Error sending KNX read request for group address: " + groupAddress, e);diff --git a/agent/src/main/java/org/openremote/agent/protocol/knx/TypeMapper.java b/agent/src/main/java/org/openremote/agent/protocol/knx/TypeMapper.javaindex e8a5649dd..0d0f09dde 100644--- a/agent/src/main/java/org/openremote/agent/protocol/knx/TypeMapper.java+++ b/agent/src/main/java/org/openremote/agent/protocol/knx/TypeMapper.java@@ -186,7 +186,7 @@ public class TypeMapper {}static public ValueDescriptor<?> toAttributeType(Datapoint datapoint) {- LOG.finer("toTypeClass looking for dptId = " + datapoint.getDPT());+ LOG.finest("toTypeClass looking for dptId = " + datapoint.getDPT());ValueDescriptor<?> t = dptToTypeMap.get(datapoint.getDPT());if (t == null) {diff --git a/agent/src/main/java/org/openremote/agent/protocol/mqtt/AbstractMQTT_IOClient.java b/agent/src/main/java/org/openremote/agent/protocol/mqtt/AbstractMQTT_IOClient.javaindex 8fcbd6951..e4028a3f4 100644--- a/agent/src/main/java/org/openremote/agent/protocol/mqtt/AbstractMQTT_IOClient.java+++ b/agent/src/main/java/org/openremote/agent/protocol/mqtt/AbstractMQTT_IOClient.java@@ -179,7 +179,7 @@ public abstract class AbstractMQTT_IOClient<S> implements IOClient<MQTTMessage<SLOG.log(Level.INFO, "Failed to publish to MQTT broker '" + getClientUri() + "'", throwable);} else {// Success- LOG.finer("Published message to MQTT broker '" + getClientUri() + "'");+ LOG.finest("Published message to MQTT broker '" + getClientUri() + "'");}});}@@ -343,7 +343,7 @@ public abstract class AbstractMQTT_IOClient<S> implements IOClient<MQTTMessage<Sreturn;}if (!disconnected) {- LOG.finer("Must be disconnected before calling connect: " + getClientUri());+ LOG.finest("Must be disconnected before calling connect: " + getClientUri());return;}diff --git a/agent/src/main/java/org/openremote/agent/protocol/simulator/SimulatorProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/simulator/SimulatorProtocol.javaindex abc7236dd..b533423cb 100644--- a/agent/src/main/java/org/openremote/agent/protocol/simulator/SimulatorProtocol.java+++ b/agent/src/main/java/org/openremote/agent/protocol/simulator/SimulatorProtocol.java@@ -106,7 +106,7 @@ public class SimulatorProtocol extends AbstractProtocol<SimulatorAgent, Simulato}// Assume write through and endpoint returned the value we sent- LOG.finer("Write to linked attribute so simulating that the endpoint returned the written value");+ LOG.finest("Write to linked attribute so simulating that the endpoint returned the written value");updateSensor(event.getAttributeRef(), processedValue);}@@ -135,7 +135,7 @@ public class SimulatorProtocol extends AbstractProtocol<SimulatorAgent, Simulato}protected ScheduledFuture<?> scheduleReplay(AttributeRef attributeRef, SimulatorReplayDatapoint[] simulatorReplayDatapoints) {- LOG.finer("Scheduling linked attribute replay update");+ LOG.finest("Scheduling linked attribute replay update");long now = LocalDateTime.now().get(ChronoField.SECOND_OF_DAY);diff --git a/agent/src/main/java/org/openremote/agent/protocol/tradfri/TradfriProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/tradfri/TradfriProtocol.javaindex 885b8b008..d5ddff1f3 100644--- a/agent/src/main/java/org/openremote/agent/protocol/tradfri/TradfriProtocol.java+++ b/agent/src/main/java/org/openremote/agent/protocol/tradfri/TradfriProtocol.java@@ -164,7 +164,7 @@ public class TradfriProtocol extends AbstractProtocol<TradfriAgent, DefaultAgent.collect(Collectors.toList());if (!obsoleteAssetIds.isEmpty()) {- LOG.finer("Removing " + obsoleteAssetIds.size() + " obsolete asset(s): " + this);+ LOG.finest("Removing " + obsoleteAssetIds.size() + " obsolete asset(s): " + this);assetService.deleteAssets(obsoleteAssetIds.toArray(new String[0]));}@@ -189,7 +189,7 @@ public class TradfriProtocol extends AbstractProtocol<TradfriAgent, DefaultAgent});if (!obsoleteAssetIds.isEmpty()) {- LOG.finer("Removing " + obsoleteAssetIds.size() + " obsolete asset(s): " + this);+ LOG.finest("Removing " + obsoleteAssetIds.size() + " obsolete asset(s): " + this);obsoleteAssetIds.forEach(this::removeDevice);assetService.deleteAssets(obsoleteAssetIds.toArray(new String[0]));}diff --git a/agent/src/main/java/org/openremote/agent/protocol/velbus/device/VelbusDevice.java b/agent/src/main/java/org/openremote/agent/protocol/velbus/device/VelbusDevice.javaindex 253ee652f..a69abe14d 100644--- a/agent/src/main/java/org/openremote/agent/protocol/velbus/device/VelbusDevice.java+++ b/agent/src/main/java/org/openremote/agent/protocol/velbus/device/VelbusDevice.java@@ -150,7 +150,7 @@ public class VelbusDevice {// Send the status request packets for this deviceif (isInitialisedAndValid() && featureProcessors != null) {- LOG.finer("Sending module status request packets");+ LOG.finest("Sending module status request packets");velbusNetwork.sendPackets(Arrays.stream(featureProcessors).flatMap(processor -> processor.getStatusRequestPackets(this).stream()).distinct().toArray(VelbusPacket[]::new));@@ -195,7 +195,7 @@ public class VelbusDevice {public void writeProperty(String property, Object value) {if (!isInitialisedAndValid()) {- LOG.finer("Ignoring property write as device is not initialised and/or it is invalid");+ LOG.finest("Ignoring property write as device is not initialised and/or it is invalid");return;}diff --git a/agent/src/main/java/org/openremote/agent/protocol/websocket/WebsocketAgentProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/websocket/WebsocketAgentProtocol.javaindex c44e412b6..ad462f5c2 100644--- a/agent/src/main/java/org/openremote/agent/protocol/websocket/WebsocketAgentProtocol.java+++ b/agent/src/main/java/org/openremote/agent/protocol/websocket/WebsocketAgentProtocol.java@@ -49,6 +49,7 @@ import java.net.URI;import java.net.URISyntaxException;import java.util.*;import java.util.concurrent.TimeUnit;+import java.util.concurrent.atomic.AtomicReference;import java.util.function.Consumer;import java.util.function.Supplier;import java.util.logging.Logger;@@ -73,18 +74,16 @@ public class WebsocketAgentProtocol extends AbstractNettyIOClientProtocol<Websocpublic static final String PROTOCOL_DISPLAY_NAME = "Websocket Client";private static final Logger LOG = SyslogCategory.getLogger(PROTOCOL, WebsocketAgentProtocol.class);public static final int CONNECTED_SEND_DELAY_MILLIS = 2000;- protected static final ResteasyClient resteasyClient;+ protected static final AtomicReference<ResteasyClient> resteasyClient = new AtomicReference<>();protected List<Runnable> protocolConnectedTasks;protected Map<AttributeRef, Runnable> attributeConnectedTasks;protected Map<String, List<String>> clientHeaders;protected final List<Pair<AttributeRef, Consumer<String>>> protocolMessageConsumers = new ArrayList<>();- static {- resteasyClient = createClient(org.openremote.container.Container.EXECUTOR_SERVICE);- }-public WebsocketAgentProtocol(WebsocketAgent agent) {super(agent);++ initClient();}@Override@@ -207,6 +206,14 @@ public class WebsocketAgentProtocol extends AbstractNettyIOClientProtocol<WebsocattributeConnectedTasks.remove(attributeRef);}+ protected static void initClient() {+ synchronized (resteasyClient) {+ if (resteasyClient.get() == null) {+ resteasyClient.set(createClient(org.openremote.container.Container.EXECUTOR_SERVICE));+ }+ }+ }+protected void onConnected() {// Look for any subscriptions that need to be processedif (protocolConnectedTasks != null) {@@ -293,7 +300,7 @@ public class WebsocketAgentProtocol extends AbstractNettyIOClientProtocol<Websoc});}- WebTargetBuilder webTargetBuilder = new WebTargetBuilder(resteasyClient, uri);+ WebTargetBuilder webTargetBuilder = new WebTargetBuilder(resteasyClient.get(), uri);if (headers != null) {webTargetBuilder.setInjectHeaders(headers);diff --git a/container/build.gradle b/container/build.gradleindex 3ca4cb688..7f9b2c1bc 100644--- a/container/build.gradle+++ b/container/build.gradle@@ -10,9 +10,9 @@ dependencies {api "org.codehaus.groovy:groovy-all:$groovyVersion"api "org.craftercms:groovy-sandbox:$groovySandboxVersion"- api "org.slf4j:slf4j-api:$slf4jVersion"+ // SLF4J JUL providerapi "org.slf4j:slf4j-jdk14:$slf4jVersion"- api "org.slf4j:jcl-over-slf4j:$slf4jVersion"+ // Log4J redirect to SLF4Japi "org.slf4j:log4j-over-slf4j:$slf4jVersion"api "com.devskiller.friendly-id:friendly-id:$friendlyIdVersion"@@ -46,18 +46,8 @@ dependencies {api "org.apache.camel:camel-jackson:$camelVersion"api "org.apache.camel:camel-snmp:$camelVersion"api "org.apache.camel:camel-health:$camelVersion"-- api("com.fasterxml.uuid:java-uuid-generator:$uuidGeneratorVersion") {- exclude group: "log4j"- }-- api("org.cyclopsgroup:jmxterm:$jmxtermVersion") {- exclude group: "javax.servlet"- exclude group: "log4j"- exclude group: "logkit"- exclude group: "commons-logging"- }-+ api "org.apache.camel:camel-management:$camelVersion"+ api("com.fasterxml.uuid:java-uuid-generator:$uuidGeneratorVersion")api "com.vladmihalcea:hibernate-types-52:$hibernateTypesVersion"}diff --git a/container/src/main/java/org/openremote/container/Container.java b/container/src/main/java/org/openremote/container/Container.javaindex 5bdcf6ebe..0c60eb684 100644--- a/container/src/main/java/org/openremote/container/Container.java+++ b/container/src/main/java/org/openremote/container/Container.java@@ -29,11 +29,9 @@ import org.openremote.model.util.ValueUtil;import java.util.*;import java.util.concurrent.ScheduledExecutorService;-import java.util.logging.Handler;-import java.util.logging.Level;-import java.util.logging.Logger;import java.util.stream.Collectors;+import static java.lang.System.Logger.Level.*;import static java.util.stream.StreamSupport.stream;import static org.openremote.container.util.MapAccess.getBoolean;import static org.openremote.container.util.MapAccess.getInteger;@@ -72,22 +70,20 @@ public class Container implements org.openremote.model.Container {}}- public static final Logger LOG;+ public static final System.Logger LOG = System.getLogger(Container.class.getName());public static ScheduledExecutorService EXECUTOR_SERVICE;public static final String OR_SCHEDULED_TASKS_THREADS_MAX = "OR_SCHEDULED_TASKS_THREADS_MAX";public static final int OR_SCHEDULED_TASKS_THREADS_MAX_DEFAULT = Math.max(Runtime.getRuntime().availableProcessors(), 2);-- static {- LogUtil.configureLogging();- LOG = Logger.getLogger(Container.class.getName());- }-protected final Map<String, String> config = new HashMap<>();protected final boolean devMode;protected Thread waitingThread;protected final Map<Class<? extends ContainerService>, ContainerService> services = new LinkedHashMap<>();+ static {+ LogUtil.initialiseJUL();+ }+/*** Discover {@link ContainerService}s using {@link ServiceLoader}; services are then ordered by* {@link ContainerService#getPriority}.@@ -126,14 +122,6 @@ public class Container implements org.openremote.model.Container {EXECUTOR_SERVICE = new NoShutdownScheduledExecutorService("Scheduled task", scheduledTasksThreadsMax);- // Any log handlers of the root logger that are container services must be registered- for (Handler handler : Logger.getLogger("").getHandlers()) {- if (handler instanceof ContainerService) {- ContainerService containerServiceLogHandler = (ContainerService) handler;- this.services.put(containerServiceLogHandler.getClass(), containerServiceLogHandler);- }- }-if (services != null) {services.forEach(svc -> this.services.put(svc.getClass(), svc));}@@ -157,33 +145,33 @@ public class Container implements org.openremote.model.Container {public synchronized void start() throws Exception {if (isRunning())return;- LOG.info(">>> Starting runtime container...");+ LOG.log(INFO, ">>> Starting runtime container...");try {for (ContainerService service : getServices()) {- LOG.info("Initializing service: " + service.getClass().getName());+ LOG.log(INFO, "Initializing service: " + service.getClass().getName());service.init(Container.this);}for (ContainerService service : getServices()) {- LOG.info("Starting service: " + service.getClass().getName());+ LOG.log(INFO, "Starting service: " + service.getClass().getName());service.start(Container.this);}} catch (Exception ex) {- LOG.log(Level.SEVERE, ">>> Runtime container startup failed", ex);+ LOG.log(ERROR, ">>> Runtime container startup failed", ex);throw ex;}- LOG.info(">>> Runtime container startup complete");+ LOG.log(INFO, ">>> Runtime container startup complete");}public synchronized void stop() {if (!isRunning())return;- LOG.info("<<< Stopping runtime container...");+ LOG.log(INFO, "<<< Stopping runtime container...");List<ContainerService> servicesToStop = Arrays.asList(getServices());Collections.reverse(servicesToStop);try {for (ContainerService service : servicesToStop) {- LOG.fine("Stopping service: " + service.getClass().getName());+ LOG.log(INFO, "Stopping service: " + service.getClass().getName());service.stop(this);}} catch (Exception ex) {@@ -191,15 +179,15 @@ public class Container implements org.openremote.model.Container {}try {- LOG.info("Cancelling scheduled tasks");+ LOG.log(INFO, "Cancelling scheduled tasks");((NoShutdownScheduledExecutorService) EXECUTOR_SERVICE).doShutdownNow();} catch (Exception e) {- LOG.log(Level.WARNING, "Exception thrown whilst trying to stop scheduled tasks", e);+ LOG.log(WARNING, "Exception thrown whilst trying to stop scheduled tasks", e);}waitingThread.interrupt();waitingThread = null;- LOG.info("<<< Runtime container stopped");+ LOG.log(INFO, "<<< Runtime container stopped");}/**diff --git a/container/src/main/java/org/openremote/container/message/MessageBrokerService.java b/container/src/main/java/org/openremote/container/message/MessageBrokerService.javaindex dd0db8109..f5cbb5770 100644--- a/container/src/main/java/org/openremote/container/message/MessageBrokerService.java+++ b/container/src/main/java/org/openremote/container/message/MessageBrokerService.java@@ -19,14 +19,12 @@*/package org.openremote.container.message;-import org.apache.camel.CamelContext;import org.apache.camel.FluentProducerTemplate;import org.apache.camel.ProducerTemplate;import org.apache.camel.builder.DefaultErrorHandlerBuilder;import org.apache.camel.component.snmp.SnmpComponent;import org.apache.camel.health.HealthCheckRegistry;import org.apache.camel.impl.DefaultCamelContext;-import org.apache.camel.impl.engine.DefaultHealthCheckResolver;import org.apache.camel.impl.engine.DefaultStreamCachingStrategy;import org.apache.camel.impl.health.ConsumersHealthCheckRepository;import org.apache.camel.impl.health.ContextHealthCheck;@@ -118,9 +116,6 @@ public class MessageBrokerService implements ContainerService {}});- // TODO make configurable in environment- context.disableJMX();-// TODO might need this for errorhandler?context.setAllowUseOriginalMessage(false);diff --git a/container/src/main/java/org/openremote/container/security/keycloak/KeycloakIdentityProvider.java b/container/src/main/java/org/openremote/container/security/keycloak/KeycloakIdentityProvider.javaindex 1c688aca2..bd157ec05 100644--- a/container/src/main/java/org/openremote/container/security/keycloak/KeycloakIdentityProvider.java+++ b/container/src/main/java/org/openremote/container/security/keycloak/KeycloakIdentityProvider.java@@ -193,7 +193,7 @@ public abstract class KeycloakIdentityProvider implements IdentityProvider {// The realm we authenticate against must be available as a request headerString realm = request.getHeader(REALM_PARAM_NAME);if (realm == null || realm.length() == 0) {- LOG.finer("No realm in request, no authentication will be attempted: " + request.getURI());+ LOG.finest("No realm in request, no authentication will be attempted: " + request.getURI());return notAuthenticatedKeycloakDeployment;}KeycloakDeployment keycloakDeployment = getKeycloakDeployment(realm, KEYCLOAK_CLIENT_ID);@@ -405,7 +405,7 @@ public abstract class KeycloakIdentityProvider implements IdentityProvider {return null;});} catch (Exception e) {- LOG.log(Level.WARNING, "Credentials are invalid", e);+ LOG.info("Credentials are invalid");return false;}@@ -428,7 +428,7 @@ public abstract class KeycloakIdentityProvider implements IdentityProvider {CacheLoader<KeycloakRealmClient, KeycloakDeployment> loader =new CacheLoader<KeycloakRealmClient, KeycloakDeployment>() {public KeycloakDeployment load(KeycloakRealmClient keycloakRealmClient) {- LOG.fine("Loading adapter config for client '" + keycloakRealmClient.clientId + "' in realm '" + keycloakRealmClient.realm + "'");+ LOG.finest("Loading adapter config for client '" + keycloakRealmClient.clientId + "' in realm '" + keycloakRealmClient.realm + "'");//KeycloakResource keycloak = getKeycloak();KeycloakResource keycloak = getTarget(httpClient, keycloakServiceUri.build(), null, null, null).proxy(KeycloakResource.class);@@ -492,6 +492,21 @@ public abstract class KeycloakIdentityProvider implements IdentityProvider {.map(Principal::getName).orElse(null);}+ public static String getSubjectName(Principal principal) {+ return Optional.ofNullable(principal).map(Principal::getName).orElse(null);+ }++ public static String getSubjectNameAndRealm(Principal principal) {+ return Optional.ofNullable(principal).map(p -> {+ if (p instanceof KeycloakPrincipal<?>) {+ String realm = ((KeycloakPrincipal<?>)p).getKeycloakSecurityContext().getRealm();+ return realm + ":" + p.getName();+ } else {+ return p.getName();+ }+ }).orElse(null);+ }+public static String getSubjectNameAndRealm(Subject subject) {if (subject == null || subject.getPrincipals() == null) {return null;diff --git a/container/src/main/java/org/openremote/container/timer/TimerService.java b/container/src/main/java/org/openremote/container/timer/TimerService.javaindex 8137ff491..c504dd2b4 100644--- a/container/src/main/java/org/openremote/container/timer/TimerService.java+++ b/container/src/main/java/org/openremote/container/timer/TimerService.java@@ -25,9 +25,6 @@ import org.openremote.model.rules.RulesClock;import java.time.Instant;import java.util.Date;-import java.util.concurrent.Executors;-import java.util.concurrent.ScheduledExecutorService;-import java.util.concurrent.ScheduledFuture;import java.util.concurrent.TimeUnit;import java.util.concurrent.atomic.AtomicLong;import java.util.logging.Logger;@@ -94,19 +91,23 @@ public class TimerService implements ContainerService, RulesClock {@Overridepublic long advanceTime(long amount, TimeUnit unit) {offset.addAndGet(unit.toMillis(amount));- return getCurrentTimeMillis();+ long currentMillis = getCurrentTimeMillis();+ LOG.info("Clock advanced to: " + (currentMillis) + "/" + new Date(currentMillis));+ return currentMillis;}@Overridepublic void stop() {if (stopTime == null) {stopTime = System.currentTimeMillis();+ LOG.info("Clock stopped at: " + (stopTime) + "/" + new Date(stopTime));}}@Overridepublic void start() {stopTime = null;+ LOG.info("Clock started at: " + (System.currentTimeMillis()) + "/" + new Date(System.currentTimeMillis()));}@Overridediff --git a/container/src/main/java/org/openremote/container/util/LogUtil.java b/container/src/main/java/org/openremote/container/util/LogUtil.javaindex b741c91a3..82d48a342 100644--- a/container/src/main/java/org/openremote/container/util/LogUtil.java+++ b/container/src/main/java/org/openremote/container/util/LogUtil.java@@ -1,5 +1,5 @@/*- * Copyright 2016, OpenRemote Inc.+ * Copyright 2023, OpenRemote Inc.** See the CONTRIBUTORS.txt file in the distribution for a* full listing of individual contributors.@@ -10,7 +10,7 @@* License, or (at your option) any later version.** This program is distributed in the hope that it will be useful,- * but WITHOUT ANY WARRANTY without even the implied warranty of+ * but WITHOUT ANY WARRANTY; without even the implied warranty of* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the* GNU Affero General Public License for more details.*@@ -19,9 +19,11 @@*/package org.openremote.container.util;-import org.openremote.model.Container;import org.openremote.model.util.TextUtil;+import org.slf4j.Logger;+import org.slf4j.LoggerFactory;+import java.io.IOException;import java.io.InputStream;import java.nio.file.Files;import java.nio.file.Path;@@ -31,63 +33,93 @@ import java.util.logging.LogManager;import static org.openremote.model.Container.OR_DEV_MODE;+/**+ * If system property <code>java.util.logging.config.file</code> or <code>java.util.logging.config.file</code> has been+ * set then the normal {@link LogManager#readConfiguration()} will be used, otherwise try to load the logging+ * configuration specified in environment variable <code>OR_LOGGING_CONFIG_FILE</code> as a file.+ * If this wasn't set, try to find the file <code>/deployment/manager/logging.properties</code>.+ * If this also wasn't found, load the given default logging configuration from the classpath+ * (logging-dev.properties when OR_DEV_MODE=true otherwise logging.properties).+ * <p>+ * This method should be called in a <code>static { ... }</code> block in the "first" class of your+ * application (typically where your <code>main()</code> method is located).+ */public class LogUtil {+ protected static final Logger LOG = LoggerFactory.getLogger(LogUtil.class);public static final String OR_LOGGING_CONFIG_FILE = "OR_LOGGING_CONFIG_FILE";- protected LogUtil() {+ public static void initialiseJUL() throws ExceptionInInitializerError {++ // Don't do anything if standard JUL system properties set+ if (!TextUtil.isNullOrEmpty(System.getProperty("java.util.logging.config.class"))) {+ LOG.info("Using specified java.util.logging.config.class system property: " + System.getProperty("java.util.logging.config.class"));+ return;+ }+ if (!TextUtil.isNullOrEmpty(System.getProperty("java.util.logging.config.file"))) {+ LOG.info("Using specified java.util.logging.config.file system property: " + System.getProperty("java.util.logging.config.file"));+ return;+ }++ InputStream configFile = getConfigInputStream();+ if (configFile != null) {+ try {+ LogManager.getLogManager().readConfiguration(configFile);+ } catch (IOException ex) {+ throw new ExceptionInInitializerError(ex);+ }+ }}- /**- * If system property <code>java.util.logging.config.file</code> has not been set, try to load the- * logging configuration specified in environment variable <code>OR_LOGGING_CONFIG_FILE</code> as a file.- * If this wasn't set, try to find the file <code>/deployment/manager/logging.properties</code>.- * If this also wasn't found, load the given default logging configuration from the classpath- * (logging-dev.properties when OR_DEV_MODE=true otherwise logging.properties).- * <p>- * This method should be called in a <code>static { ... }</code> block in the "first" class of your- * application (typically where your <code>main()</code> method is located).- */- public static void configureLogging() throws ExceptionInInitializerError {- // If no JUL configuration is provided- if (System.getProperty("java.util.logging.config.file") == null) {- boolean logConfigFound = false;- Path loggingConfigFile = !TextUtil.isNullOrEmpty(System.getenv(OR_LOGGING_CONFIG_FILE)) ? Paths.get(System.getenv(OR_LOGGING_CONFIG_FILE)) : null;-- // Load the logging configuration file specified with an environment variable- if (loggingConfigFile != null) {- if (Files.isReadable(loggingConfigFile)) {- System.out.println("Using logging configuration: " + loggingConfigFile.toAbsolutePath());-- try (InputStream is = Files.newInputStream(loggingConfigFile)) {- LogManager.getLogManager().readConfiguration(is);- logConfigFound = true;- } catch (Exception ex) {- throw new ExceptionInInitializerError(ex);- }- }+ protected static InputStream getConfigInputStream() {++ // Look for env variable config file+ boolean envConfigFileSet = !TextUtil.isNullOrEmpty(System.getenv(OR_LOGGING_CONFIG_FILE));+ if (envConfigFileSet) {+ InputStream configFile = getFileInputStream(System.getenv(OR_LOGGING_CONFIG_FILE));++ if (configFile != null) {+ LOG.info("Using logging configuration: " + System.getenv(OR_LOGGING_CONFIG_FILE));+ return configFile;}- if (!logConfigFound) {- // Look for logging config on the classpath (load a default configuration if none specified)- String devModeStr = System.getenv(OR_DEV_MODE);- boolean isDevMode = devModeStr == null || "TRUE".equals(devModeStr.toUpperCase(Locale.ROOT));- String loggingFile = loggingConfigFile != null ? loggingConfigFile.toString() : isDevMode ? "logging-dev.properties" : "logging.properties";-- try (InputStream is = Container.class.getClassLoader().getResourceAsStream(loggingFile)) {- if (is != null) {- System.out.println("Using logging configuration on classpath: " + loggingFile);- logConfigFound = true;- LogManager.getLogManager().readConfiguration(is);- }- } catch (Exception ex) {- throw new ExceptionInInitializerError(ex);- }+ // Look for the file on the classpath+ configFile = Thread.currentThread().getContextClassLoader().getResourceAsStream(System.getenv(OR_LOGGING_CONFIG_FILE));+ if (configFile != null) {+ LOG.info("Using logging configuration from classpath: " + System.getenv(OR_LOGGING_CONFIG_FILE));+ return configFile;}+ }- if (!logConfigFound) {- throw new ExceptionInInitializerError("OR_LOGGING_CONFIG_FILE is not readable: " + loggingConfigFile);+ // Use built in config on the classpath+ String devModeStr = System.getenv(OR_DEV_MODE);+ boolean isDevMode = devModeStr == null || "TRUE".equals(devModeStr.toUpperCase(Locale.ROOT));+ String loggingFile = isDevMode ? "logging-dev.properties" : "logging.properties";+ InputStream configFile = org.openremote.model.Container.class.getClassLoader().getResourceAsStream(loggingFile);++ if (configFile != null) {+ LOG.info("Using built in logging configuration from classpath: " + loggingFile);+ return configFile;+ }++ return null;+ }++ protected static InputStream getFileInputStream(String path) {+ if (TextUtil.isNullOrEmpty(path)) {+ return null;+ }++ Path loggingConfigFile = Paths.get(path);++ if (Files.isReadable(loggingConfigFile)) {+ try {+ return Files.newInputStream(loggingConfigFile);+ } catch (Exception ex) {+ throw new ExceptionInInitializerError(ex);}}++ return null;}}diff --git a/container/src/main/java/org/openremote/container/web/ClientRequestInfo.java b/container/src/main/java/org/openremote/container/web/ClientRequestInfo.javadeleted file mode 100644index 85de208e4..000000000--- a/container/src/main/java/org/openremote/container/web/ClientRequestInfo.java+++ /dev/null@@ -1,31 +0,0 @@-package org.openremote.container.web;--/**- * Details for a client web request, used when forwarding calls through reverse proxy.- */-public class ClientRequestInfo {-- final protected String remoteAddress;- final protected String accessToken;-- public ClientRequestInfo(String remoteAddress, String accessToken) {- this.remoteAddress = remoteAddress;- this.accessToken = accessToken;- }-- public String getRemoteAddress() {- return remoteAddress;- }-- public String getAccessToken() {- return accessToken;- }-- @Override- public String toString() {- return getClass().getSimpleName() + "{" +- "remoteAddress='" + remoteAddress + '\'' +- ", authToken='" + accessToken + '\'' +- '}';- }-}diff --git a/container/src/main/java/org/openremote/container/web/GZIPEncodingInterceptor.java b/container/src/main/java/org/openremote/container/web/GZIPEncodingInterceptor.javadeleted file mode 100644index 335a6f77f..000000000--- a/container/src/main/java/org/openremote/container/web/GZIPEncodingInterceptor.java+++ /dev/null@@ -1,104 +0,0 @@-package org.openremote.container.web;--import org.jboss.resteasy.util.CommitHeaderOutputStream;--import javax.annotation.Priority;-import javax.ws.rs.Priorities;-import javax.ws.rs.WebApplicationException;-import javax.ws.rs.core.HttpHeaders;-import javax.ws.rs.ext.Provider;-import javax.ws.rs.ext.WriterInterceptor;-import javax.ws.rs.ext.WriterInterceptorContext;-import java.io.IOException;-import java.io.OutputStream;-import java.util.zip.GZIPOutputStream;--import org.jboss.resteasy.resteasy_jaxrs.i18n.*;--/**- * See Resteasy source.- *- * @author <a href="mailto:[email protected]">Bill Burke</a>- * @version $Revision: 1 $- */-@Provider-@Priority(Priorities.ENTITY_CODER)-public class GZIPEncodingInterceptor implements WriterInterceptor {-- // TODO Allow this to be disabled, e.g. in tests with "fake" clients- final protected boolean enabled;-- public GZIPEncodingInterceptor(boolean enabled) {- this.enabled = enabled;- }-- public static class EndableGZIPOutputStream extends GZIPOutputStream {- public EndableGZIPOutputStream(OutputStream os) throws IOException {- super(os);- }-- @Override- public void finish() throws IOException {- super.finish();- def.end(); // make sure on finish the deflater's end() is called to release the native code pointer- }- }-- public static class CommittedGZIPOutputStream extends CommitHeaderOutputStream {- protected CommittedGZIPOutputStream(OutputStream delegate, CommitCallback headers) {- super(delegate, headers);- }-- protected GZIPOutputStream gzip;-- public GZIPOutputStream getGzip() {- return gzip;- }-- @Override- public synchronized void commit() {- if (isHeadersCommitted) return;- isHeadersCommitted = true;- try {- // GZIPOutputStream constructor writes to underlying OS causing headers to be written.- // so we swap gzip OS in when we are ready to write.- gzip = new EndableGZIPOutputStream(delegate);- delegate = gzip;- } catch (IOException e) {- throw new RuntimeException(e);- }- }- }-- @Override- public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {- LogMessages.LOGGER.debugf("Interceptor : %s, Method : aroundWriteTo", getClass().getName());-- // TODO Use a property because we can't call Response.setHeader() in our resources- Object encoding = context.getProperty(HttpHeaders.CONTENT_ENCODING);- // Object encoding = context.getHeaders().getFirst(HttpHeaders.CONTENT_ENCODING);-- if (enabled && encoding != null && encoding.toString().equalsIgnoreCase("gzip")) {- OutputStream old = context.getOutputStream();- // GZIPOutputStream constructor writes to underlying OS causing headers to be written.- CommittedGZIPOutputStream gzipOutputStream = new CommittedGZIPOutputStream(old, null);-- // Any content length set will be obsolete- context.getHeaders().remove("Content-Length");-- // TODO Also need to set the header here- context.getHeaders().add(HttpHeaders.CONTENT_ENCODING, "gzip");-- context.setOutputStream(gzipOutputStream);- try {- context.proceed();- } finally {- if (gzipOutputStream.getGzip() != null) gzipOutputStream.getGzip().finish();- context.setOutputStream(old);- }- return;- } else {- context.proceed();- }- }-}diff --git a/container/src/main/java/org/openremote/container/web/RequestLogger.java b/container/src/main/java/org/openremote/container/web/RequestLogger.javanew file mode 100644index 000000000..09fd17324--- /dev/null+++ b/container/src/main/java/org/openremote/container/web/RequestLogger.java@@ -0,0 +1,64 @@+/*+ * Copyright 2023, OpenRemote Inc.+ *+ * See the CONTRIBUTORS.txt file in the distribution for a+ * full listing of individual contributors.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <http://www.gnu.org/licenses/>.+ */+package org.openremote.container.web;++import org.openremote.container.security.keycloak.KeycloakIdentityProvider;+import org.openremote.model.syslog.SyslogCategory;++import javax.servlet.http.HttpServletRequest;+import javax.ws.rs.container.ContainerRequestContext;+import javax.ws.rs.container.ContainerRequestFilter;+import javax.ws.rs.core.Context;+import javax.ws.rs.core.HttpHeaders;+import javax.ws.rs.core.SecurityContext;+import javax.ws.rs.ext.Provider;+import java.io.IOException;++@Provider+public class RequestLogger implements ContainerRequestFilter {++ protected static final System.Logger LOG = System.getLogger(RequestLogger.class.getName() + "." + SyslogCategory.API.name());++ @Context+ private HttpServletRequest request;++ @Context+ protected SecurityContext securityContext;++ @Override+ public void filter(ContainerRequestContext requestContext) throws IOException {+ LOG.log(System.Logger.Level.DEBUG, () -> {+ String requestPath = request.getRequestURI();+ String address = request.getRemoteAddr();+ String port = String.valueOf(request.getRemotePort());+ String forwardedAddress = requestContext.getHeaderString("X-Forwarded-For");+ String method = requestContext.getMethod();+ String realm = requestContext.getHeaderString("Realm");+ String responseType = requestContext.getHeaderString(HttpHeaders.ACCEPT);+ String usernameAndRealm = securityContext != null+ ? KeycloakIdentityProvider.getSubjectNameAndRealm(securityContext.getUserPrincipal())+ : null;++ return "Client request '" + method + " " + requestPath +" (responseType=" + responseType+ + ")', requestRealm=" + realm + ", username="+ usernameAndRealm + ", origin="+ + address + ":" + port + ", forwarded-for=" + forwardedAddress;+ });+ }+}diff --git a/container/src/main/java/org/openremote/container/web/WebService.java b/container/src/main/java/org/openremote/container/web/WebService.javaindex 42f4abbb8..991c2387f 100644--- a/container/src/main/java/org/openremote/container/web/WebService.java+++ b/container/src/main/java/org/openremote/container/web/WebService.java@@ -20,6 +20,8 @@package org.openremote.container.web;import io.undertow.Undertow;+import io.undertow.security.api.SecurityContext;+import io.undertow.security.idm.Account;import io.undertow.server.HttpHandler;import io.undertow.server.HttpServerExchange;import io.undertow.server.handlers.RequestDumpingHandler;@@ -28,25 +30,29 @@ import io.undertow.servlet.api.DeploymentInfo;import io.undertow.servlet.api.DeploymentManager;import io.undertow.servlet.api.FilterInfo;import io.undertow.servlet.util.ImmediateInstanceHandle;+import io.undertow.util.HeaderMap;+import org.jboss.resteasy.plugins.interceptors.encoding.GZIPEncodingInterceptor;import org.jboss.resteasy.spi.ResteasyDeployment;import org.openremote.container.json.JacksonConfig;import org.openremote.container.security.CORSFilter;import org.openremote.container.security.IdentityService;+import org.openremote.container.security.keycloak.KeycloakIdentityProvider;import org.openremote.model.Container;import org.openremote.model.ContainerService;import org.openremote.model.util.TextUtil;import org.xnio.Options;import javax.servlet.DispatcherType;+import javax.ws.rs.core.HttpHeaders;import javax.ws.rs.core.UriBuilder;import java.net.Inet4Address;import java.net.URI;import java.util.*;import java.util.concurrent.atomic.AtomicReference;import java.util.function.Predicate;-import java.util.logging.Logger;import java.util.stream.Collectors;+import static java.lang.System.Logger.Level.*;import static org.openremote.container.util.MapAccess.*;import static org.openremote.model.Constants.OR_ADDITIONAL_HOSTNAMES;import static org.openremote.model.Constants.OR_HOSTNAME;@@ -90,7 +96,7 @@ public abstract class WebService implements ContainerService {public static final int OR_WEBSERVER_IO_THREADS_MAX_DEFAULT = Math.max(Runtime.getRuntime().availableProcessors(), 2);public static final String OR_WEBSERVER_WORKER_THREADS_MAX = "OR_WEBSERVER_WORKER_THREADS_MAX";public static final int WEBSERVER_WORKER_THREADS_MAX_DEFAULT = Math.max(Runtime.getRuntime().availableProcessors(), 10);- private static final Logger LOG = Logger.getLogger(WebService.class.getName());+ private static final System.Logger LOG = System.getLogger(WebService.class.getName());protected static AtomicReference<CORSFilter> corsFilterRef;protected boolean devMode;protected String host;@@ -137,7 +143,7 @@ public abstract class WebService implements ContainerService {public void start(Container container) throws Exception {if (undertow != null) {undertow.start();- LOG.info("Webserver ready on http://" + host + ":" + port);+ LOG.log(INFO, "Webserver ready on http://" + host + ":" + port);}}@@ -165,7 +171,7 @@ public abstract class WebService implements ContainerService {);identityService.secureDeployment(deploymentInfo);} else {- LOG.info("Deploying insecure web context: " + deploymentInfo.getContextPath());+ LOG.log(INFO, "Deploying insecure web context: " + deploymentInfo.getContextPath());}// This will catch anything not handled by Resteasy/Servlets, such as IOExceptions "at the wrong time"@@ -218,16 +224,31 @@ public abstract class WebService implements ContainerService {protected Undertow.Builder build(Container container, Undertow.Builder builder) {- LOG.info("Building web routing with handler(s): " + getRequestHandlers().stream().map(h -> h.name).collect(Collectors.joining("\n")));+ LOG.log(INFO, () -> "Building web routing with handler(s): " + getRequestHandlers().stream().map(h -> h.name).collect(Collectors.joining("\n")));HttpHandler handler = exchange -> {- String requestPath = exchange.getRequestPath();- LOG.fine("Handling request: " + exchange.getRequestMethod() + " " + exchange.getRequestPath());++ LOG.log(DEBUG, () -> {+ String requestPath = exchange.getRequestURI();+ String address = exchange.getSourceAddress().toString();+ HeaderMap headers = exchange.getRequestHeaders();+ String forwardedAddress = headers.getFirst("X-Forwarded-For");+ String responseType = headers.getFirst(HttpHeaders.ACCEPT);+ SecurityContext securityContext = exchange.getSecurityContext();+ Account account = securityContext != null ? securityContext.getAuthenticatedAccount() : null;+ String userAndRealm+ = account != null+ ? KeycloakIdentityProvider.getSubjectNameAndRealm(account.getPrincipal())+ : null;++ return "Client request '" + requestPath +" (responseType=" + responseType +")': user=" + userAndRealm + ", origin=" ++ address +", forwarded-for=" + forwardedAddress;+ });boolean handled = false;for (RequestHandler requestHandler : getRequestHandlers()) {if (requestHandler.handlePredicate.test(exchange)) {- LOG.fine("Handling '" + requestPath + "' with handler: " + requestHandler.name);+ LOG.log(TRACE, () -> "Handling '" + exchange.getRequestURI() + "' with handler: " + requestHandler.name);requestHandler.handler.handleRequest(exchange);handled = true;break;@@ -235,7 +256,7 @@ public abstract class WebService implements ContainerService {}if (!handled) {- LOG.warning("No handler found for request: " + exchange.getRequestPath());+ LOG.log(WARNING, "No handler found for request: " + exchange.getRequestURI());}};@@ -262,9 +283,12 @@ public abstract class WebService implements ContainerService {resteasyDeployment.getProviders().add(new WebServiceExceptions.ForbiddenResteasyExceptionMapper(devMode));resteasyDeployment.getProviders().add(new JacksonConfig());- resteasyDeployment.getProviders().add(new GZIPEncodingInterceptor(!container.isDevMode()));+ if (!container.isDevMode()) {+ resteasyDeployment.getProviders().add(GZIPEncodingInterceptor.class);+ }resteasyDeployment.getActualProviderClasses().add(AlreadyGzippedWriterInterceptor.class);resteasyDeployment.getActualProviderClasses().add(ClientErrorExceptionHandler.class);+ resteasyDeployment.getActualProviderClasses().add(RequestLogger.class);resteasyDeployment.setSecurityEnabled(secure);diff --git a/container/src/main/java/org/openremote/container/web/socket/WebsocketAdapter.java b/container/src/main/java/org/openremote/container/web/socket/WebsocketAdapter.javaindex d08930359..1b6458048 100644--- a/container/src/main/java/org/openremote/container/web/socket/WebsocketAdapter.java+++ b/container/src/main/java/org/openremote/container/web/socket/WebsocketAdapter.java@@ -19,8 +19,10 @@*/package org.openremote.container.web.socket;+import io.undertow.websockets.jsr.UndertowSession;import org.apache.camel.Exchange;import org.openremote.container.security.AuthContext;+import org.openremote.container.security.keycloak.KeycloakIdentityProvider;import org.openremote.container.web.ConnectionConstants;import org.openremote.model.Constants;@@ -45,10 +47,7 @@ public class WebsocketAdapter extends Endpoint {@Overridepublic void onOpen(Session session, EndpointConfig config) {- if (LOG.isLoggable(Level.FINE))- LOG.fine("Websocket session open: " + session.getId());- // TODO We never expire idle websocket sessions, the assumption is that only authenticated clients can- // open a session and if their SSO (managed by Keycloak) expires, they are logged out+ LOG.fine("Client connection created: " + sessionToString(session));session.setMaxIdleTimeout(0);consumer.getEndpoint().getWebsocketSessions().add(session);this.consumer.sendMessage(null, exchange -> {@@ -56,8 +55,8 @@ public class WebsocketAdapter extends Endpoint {exchange.getIn().setHeader(ConnectionConstants.SESSION_OPEN, true);});session.addMessageHandler(String.class, message -> {- if (LOG.isLoggable(Level.FINE)) {- LOG.fine("Websocket session " + session.getId() + " message received: " + message);+ if (LOG.isLoggable(Level.FINEST)) {+ LOG.finest("Websocket session '" + sessionToString(session) + "' message received: " + message);}this.consumer.sendMessage(message, exchange -> this.prepareExchange(exchange, session));});@@ -65,9 +64,7 @@ public class WebsocketAdapter extends Endpoint {@Overridepublic void onClose(Session session, CloseReason closeReason) {- if (LOG.isLoggable(Level.FINE)) {- LOG.fine("Websocket session close: " + session.getId() + " " + closeReason);- }+ LOG.fine("Client connection closed: " + sessionToString(session));this.consumer.sendMessage(closeReason, exchange -> {this.prepareExchange(exchange, session);exchange.getIn().setHeader(ConnectionConstants.SESSION_CLOSE, true);@@ -78,11 +75,9 @@ public class WebsocketAdapter extends Endpoint {@Overridepublic void onError(Session session, Throwable thr) {super.onError(session, thr);-// Ignore connection resetif (!(thr instanceof IOException && thr.getMessage().equals("Connection reset by peer"))) {- if (LOG.isLoggable(Level.INFO))- LOG.log(Level.INFO, "Websocket session error: " + session.getId(), thr);+ LOG.info("Client connection error: " + sessionToString(session));}this.consumer.sendMessage(thr, exchange -> {this.prepareExchange(exchange, session);@@ -91,6 +86,13 @@ public class WebsocketAdapter extends Endpoint {consumer.getEndpoint().getWebsocketSessions().remove(session);}+ protected String sessionToString(Session session) {+ UndertowSession undertowSession = ((UndertowSession) session);+ String sourceAddress = undertowSession.getWebSocketChannel().getSourceAddress().toString();+ String usernameAndRealm = KeycloakIdentityProvider.getSubjectNameAndRealm(undertowSession.getUserPrincipal());+ return "connection=" + sourceAddress + ", sessionID=" + session.getId() + ", subject=" + usernameAndRealm;+ }+protected void prepareExchange(Exchange exchange, Session session) {exchange.getIn().setHeader(ConnectionConstants.SESSION_KEY, session.getId());exchange.getIn().setHeader(Constants.AUTH_CONTEXT, getHandshakeAuth(session));diff --git a/container/src/main/java/org/openremote/container/web/socket/WebsocketProducer.java b/container/src/main/java/org/openremote/container/web/socket/WebsocketProducer.javaindex 9f1a755ff..29a6881e1 100644--- a/container/src/main/java/org/openremote/container/web/socket/WebsocketProducer.java+++ b/container/src/main/java/org/openremote/container/web/socket/WebsocketProducer.java@@ -97,7 +97,7 @@ public class WebsocketProducer extends DefaultProducer {if (session != null && session.isOpen()) {if (message instanceof String) {if (LOG.isLoggable(Level.FINE))- LOG.finer("Sending to session " + session.getId() + ": " + message);+ LOG.finest("Sending to session " + session.getId() + ": " + message);session.getBasicRemote().sendText((String) message);}}diff --git a/gradle.properties b/gradle.propertiesindex 6b9191966..5c2987145 100644--- a/gradle.properties+++ b/gradle.properties@@ -4,7 +4,7 @@ jaxrsSpecVersion = 2.0.1.FinaljavaxAnnotationsVersion = 2.0.1.FinaljavaxPersistenceVersion = 1.0.2.FinaljavaxELVersion = 2.2.6-slf4jVersion = 1.7.30+slf4jVersion = 2.0.6guavaVersion = 31.1-jreundertowVersion = 2.2.18.FinalresteasyVersion = 3.14.0.Final@@ -57,3 +57,4 @@ suncalcVersion=3.5snapshotsRepoUrl=https://s01.oss.sonatype.org/content/repositories/snapshots/releasesRepoUrl=https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/activeMQVersion = 2.26.0+jbossLoggingManagerVersion=2.1.19.Finaldiff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jarindex 457aad0d9..7454180f2 100644Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differdiff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.propertiesindex 84d1f85fd..070cb702f 100644--- a/gradle/wrapper/gradle-wrapper.properties+++ b/gradle/wrapper/gradle-wrapper.properties@@ -1,5 +1,5 @@distributionBase=GRADLE_USER_HOMEdistributionPath=wrapper/dists-distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip+distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zipzipStoreBase=GRADLE_USER_HOMEzipStorePath=wrapper/distsdiff --git a/gradlew b/gradlewindex af6708ff2..c53aefaa5 100755--- a/gradlew+++ b/gradlew@@ -1,78 +1,129 @@-#!/usr/bin/env sh+#!/bin/sh++#+# Copyright � 2015-2021 the original authors.+#+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# https://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+###############################################################################-##-## Gradle start up script for UN*X-##+#+# Gradle start up script for POSIX generated by Gradle.+#+# Important for running:+#+# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is+# noncompliant, but you have some other compliant shell such as ksh or+# bash, then to run this script, type that shell name before the whole+# command line, like:+#+# ksh Gradle+#+# Busybox and similar reduced shells will NOT work, because this script+# requires all of these POSIX shell features:+# * functions;+# * expansions �$var�, �${var}�, �${var:-default}�, �${var+SET}�,+# �${var#prefix}�, �${var%suffix}�, and �$( cmd )�;+# * compound commands having a testable exit status, especially �case�;+# * various built-in commands including �command�, �set�, and �ulimit�.+#+# Important for patching:+#+# (2) This script targets any POSIX shell, so it avoids extensions provided+# by Bash, Ksh, etc; in particular arrays are avoided.+#+# The "traditional" practice of packing multiple parameters into a+# space-separated string is a well documented source of bugs and security+# problems, so this is (mostly) avoided, by progressively accumulating+# options in "$@", and eventually passing that to Java.+#+# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,+# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;+# see the in-line comments for details.+#+# There are tweaks for specific operating systems such as AIX, CygWin,+# Darwin, MinGW, and NonStop.+#+# (3) This script is generated from the Groovy template+# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt+# within the Gradle project.+#+# You can find Gradle at https://github.com/gradle/gradle/.+################################################################################ Attempt to set APP_HOME+# Resolve links: $0 may be a link-PRG="$0"-# Need this for relative symlinks.-while [ -h "$PRG" ] ; do- ls=`ls -ld "$PRG"`- link=`expr "$ls" : '.*-> \(.*\)$'`- if expr "$link" : '/.*' > /dev/null; then- PRG="$link"- else- PRG=`dirname "$PRG"`"/$link"- fi+app_path=$0++# Need this for daisy-chained symlinks.+while+ APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path+ [ -h "$app_path" ]+do+ ls=$( ls -ld "$app_path" )+ link=${ls#*' -> '}+ case $link in #(+ /*) app_path=$link ;; #(+ *) app_path=$APP_HOME$link ;;+ esacdone-SAVED="`pwd`"-cd "`dirname \"$PRG\"`/" >/dev/null-APP_HOME="`pwd -P`"-cd "$SAVED" >/dev/null++APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exitAPP_NAME="Gradle"-APP_BASE_NAME=`basename "$0"`+APP_BASE_NAME=${0##*/}# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.-DEFAULT_JVM_OPTS='"-Xmx64m"'+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'# Use the maximum available, or set MAX_FD != -1 to use that value.-MAX_FD="maximum"+MAX_FD=maximumwarn () {echo "$*"-}+} >&2die () {echoecho "$*"echoexit 1-}+} >&2# OS specific support (must be 'true' or 'false').cygwin=falsemsys=falsedarwin=falsenonstop=false-case "`uname`" in- CYGWIN* )- cygwin=true- ;;- Darwin* )- darwin=true- ;;- MINGW* )- msys=true- ;;- NONSTOP* )- nonstop=true- ;;+case "$( uname )" in #(+ CYGWIN* ) cygwin=true ;; #(+ Darwin* ) darwin=true ;; #(+ MSYS* | MINGW* ) msys=true ;; #(+ NONSTOP* ) nonstop=true ;;esacCLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar+# Determine the Java command to use to start the JVM.if [ -n "$JAVA_HOME" ] ; thenif [ -x "$JAVA_HOME/jre/sh/java" ] ; then# IBM's JDK on AIX uses strange locations for the executables- JAVACMD="$JAVA_HOME/jre/sh/java"+ JAVACMD=$JAVA_HOME/jre/sh/javaelse- JAVACMD="$JAVA_HOME/bin/java"+ JAVACMD=$JAVA_HOME/bin/javafiif [ ! -x "$JAVACMD" ] ; thendie "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME@@ -81,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match thelocation of your Java installation."fielse- JAVACMD="java"+ JAVACMD=javawhich java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.Please set the JAVA_HOME variable in your environment to match the@@ -89,84 +140,95 @@ location of your Java installation."fi# Increase the maximum file descriptors if we can.-if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then- MAX_FD_LIMIT=`ulimit -H -n`- if [ $? -eq 0 ] ; then- if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then- MAX_FD="$MAX_FD_LIMIT"- fi- ulimit -n $MAX_FD- if [ $? -ne 0 ] ; then- warn "Could not set maximum file descriptor limit: $MAX_FD"- fi- else- warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"- fi+if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then+ case $MAX_FD in #(+ max*)+ MAX_FD=$( ulimit -H -n ) ||+ warn "Could not query maximum file descriptor limit"+ esac+ case $MAX_FD in #(+ '' | soft) :;; #(+ *)+ ulimit -n "$MAX_FD" ||+ warn "Could not set maximum file descriptor limit to $MAX_FD"+ esacfi-# For Darwin, add options to specify how the application appears in the dock-if $darwin; then- GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""-fi+# Collect all arguments for the java command, stacking in reverse order:+# * args from the command line+# * the main class name+# * -classpath+# * -D...appname settings+# * --module-path (only if needed)+# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.++# For Cygwin or MSYS, switch paths to Windows format before running java+if "$cygwin" || "$msys" ; then+ APP_HOME=$( cygpath --path --mixed "$APP_HOME" )+ CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )++ JAVACMD=$( cygpath --unix "$JAVACMD" )-# For Cygwin, switch paths to Windows format before running java-if $cygwin ; then- APP_HOME=`cygpath --path --mixed "$APP_HOME"`- CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`- JAVACMD=`cygpath --unix "$JAVACMD"`-- # We build the pattern for arguments to be converted via cygpath- ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`- SEP=""- for dir in $ROOTDIRSRAW ; do- ROOTDIRS="$ROOTDIRS$SEP$dir"- SEP="|"- done- OURCYGPATTERN="(^($ROOTDIRS))"- # Add a user-defined pattern to the cygpath arguments- if [ "$GRADLE_CYGPATTERN" != "" ] ; then- OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"- fi# Now convert the arguments - kludge to limit ourselves to /bin/sh- i=0- for arg in "$@" ; do- CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`- CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option-- if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition- eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`- else- eval `echo args$i`="\"$arg\""+ for arg do+ if+ case $arg in #(+ -*) false ;; # don't mess with options #(+ /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath+ [ -e "$t" ] ;; #(+ *) false ;;+ esac+ then+ arg=$( cygpath --path --ignore --mixed "$arg" )fi- i=$((i+1))+ # Roll the args list around exactly as many times as the number of+ # args, so each arg winds up back in the position where it started, but+ # possibly modified.+ #+ # NB: a `for` loop captures its iteration list before it begins, so+ # changing the positional parameters here affects neither the number of+ # iterations, nor the values presented in `arg`.+ shift # remove old arg+ set -- "$@" "$arg" # push replacement argdone- case $i in- (0) set -- ;;- (1) set -- "$args0" ;;- (2) set -- "$args0" "$args1" ;;- (3) set -- "$args0" "$args1" "$args2" ;;- (4) set -- "$args0" "$args1" "$args2" "$args3" ;;- (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;- (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;- (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;- (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;- (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;- esacfi-# Escape application args-save () {- for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done- echo " "-}-APP_ARGS=$(save "$@")--# Collect all arguments for the java command, following the shell quoting and substitution rules-eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"--# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong-if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then- cd "$(dirname "$0")"-fi+# Collect all arguments for the java command;+# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of+# shell script including quotes and variable substitutions, so put them in+# double quotes to make sure that they get re-expanded; and+# * put everything else in single quotes, so that it's not re-expanded.++set -- \+ "-Dorg.gradle.appname=$APP_BASE_NAME" \+ -classpath "$CLASSPATH" \+ org.gradle.wrapper.GradleWrapperMain \+ "$@"++# Use "xargs" to parse quoted args.+#+# With -n1 it outputs one arg per line, with the quotes and backslashes removed.+#+# In Bash we could simply go:+#+# readarray ARGS < <( xargs -n1 <<<"$var" ) &&+# set -- "${ARGS[@]}" "$@"+#+# but POSIX shell has neither arrays nor command substitution, so instead we+# post-process each arg (as a line of input to sed) to backslash-escape any+# character that might be a shell metacharacter, then use eval to reverse+# that process (while maintaining the separation between arguments), and wrap+# the whole thing up as a single "set" statement.+#+# This will of course break if any of these variables contains a newline or+# an unmatched quote.+#++eval "set -- $(+ printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |+ xargs -n1 |+ sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |+ tr '\n' ' '+ )" '"$@"'exec "$JAVACMD" "$@"diff --git a/gradlew.bat b/gradlew.batindex 6d57edc70..107acd32c 100644--- a/gradlew.bat+++ b/gradlew.bat@@ -1,3 +1,19 @@+@rem+@rem Copyright 2015 the original author or authors.+@rem+@rem Licensed under the Apache License, Version 2.0 (the "License");+@rem you may not use this file except in compliance with the License.+@rem You may obtain a copy of the License at+@rem+@rem https://www.apache.org/licenses/LICENSE-2.0+@rem+@rem Unless required by applicable law or agreed to in writing, software+@rem distributed under the License is distributed on an "AS IS" BASIS,+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+@rem See the License for the specific language governing permissions and+@rem limitations under the License.+@rem+@if "%DEBUG%" == "" @echo off@rem ##########################################################################@rem@@ -13,15 +29,18 @@ if "%DIRNAME%" == "" set DIRNAME=.set APP_BASE_NAME=%~n0set APP_HOME=%DIRNAME%+@rem Resolve any "." and ".." in APP_HOME to make it shorter.+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.-set DEFAULT_JVM_OPTS="-Xmx64m"+set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"@rem Find java.exeif defined JAVA_HOME goto findJavaFromJavaHomeset JAVA_EXE=java.exe%JAVA_EXE% -version >NUL 2>&1-if "%ERRORLEVEL%" == "0" goto init+if "%ERRORLEVEL%" == "0" goto executeecho.echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.@@ -35,7 +54,7 @@ goto failset JAVA_HOME=%JAVA_HOME:"=%set JAVA_EXE=%JAVA_HOME%/bin/java.exe-if exist "%JAVA_EXE%" goto init+if exist "%JAVA_EXE%" goto executeecho.echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%@@ -45,28 +64,14 @@ echo location of your Java installation.goto fail-:init-@rem Get command-line arguments, handling Windows variants--if not "%OS%" == "Windows_NT" goto win9xME_args--:win9xME_args-@rem Slurp the command line arguments.-set CMD_LINE_ARGS=-set _SKIP=2--:win9xME_args_slurp-if "x%~1" == "x" goto execute--set CMD_LINE_ARGS=%*-:execute@rem Setup the command lineset CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar+@rem Execute Gradle-"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*:end@rem End local scope for the variables with windows NT shelldiff --git a/manager/build.gradle b/manager/build.gradleindex a3682b332..e486628f9 100644--- a/manager/build.gradle+++ b/manager/build.gradle@@ -35,12 +35,13 @@ dependencies {implementation("org.apache.activemq:artemis-mqtt-protocol:$activeMQVersion") {exclude group: "org.osgi"- exclude group: "org.jboss.logging"+ exclude group: "org.jboss.logmanager"}// Needed for reference in testsapi("org.apache.activemq:artemis-server:$activeMQVersion") {exclude group: "org.osgi"+ exclude group: "org.jboss.logmanager"}implementation("org.quartz-scheduler:quartz:$quartzVersion") {@@ -48,6 +49,8 @@ dependencies {}implementation "org.shredzone.commons:commons-suncalc:$suncalcVersion"++ implementation "org.slf4j:slf4j-api:$slf4jVersion"}jar {diff --git a/manager/src/main/java/org/openremote/manager/agent/AgentService.java b/manager/src/main/java/org/openremote/manager/agent/AgentService.javaindex e33a9a5ba..2be99396e 100644--- a/manager/src/main/java/org/openremote/manager/agent/AgentService.java+++ b/manager/src/main/java/org/openremote/manager/agent/AgentService.java@@ -393,7 +393,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Asseprotocol.start(container);LOG.fine("Started protocol instance:" + protocol);- LOG.finer("Linking attributes to protocol instance: " + protocol);+ LOG.finest("Linking attributes to protocol instance: " + protocol);// Get all assets that have attributes with agent link meta for this agentList<Asset<?>> assets = assetStorageService.findAll(@@ -405,7 +405,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Asse));- LOG.finer("Found '" + assets.size() + "' asset(s) with attributes linked to this protocol instance: " + protocol);+ LOG.finest("Found '" + assets.size() + "' asset(s) with attributes linked to this protocol instance: " + protocol);assets.forEach(asset ->@@ -473,7 +473,7 @@ public class AgentService extends RouteBuilder implements ContainerService, AsseAttributeRef attributeRef = new AttributeRef(assetId, attribute.getName());try {if (!protocol.getLinkedAttributes().containsKey(attributeRef)) {- LOG.finer("Linking attribute '" + attributeRef + "' to protocol: " + protocol);+ LOG.finest("Linking attribute '" + attributeRef + "' to protocol: " + protocol);protocol.linkAttribute(assetId, attribute);}} catch (Exception ex) {@@ -497,7 +497,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Assetry {AttributeRef attributeRef = new AttributeRef(assetId, attribute.getName());if (protocol.getLinkedAttributes().containsKey(attributeRef)) {- LOG.finer("Unlinking attribute '" + attributeRef + "' to protocol: " + protocol);+ LOG.finest("Unlinking attribute '" + attributeRef + "' to protocol: " + protocol);protocol.unlinkAttribute(assetId, attribute);}} catch (Exception ex) {@@ -541,7 +541,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Asseagent.addOrReplaceAttributes(attribute);if (source == CLIENT && agent.isConfigurationAttribute(attribute.getName())) {- LOG.finer("Agent attribute event occurred from a client for an agent config attribute so updating: agent=" + agent.getId() + ", event=" + attributeEvent);+ LOG.finest("Agent attribute event occurred from a client for an agent config attribute so updating: agent=" + agent.getId() + ", event=" + attributeEvent);onAgentUpdated(agent);}}@@ -553,7 +553,7 @@ public class AgentService extends RouteBuilder implements ContainerService, AsseBoolean result = withLockReturning(getClass().getSimpleName() + "::processAssetUpdate", () ->attribute.getMetaValue(AGENT_LINK).map(agentLink -> {- LOG.finer("Attribute write for agent linked attribute: agent=" + agentLink.getId() + ", asset=" + asset.getId() + ", attribute=" + attribute.getName());+ LOG.finest("Attribute write for agent linked attribute: agent=" + agentLink.getId() + ", asset=" + asset.getId() + ", attribute=" + attribute.getName());messageBrokerService.getFluentProducerTemplate().withBody(attributeEvent)@@ -678,7 +678,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Asseprotected void notifyChildAssetChange(String agentId, PersistenceEvent<Asset<?>> assetPersistenceEvent) {withLock(getClass().getSimpleName() + "::notifyChildAssetChange", () ->childAssetSubscriptions.computeIfPresent(agentId, (id, consumerList) -> {- LOG.finer("Notifying child asset change consumers of change to agent child asset: Agent ID=" + id + ", Asset<?> ID=" + assetPersistenceEvent.getEntity().getId());+ LOG.finest("Notifying child asset change consumers of change to agent child asset: Agent ID=" + id + ", Asset<?> ID=" + assetPersistenceEvent.getEntity().getId());try {consumerList.forEach(consumer -> consumer.accept(assetPersistenceEvent));} catch (Exception e) {diff --git a/manager/src/main/java/org/openremote/manager/app/ConfigurationService.java b/manager/src/main/java/org/openremote/manager/app/ConfigurationService.javaindex 12167da36..af203c621 100644--- a/manager/src/main/java/org/openremote/manager/app/ConfigurationService.java+++ b/manager/src/main/java/org/openremote/manager/app/ConfigurationService.java@@ -90,6 +90,7 @@ public class ConfigurationService extends RouteBuilder implements ContainerServiLOG.log(Level.INFO, "Saving manager_config.json");try {OutputStream out = new FileOutputStream(new File(pathPublicRoot + "/manager_config.json"));+ out.close();ObjectMapper mapper = new ObjectMapper();mapperdiff --git a/manager/src/main/java/org/openremote/manager/asset/AssetProcessingService.java b/manager/src/main/java/org/openremote/manager/asset/AssetProcessingService.javaindex 534c6ccc0..65550971a 100644--- a/manager/src/main/java/org/openremote/manager/asset/AssetProcessingService.java+++ b/manager/src/main/java/org/openremote/manager/asset/AssetProcessingService.java@@ -20,7 +20,6 @@package org.openremote.manager.asset;import org.apache.camel.Exchange;-import org.apache.camel.FluentProducerTemplate;import org.apache.camel.Processor;import org.apache.camel.builder.RouteBuilder;import org.openremote.container.message.MessageBrokerService;@@ -49,6 +48,7 @@ import org.openremote.model.value.ValueType;import javax.persistence.EntityManager;import java.util.*;+import java.util.function.Supplier;import java.util.logging.Level;import java.util.logging.Logger;@@ -213,14 +213,14 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSer// Check realm against userif (!identityService.getIdentityProvider().isRealmActiveAndAccessible(authContext,requestedRealm)) {- LOG.fine("Realm is inactive, inaccessible or nonexistent: " + requestedRealm);+ LOG.info("Realm is inactive, inaccessible or nonexistent: " + requestedRealm);return false;}// Users must have write attributes roleif (authContext != null && !authContext.hasResourceRoleOrIsSuperUser(ClientRole.WRITE_ATTRIBUTES.getValue(),Constants.KEYCLOAK_CLIENT_ID)) {- LOG.finer("User doesn't have required role '" + ClientRole.WRITE_ATTRIBUTES + "': username=" + authContext.getUsername() + ", userRealm=" + authContext.getAuthenticatedRealmName());+ LOG.fine("User doesn't have required role '" + ClientRole.WRITE_ATTRIBUTES + "': username=" + authContext.getUsername() + ", userRealm=" + authContext.getAuthenticatedRealmName());return false;}@@ -231,10 +231,10 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSerAttribute<?> attribute = asset != null ? asset.getAttribute(attributeEvent.getAttributeName()).orElse(null) : null;if (asset == null || !asset.hasAttribute(attributeEvent.getAttributeName())) {- LOG.finer("Cannot authorize asset event as asset and/or attribute doesn't exist: " + attributeEvent.getAssetId());+ LOG.info("Cannot authorize asset event as asset and/or attribute doesn't exist: " + attributeEvent.getAssetId());return false;} else if (!Objects.equals(requestedRealm, asset.getRealm())) {- LOG.finer("Asset is not in the requested realm: requestedRealm=" + requestedRealm + ", ref=" + attributeEvent.getAttributeRef());+ LOG.info("Asset is not in the requested realm: requestedRealm=" + requestedRealm + ", ref=" + attributeEvent.getAttributeRef());return false;}@@ -244,19 +244,19 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSer// Must be asset linked to userif (!assetStorageService.isUserAsset(authContext.getUserId(),attributeEvent.getAssetId())) {- LOG.finer("User is not linked to asset '" + attributeEvent.getAssetId() + "': username=" + authContext.getUsername() + ", userRealm=" + authContext.getAuthenticatedRealmName());+ LOG.fine("Restricted user is not linked to asset '" + attributeEvent.getAssetId() + "': username=" + authContext.getUsername() + ", userRealm=" + authContext.getAuthenticatedRealmName());return false;}if (attribute == null || !attribute.getMetaValue(MetaItemType.ACCESS_RESTRICTED_WRITE).orElse(false)) {- LOG.finer("Asset attribute doesn't support restricted write on '" + attributeEvent.getAttributeRef() + "': username=" + authContext.getUsername() + ", userRealm=" + authContext.getAuthenticatedRealmName());+ LOG.fine("Asset attribute doesn't support restricted write on '" + attributeEvent.getAttributeRef() + "': username=" + authContext.getUsername() + ", userRealm=" + authContext.getAuthenticatedRealmName());return false;}}} else {// Check attribute has public write flag for anonymous writeif (attribute == null || !attribute.hasMeta(MetaItemType.ACCESS_PUBLIC_WRITE)) {- LOG.finer("Asset doesn't support public write on '" + attributeEvent.getAttributeRef() + "': username=null");+ LOG.fine("Asset doesn't support public write on '" + attributeEvent.getAttributeRef() + "': username=null");return false;}}@@ -295,6 +295,8 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSer.to(ASSET_QUEUE);// Process attribute events+ // TODO: Make SENDER much more granular (switch to microservices with RBAC)+ // TODO: Unify logging of attribute updates/* TODO This message consumer should be transactionally consistent with the database, this is currently not the caseOur "if I have not processed this message before" duplicate detection:@@ -371,7 +373,7 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSerObject value = event.getValue().map(eventValue -> {Class<?> attributeValueType = oldAttribute.getType().getType();return ValueUtil.getValueCoerced(eventValue, attributeValueType).orElseThrow(() -> {- LOG.fine("Failed to coerce attribute event value into the correct value type: event value type=" + eventValue.getClass() + ", attribute value type=" + attributeValueType);+ LOG.info("Failed to coerce attribute event value into the correct value type: realm=" + event.getRealm() + ", attribute=" + event.getAttributeRef() + ", event value type=" + eventValue.getClass() + ", attribute value type=" + attributeValueType);return new AssetProcessingException(INVALID_VALUE_FOR_WELL_KNOWN_ATTRIBUTE);});@@ -421,6 +423,10 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSerAttribute updatedAttribute = ValueUtil.clone(oldAttribute);updatedAttribute.setValue(value, eventTime);+ // Need to record time here otherwise an infinite loop generated inside one of the processors means the timestamp+ // is not updated so tests can't then detect the problem.+ lastProcessedEventTimestamp = System.currentTimeMillis();+// Push through all processorsprocessAssetUpdate(em, asset, updatedAttribute, source);});@@ -460,18 +466,22 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSerAttribute<?> attribute,Source source) throws AssetProcessingException {- String attributeStr = "Asset ID=" + asset.getId() + ", Asset name=" + asset.getName() + ", " + attribute;+ Supplier<String> attributeStrSupplier = () -> "Asset ID=" + asset.getId() + ", Asset name=" + asset.getName() + ", " + attribute;- LOG.finest(">>> Processing start: " + attributeStr);+ if (LOG.isLoggable(Level.FINEST)) {+ LOG.finest(">>> Attribute event processing start: " + attributeStrSupplier.get());+ }- // Need to record time here otherwise an infinite loop generated inside one of the processors means the timestamp- // is not updated so tests can't then detect the problem.- lastProcessedEventTimestamp = System.currentTimeMillis();String consumerProcessor = null;-boolean complete = false;+ long startMillis = System.currentTimeMillis();+for (AssetUpdateProcessor processor : processors) {- LOG.finest("==> Processor " + processor + " accepts: " + attributeStr);++ if (LOG.isLoggable(Level.FINEST)) {+ LOG.finest("==> Processor " + processor + " accepts: " + attributeStrSupplier.get());+ }+try {complete = processor.processAssetUpdate(em, asset, attribute, source);} catch (AssetProcessingException ex) {@@ -484,20 +494,12 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSer);}if (complete) {- if (LOG.isLoggable(Level.FINEST)) {- consumerProcessor = processor.toString();- LOG.finest("<== Processor " + consumerProcessor + " completely consumed (time since processing started=" + (System.currentTimeMillis() - lastProcessedEventTimestamp) + "ms): " + attributeStr);- }+ consumerProcessor = processor.toString();break;- } else {- if (LOG.isLoggable(Level.FINEST)) {- LOG.finest("<== Processor " + processor + " done (time since processing started=" + (System.currentTimeMillis() - lastProcessedEventTimestamp) + "ms): " + attributeStr);- }}}if (!complete) {- LOG.finest("No processor consumed the update completely, storing (time since processing started=" + (System.currentTimeMillis() - lastProcessedEventTimestamp) + "ms): " + attributeStr);if (!assetStorageService.updateAttributeValue(em, asset, attribute)) {throw new AssetProcessingException(STATE_STORAGE_FAILED, "database update failed, no rows updated"@@ -505,10 +507,9 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSer}}- if (consumerProcessor != null) {- LOG.fine("<<< Processing complete in " + (System.currentTimeMillis() - lastProcessedEventTimestamp) + "ms consumed by '" + consumerProcessor +"': " + attributeStr);- } else {- LOG.fine("<<< Processing complete in " + (System.currentTimeMillis() - lastProcessedEventTimestamp) + "ms: " + attributeStr);++ if (LOG.isLoggable(Level.FINE)) {+ LOG.fine("<<< Attribute event processed in " + (System.currentTimeMillis() - startMillis) + "ms: attribute=" + attributeStrSupplier.get() + ", consumer=" + consumerProcessor);}return complete;}diff --git a/manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.java b/manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.javaindex 22e9b4afe..d6856773d 100644--- a/manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.java+++ b/manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.java@@ -477,7 +477,7 @@ public class AssetResourceImpl extends ManagerWebResource implements AssetResour}if (asset == null) {- LOG.finer("No asset in request");+ LOG.finest("No asset in request");throw new WebApplicationException(BAD_REQUEST);}diff --git a/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java b/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.javaindex 583988ce8..2d1a98288 100644--- a/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java+++ b/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java@@ -75,6 +75,7 @@ import java.util.logging.Logger;import java.util.stream.Collectors;import java.util.stream.IntStream;+import static java.util.logging.Level.FINE;import static java.util.stream.Collectors.groupingBy;import static org.openremote.container.persistence.PersistenceService.PERSISTENCE_TOPIC;import static org.openremote.container.persistence.PersistenceService.isPersistenceEventForEntityType;@@ -452,21 +453,21 @@ public class AssetStorageService extends RouteBuilder implements ContainerServicif (!isSuperUser) {if (TextUtil.isNullOrEmpty(realm)) {String msg = "Realm must be specified to read assets";- LOG.finer(msg);+ LOG.finest(msg);return false;}if (isAnonymous) {if (query.access != null && query.access != PUBLIC) {String msg = "Only public access allowed for anonymous requests";- LOG.finer(msg);+ LOG.finest(msg);return false;}query.access = PUBLIC;} else if (isRestricted) {if (query.access == PRIVATE) {String msg = "Only public or restricted access allowed for restricted requests";- LOG.finer(msg);+ LOG.finest(msg);return false;}if (query.access == null) {@@ -476,13 +477,13 @@ public class AssetStorageService extends RouteBuilder implements ContainerServicif (query.access != PUBLIC && !authContext.hasResourceRole(ClientRole.READ_ASSETS.getValue(), Constants.KEYCLOAK_CLIENT_ID)) {String msg = "User must have '" + ClientRole.READ_ASSETS.getValue() + "' role to read non public assets";- LOG.finer(msg);+ LOG.finest(msg);return false;}if (query.access != PUBLIC && !realm.equals(authContext.getAuthenticatedRealmName())) {String msg = "Realm must match authenticated realm for non public access queries";- LOG.finer(msg);+ LOG.finest(msg);return false;}@@ -495,7 +496,7 @@ public class AssetStorageService extends RouteBuilder implements ContainerServicif (!identityService.getIdentityProvider().isRealmActiveAndAccessible(authContext, realm)) {String msg = "Realm is not present or is inactive";- LOG.finer(msg);+ LOG.finest(msg);return false;}@@ -637,8 +638,8 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic@SuppressWarnings("unchecked")public <T extends Asset<?>> T merge(T asset, boolean overrideVersion, boolean skipGatewayCheck, String userName) throws IllegalStateException, ConstraintViolationException {- if (LOG.isLoggable(Level.FINER)) {- LOG.finer("Merging asset: " + asset);+ if (LOG.isLoggable(Level.FINEST)) {+ LOG.finest("Merging asset: " + asset);}return persistenceService.doReturningTransaction(em -> {@@ -675,13 +676,13 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic// Verify type has not been changedif (!existingAsset.getType().equals(asset.getType())) {String msg = "Asset type cannot be changed: asset=" + asset;- LOG.info(msg);+ LOG.warning(msg);throw new IllegalStateException(msg);}if (!existingAsset.getRealm().equals(asset.getRealm())) {String msg = "Asset realm cannot be changed: asset=" + asset;- LOG.info(msg);+ LOG.warning(msg);throw new IllegalStateException(msg);}@@ -706,13 +707,13 @@ public class AssetStorageService extends RouteBuilder implements ContainerServicif (!identityService.getIdentityProvider().realmExists(asset.getRealm())) {String msg = "Asset realm not found or is inactive: asset=" + asset;- LOG.info(msg);+ LOG.warning(msg);throw new IllegalStateException(msg);}if (asset.getParentId() != null && asset.getParentId().equals(asset.getId())) {String msg = "Asset parent cannot be the asset: asset=" + asset;- LOG.info(msg);+ LOG.warning(msg);throw new IllegalStateException(msg);}@@ -725,21 +726,21 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic// The parent must existif (parent == null) {String msg = "Asset parent not found: asset=" + asset;- LOG.info(msg);+ LOG.warning(msg);throw new IllegalStateException(msg);}// The parent can not be a child of the assetif (parent.pathContains(asset.getId())) {String msg = "Asset parent cannot be a descendant of the asset: asset=" + asset;- LOG.info(msg);+ LOG.warning(msg);throw new IllegalStateException(msg);}// The parent should be in the same realmif (!parent.getRealm().equals(asset.getRealm())) {String msg = "Asset parent must be in the same realm: asset=" + asset;- LOG.info(msg);+ LOG.warning(msg);throw new IllegalStateException(msg);}@@ -748,7 +749,7 @@ public class AssetStorageService extends RouteBuilder implements ContainerServicString childAssetType = parent.getAttributes().getValue(GroupAsset.CHILD_ASSET_TYPE).orElseThrow(() -> {String msg = "Asset parent is of type GROUP but the childAssetType attribute is invalid: asset=" + asset;- LOG.info(msg);+ LOG.warning(msg);return new IllegalStateException(msg);});@@ -763,7 +764,7 @@ public class AssetStorageService extends RouteBuilder implements ContainerServicif (!typeMatch) {String msg = "Asset type does not match parent GROUP asset's childAssetType attribute: asset=" + asset;- LOG.info(msg);+ LOG.warning(msg);throw new IllegalStateException(msg);}}@@ -775,7 +776,7 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic.map(childAssetTypeString -> TextUtil.isNullOrEmpty(childAssetTypeString) ? null : childAssetTypeString).orElseThrow(() -> {String msg = "Asset of type GROUP childAssetType attribute must be a valid string: asset=" + asset;- LOG.info(msg);+ LOG.warning(msg);return new IllegalStateException(msg);});@@ -783,13 +784,13 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic.getChildAssetType().orElseThrow(() -> {String msg = "Asset of type GROUP childAssetType attribute must be a valid string: asset=" + asset;- LOG.info(msg);+ LOG.warning(msg);return new IllegalStateException(msg);}) : childAssetType;if (!childAssetType.equals(existingChildAssetType)) {String msg = "Asset of type GROUP so childAssetType attribute cannot be changed: asset=" + asset;- LOG.info(msg);+ LOG.warning(msg);throw new IllegalStateException(msg);}}@@ -809,15 +810,15 @@ public class AssetStorageService extends RouteBuilder implements ContainerServicuser = identityService.getIdentityProvider().getUserByUsername(asset.getRealm(), userName);if (user == null) {String msg = "User not found: " + userName;- LOG.info(msg);+ LOG.warning(msg);throw new IllegalStateException(msg);}}T updatedAsset = em.merge(asset);- if (LOG.isLoggable(Level.FINE)) {- LOG.fine("Asset merge took (ms): " + (System.currentTimeMillis() - startTime));+ if (LOG.isLoggable(FINE)) {+ LOG.fine("Asset merge took: " + (System.currentTimeMillis() - startTime) + "ms");}if (user != null) {@@ -1148,6 +1149,10 @@ public class AssetStorageService extends RouteBuilder implements ContainerServicUserAssetLink.class,null,null));++ if (LOG.isLoggable(FINE)) {+ LOG.fine("Deleted user asset links: count=" + userAssetLinks.size() + ", links=" + userAssetLinks.stream().map(Object::toString).collect(Collectors.joining(", ")));+ }}/**@@ -1195,7 +1200,9 @@ public class AssetStorageService extends RouteBuilder implements ContainerServicem.unwrap(Session.class).doWork(connection -> {- LOG.finest("Storing user assets: count=" + userAssets.size());+ if (LOG.isLoggable(FINE)) {+ LOG.fine("Storing user asset links: count=" + userAssets.size() + ", links=" + userAssets.stream().map(Object::toString).collect(Collectors.joining(", ")));+ }PreparedStatement st;try {@@ -1220,7 +1227,7 @@ public class AssetStorageService extends RouteBuilder implements ContainerServicnull));} catch (Exception e) {- String msg = "Failed to create user assets: count=" + userAssets.size();+ String msg = "Failed to create user asset links: count=" + userAssets.size();LOG.log(Level.WARNING, msg, e);throw new IllegalStateException(msg, e);}@@ -1277,7 +1284,7 @@ public class AssetStorageService extends RouteBuilder implements ContainerServicboolean containsCalendarPredicate = queryAndContainsCalendarPredicate.value;if (containsCalendarPredicate && (query.select != null && (query.select.attributes == null))) {- LOG.info("Asset query contains a calendar event predicate which requires the attribute values and types to be included in the select (as calendar event predicate is applied post DB query)");+ LOG.warning("Asset query contains a calendar event predicate which requires the attribute values and types to be included in the select (as calendar event predicate is applied post DB query)");throw new IllegalArgumentException("Asset query contains a calendar event predicate which requires the attribute values and types to be included in the select (as calendar event predicate is applied post DB query)");}@@ -1313,7 +1320,7 @@ public class AssetStorageService extends RouteBuilder implements ContainerServicreturn assets.stream().filter(asset -> calendarEventPredicateMatches(timerService::getCurrentTimeMillis, query, asset)).toList();}- if (LOG.isLoggable(Level.FINE)) {+ if (LOG.isLoggable(FINE)) {LOG.fine("Asset query took " + (System.currentTimeMillis() - startMillis) + "ms: return count=" + assets.size());}@@ -1417,8 +1424,8 @@ public class AssetStorageService extends RouteBuilder implements ContainerServicreturn;}- if (LOG.isLoggable(Level.FINER)) {- LOG.finer("Asset created: " + loadedAsset.toStringAll());+ if (LOG.isLoggable(Level.FINEST)) {+ LOG.finest("Asset created: " + loadedAsset.toStringAll());} else {LOG.fine("Asset created: " + loadedAsset);}@@ -1454,7 +1461,7 @@ public class AssetStorageService extends RouteBuilder implements ContainerServicreturn;}- LOG.finer("Asset updated: " + persistenceEvent);+ LOG.finest("Asset updated: " + persistenceEvent);clientEventService.publishEvent(new AssetEvent(AssetEvent.Cause.UPDATE, loadedAsset, persistenceEvent.getPropertyNames().toArray(String[]::new))@@ -1486,8 +1493,8 @@ public class AssetStorageService extends RouteBuilder implements ContainerServicbreak;case DELETE:- if (LOG.isLoggable(Level.FINER)) {- LOG.finer("Asset deleted: " + asset.toStringAll());+ if (LOG.isLoggable(Level.FINEST)) {+ LOG.finest("Asset deleted: " + asset.toStringAll());} else {LOG.fine("Asset deleted: " + asset);}diff --git a/manager/src/main/java/org/openremote/manager/asset/AttributeLinkingService.java b/manager/src/main/java/org/openremote/manager/asset/AttributeLinkingService.javaindex c751f7ae5..5fd3569a9 100644--- a/manager/src/main/java/org/openremote/manager/asset/AttributeLinkingService.java+++ b/manager/src/main/java/org/openremote/manager/asset/AttributeLinkingService.java@@ -128,14 +128,14 @@ public class AttributeLinkingService implements ContainerService, AssetUpdatePro}protected void sendAttributeEvent(AttributeEvent attributeEvent) {- LOG.finer("Sending attribute event for linked attribute: " + attributeEvent);+ LOG.finest("Sending attribute event for linked attribute: " + attributeEvent);assetProcessingService.sendAttributeEvent(attributeEvent, ATTRIBUTE_LINKING_SERVICE);}protected void processLinkedAttributeUpdate(EntityManager em, AttributeLink attributeLink, AttributeState attributeState) {if (attributeState == null)return;- LOG.finer("Processing attribute state for linked attribute");+ LOG.finest("Processing attribute state for linked attribute");if (attributeLink == null) {throw new AssetProcessingException(AttributeWriteFailure.INVALID_ATTRIBUTE_LINK);@@ -150,7 +150,7 @@ public class AttributeLinkingService implements ContainerService, AssetUpdatePro);if (sendConvertedValue.key) {- LOG.finer("Value converter matched ignore value");+ LOG.finest("Value converter matched ignore value");return;}diff --git a/manager/src/main/java/org/openremote/manager/datapoint/AbstractDatapointService.java b/manager/src/main/java/org/openremote/manager/datapoint/AbstractDatapointService.javaindex 5e2fd1772..d69e4fb09 100644--- a/manager/src/main/java/org/openremote/manager/datapoint/AbstractDatapointService.java+++ b/manager/src/main/java/org/openremote/manager/datapoint/AbstractDatapointService.java@@ -176,7 +176,7 @@ public abstract class AbstractDatapointService<T extends Datapoint> implements CAttributeRef attributeRef = new AttributeRef(assetId, attribute.getName());- getLogger().finer("Getting datapoints for: " + attributeRef);+ getLogger().finest("Getting datapoints for: " + attributeRef);return persistenceService.doReturningTransaction(entityManager ->diff --git a/manager/src/main/java/org/openremote/manager/datapoint/AssetDatapointService.java b/manager/src/main/java/org/openremote/manager/datapoint/AssetDatapointService.javaindex df3895996..24be39209 100644--- a/manager/src/main/java/org/openremote/manager/datapoint/AssetDatapointService.java+++ b/manager/src/main/java/org/openremote/manager/datapoint/AssetDatapointService.java@@ -131,7 +131,7 @@ public class AssetDatapointService extends AbstractDatapointService<AssetDatapoi}protected void purgeDataPoints() {- LOG.info("Starting data points purge daily task");+ LOG.info("Running data points purge daily task");try {// Get list of attributes that have custom durations@@ -183,8 +183,6 @@ public class AssetDatapointService extends AbstractDatapointService<AssetDatapoi} catch (Exception e) {LOG.log(Level.WARNING, "Failed to run data points purge", e);}-- LOG.info("Finished data points purge daily task");}protected String buildWhereClause(List<Pair<String, Attribute<?>>> attributes, boolean negate) {diff --git a/manager/src/main/java/org/openremote/manager/datapoint/AssetPredictedDatapointService.java b/manager/src/main/java/org/openremote/manager/datapoint/AssetPredictedDatapointService.javaindex 8e9ed5f3a..e2c6957e6 100644--- a/manager/src/main/java/org/openremote/manager/datapoint/AssetPredictedDatapointService.java+++ b/manager/src/main/java/org/openremote/manager/datapoint/AssetPredictedDatapointService.java@@ -107,7 +107,7 @@ public class AssetPredictedDatapointService extends AbstractDatapointService<Assprotected void purgeDataPoints() {try {// Purge data points not in the above list using default duration- LOG.finer("Purging predicted data points older than now");+ LOG.finest("Purging predicted data points older than now");doPurge("where dp.timestamp < :dt", Date.from(timerService.getNow().truncatedTo(HOURS)));} catch (Exception e) {LOG.log(Level.WARNING, "Failed to run data points purge", e);diff --git a/manager/src/main/java/org/openremote/manager/energy/EnergyOptimisationService.java b/manager/src/main/java/org/openremote/manager/energy/EnergyOptimisationService.javaindex d9f5d3d01..384b56fb3 100644--- a/manager/src/main/java/org/openremote/manager/energy/EnergyOptimisationService.java+++ b/manager/src/main/java/org/openremote/manager/energy/EnergyOptimisationService.java@@ -294,7 +294,7 @@ public class EnergyOptimisationService extends RouteBuilder implements ContainerassetOptimisationInstanceMap.put(optimisationAsset.getId(), new OptimisationInstance(optimisationAsset, optimiser, optimisationFuture));// Execute first optimisation at the period that started previous to now- LOG.finer(getLogPrefix(optimisationAsset.getId()) + "Running first optimisation for time '" + formatter.format(optimisationStartTime));+ LOG.finest(getLogPrefix(optimisationAsset.getId()) + "Running first optimisation for time '" + formatter.format(optimisationStartTime));executorService.execute(() -> {try {@@ -386,7 +386,7 @@ public class EnergyOptimisationService extends RouteBuilder implements Containerreturn;}- LOG.finer(getLogPrefix(optimisationAssetId) + "Running for time '" + formatter.format(optimisationTime));+ LOG.finest(getLogPrefix(optimisationAssetId) + "Running for time '" + formatter.format(optimisationTime));long startTimeMillis = timerService.getCurrentTimeMillis();EnergyOptimiser optimiser = optimisationInstance.energyOptimiser;@@ -587,9 +587,9 @@ public class EnergyOptimisationService extends RouteBuilder implements ContainercheckTimeoutAndThrow(optimisationAssetId, startTimeMillis);- if (LOG.isLoggable(Level.FINER)) {- LOG.finer(getLogPrefix(optimisationAssetId) + "Found plain consumer and producer child assets count=" + count.get());- LOG.finer("Calculated net power of consumers and producers: " + Arrays.toString(powerNets));+ if (LOG.isLoggable(Level.FINEST)) {+ LOG.finest(getLogPrefix(optimisationAssetId) + "Found plain consumer and producer child assets count=" + count.get());+ LOG.finest("Calculated net power of consumers and producers: " + Arrays.toString(powerNets));}// Get supplier costs for each interval@@ -611,7 +611,7 @@ public class EnergyOptimisationService extends RouteBuilder implements Containerdouble[] carbonImport = get24HAttributeValues(supplierAsset.getId(), supplierAsset.getAttribute(ElectricitySupplierAsset.CARBON_IMPORT).orElse(null), optimiser.getIntervalSize(), intervalCount, optimisationTime);double[] carbonExport = get24HAttributeValues(supplierAsset.getId(), supplierAsset.getAttribute(ElectricitySupplierAsset.CARBON_EXPORT).orElse(null), optimiser.getIntervalSize(), intervalCount, optimisationTime);- LOG.finer(getLogPrefix(optimisationAssetId) + "Adjusting costs to include some carbon weighting, financialWeightingImport=" + financialWeightingImport + ", financialWeightingExport=" + financialWeightingExport);+ LOG.finest(getLogPrefix(optimisationAssetId) + "Adjusting costs to include some carbon weighting, financialWeightingImport=" + financialWeightingImport + ", financialWeightingExport=" + financialWeightingExport);for (int i = 0; i < costsImport.length; i++) {costsImport[i] = (financialWeightingImport * costsImport[i]) + ((1-financialWeightingImport) * carbonImport[i]);@@ -619,9 +619,9 @@ public class EnergyOptimisationService extends RouteBuilder implements Container}}- if (LOG.isLoggable(Level.FINER)) {- LOG.finer(getLogPrefix(optimisationAssetId) + "Import costs: " + Arrays.toString(costsImport));- LOG.finer(getLogPrefix(optimisationAssetId) + "Export costs: " + Arrays.toString(costsExport));+ if (LOG.isLoggable(Level.FINEST)) {+ LOG.finest(getLogPrefix(optimisationAssetId) + "Import costs: " + Arrays.toString(costsImport));+ LOG.finest(getLogPrefix(optimisationAssetId) + "Export costs: " + Arrays.toString(costsExport));}// Savings variables@@ -648,7 +648,7 @@ public class EnergyOptimisationService extends RouteBuilder implements ContainercheckTimeoutAndThrow(optimisationAssetId, startTimeMillis);- LOG.finer(getLogPrefix(optimisationAssetId) + "Optimising power set points for storage asset: " + storageAsset);+ LOG.finest(getLogPrefix(optimisationAssetId) + "Optimising power set points for storage asset: " + storageAsset);if (!supportsExport && !supportsImport) {LOG.finest(getLogPrefix(optimisationAssetId) + "Storage asset doesn't support import or export: " + storageAsset.getId());@@ -683,7 +683,7 @@ public class EnergyOptimisationService extends RouteBuilder implements Containerint[][] energySchedule = energyLevelScheduleOptional.map(dayArr -> Arrays.stream(dayArr).map(hourArr -> Arrays.stream(hourArr).mapToInt(i -> i != null ? i : 0).toArray()).toArray(int[][]::new)).orElse(null);if (energySchedule != null) {- LOG.finer(getLogPrefix(optimisationAssetId) + "Applying energy schedule for storage asset: " + storageAsset.getId());+ LOG.finest(getLogPrefix(optimisationAssetId) + "Applying energy schedule for storage asset: " + storageAsset.getId());optimiser.applyEnergySchedule(energyLevelMins, energyLevelMaxs, energyCapacity, energySchedule, LocalDateTime.ofInstant(Instant.ofEpochMilli(timerService.getCurrentTimeMillis()), ZoneId.systemDefault()));}@@ -695,7 +695,7 @@ public class EnergyOptimisationService extends RouteBuilder implements ContainerFunction<Integer, Double> powerExportMaxCalculator = interval -> interval == 0 && !isConnected ? 0 : powerExportMax;if (hasEnergyMinRequirement) {- LOG.finer(getLogPrefix(optimisationAssetId) + "Normalising min energy requirements for storage asset: " + storageAsset.getId());+ LOG.finest(getLogPrefix(optimisationAssetId) + "Normalising min energy requirements for storage asset: " + storageAsset.getId());optimiser.normaliseEnergyMinRequirements(energyLevelMins, powerImportMaxCalculator, powerExportMaxCalculator, energyLevel);if (LOG.isLoggable(Level.FINEST)) {LOG.finest(getLogPrefix(optimisationAssetId) + "Min energy requirements for storage asset '" + storageAsset.getId() + "': " + Arrays.toString(energyLevelMins));@@ -712,7 +712,7 @@ public class EnergyOptimisationService extends RouteBuilder implements Containerif (i == 0) {if (!storageAssetConnected(storageAsset)) {- LOG.finer("Optimised storage asset not connected so interval 0 will not be counted or actioned: " + storageAsset.getId());+ LOG.finest("Optimised storage asset not connected so interval 0 will not be counted or actioned: " + storageAsset.getId());setpoints[i] = 0;continue;}@@ -870,7 +870,7 @@ public class EnergyOptimisationService extends RouteBuilder implements Containerboolean supportsExport = storageAsset.isSupportsExport().orElse(false);boolean supportsImport = storageAsset.isSupportsImport().orElse(false);- LOG.finer(getLogPrefix(optimisationAssetId) + "Optimising storage asset: " + storageAsset);+ LOG.finest(getLogPrefix(optimisationAssetId) + "Optimising storage asset: " + storageAsset);double energyCapacity = storageAsset.getEnergyCapacity().orElse(0d);double energyLevel = Math.min(energyCapacity, storageAsset.getEnergyLevel().orElse(-1d));@@ -892,7 +892,7 @@ public class EnergyOptimisationService extends RouteBuilder implements Container// If asset supports exporting energy (V2G, battery storage, etc.) then need to determine if there are// opportunities to export energy to save/earn, taking into consideration the cost of exporting from this assetif (supportsExport) {- LOG.finer(getLogPrefix(optimisationAssetId) + "Storage asset supports export so calculating export cost and power levels for each interval: " + storageAsset.getId());+ LOG.finest(getLogPrefix(optimisationAssetId) + "Storage asset supports export so calculating export cost and power levels for each interval: " + storageAsset.getId());// Find intervals that save/earn by exporting energy from this storage asset by looking at power levelsBiFunction<Integer, Double, double[]> exportOptimiser = optimiser.getExportOptimiser(powerNets, exportPowerLimits, costImports, costExports, storageAsset.getTariffExport().orElse(0d));exportCostAndPower = IntStream.range(0, intervalCount).mapToObj(it -> exportOptimiser.apply(it, powerExportMax))@@ -903,7 +903,7 @@ public class EnergyOptimisationService extends RouteBuilder implements Container// save/earn, taking into consideration the cost of importing to this asset, also need to ensure that min// energy demands are met.if (supportsImport) {- LOG.finer(getLogPrefix(optimisationAssetId) + "Storage asset supports import so calculating export cost and power levels for each interval: " + storageAsset.getId());+ LOG.finest(getLogPrefix(optimisationAssetId) + "Storage asset supports import so calculating export cost and power levels for each interval: " + storageAsset.getId());BiFunction<Integer, double[], double[]> importOptimiser = optimiser.getImportOptimiser(powerNets, importPowerLimits, costImports, costExports, storageAsset.getTariffImport().orElse(0d));importCostAndPower = IntStream.range(0, intervalCount).mapToObj(it -> importOptimiser.apply(it, new double[]{0d, powerImportMax})).toArray(double[][]::new);@@ -911,7 +911,7 @@ public class EnergyOptimisationService extends RouteBuilder implements Containerboolean hasEnergyMinRequirement = Arrays.stream(normalisedEnergyLevelMins).anyMatch(el -> el > 0);if (hasEnergyMinRequirement) {- LOG.finer(getLogPrefix(optimisationAssetId) + "Applying imports to achieve min energy level requirements for storage asset: " + storageAsset.getId());+ LOG.finest(getLogPrefix(optimisationAssetId) + "Applying imports to achieve min energy level requirements for storage asset: " + storageAsset.getId());optimiser.applyEnergyMinImports(importCostAndPower, normalisedEnergyLevelMins, powerSetpoints, energyLevelCalculator, importOptimiser, powerImportMaxCalculator);if (LOG.isLoggable(Level.FINEST)) {LOG.finest(getLogPrefix(optimisationAssetId) + "Setpoints to achieve min energy level requirements for storage asset '" + storageAsset.getId() + "': " + Arrays.toString(powerSetpoints));@@ -921,8 +921,8 @@ public class EnergyOptimisationService extends RouteBuilder implements Containeroptimiser.applyEarningOpportunities(importCostAndPower, exportCostAndPower, normalisedEnergyLevelMins, energyLevelMaxs, powerSetpoints, energyLevelCalculator, powerImportMaxCalculator, powerExportMaxCalculator);- if (LOG.isLoggable(Level.FINER)) {- LOG.finer(getLogPrefix(optimisationAssetId) + "Calculated earning opportunity power set points for storage asset '" + storageAsset.getId() + "': " + Arrays.toString(powerSetpoints));+ if (LOG.isLoggable(Level.FINEST)) {+ LOG.finest(getLogPrefix(optimisationAssetId) + "Calculated earning opportunity power set points for storage asset '" + storageAsset.getId() + "': " + Arrays.toString(powerSetpoints));}return powerSetpoints;diff --git a/manager/src/main/java/org/openremote/manager/energy/EnergyOptimiser.java b/manager/src/main/java/org/openremote/manager/energy/EnergyOptimiser.javaindex d77a07af9..5196643ce 100644--- a/manager/src/main/java/org/openremote/manager/energy/EnergyOptimiser.java+++ b/manager/src/main/java/org/openremote/manager/energy/EnergyOptimiser.java@@ -361,7 +361,7 @@ public class EnergyOptimiser {* updated as a result.*/public void applyEarningOpportunities(double[][] importCostAndPower, double[][] exportCostAndPower, double[] energyLevelMins, double[] energyLevelMaxs, double[] powerSetpoints, Function<Integer, Double> energyLevelCalculator, Function<Integer, Double> powerImportMaxCalculator, Function<Integer, Double> powerExportMaxCalculator) {- LOG.finer("Applying earning opportunities");+ LOG.finest("Applying earning opportunities");// Look for import and export earning opportunitiesdouble[][] primary = importCostAndPower != null ? importCostAndPower : exportCostAndPower; // Never null@@ -520,7 +520,7 @@ public class EnergyOptimiser {energySpaceMax = Math.min(energySpaceMax, energySpace);powerCapacity = Math.min(impPowerMax - powerSetpoints[interval], (energySpaceMax / intervalSize));powerSetpoints[interval] = powerSetpoints[interval] + powerCapacity;- LOG.finer("Applied import earning opportunity: set point=" + powerSetpoints[interval] + " (delta: " + powerCapacity + ")");+ LOG.finest("Applied import earning opportunity: set point=" + powerSetpoints[interval] + " (delta: " + powerCapacity + ")");}}@@ -660,7 +660,7 @@ public class EnergyOptimiser {energySurplusMax = Math.min(energySurplusMax, energySurplus);powerCapacity = Math.max(expPowerMax - powerSetpoints[interval], -1d * (energySurplusMax / intervalSize));powerSetpoints[interval] = powerSetpoints[interval] + powerCapacity;- LOG.finer("Applied export earning opportunity: interval=" + interval + ", set point=" + powerSetpoints[interval] + " (delta: " + powerCapacity + ")");+ LOG.finest("Applied export earning opportunity: interval=" + interval + ", set point=" + powerSetpoints[interval] + " (delta: " + powerCapacity + ")");}}diff --git a/manager/src/main/java/org/openremote/manager/energy/ForecastSolarService.java b/manager/src/main/java/org/openremote/manager/energy/ForecastSolarService.javaindex 221f09088..3f144f9e6 100644--- a/manager/src/main/java/org/openremote/manager/energy/ForecastSolarService.java+++ b/manager/src/main/java/org/openremote/manager/energy/ForecastSolarService.java@@ -34,6 +34,7 @@ import java.util.*;import java.util.concurrent.ScheduledExecutorService;import java.util.concurrent.ScheduledFuture;import java.util.concurrent.TimeUnit;+import java.util.concurrent.atomic.AtomicReference;import java.util.logging.Level;import java.util.logging.Logger;@@ -84,17 +85,11 @@ public class ForecastSolarService extends RouteBuilder implements ContainerServiprotected TimerService timerService;protected static final Logger LOG = SyslogCategory.getLogger(DATA, ForecastSolarService.class.getName());-- protected static ResteasyClient resteasyClient;+ protected static final AtomicReference<ResteasyClient> resteasyClient = new AtomicReference<>();protected ResteasyWebTarget forecastSolarTarget;private String forecastSolarApiKey;-private final Map<String, ScheduledFuture<?>> calculationFutures = new HashMap<>();- static {- resteasyClient = createClient(org.openremote.container.Container.EXECUTOR_SERVICE);- }-@SuppressWarnings("unchecked")@Overridepublic void configure() throws Exception {@@ -126,7 +121,9 @@ public class ForecastSolarService extends RouteBuilder implements ContainerServireturn;}- forecastSolarTarget = resteasyClient+ initClient();++ forecastSolarTarget = resteasyClient.get().target("https://api.forecast.solar/" + forecastSolarApiKey + "/estimate");container.getService(MessageBrokerService.class).getContext().addRoutes(this);@@ -158,6 +155,14 @@ public class ForecastSolarService extends RouteBuilder implements ContainerServinew ArrayList<>(calculationFutures.keySet()).forEach(this::stopProcessing);}+ protected static void initClient() {+ synchronized (resteasyClient) {+ if (resteasyClient.get() == null) {+ resteasyClient.set(createClient(org.openremote.container.Container.EXECUTOR_SERVICE));+ }+ }+ }+protected void processAttributeEvent(AttributeEvent attributeEvent) {processElectricityProducerSolarAssetAttributeEvent(attributeEvent);}diff --git a/manager/src/main/java/org/openremote/manager/energy/ForecastWindService.java b/manager/src/main/java/org/openremote/manager/energy/ForecastWindService.javaindex 749c6256a..877910ff0 100644--- a/manager/src/main/java/org/openremote/manager/energy/ForecastWindService.java+++ b/manager/src/main/java/org/openremote/manager/energy/ForecastWindService.java@@ -32,6 +32,7 @@ import java.util.Map;import java.util.concurrent.ScheduledExecutorService;import java.util.concurrent.ScheduledFuture;import java.util.concurrent.TimeUnit;+import java.util.concurrent.atomic.AtomicReference;import java.util.logging.Level;import java.util.logging.Logger;@@ -110,6 +111,7 @@ public class ForecastWindService extends RouteBuilder implements ContainerServicpublic static final String OR_OPEN_WEATHER_API_APP_ID = "OR_OPEN_WEATHER_API_APP_ID";protected static final Logger LOG = SyslogCategory.getLogger(DATA, ForecastWindService.class.getName());+ protected static final AtomicReference<ResteasyClient> resteasyClient = new AtomicReference<>();protected AssetStorageService assetStorageService;protected AssetProcessingService assetProcessingService;protected GatewayService gatewayService;@@ -117,18 +119,11 @@ public class ForecastWindService extends RouteBuilder implements ContainerServicprotected ClientEventService clientEventService;protected ScheduledExecutorService executorService;protected RulesService rulesService;--- protected static ResteasyClient resteasyClient;private ResteasyWebTarget weatherForecastWebTarget;private String openWeatherAppId;private final Map<String, ScheduledFuture<?>> calculationFutures = new HashMap<>();- static {- resteasyClient = createClient(org.openremote.container.Container.EXECUTOR_SERVICE);- }-@SuppressWarnings("unchecked")@Overridepublic void configure() throws Exception {@@ -159,7 +154,9 @@ public class ForecastWindService extends RouteBuilder implements ContainerServicreturn;}- weatherForecastWebTarget = resteasyClient+ initClient();++ weatherForecastWebTarget = resteasyClient.get().target("https://api.openweathermap.org/data/2.5").queryParam("units", "metric").queryParam("exclude", "minutely,daily,alerts")@@ -195,6 +192,14 @@ public class ForecastWindService extends RouteBuilder implements ContainerServicnew ArrayList<>(calculationFutures.keySet()).forEach(this::stopCalculation);}+ protected static void initClient() {+ synchronized (resteasyClient) {+ if (resteasyClient.get() == null) {+ resteasyClient.set(createClient(org.openremote.container.Container.EXECUTOR_SERVICE));+ }+ }+ }+protected void processAttributeEvent(AttributeEvent attributeEvent) {processElectricityProducerWindAssetAttributeEvent(attributeEvent);}diff --git a/manager/src/main/java/org/openremote/manager/event/ClientEventService.java b/manager/src/main/java/org/openremote/manager/event/ClientEventService.javaindex 3a20f3654..f5bf54783 100644--- a/manager/src/main/java/org/openremote/manager/event/ClientEventService.java+++ b/manager/src/main/java/org/openremote/manager/event/ClientEventService.java@@ -27,7 +27,6 @@ import org.openremote.container.timer.TimerService;import org.openremote.container.web.ConnectionConstants;import org.openremote.manager.gateway.GatewayService;import org.openremote.manager.mqtt.DefaultMQTTHandler;-import org.openremote.manager.mqtt.MQTTBrokerService;import org.openremote.manager.security.ManagerIdentityService;import org.openremote.manager.web.ManagerWebService;import org.openremote.model.Constants;@@ -45,6 +44,7 @@ import java.util.concurrent.ConcurrentMap;import java.util.concurrent.CopyOnWriteArraySet;import java.util.concurrent.ExecutorService;import java.util.function.Consumer;+import java.util.logging.Level;import java.util.logging.Logger;import static org.apache.camel.builder.PredicateBuilder.or;@@ -92,6 +92,7 @@ import static org.openremote.container.web.ConnectionConstants.SESSION_TERMINATO* </p></dd>* </dl>*/+// TODO: Implement session expiry based on security principalpublic class ClientEventService extends RouteBuilder implements ContainerService {protected static class SessionInfo {@@ -251,7 +252,7 @@ public class ClientEventService extends RouteBuilder implements ContainerService.when(header(ConnectionConstants.SESSION_OPEN)).process(exchange -> {String sessionKey = getSessionKey(exchange);- LOG.fine("Adding session: " + sessionKey);+ LOG.finest("Adding session: " + sessionKey);sessionKeyInfoMap.put(sessionKey, createSessionInfo(sessionKey, exchange));passToInterceptors(exchange);})@@ -262,7 +263,7 @@ public class ClientEventService extends RouteBuilder implements ContainerService)).process(exchange -> {String sessionKey = getSessionKey(exchange);- LOG.fine("Removing session: " + sessionKey);+ LOG.finest("Removing session: " + sessionKey);sessionKeyInfoMap.remove(sessionKey);eventSubscriptions.cancelAll(sessionKey);passToInterceptors(exchange);@@ -378,9 +379,9 @@ public class ClientEventService extends RouteBuilder implements ContainerServiceif (!authorized) {if (authContext != null) {- LOG.info("Client not authorised to subscribe: subscription=" + subscription + ", requestRealm=" + realm + ", username=" + authContext.getAuthenticatedRealmName() + ", userRealm=" + authContext.getAuthenticatedRealmName());+ LOG.fine("Client not authorised to subscribe: subscription=" + subscription + ", requestRealm=" + realm + ", username=" + authContext.getUsername() + ", userRealm=" + authContext.getAuthenticatedRealmName());} else {- LOG.info("Client not authorised to subscribe: subscription=" + subscription + ", requestRealm=" + realm + ", user=null");+ LOG.fine("Client not authorised to subscribe: subscription=" + subscription + ", requestRealm=" + realm + ", user=null");}}@@ -396,9 +397,9 @@ public class ClientEventService extends RouteBuilder implements ContainerServiceif (!authorized) {if (authContext != null) {- LOG.info("Client not authorised to send event: type=" + event.getEventType() + ", requestRealm=" + realm + ", username=" + authContext.getAuthenticatedRealmName() + ", userRealm=" + authContext.getAuthenticatedRealmName());+ LOG.fine("Client not authorised to send event: type=" + event.getEventType() + ", requestRealm=" + realm + ", username=" + authContext.getUsername() + ", userRealm=" + authContext.getAuthenticatedRealmName());} else {- LOG.info("Client not authorised to send event: type=" + event.getEventType() + ", requestRealm=" + realm + ", user=null");+ LOG.fine("Client not authorised to send event: type=" + event.getEventType() + ", requestRealm=" + realm + ", user=null");}}@@ -414,7 +415,9 @@ public class ClientEventService extends RouteBuilder implements ContainerServiceif (messageBrokerService != null && messageBrokerService.getFluentProducerTemplate() != null) {// Don't log that we are publishing a syslog event,if (!(event instanceof SyslogEvent)) {- LOG.finer("Publishing: " + event);+ if (LOG.isLoggable(Level.FINEST)) {+ LOG.finest("Publishing: " + event);+ }}messageBrokerService.getFluentProducerTemplate().withBody(event)@@ -425,10 +428,12 @@ public class ClientEventService extends RouteBuilder implements ContainerServicepublic void sendToSession(String sessionKey, Object data) {if (messageBrokerService != null && messageBrokerService.getFluentProducerTemplate() != null) {- LOG.finer("Sending to session '" + sessionKey + "': " + data);+ if (LOG.isLoggable(Level.FINEST)) {+ LOG.finest("Sending to session '" + sessionKey + "': " + data);+ }SessionInfo sessionInfo = sessionKeyInfoMap.get(sessionKey);if (sessionInfo == null) {- LOG.fine("Cannot send to requested session it doesn't exist or is disconnected");+ LOG.info("Cannot send to requested session it doesn't exist or is disconnected:" + sessionKey);return;}if (sessionInfo.connectionType.equals(HEADER_CONNECTION_TYPE_WEBSOCKET)) {@@ -464,7 +469,7 @@ public class ClientEventService extends RouteBuilder implements ContainerServiceinterceptor.accept(exchange);boolean stop = exchange.isRouteStop();if (stop) {- LOG.finer("Client event interceptor marked exchange as `stop routing`");+ LOG.finest("Client event interceptor marked exchange as `stop routing`");}return stop;}));diff --git a/manager/src/main/java/org/openremote/manager/event/EventSubscriptions.java b/manager/src/main/java/org/openremote/manager/event/EventSubscriptions.javaindex f83d940cf..09e6a5cc1 100644--- a/manager/src/main/java/org/openremote/manager/event/EventSubscriptions.java+++ b/manager/src/main/java/org/openremote/manager/event/EventSubscriptions.java@@ -87,7 +87,7 @@ public class EventSubscriptions {}protected void createOrUpdate(String sessionKey, EventSubscription<?> subscription) {- LOG.finer("For session '" + sessionKey + "', creating/updating: " + subscription);+ LOG.finest("Create/update subscription for session '" + sessionKey + "': " + subscription);SessionSubscriptions sessionSubscriptions =this.sessionSubscriptionIdMap.computeIfAbsent(sessionKey, k -> new SessionSubscriptions());sessionSubscriptions.createOrUpdate(subscription);@@ -100,7 +100,7 @@ public class EventSubscriptions {if (subscription.getEventType() == null && subscription.getSubscriptionId() == null) {return;}- LOG.finer("For session '" + sessionKey + "', cancelling: " + subscription);+ LOG.finest("Cancel subscription for session '" + sessionKey + "': " + subscription);SessionSubscriptions sessionSubscriptions = this.sessionSubscriptionIdMap.get(sessionKey);if (!TextUtil.isNullOrEmpty(subscription.getSubscriptionId())) {sessionSubscriptions.cancelById(subscription.getSubscriptionId());@@ -114,7 +114,7 @@ public class EventSubscriptions {protected void cancelAll(String sessionKey) {if (this.sessionSubscriptionIdMap.containsKey(sessionKey)) {- LOG.finer("Cancelling all subscriptions for session: " + sessionKey);+ LOG.finest("Cancelling all subscriptions for session: " + sessionKey);this.sessionSubscriptionIdMap.remove(sessionKey);}}@@ -140,7 +140,7 @@ public class EventSubscriptions {T filteredEvent = sessionSub.subscription.getFilter() == null ? event : sessionSub.subscription.getFilter().apply(event);if (filteredEvent != null) {- LOG.finer("Creating message for subscribed session '" + sessionKey + "': " + event);+ LOG.finest("Creating message for subscribed session '" + sessionKey + "': " + event);List<T> events = Collections.singletonList(event);TriggeredEventSubscription<T> triggeredEventSubscription = new TriggeredEventSubscription<>(events, sessionSub.subscriptionId);diff --git a/manager/src/main/java/org/openremote/manager/gateway/GatewayClientService.java b/manager/src/main/java/org/openremote/manager/gateway/GatewayClientService.javaindex e475c8fc4..4587193fa 100644--- a/manager/src/main/java/org/openremote/manager/gateway/GatewayClientService.java+++ b/manager/src/main/java/org/openremote/manager/gateway/GatewayClientService.java@@ -309,7 +309,7 @@ public class GatewayClientService extends RouteBuilder implements ContainerServiif (assetEvent.getCause() == AssetEvent.Cause.CREATE || assetEvent.getCause() == AssetEvent.Cause.UPDATE) {Asset asset = assetEvent.getAsset();asset.setRealm(connection.getLocalRealm());- LOG.finer("Request from central manager to create/update an asset: Realm=" + connection.getLocalRealm() + ", Asset<?> ID=" + asset.getId());+ LOG.finest("Request from central manager to create/update an asset: Realm=" + connection.getLocalRealm() + ", Asset<?> ID=" + asset.getId());try {asset = assetStorageService.merge(asset, true);} catch (Exception e) {@@ -318,7 +318,7 @@ public class GatewayClientService extends RouteBuilder implements ContainerServi}} else if (event instanceof DeleteAssetsRequestEvent) {DeleteAssetsRequestEvent deleteRequest = (DeleteAssetsRequestEvent)event;- LOG.finer("Request from central manager to delete asset(s): Realm=" + connection.getLocalRealm() + ", Asset<?> IDs=" + Arrays.toString(deleteRequest.getAssetIds().toArray()));+ LOG.finest("Request from central manager to delete asset(s): Realm=" + connection.getLocalRealm() + ", Asset<?> IDs=" + Arrays.toString(deleteRequest.getAssetIds().toArray()));boolean success = false;try {success = assetStorageService.delete(deleteRequest.getAssetIds());diff --git a/manager/src/main/java/org/openremote/manager/mqtt/ActiveMQORSecurityManager.java b/manager/src/main/java/org/openremote/manager/mqtt/ActiveMQORSecurityManager.javaindex f9d386529..3b8b78e2c 100644--- a/manager/src/main/java/org/openremote/manager/mqtt/ActiveMQORSecurityManager.java+++ b/manager/src/main/java/org/openremote/manager/mqtt/ActiveMQORSecurityManager.java@@ -166,14 +166,14 @@ public class ActiveMQORSecurityManager extends ActiveMQJAASSecurityManager {String topicClientID = MQTTHandler.topicClientID(topic);if (topicClientID == null) {- LOG.warning("Client ID not found but it must be included as the second token in the topic: topic=" + topic);+ LOG.info("Client ID not found but it must be included as the second token in the topic: topic=" + topic);return false;}RemotingConnection connection = RemotingConnectionPrincipal.getRemotingConnectionFromSubject(subject);if (connection == null) {- LOG.warning("Failed to find connection for the specified client ID: clientID=" + topicClientID);+ LOG.info("Failed to find connection for the specified client ID: clientID=" + topicClientID);return false;}@@ -184,7 +184,7 @@ public class ActiveMQORSecurityManager extends ActiveMQJAASSecurityManager {// See if a custom handler wants to handle authorisation for this topic pub/subfor (MQTTHandler handler : brokerService.getCustomHandlers()) {if (handler.handlesTopic(topic)) {- LOG.fine("Passing topic to handler for " + (isWrite ? "pub" : "sub") + ": handler=" + handler.getName() + ", topic=" + topic + ", " + brokerService.connectionToString(connection));+ LOG.finest("Passing topic to handler for " + (isWrite ? "pub" : "sub") + ": handler=" + handler.getName() + ", topic=" + topic + ", " + brokerService.connectionToString(connection));boolean result;if (isWrite) {@@ -193,15 +193,15 @@ public class ActiveMQORSecurityManager extends ActiveMQJAASSecurityManager {result = handler.checkCanSubscribe(connection, securityContext, topic);}if (result) {- LOG.info("Handler '" + handler.getName() + "' has authorised " + (isWrite ? "pub" : "sub") + ": topic=" + topic + ", " + brokerService.connectionToString(connection));+ LOG.finest("Handler '" + handler.getName() + "' has authorised " + (isWrite ? "pub" : "sub") + ": topic=" + topic + ", " + brokerService.connectionToString(connection));} else {- LOG.info("Handler '" + handler.getName() + "' has not authorised " + (isWrite ? "pub" : "sub") + ": topic=" + topic + ", " + brokerService.connectionToString(connection));+ LOG.finest("Handler '" + handler.getName() + "' has not authorised " + (isWrite ? "pub" : "sub") + ": topic=" + topic + ", " + brokerService.connectionToString(connection));}return result;}}- LOG.info("No handler has allowed " + (isWrite ? "pub" : "sub") + ": topic=" + topic + ", " + brokerService.connectionToString(connection));+ LOG.info("Un-supported request " + (isWrite ? "pub" : "sub") + ": topic=" + topic + ", " + brokerService.connectionToString(connection));return false;}diff --git a/manager/src/main/java/org/openremote/manager/mqtt/ConnectionMonitorHandler.java b/manager/src/main/java/org/openremote/manager/mqtt/ConnectionMonitorHandler.javaindex 6eb98de95..1b75c0826 100644--- a/manager/src/main/java/org/openremote/manager/mqtt/ConnectionMonitorHandler.java+++ b/manager/src/main/java/org/openremote/manager/mqtt/ConnectionMonitorHandler.java@@ -248,7 +248,7 @@ public class ConnectionMonitorHandler extends MQTTHandler {}protected void addSessionAttributes(String realm, List<Pair<String, Attribute<?>>> assetIdsAttrs) {- LOG.finer("Adding '" + assetIdsAttrs.size() + "' attributes(s) with user linked attributes in realm: " + realm);+ LOG.fine("Adding '" + assetIdsAttrs.size() + "' attributes(s) with user linked attributes in realm: " + realm);List<String> usernames = assetIdsAttrs.stream().map(assetIdAttr -> assetIdAttr.getValue().getMetaValue(USER_CONNECTED).orElse(null)).filter(Objects::nonNull)@@ -264,7 +264,7 @@ public class ConnectionMonitorHandler extends MQTTHandler {String userID = userIds.get(usernames.indexOf(User.SERVICE_ACCOUNT_PREFIX + username));if (userID == null) {- LOG.warning("Invalid username so skipping: " + username);+ LOG.warning("Invalid username so skipping add session attributes: realm=" + realm + ", username=" + username);} else {addSessionAttribute(userID, new AttributeRef(assetIdAttr.key, assetIdAttr.getValue().getName()));}@@ -303,7 +303,7 @@ public class ConnectionMonitorHandler extends MQTTHandler {}}- LOG.finer("Updating connected status for '" + userID + "' on " + attributeRefs.size() + " attribute(s) connected=" + connected);+ LOG.fine("Updating connected status for '" + userID + "' on " + attributeRefs.size() + " attribute(s) connected=" + connected);attributeRefs.forEach(attributeRef ->assetProcessingService.sendAttributeEvent(new AttributeEvent(attributeRef, connected)));}diff --git a/manager/src/main/java/org/openremote/manager/mqtt/DefaultMQTTHandler.java b/manager/src/main/java/org/openremote/manager/mqtt/DefaultMQTTHandler.javaindex 8574424a9..0a49856ed 100644--- a/manager/src/main/java/org/openremote/manager/mqtt/DefaultMQTTHandler.java+++ b/manager/src/main/java/org/openremote/manager/mqtt/DefaultMQTTHandler.java@@ -123,8 +123,6 @@ public class DefaultMQTTHandler extends MQTTHandler {}}})- .otherwise()- .process(exchange -> LOG.fine("Unsupported message body: " + exchange.getIn().getBody())).end();}});@@ -196,14 +194,14 @@ public class DefaultMQTTHandler extends MQTTHandler {public boolean canSubscribe(RemotingConnection connection, KeycloakSecurityContext securityContext, Topic topic) {if (!isKeycloak) {- LOG.fine("Identity provider is not keycloak");+ LOG.finest("Identity provider is not keycloak");return false;}AuthContext authContext = getAuthContextFromSecurityContext(securityContext);if (authContext == null) {- LOG.fine("Anonymous connection not supported: topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));+ LOG.finest("Anonymous connection not supported: topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));return false;}@@ -211,58 +209,58 @@ public class DefaultMQTTHandler extends MQTTHandler {boolean isAssetTopic = isAssetTopic(topic);if (!isAssetTopic && !isAttributeTopic) {- LOG.fine("Topic must have 3 or more tokens and third token must be 'asset, attribute or attributevalue': topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));+ LOG.finest("Topic must have 3 or more tokens and third token must be 'asset, attribute or attributevalue': topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));return false;}if (isAssetTopic) {if (topic.getTokens().size() < 4 || topic.getTokens().size() > 5) {- LOG.fine("Asset subscribe token count should be 4 or 5: topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));+ LOG.finest("Asset subscribe token count should be 4 or 5: topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));return false;}if (topic.getTokens().size() == 4) {if (!Pattern.matches(ASSET_ID_REGEXP, topicTokenIndexToString(topic, 3))&& !TOKEN_MULTI_LEVEL_WILDCARD.equals(topicTokenIndexToString(topic, 3))&& !TOKEN_SINGLE_LEVEL_WILDCARD.equals(topicTokenIndexToString(topic, 3))) {- LOG.fine("Asset subscribe forth token must be an asset ID or wildcard: topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));+ LOG.finest("Asset subscribe forth token must be an asset ID or wildcard: topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));return false;}} else if (topic.getTokens().size() == 5) {if (!Pattern.matches(ASSET_ID_REGEXP, topicTokenIndexToString(topic, 3))) {- LOG.fine("Asset subscribe forth token must be an asset ID: topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));+ LOG.finest("Asset subscribe forth token must be an asset ID: topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));return false;}if (!TOKEN_MULTI_LEVEL_WILDCARD.equals(topicTokenIndexToString(topic, 4))&& !TOKEN_SINGLE_LEVEL_WILDCARD.equals(topicTokenIndexToString(topic, 4))) {- LOG.fine("Asset subscribe fifth token must be a wildcard: topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));+ LOG.finest("Asset subscribe fifth token must be a wildcard: topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));return false;}}} else {// Attribute topicif (topic.getTokens().size() < 5 || topic.getTokens().size() > 6) {- LOG.fine("Attribute subscribe token count should be 5 or 6: topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));+ LOG.finest("Attribute subscribe token count should be 5 or 6: topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));return false;}if (topic.getTokens().size() == 5) {if (TOKEN_MULTI_LEVEL_WILDCARD.equals(topicTokenIndexToString(topic, 3))) {- LOG.fine("Attribute subscribe multi level wildcard must be last token: topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));+ LOG.finest("Attribute subscribe multi level wildcard must be last token: topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));return false;}if (!Pattern.matches(ASSET_ID_REGEXP, topicTokenIndexToString(topic, 4))&& !TOKEN_MULTI_LEVEL_WILDCARD.equals(topicTokenIndexToString(topic, 4))&& !TOKEN_SINGLE_LEVEL_WILDCARD.equals(topicTokenIndexToString(topic, 4))) {- LOG.fine("Attribute subscribe fifth token must be an asset ID or a wildcard: topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));+ LOG.finest("Attribute subscribe fifth token must be an asset ID or a wildcard: topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));return false;}} else if (topic.getTokens().size() == 6) {if (!Pattern.matches(ASSET_ID_REGEXP, topicTokenIndexToString(topic, 4))) {- LOG.fine("Attribute subscribe fifth token must be an asset ID: topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));+ LOG.finest("Attribute subscribe fifth token must be an asset ID: topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));return false;}if (!TOKEN_MULTI_LEVEL_WILDCARD.equals(topicTokenIndexToString(topic, 5))&& !TOKEN_SINGLE_LEVEL_WILDCARD.equals(topicTokenIndexToString(topic, 5))) {- LOG.fine("Attribute subscribe sixth token must be a wildcard: topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));+ LOG.finest("Attribute subscribe sixth token must be a wildcard: topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));return false;}}@@ -272,7 +270,7 @@ public class DefaultMQTTHandler extends MQTTHandler {AssetFilter<?> filter = buildAssetFilter(topic);if (filter == null) {- LOG.fine("Failed to process subscription topic: topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));+ LOG.finest("Failed to process subscription topic: topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));return false;}@@ -282,54 +280,31 @@ public class DefaultMQTTHandler extends MQTTHandler {);if (!clientEventService.authorizeEventSubscription(topicRealm(topic), authContext, subscription)) {- LOG.fine("Subscription was not authorised for this user and topic: topic=" + topic + ", subject=" + authContext);+ LOG.finest("Subscription was not authorised for this user and topic: topic=" + topic + ", subject=" + authContext);return false;}return true;--// Asset<?> asset;-// if(identityProvider.isRestrictedUser(authContext.getUserId())) {-// Optional<UserAssetLink> userAsset = assetStorageService.findUserAssets(connection.realm, authContext.getUserId(), assetId).stream().findFirst();-// asset = userAsset.map(value -> assetStorageService.find(value.getId().getAssetId())).orElse(null);-// } else {-// asset = assetStorageService.find(assetId, false);-// }-//-// if (asset == null) {-// LOG.fine("Asset not found for topic '" + topic + "': " + connection);-// return false;-// }-//-// if (isAttributeTopic && topicTokenCountGreaterThan(topic, 4)-// && !(Token.topic.getTokens().get(4)SINGLE_LEVEL_WILDCARD.equals(topicTokens.get(4)) || MULTI_LEVEL_WILDCARD.equals(topicTokens.get(4)))) {-// String attributeName = topicTokens.get(4);-//-// if (!asset.hasAttribute(attributeName)) {-// LOG.fine("Asset attribute not found for topic '" + topic + "': " + connection);-// return false;-// }-// }}@Overridepublic boolean canPublish(RemotingConnection connection, KeycloakSecurityContext securityContext, Topic topic) {if (!isKeycloak) {- LOG.fine("Identity provider is not keycloak");+ LOG.finest("Identity provider is not keycloak");return false;}AuthContext authContext = getAuthContextFromSecurityContext(securityContext);if (authContext == null) {- LOG.fine("Anonymous publish not supported: topic=" + topic + ", connection=" + mqttBrokerService.connectionToString(connection));+ LOG.finest("Anonymous publish not supported: topic=" + topic + ", connection=" + mqttBrokerService.connectionToString(connection));return false;}if (isAttributeValueWriteTopic(topic)) {if (topic.getTokens().size() != 5 || !Pattern.matches(ASSET_ID_REGEXP, topicTokenIndexToString(topic, 4))) {- LOG.fine("Publish attribute value topic should be {realm}/{clientId}/writeattributevalue/{attributeName}/{assetId}: topic=" + topic + ", connection=" + mqttBrokerService.connectionToString(connection));+ LOG.finest("Publish attribute value topic should be {realm}/{clientId}/writeattributevalue/{attributeName}/{assetId}: topic=" + topic + ", connection=" + mqttBrokerService.connectionToString(connection));return false;}} else {@@ -339,7 +314,7 @@ public class DefaultMQTTHandler extends MQTTHandler {// We don't know the value at this point so just use a null value for authorization (value type will be handled// when the event is processed)if (!clientEventService.authorizeEventWrite(topicRealm(topic), authContext, buildAttributeEvent(topic.getTokens(), null))) {- LOG.info("Publish was not authorised for this user and topic: topic=" + topic + ", subject=" + authContext);+ LOG.finest("Publish was not authorised for this user and topic: topic=" + topic + ", subject=" + authContext);return false;}@@ -356,7 +331,7 @@ public class DefaultMQTTHandler extends MQTTHandler {Class subscriptionClass = isAssetTopic ? AssetEvent.class : AttributeEvent.class;if (filter == null) {- LOG.fine("Invalid event filter generated for topic '" + topic + "': " + connection);+ LOG.info("Invalid event filter generated for topic '" + topic + "': " + connection);return;}@@ -437,7 +412,7 @@ public class DefaultMQTTHandler extends MQTTHandler {@Overridepublic void onUserAssetLinksChanged(RemotingConnection connection) {if (connectionSubscriberInfoMap.containsKey(getConnectionIDString(connection))) {- LOG.fine("User asset links have changed for a connected user with active subscriptions so force disconnecting them: " + mqttBrokerService.connectionToString(connection));+ LOG.info("User asset links have changed for a connected user with active subscriptions so force disconnecting them: " + mqttBrokerService.connectionToString(connection));mqttBrokerService.doForceDisconnect(connection);}}diff --git a/manager/src/main/java/org/openremote/manager/mqtt/MQTTBrokerService.java b/manager/src/main/java/org/openremote/manager/mqtt/MQTTBrokerService.javaindex 9c91fba25..d71c86adb 100644--- a/manager/src/main/java/org/openremote/manager/mqtt/MQTTBrokerService.java+++ b/manager/src/main/java/org/openremote/manager/mqtt/MQTTBrokerService.java@@ -66,7 +66,6 @@ import org.openremote.model.ContainerService;import org.openremote.model.PersistenceEvent;import org.openremote.model.asset.UserAssetLink;import org.openremote.model.security.User;-import org.openremote.model.syslog.SyslogCategory;import org.openremote.model.util.Debouncer;import org.openremote.model.util.TextUtil;import org.openremote.model.util.ValueUtil;@@ -79,10 +78,9 @@ import java.util.concurrent.ConcurrentHashMap;import java.util.concurrent.ConcurrentMap;import java.util.concurrent.ScheduledExecutorService;import java.util.concurrent.TimeUnit;-import java.util.logging.Level;-import java.util.logging.Logger;import java.util.stream.Collectors;+import static java.lang.System.Logger.Level.*;import static java.util.stream.StreamSupport.stream;import static org.apache.activemq.artemis.core.protocol.mqtt.MQTTUtil.MQTT_QOS_LEVEL_KEY;import static org.openremote.container.persistence.PersistenceService.PERSISTENCE_TOPIC;@@ -100,7 +98,7 @@ public class MQTTBrokerService extends RouteBuilder implements ContainerService,public static final String MQTT_SERVER_LISTEN_PORT = "MQTT_SERVER_LISTEN_PORT";public static final String ANONYMOUS_USERNAME = "anonymous";protected final WildcardConfiguration wildcardConfiguration = new WildcardConfiguration();- protected static final Logger LOG = SyslogCategory.getLogger(API, MQTTBrokerService.class);+ protected static final System.Logger LOG = System.getLogger(MQTTBrokerService.class.getName() + "." + API.name());protected AssetStorageService assetStorageService;protected AuthorisationService authorisationService;@@ -150,7 +148,7 @@ public class MQTTBrokerService extends RouteBuilder implements ContainerService,.build();if (!identityService.isKeycloakEnabled()) {- LOG.warning("MQTT connections are not supported when not using Keycloak identity provider");+ LOG.log(WARNING, "MQTT connections are not supported when not using Keycloak identity provider");active = false;} else {active = true;@@ -168,7 +166,7 @@ public class MQTTBrokerService extends RouteBuilder implements ContainerService,try {handler.init(container);} catch (Exception e) {- LOG.log(Level.WARNING, "MQTT custom handler threw an exception whilst initialising: handler=" + handler.getName(), e);+ LOG.log(WARNING, "MQTT custom handler threw an exception whilst initialising: handler=" + handler.getName(), e);throw e;}}@@ -221,7 +219,7 @@ public class MQTTBrokerService extends RouteBuilder implements ContainerService,server.setSecurityManager(securityManager);server.start();- LOG.fine("Started MQTT broker");+ LOG.log(DEBUG, "Started MQTT broker");// Add notification handler for subscribe/unsubscribe and publish eventsserver.getActiveMQServer().getManagementService().addNotificationListener(notification -> {@@ -262,7 +260,7 @@ public class MQTTBrokerService extends RouteBuilder implements ContainerService,try {handler.start(container);} catch (Exception e) {- LOG.log(Level.WARNING, "MQTT custom handler threw an exception whilst starting: handler=" + handler.getName(), e);+ LOG.log(WARNING, "MQTT custom handler threw an exception whilst starting: handler=" + handler.getName(), e);throw e;}}@@ -293,7 +291,7 @@ public class MQTTBrokerService extends RouteBuilder implements ContainerService,}if (forceDisconnect) {- LOG.fine("User modified or deleted so force closing any sessions for this user: " + user);+ LOG.log(TRACE, "User modified or deleted so force closing any sessions for this user: " + user);// Find existing connection for this usergetUserConnections(user.getId()).forEach(this::doForceDisconnect);}@@ -312,7 +310,7 @@ public class MQTTBrokerService extends RouteBuilder implements ContainerService,userAssetDisconnectDebouncer.cancelAll(true);server.stop();- LOG.fine("Stopped MQTT broker");+ LOG.log(DEBUG, "Stopped MQTT broker");stream(ServiceLoader.load(MQTTHandler.class).spliterator(), false).sorted(Comparator.comparingInt(MQTTHandler::getPriority).reversed())@@ -320,7 +318,7 @@ public class MQTTBrokerService extends RouteBuilder implements ContainerService,try {handler.stop();} catch (Exception e) {- LOG.log(Level.WARNING, "MQTT custom handler threw an exception whilst stopping: handler=" + handler.getName(), e);+ LOG.log(WARNING, "MQTT custom handler threw an exception whilst stopping: handler=" + handler.getName(), e);}});}@@ -341,13 +339,13 @@ public class MQTTBrokerService extends RouteBuilder implements ContainerService,if (exception.getType() == ActiveMQExceptionType.REMOTE_DISCONNECT) {// Seems to be the type for graceful close of connection// Notify handlers of connection close- LOG.info("Client connection closed: " + connectionToString(connection));+ LOG.log(DEBUG, () -> "Client connection closed: " + connectionToString(connection));for (MQTTHandler handler : getCustomHandlers()) {handler.onDisconnect(connection);}} else {// Notify handlers of connection failure- LOG.info("Client connection failed: " + connectionToString(connection));+ LOG.log(DEBUG, () -> "Client connection failed: " + connectionToString(connection));for (MQTTHandler handler : getCustomHandlers()) {handler.onConnectionLost(connection);}@@ -380,7 +378,7 @@ public class MQTTBrokerService extends RouteBuilder implements ContainerService,clientIDConnectionMap.put(remotingConnection.getClientID(), remotingConnection);if (!connectionIDConnectionMap.containsKey(connectionID)) {- LOG.info("Client connection created: " + connectionToString(remotingConnection));+ LOG.log(DEBUG, () -> "Client connection created: " + connectionToString(remotingConnection));connectionIDConnectionMap.put(connectionID, remotingConnection);for (MQTTHandler handler : getCustomHandlers()) {handler.onConnect(remotingConnection);@@ -397,9 +395,10 @@ public class MQTTBrokerService extends RouteBuilder implements ContainerService,for (MQTTHandler handler : getCustomHandlers()) {if (handler.handlesTopic(topic)) {- LOG.fine("Handler has handled subscribe: handler=" + handler.getName() + ", topic=" + topic + ", " + connectionToString(connection));+ String connectionStr = LOG.isLoggable(DEBUG) ? connectionToString(connection) : null;+ LOG.log(TRACE, "Handler has handled subscribe: handler=" + handler.getName() + ", topic=" + topic + ", " + connectionStr);+ LOG.log(DEBUG, "Client subscribed '" + topicStr + "': " + connectionStr);handler.onSubscribe(connection, topic);- LOG.info("Client subscribed '" + topicStr + "': " + connectionToString(connection));break;}}@@ -410,9 +409,10 @@ public class MQTTBrokerService extends RouteBuilder implements ContainerService,for (MQTTHandler handler : getCustomHandlers()) {if (handler.handlesTopic(topic)) {- LOG.fine("Handler has handled unsubscribe: handler=" + handler.getName() + ", topic=" + topic + ", " + connectionToString(connection));+ String connectionStr = LOG.isLoggable(DEBUG) ? connectionToString(connection) : null;+ LOG.log(TRACE, "Handler has handled unsubscribe: handler=" + handler.getName() + ", topic=" + topic + ", " + connectionStr);+ LOG.log(DEBUG, "Client unsubscribed '" + topicStr + "': " + connectionStr);handler.onUnsubscribe(connection, topic);- LOG.info("Client unsubscribed '" + topicStr + "': " + connectionToString(connection));break;}}@@ -433,7 +433,7 @@ public class MQTTBrokerService extends RouteBuilder implements ContainerService,// Only notify handlers if subject is a restricted userif (subject != null && KeycloakIdentityProvider.getSecurityContext(subject).getToken().getRealmAccess().isUserInRole(Constants.RESTRICTED_USER_REALM_ROLE)) {- LOG.fine("User asset links modified for connected restricted user so passing to handlers to decide what to do: user=" + subject);+ LOG.log(TRACE, "User asset links modified for connected restricted user so passing to handlers to decide what to do: user=" + subject);// Pass to handlers to decide what to douserConnections.forEach(connection -> {for (MQTTHandler handler : customHandlers) {@@ -460,7 +460,7 @@ public class MQTTBrokerService extends RouteBuilder implements ContainerService,}protected void doForceDisconnect(RemotingConnection connection) {- LOG.info("Force disconnecting client connection: " + connectionToString(connection));+ LOG.log(DEBUG, "Force disconnecting client connection: " + connectionToString(connection));connection.disconnect(false);}@@ -476,7 +476,7 @@ public class MQTTBrokerService extends RouteBuilder implements ContainerService,}}} catch (Exception e) {- LOG.log(Level.WARNING, "Couldn't send AttributeEvent to MQTT client", e);+ LOG.log(WARNING, "Couldn't send AttributeEvent to MQTT client", e);}}@@ -552,7 +552,7 @@ public class MQTTBrokerService extends RouteBuilder implements ContainerService,public void notifyConnectionAuthenticated(RemotingConnection connection) {if (connection.getSubject() != null) {// Notify handlers that connection authenticated- LOG.info("Client connection authenticated: " + connectionToString(connection));+ LOG.log(DEBUG, "Client connection authenticated: " + connectionToString(connection));for (MQTTHandler handler : getCustomHandlers()) {handler.onConnectionAuthenticated(connection);}diff --git a/manager/src/main/java/org/openremote/manager/mqtt/MQTTHandler.java b/manager/src/main/java/org/openremote/manager/mqtt/MQTTHandler.javaindex 1ae274c57..dedaee82f 100644--- a/manager/src/main/java/org/openremote/manager/mqtt/MQTTHandler.java+++ b/manager/src/main/java/org/openremote/manager/mqtt/MQTTHandler.java@@ -44,6 +44,7 @@ import java.util.Set;import java.util.logging.Level;import java.util.logging.Logger;+import static java.lang.System.Logger.Level.WARNING;import static org.openremote.manager.mqtt.MQTTBrokerService.LOG;/**@@ -106,7 +107,7 @@ public abstract class MQTTHandler {protected void addPublishConsumer(String topic) {try {- getLogger().fine("Adding publish consumer for topic '" + topic + "': handler=" + getName());+ getLogger().info("Adding publish consumer for topic '" + topic + "': handler=" + getName());String coreTopic = MQTTUtil.convertMqttTopicFilterToCoreAddress(topic, mqttBrokerService.wildcardConfiguration);mqttBrokerService.internalSession.createQueue(new QueueConfiguration(coreTopic).setRoutingType(RoutingType.ANYCAST).setPurgeOnNoConsumers(true).setAutoCreateAddress(true).setAutoCreated(true));ClientConsumer consumer = mqttBrokerService.internalSession.createConsumer(coreTopic);@@ -116,11 +117,11 @@ public abstract class MQTTHandler {RemotingConnection connection = mqttBrokerService.getConnectionFromClientID(clientID);if (connection == null) {- LOG.warning("Failed to find connection for connected client so dropping publish to topic '" + topic + "': clientID=" + clientID);+ LOG.log(WARNING, "Failed to find connection for connected client so dropping publish to topic '" + topic + "': clientID=" + clientID);return;}- getLogger().info("Client published to '" + publishTopic + "': " + mqttBrokerService.connectionToString(connection));+ getLogger().fine("Client published to '" + publishTopic + "': " + mqttBrokerService.connectionToString(connection));onPublish(connection, publishTopic, message.getReadOnlyBodyBuffer().byteBuf());});} catch (ActiveMQException e) {@@ -171,11 +172,11 @@ public abstract class MQTTHandler {*/public boolean handlesTopic(Topic topic) {if (!topicTokenCountGreaterThan(topic, 2)) {- getLogger().finer("Topic must contain more than 2 tokens");+ getLogger().finest("Topic must contain more than 2 tokens");return false;}if (!topicMatches(topic)) {- getLogger().finer("Topic failed to match this handler");+ getLogger().finest("Topic failed to match this handler");return false;}return true;@@ -191,7 +192,7 @@ public abstract class MQTTHandler {return false;}if (!topicRealmAllowed(securityContext, topic) || !topicClientIdMatches(connection, topic)) {- getLogger().fine("Topic realm and client ID tokens must match the connection, topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));+ getLogger().finest("Topic realm and client ID tokens must match the connection, topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));return false;}return canSubscribe(connection, securityContext, topic);@@ -203,11 +204,11 @@ public abstract class MQTTHandler {*/public boolean checkCanPublish(RemotingConnection connection, KeycloakSecurityContext securityContext, Topic topic) {if (securityContext == null) {- getLogger().fine("Anonymous connection publishes not supported by this handler topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));+ getLogger().finest("Anonymous connection publishes not supported by this handler topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));return false;}if (!topicRealmAllowed(securityContext, topic) || !topicClientIdMatches(connection, topic)) {- getLogger().fine("Topic realm and client ID tokens must match the connection topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));+ getLogger().finest("Topic realm and client ID tokens must match the connection topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));return false;}return canPublish(connection, securityContext, topic);diff --git a/manager/src/main/java/org/openremote/manager/mqtt/UserAssetProvisioningMQTTHandler.java b/manager/src/main/java/org/openremote/manager/mqtt/UserAssetProvisioningMQTTHandler.javaindex d9cd0e337..1afd9ba7b 100644--- a/manager/src/main/java/org/openremote/manager/mqtt/UserAssetProvisioningMQTTHandler.java+++ b/manager/src/main/java/org/openremote/manager/mqtt/UserAssetProvisioningMQTTHandler.java@@ -92,7 +92,7 @@ public class UserAssetProvisioningMQTTHandler extends MQTTHandler {}if (forceDisconnect) {- LOG.info("Provisioning config modified or deleted so forcing connected clients to disconnect: " + persistenceEvent.getEntity());+ LOG.fine("Provisioning config modified or deleted so forcing connected clients to disconnect: " + persistenceEvent.getEntity());mqttHandler.forceClientDisconnects(persistenceEvent.getEntity().getId());}});@@ -215,7 +215,7 @@ public class UserAssetProvisioningMQTTHandler extends MQTTHandler {ProvisioningMessage provisioningMessage = ValueUtil.parse(payloadContent, ProvisioningMessage.class).orElseGet(() -> {- LOG.info("Failed to parse message from client: topic=" + topic+ mqttBrokerService.connectionToString(connection));+ LOG.info("Failed to parse message from client: topic=" + topic + mqttBrokerService.connectionToString(connection));mqttBrokerService.publishMessage(getResponseTopic(topic), new ErrorResponseMessage(ErrorResponseMessage.Error.MESSAGE_INVALID), MqttQoS.AT_MOST_ONCE);return null;});@@ -257,10 +257,10 @@ public class UserAssetProvisioningMQTTHandler extends MQTTHandler {protected void processX509ProvisioningMessage(RemotingConnection connection, Topic topic, X509ProvisioningMessage provisioningMessage) {- LOG.finer("Processing provisioning message on: topic=" + topic + mqttBrokerService.connectionToString(connection));+ LOG.fine("Processing provisioning message on: topic=" + topic + mqttBrokerService.connectionToString(connection));if (TextUtil.isNullOrEmpty(provisioningMessage.getCert())) {- LOG.info("Certificate is missing from X509 provisioning message: topic=" + topic + mqttBrokerService.connectionToString(connection));+ LOG.warning("Certificate is missing from X509 provisioning message: topic=" + topic + mqttBrokerService.connectionToString(connection));mqttBrokerService.publishMessage(getResponseTopic(topic), new ErrorResponseMessage(ErrorResponseMessage.Error.CERTIFICATE_INVALID), MqttQoS.AT_MOST_ONCE);return;}@@ -270,7 +270,7 @@ public class UserAssetProvisioningMQTTHandler extends MQTTHandler {try {clientCertificate = ProvisioningUtil.getX509Certificate(provisioningMessage.getCert());} catch (CertificateException e) {- LOG.log(Level.INFO, "Failed to parse client X.509 certificate: topic=" + topic+ mqttBrokerService.connectionToString(connection), e);+ LOG.log(Level.WARNING, "Failed to parse client X.509 certificate: topic=" + topic+ mqttBrokerService.connectionToString(connection), e);mqttBrokerService.publishMessage(getResponseTopic(topic), new ErrorResponseMessage(ErrorResponseMessage.Error.CERTIFICATE_INVALID), MqttQoS.AT_MOST_ONCE);return;}@@ -278,14 +278,14 @@ public class UserAssetProvisioningMQTTHandler extends MQTTHandler {X509ProvisioningConfig matchingConfig = getMatchingX509ProvisioningConfig(connection, clientCertificate);if (matchingConfig == null) {- LOG.info("No matching provisioning config found for client certificate: topic=" + topic+ mqttBrokerService.connectionToString(connection));+ LOG.finest("No matching provisioning config found for client certificate: topic=" + topic+ mqttBrokerService.connectionToString(connection));mqttBrokerService.publishMessage(getResponseTopic(topic), new ErrorResponseMessage(ErrorResponseMessage.Error.UNAUTHORIZED), MqttQoS.AT_MOST_ONCE);return;}// Check if config is disabledif (matchingConfig.isDisabled()) {- LOG.fine("Matching provisioning config is disabled for client certificate: topic=" + topic+ mqttBrokerService.connectionToString(connection));+ LOG.finest("Matching provisioning config is disabled for client certificate: topic=" + topic+ mqttBrokerService.connectionToString(connection));mqttBrokerService.publishMessage(getResponseTopic(topic), new ErrorResponseMessage(ErrorResponseMessage.Error.CONFIG_DISABLED), MqttQoS.AT_MOST_ONCE);return;}@@ -295,13 +295,13 @@ public class UserAssetProvisioningMQTTHandler extends MQTTHandler {String uniqueId = topicTokenIndexToString(topic, 1);if (TextUtil.isNullOrEmpty(certUniqueId)) {- LOG.info("Client X.509 certificate missing unique ID in subject CN: topic=" + topic+ mqttBrokerService.connectionToString(connection));+ LOG.finest("Client X.509 certificate missing unique ID in subject CN: topic=" + topic+ mqttBrokerService.connectionToString(connection));mqttBrokerService.publishMessage(getResponseTopic(topic), new ErrorResponseMessage(ErrorResponseMessage.Error.UNIQUE_ID_MISMATCH), MqttQoS.AT_MOST_ONCE);return;}if (TextUtil.isNullOrEmpty(uniqueId) || !certUniqueId.equals(uniqueId)) {- LOG.info("Client X.509 certificate unique ID doesn't match topic unique ID: topic=" + topic+ mqttBrokerService.connectionToString(connection));+ LOG.finest("Client X.509 certificate unique ID doesn't match topic unique ID: topic=" + topic+ mqttBrokerService.connectionToString(connection));mqttBrokerService.publishMessage(getResponseTopic(topic), new ErrorResponseMessage(ErrorResponseMessage.Error.UNIQUE_ID_MISMATCH), MqttQoS.AT_MOST_ONCE);return;}@@ -321,7 +321,7 @@ public class UserAssetProvisioningMQTTHandler extends MQTTHandler {if (serviceUser != null) {if (!serviceUser.getEnabled()) {- LOG.info("Client service user has been disabled: topic=" + topic+ mqttBrokerService.connectionToString(connection));+ LOG.finest("Client service user has been disabled: topic=" + topic+ mqttBrokerService.connectionToString(connection));mqttBrokerService.publishMessage(getResponseTopic(topic), new ErrorResponseMessage(ErrorResponseMessage.Error.USER_DISABLED), MqttQoS.AT_MOST_ONCE);return;}@@ -329,7 +329,7 @@ public class UserAssetProvisioningMQTTHandler extends MQTTHandler {serviceUser = createClientServiceUser(realm, serviceUsername, matchingConfig);}} catch (Exception e) {- LOG.log(Level.WARNING, "Failed to retrieve/create service user: topic=" + topic+ mqttBrokerService.connectionToString(connection), e);+ LOG.log(Level.WARNING, "Failed to retrieve/create service user: topic=" + topic + mqttBrokerService.connectionToString(connection), e);mqttBrokerService.publishMessage(getResponseTopic(topic), new ErrorResponseMessage(ErrorResponseMessage.Error.SERVER_ERROR), MqttQoS.AT_MOST_ONCE);return;}@@ -338,30 +338,31 @@ public class UserAssetProvisioningMQTTHandler extends MQTTHandler {// Prepend realm name to unique ID to generate asset ID to further improve uniquenessString assetId = UniqueIdentifierGenerator.generateId(matchingConfig.getRealm() + uniqueId);- LOG.fine("Client unique ID '" + uniqueId + "' mapped to asset ID '" + assetId + "': topic=" + topic+ mqttBrokerService.connectionToString(connection));+ LOG.finest("Client unique ID '" + uniqueId + "' mapped to asset ID '" + assetId + "': topic=" + topic+ mqttBrokerService.connectionToString(connection));try {// Look for existing assetasset = assetStorageService.find(assetId);if (asset != null) {- LOG.finer("Client asset found: topic=" + topic+ mqttBrokerService.connectionToString(connection) + ", assetId=" + assetId);+ LOG.finest("Client asset found: topic=" + topic + mqttBrokerService.connectionToString(connection) + ", assetId=" + assetId);if (!matchingConfig.getRealm().equals(asset.getRealm())) {- LOG.info("Client asset realm mismatch : topic=" + topic+ mqttBrokerService.connectionToString(connection) + ", assetId=" + assetId);+ LOG.warning("Client asset realm mismatch : topic=" + topic + mqttBrokerService.connectionToString(connection) + ", assetId=" + assetId);mqttBrokerService.publishMessage(getResponseTopic(topic), new ErrorResponseMessage(ErrorResponseMessage.Error.ASSET_ERROR), MqttQoS.AT_MOST_ONCE);return;}} else {+ LOG.finest("Creating client asset: topic=" + topic + mqttBrokerService.connectionToString(connection) + ", assetId=" + assetId);asset = createClientAsset(realm, assetId, uniqueId, serviceUser, matchingConfig);}} catch (Exception e) {- LOG.log(Level.WARNING, "Failed to retrieve/create asset: topic=" + topic+ mqttBrokerService.connectionToString(connection) + ", config=" + matchingConfig, e);+ LOG.log(Level.WARNING, "Failed to retrieve/create asset: topic=" + topic + mqttBrokerService.connectionToString(connection) + ", config=" + matchingConfig, e);mqttBrokerService.publishMessage(getResponseTopic(topic), new ErrorResponseMessage(ErrorResponseMessage.Error.SERVER_ERROR), MqttQoS.AT_MOST_ONCE);return;}- LOG.fine("Client successfully initialised: topic=" + topic+ mqttBrokerService.connectionToString(connection) + ", config=" + matchingConfig);+ LOG.fine("Client successfully initialised: topic=" + topic + mqttBrokerService.connectionToString(connection) + ", config=" + matchingConfig + ", username=" + serviceUsername + ", asset=" + asset);// Authenticate the connection using this service user's credentials - this will also update the connection's subjectconnection.setSubject(null); // Clear existing anonymous subject@@ -420,7 +421,7 @@ public class UserAssetProvisioningMQTTHandler extends MQTTHandler {}protected User createClientServiceUser(String realm, String username, ProvisioningConfig<?, ?> provisioningConfig) {- LOG.fine("Creating client service user: realm=" + realm + ", username=" + username);+ LOG.finest("Creating client service user: realm=" + realm + ", username=" + username);User serviceUser = new User().setServiceAccount(true)@@ -431,7 +432,7 @@ public class UserAssetProvisioningMQTTHandler extends MQTTHandler {serviceUser = identityProvider.createUpdateUser(realm, serviceUser, secret, true);if (provisioningConfig.getUserRoles() != null && provisioningConfig.getUserRoles().length > 0) {- LOG.finer("Setting user roles: realm=" + realm + ", username=" + username + ", roles=" + Arrays.toString(provisioningConfig.getUserRoles()));+ LOG.finest("Setting user roles: realm=" + realm + ", username=" + username + ", roles=" + Arrays.toString(provisioningConfig.getUserRoles()));identityProvider.updateUserRoles(realm,serviceUser.getId(),@@ -439,11 +440,11 @@ public class UserAssetProvisioningMQTTHandler extends MQTTHandler {Arrays.stream(provisioningConfig.getUserRoles()).map(ClientRole::getValue).toArray(String[]::new));} else {- LOG.finer("No user roles defined: realm=" + realm + ", username=" + username);+ LOG.finest("No user roles defined: realm=" + realm + ", username=" + username);}if (provisioningConfig.isRestrictedUser()) {- LOG.finer("User will be made restricted: realm=" + realm + ", username=" + username);+ LOG.finest("User will be made restricted: realm=" + realm + ", username=" + username);identityProvider.updateUserRealmRoles(realm, serviceUser.getId(), identityProvider.addRealmRoles(realm, serviceUser.getId(),RESTRICTED_USER_REALM_ROLE));}@@ -453,7 +454,7 @@ public class UserAssetProvisioningMQTTHandler extends MQTTHandler {}protected Asset<?> createClientAsset(String realm, String assetId, String uniqueId, User serviceUser, ProvisioningConfig<?, ?> provisioningConfig) throws RuntimeException {- LOG.fine("Creating client asset: realm=" + realm + ", username=" + serviceUser.getUsername());+ LOG.finest("Creating client asset: realm=" + realm + ", username=" + serviceUser.getUsername());if (TextUtil.isNullOrEmpty(provisioningConfig.getAssetTemplate())) {return null;@@ -486,10 +487,10 @@ public class UserAssetProvisioningMQTTHandler extends MQTTHandler {// Force disconnect of each connection and the disconnect handler will remove the connection from the mapconnections.forEach(connection -> {try {- LOG.finer("Force disconnecting client that is using provisioning config ID '" + provisioningConfigId + "': " + mqttBrokerService.connectionToString(connection));+ LOG.fine("Force disconnecting client that is using provisioning config ID '" + provisioningConfigId + "': " + mqttBrokerService.connectionToString(connection));connection.disconnect(false);} catch (Exception e) {- getLogger().log(Level.INFO, "Failed to disconnect client: connection=" + connection, e);+ getLogger().log(Level.WARNING, "Failed to disconnect client: connection=" + connection, e);}});connections.clear();diff --git a/manager/src/main/java/org/openremote/manager/rules/JsonRulesBuilder.java b/manager/src/main/java/org/openremote/manager/rules/JsonRulesBuilder.javaindex 54b3f0fc3..540606037 100644--- a/manager/src/main/java/org/openremote/manager/rules/JsonRulesBuilder.java+++ b/manager/src/main/java/org/openremote/manager/rules/JsonRulesBuilder.java@@ -335,7 +335,7 @@ public class JsonRulesBuilder extends RulesBuilder {}if (noLongerMatches) {- log(Level.FINER, "Rule trigger previously matched asset state no longer matches so resetting: " + previousAssetState);+ log(Level.FINEST, "Rule trigger previously matched asset state no longer matches so resetting: " + previousAssetState);}return noLongerMatches;@@ -691,12 +691,12 @@ public class JsonRulesBuilder extends RulesBuilder {try {if (ruleState.thenMatched()) {- log(Level.FINER, "Triggered rule so executing 'then' actions for rule: " + rule.name);+ log(Level.FINEST, "Triggered rule so executing 'then' actions for rule: " + rule.name);executeRuleActions(rule, rule.then, "then", false, facts, ruleState, assetsFacade, usersFacade, notificationsFacade, webhooksFacade, predictedDatapointsFacade, scheduledActionConsumer);}if (rule.otherwise != null && ruleState.otherwiseMatched()) {- log(Level.FINER, "Triggered rule so executing 'otherwise' actions for rule: " + rule.name);+ log(Level.FINEST, "Triggered rule so executing 'otherwise' actions for rule: " + rule.name);executeRuleActions(rule, rule.otherwise, "otherwise", true, facts, ruleState, assetsFacade, usersFacade, notificationsFacade, webhooksFacade, predictedDatapointsFacade, scheduledActionConsumer);}} catch (Exception e) {diff --git a/manager/src/main/java/org/openremote/manager/rules/RulesEngine.java b/manager/src/main/java/org/openremote/manager/rules/RulesEngine.javaindex 39bfea459..38afdfeee 100644--- a/manager/src/main/java/org/openremote/manager/rules/RulesEngine.java+++ b/manager/src/main/java/org/openremote/manager/rules/RulesEngine.java@@ -281,7 +281,7 @@ public class RulesEngine<T extends Ruleset> {} else {deployment.updateValidity();if (deployment.hasExpired()) {- LOG.finer("Ruleset validity period has expired: " + ruleset.getName());+ LOG.finest("Ruleset validity period has expired: " + ruleset.getName());deployment.setStatus(EXPIRED);publishRulesetStatus(deployment);compiled = true;@@ -313,7 +313,7 @@ public class RulesEngine<T extends Ruleset> {RulesetDeployment deployment = deployments.get(ruleset.getId());if (deployment == null) {- LOG.finer("Ruleset cannot be retracted as it was never deployed: " + ruleset);+ LOG.finest("Ruleset cannot be retracted as it was never deployed: " + ruleset);return deployments.size() == 0;}@@ -340,7 +340,7 @@ public class RulesEngine<T extends Ruleset> {}if (deployments.size() == 0) {- LOG.finer("No rulesets so nothing to start");+ LOG.finest("No rulesets so nothing to start");return;}@@ -487,7 +487,7 @@ public class RulesEngine<T extends Ruleset> {long fireTimeMillis = quickFire ? rulesService.quickFireMillis : rulesService.tempFactExpirationMillis;- LOG.finer("Scheduling rules firing in " + fireTimeMillis + "ms on: " + this);+ LOG.finest("Scheduling rules firing in " + fireTimeMillis + "ms on: " + this);fireTimer = executorService.schedule(() -> {synchronized (RulesEngine.this) {@@ -534,7 +534,7 @@ public class RulesEngine<T extends Ruleset> {if (deployment.getStatus() == DEPLOYED) {- LOG.finer("Executing rules of: " + deployment);+ LOG.finest("Executing rules of: " + deployment);// If full detail logging is enabled// Log asset states and events before firing@@ -550,7 +550,7 @@ public class RulesEngine<T extends Ruleset> {executionTotalMillis += executionMillis;LOG.fine("Rules deployment '" + deployment.getName() + "' executed in: " + executionMillis + "ms");} else {- LOG.finer("Rules deployment '" + deployment.getName() + "' skipped as status is: " + deployment.getStatus());+ LOG.finest("Rules deployment '" + deployment.getName() + "' skipped as status is: " + deployment.getStatus());}} catch (Exception ex) {LOG.log(Level.SEVERE, "On " + RulesEngine.this + ", error executing rules of: " + deployment, ex);@@ -676,7 +676,7 @@ public class RulesEngine<T extends Ruleset> {engineInfo);- LOG.finer("Publishing rules engine status event: " + event);+ LOG.finest("Publishing rules engine status event: " + event);// Notify clientsclientEventService.publishEvent(event);@@ -695,7 +695,7 @@ public class RulesEngine<T extends Ruleset> {ruleset);- LOG.finer("Publishing ruleset status event: " + event);+ LOG.finest("Publishing ruleset status event: " + event);// Notify clientsclientEventService.publishEvent(event);diff --git a/manager/src/main/java/org/openremote/manager/rules/RulesFacts.java b/manager/src/main/java/org/openremote/manager/rules/RulesFacts.javaindex 47933c3f5..de149581f 100644--- a/manager/src/main/java/org/openremote/manager/rules/RulesFacts.java+++ b/manager/src/main/java/org/openremote/manager/rules/RulesFacts.java@@ -87,12 +87,12 @@ public class RulesFacts extends Facts implements RuleListener {}protected void startTrackingLocationRules() {- LOG.finer("Tracking location predicate rules: started");+ LOG.finest("Tracking location predicate rules: started");trackLocationRules = true;}protected List<RulesEngine.AssetStateLocationPredicates> stopTrackingLocationRules() {- LOG.finer("Tracking location predicate rules: stopping");+ LOG.finest("Tracking location predicate rules: stopping");trackLocationRules = false;Map<String, Set<GeofencePredicate>> assetStateLocationPredicateMap = this.assetStateLocationPredicateMap;this.assetStateLocationPredicateMap = null;@@ -624,7 +624,7 @@ public class RulesFacts extends Facts implements RuleListener {protected void storeLocationPredicates(List<GeofencePredicate> foundLocationPredicates) {if (foundLocationPredicates != null && !foundLocationPredicates.isEmpty()) {- LOG.finer("Location predicate found");+ LOG.finest("Location predicate found");// Collect asset states only where the attribute is location (location predicates only make sense when the location// attribute is exposed to rules - we don't support RULE_EVENT facts just RULE_STATECollection<AssetState<?>> locationAssetStates = getAssetStates().stream().filter(assetState -> assetState.getName().equalsIgnoreCase(Asset.LOCATION.getName())).collect(Collectors.toSet());diff --git a/manager/src/main/java/org/openremote/manager/rules/RulesService.java b/manager/src/main/java/org/openremote/manager/rules/RulesService.javaindex 082eea8d6..c55c5b0a2 100644--- a/manager/src/main/java/org/openremote/manager/rules/RulesService.java+++ b/manager/src/main/java/org/openremote/manager/rules/RulesService.java@@ -55,6 +55,7 @@ import org.openremote.model.security.Realm;import org.openremote.model.util.Pair;import org.openremote.model.util.TextUtil;import org.openremote.model.util.TimeUtil;+import org.openremote.model.value.MetaHolder;import org.openremote.model.value.MetaItemType;import javax.persistence.EntityManager;@@ -366,8 +367,13 @@ public class RulesService extends RouteBuilder implements ContainerService, Asse}}- protected static boolean attributeIsRuleState(Attribute<?> attribute) {- return attribute.getMetaValue(MetaItemType.RULE_STATE).orElse(attribute.hasMeta(MetaItemType.AGENT_LINK));+ protected static boolean isRuleState(MetaHolder metaHolder) {+ if (metaHolder.getMeta() == null) {+ return false;+ }++ return metaHolder.getMeta().getValue(MetaItemType.RULE_STATE)+ .orElse(metaHolder.getMeta().has(MetaItemType.AGENT_LINK));}@Override@@ -388,7 +394,7 @@ public class RulesService extends RouteBuilder implements ContainerService, Asse// We might process two facts for a single attribute update, if that is what the user wants// First as asset state- if (assetState.getMetaValue(MetaItemType.RULE_STATE).orElse(assetState.hasMeta(MetaItemType.AGENT_LINK))) {+ if (isRuleState(assetState)) {updateAssetState(assetState);}@@ -513,10 +519,10 @@ public class RulesService extends RouteBuilder implements ContainerService, Asseasset.getAttributes().stream()- .filter(RulesService::attributeIsRuleState)+ .filter(RulesService::isRuleState).forEach(attribute -> {AssetState<?> assetState = new AssetState<>(asset, attribute, Source.INTERNAL);- LOG.finer("Asset was persisted (" + persistenceEvent.getCause() + "), inserting fact: " + assetState);+ LOG.finest("Asset was persisted (" + persistenceEvent.getCause() + "), inserting fact: " + assetState);updateAssetState(assetState);});break;@@ -529,23 +535,23 @@ public class RulesService extends RouteBuilder implements ContainerService, AsseList<Attribute<?>> oldStateAttributes = oldAttributes.stream()- .filter(RulesService::attributeIsRuleState).toList();+ .filter(RulesService::isRuleState).toList();List<Attribute<?>> newStateAttributes = currentAttributes.stream()- .filter(RulesService::attributeIsRuleState).toList();+ .filter(RulesService::isRuleState).toList();// Just retract all old attributes rather than compare every value that might cause asset state to mutateoldStateAttributes.forEach(attribute -> {AssetState<?> assetState = new AssetState<>(asset, attribute, Source.INTERNAL);- LOG.finer("Asset was persisted (" + persistenceEvent.getCause() + "), retracting obsolete fact: " + assetState);+ LOG.finest("Asset was persisted (" + persistenceEvent.getCause() + "), retracting obsolete fact: " + assetState);retractAssetState(assetState);});// Insert new states for new or changed attributesnewStateAttributes.forEach(attribute -> {AssetState<?> assetState = new AssetState<>(asset, attribute, Source.INTERNAL);- LOG.finer("Asset was persisted (" + persistenceEvent.getCause() + "), inserting fact: " + assetState);+ LOG.finest("Asset was persisted (" + persistenceEvent.getCause() + "), inserting fact: " + assetState);updateAssetState(assetState);});break;@@ -553,10 +559,10 @@ public class RulesService extends RouteBuilder implements ContainerService, Assecase DELETE:// Retract any facts that were associated with this assetasset.getAttributes().stream()- .filter(RulesService::attributeIsRuleState)+ .filter(RulesService::isRuleState).forEach(attribute -> {AssetState<?> assetState = new AssetState<>(asset, attribute, Source.INTERNAL);- LOG.finer("Asset was persisted (" + persistenceEvent.getCause() + "), retracting fact: " + assetState);+ LOG.finest("Asset was persisted (" + persistenceEvent.getCause() + "), retracting fact: " + assetState);retractAssetState(assetState);});break;@@ -801,7 +807,7 @@ public class RulesService extends RouteBuilder implements ContainerService, Asse}protected void updateAssetState(AssetState<?> assetState) {- LOG.finer("Updating asset state: " + assetState);+ LOG.finest("Updating asset state: " + assetState);// Get the chain of rule engines that we need to pass throughList<RulesEngine<?>> rulesEngines = getEnginesInScope(assetState.getRealm(), assetState.getPath());@@ -875,7 +881,7 @@ public class RulesService extends RouteBuilder implements ContainerService, Assereturn assets.stream().map(asset ->new Pair<>(asset, asset.getAttributes().stream()- .filter(RulesService::attributeIsRuleState))+ .filter(RulesService::isRuleState)));}diff --git a/manager/src/main/java/org/openremote/manager/rules/RulesetDeployment.java b/manager/src/main/java/org/openremote/manager/rules/RulesetDeployment.javaindex 7e8000da2..934226959 100644--- a/manager/src/main/java/org/openremote/manager/rules/RulesetDeployment.java+++ b/manager/src/main/java/org/openremote/manager/rules/RulesetDeployment.java@@ -272,7 +272,7 @@ public class RulesetDeployment {jsonRulesBuilder = new JsonRulesBuilder(ruleset, timerService, assetStorageService, executorService, assetsFacade, usersFacade, notificationsFacade, webhooksFacade, historicDatapointsFacade, predictedDatapointsFacade, this::scheduleRuleAction);for (Rule rule : jsonRulesBuilder.build()) {- RulesEngine.LOG.finer("Registering JSON rule: " + rule.getName());+ RulesEngine.LOG.finest("Registering JSON rule: " + rule.getName());rules.register(rule);}@@ -418,7 +418,7 @@ public class RulesetDeployment {throw new IllegalArgumentException("Defined 'then' is not a function in rule: " + name);}- RulesEngine.LOG.finer("Registering javascript rule: " + name);+ RulesEngine.LOG.finest("Registering javascript rule: " + name);rules.register(new RuleBuilder().name(name).description(description).priority(priority).when(when).then(then).build()@@ -452,7 +452,7 @@ public class RulesetDeployment {script.setBinding(binding);script.run();for (Rule rule : rulesBuilder.build()) {- RulesEngine.LOG.finer("Registering groovy rule: " + rule.getName());+ RulesEngine.LOG.finest("Registering groovy rule: " + rule.getName());rules.register(rule);}diff --git a/manager/src/main/java/org/openremote/manager/rules/RulesetStorageService.java b/manager/src/main/java/org/openremote/manager/rules/RulesetStorageService.javaindex d36f7fa36..be1c296cb 100644--- a/manager/src/main/java/org/openremote/manager/rules/RulesetStorageService.java+++ b/manager/src/main/java/org/openremote/manager/rules/RulesetStorageService.java@@ -120,7 +120,7 @@ public class RulesetStorageService implements ContainerService {public <T extends Ruleset> List<T> findAll(Class<T> rulesetType, RulesetQuery query) {return persistenceService.doReturningTransaction(em -> {- LOG.finer("Building: " + query);+ LOG.finest("Building: " + query);StringBuilder sb = new StringBuilder();List<ParameterBinder> binders = new ArrayList<>();appendSelectString(sb, rulesetType, query);@@ -134,7 +134,7 @@ public class RulesetStorageService implements ContainerService {return em.unwrap(Session.class).doReturningWork(new AbstractReturningWork<List<T>>() {@Overridepublic List<T> execute(Connection connection) throws SQLException {- LOG.finer("Executing: " + sqlQuery);+ LOG.finest("Executing: " + sqlQuery);try (PreparedStatement st = connection.prepareStatement(sqlQuery)) {binders.forEach(parameterBinder -> parameterBinder.accept(st));diff --git a/manager/src/main/java/org/openremote/manager/rules/geofence/ORConsoleGeofenceAssetAdapter.java b/manager/src/main/java/org/openremote/manager/rules/geofence/ORConsoleGeofenceAssetAdapter.javaindex 229b87ac9..cd6ab7e99 100644--- a/manager/src/main/java/org/openremote/manager/rules/geofence/ORConsoleGeofenceAssetAdapter.java+++ b/manager/src/main/java/org/openremote/manager/rules/geofence/ORConsoleGeofenceAssetAdapter.java@@ -212,7 +212,7 @@ public class ORConsoleGeofenceAssetAdapter extends RouteBuilder implements Geofeif (assetStateLocationPredicates == null) {// No geofences exist for this asset- LOG.finer("Request for console '" + assetId + "' geofences: 0 found");+ LOG.finest("Request for console '" + assetId + "' geofences: 0 found");return new GeofenceDefinition[0];}@@ -222,7 +222,7 @@ public class ORConsoleGeofenceAssetAdapter extends RouteBuilder implements GeofelocationPredicate)).toArray(GeofenceDefinition[]::new);- LOG.finer("Request for console '" + assetId + "' geofences: " + geofences.length + " found");+ LOG.finest("Request for console '" + assetId + "' geofences: " + geofences.length + " found");return geofences;}diff --git a/manager/src/main/java/org/openremote/manager/security/ManagerKeycloakIdentityProvider.java b/manager/src/main/java/org/openremote/manager/security/ManagerKeycloakIdentityProvider.javaindex 5287fcaf3..13e3359d1 100644--- a/manager/src/main/java/org/openremote/manager/security/ManagerKeycloakIdentityProvider.java+++ b/manager/src/main/java/org/openremote/manager/security/ManagerKeycloakIdentityProvider.java@@ -291,7 +291,7 @@ public class ManagerKeycloakIdentityProvider extends KeycloakIdentityProvider imif(existingUser != null && !allowUpdate) {String msg = "Attempt to create user but it already exists: User=" + user;- LOG.fine(msg);+ LOG.warning(msg);throw new ForbiddenException(msg);}@@ -301,7 +301,7 @@ public class ManagerKeycloakIdentityProvider extends KeycloakIdentityProvider imUserRepresentation userRep = clientResource.getServiceAccountUser();if (userRep == null) {String msg = "Attempt to update/create service user but a regular client with same client ID as this username already exists: User=" + user;- LOG.fine(msg);+ LOG.warning(msg);throw new NotAllowedException(msg);}return userRep;@@ -314,7 +314,7 @@ public class ManagerKeycloakIdentityProvider extends KeycloakIdentityProvider imif (existingUser != null && user.getId() != null && !existingUser.getId().equals(user.getId())) {String msg = "Attempt to update user but retrieved user ID doesn't match supplied so ignoring: User=" + user;- LOG.fine(msg);+ LOG.warning(msg);throw new BadRequestException(msg);}@@ -323,13 +323,13 @@ public class ManagerKeycloakIdentityProvider extends KeycloakIdentityProvider imif (existingUser.isServiceAccount() != user.isServiceAccount()) {String msg = "Attempt to update user service account flag not allowed: User=" + user;- LOG.fine(msg);+ LOG.warning(msg);throw new NotAllowedException(msg);}if (existingUser.isServiceAccount() && !existingUser.getUsername().equals(user.getUsername())) {String msg = "Attempt to update username of service user not allowed: User=" + user;- LOG.fine(msg);+ LOG.warning(msg);throw new NotAllowedException(msg);}}@@ -905,12 +905,12 @@ public class ManagerKeycloakIdentityProvider extends KeycloakIdentityProvider im// Handle removed rolesexistingRealmRoles.stream().filter(realmRole -> !realmRoles.contains(realmRole)).forEach(realmRole -> {- LOG.finer("Removing realm role + " + realmRole);+ LOG.finest("Removing realm role + " + realmRole);rolesResource.deleteRole(realmRole.getName());});// Handle added rolesrealmRoles.stream().filter(realmRole -> !existingRealmRoles.contains(realmRole)).forEach(realmRole -> {- LOG.finer("Adding realm role + " + realmRole);+ LOG.finest("Adding realm role + " + realmRole);rolesResource.create(new RoleRepresentation(realmRole.getName(), realmRole.getDescription(), false));});}@@ -949,7 +949,7 @@ public class ManagerKeycloakIdentityProvider extends KeycloakIdentityProvider imList<RoleRepresentation> existingRealmRoles = rolesResource.list();realm.getNormalisedRealmRoles().stream().filter(realmRole -> existingRealmRoles.stream().noneMatch(roleRepresentation -> roleRepresentation.getName().equals(realmRole.getName()))).forEach(realmRole -> {- LOG.finer("Adding realm role + " + realmRole);+ LOG.finest("Adding realm role + " + realmRole);rolesResource.create(new RoleRepresentation(realmRole.getName(), realmRole.getDescription(), false));});diff --git a/manager/src/main/java/org/openremote/manager/setup/ManagerSetup.java b/manager/src/main/java/org/openremote/manager/setup/ManagerSetup.javaindex eaa312029..1bf44f046 100644--- a/manager/src/main/java/org/openremote/manager/setup/ManagerSetup.java+++ b/manager/src/main/java/org/openremote/manager/setup/ManagerSetup.java@@ -22,8 +22,8 @@ package org.openremote.manager.setup;import org.openremote.manager.asset.AssetProcessingService;import org.openremote.manager.asset.AssetStorageService;import org.openremote.manager.datapoint.AssetDatapointService;-import org.openremote.manager.persistence.ManagerPersistenceService;import org.openremote.manager.datapoint.AssetPredictedDatapointService;+import org.openremote.manager.persistence.ManagerPersistenceService;import org.openremote.manager.rules.RulesetStorageService;import org.openremote.manager.security.ManagerIdentityService;import org.openremote.model.Constants;@@ -31,14 +31,15 @@ import org.openremote.model.Container;import org.openremote.model.asset.Asset;import org.openremote.model.asset.agent.AgentLink;import org.openremote.model.asset.impl.*;-import org.openremote.model.attribute.*;+import org.openremote.model.attribute.Attribute;+import org.openremote.model.attribute.MetaItem;import org.openremote.model.geo.GeoJSONPoint;import org.openremote.model.setup.Setup;import org.openremote.model.util.ValueUtil;import org.openremote.model.value.ValueFormat;import org.openremote.model.value.ValueType;--import jline.internal.Log;+import org.slf4j.Logger;+import org.slf4j.LoggerFactory;import java.io.IOException;import java.nio.file.Files;@@ -48,16 +49,16 @@ import java.util.concurrent.ScheduledExecutorService;import java.util.function.Function;import java.util.function.Supplier;+import static org.openremote.container.util.MapAccess.getString;import static org.openremote.model.Constants.*;import static org.openremote.model.value.MetaItemType.*;import static org.openremote.model.value.ValueType.*;-import static org.openremote.container.util.MapAccess.getString;public class ManagerSetup implements Setup {public static final String OR_PROVISIONING_DOCROOT = "OR_PROVISIONING_DOCROOT";public static final String OR_PROVISIONING_DOCROOT_DEFAULT = "deployment/manager/provisioning";-+ protected static final Logger LOG = LoggerFactory.getLogger(ManagerSetup.class);protected Path provisionDocRoot;final protected ScheduledExecutorService executorService;@@ -462,7 +463,7 @@ public class ManagerSetup implements Setup {return;}- Log.info("Provisioning assets");+ LOG.info("Provisioning assets");Files.list(Paths.get(provisionDocRoot.toString(), "assets")).sorted().forEach(file -> {@@ -470,9 +471,9 @@ public class ManagerSetup implements Setup {Asset<?> asset = ValueUtil.JSON.readValue(file.toFile(), Asset.class);asset = assetStorageService.merge(asset);- Log.info("Asset merged: " + asset.toString());+ LOG.info("Asset merged: " + asset.toString());} catch (IOException e) {- Log.warn("Processing of file " + file.getFileName() + " went wrong", e);+ LOG.warn("Processing of file " + file.getFileName() + " went wrong", e);}});diff --git a/manager/src/main/java/org/openremote/manager/setup/SetupService.java b/manager/src/main/java/org/openremote/manager/setup/SetupService.javaindex 2bdd59c47..2cf2b10db 100644--- a/manager/src/main/java/org/openremote/manager/setup/SetupService.java+++ b/manager/src/main/java/org/openremote/manager/setup/SetupService.java@@ -67,6 +67,8 @@ public class SetupService implements ContainerService {boolean keycloakEnabled = container.getService(ManagerIdentityService.class).isKeycloakEnabled();String setupType = container.getConfig().get(SetupTasks.OR_SETUP_TYPE);+ LOG.info(SetupTasks.OR_SETUP_TYPE + " value: " + setupType);+if (keycloakEnabled) {// Keycloak is not managed by persistence service so need separate clean tasktasks.add(new KeycloakCleanSetup(container));@@ -77,7 +79,6 @@ public class SetupService implements ContainerService {.flatMap(discoveredSetupTasks -> {LOG.info("Found custom SetupTasks provider on classpath: " + discoveredSetupTasks.getClass().getName());List<Setup> tasks = discoveredSetupTasks.createTasks(container, setupType, keycloakEnabled);- LOG.info("Custom SetupTasks provider task count for setupType '" + setupType + "' = " + (tasks == null ? 0 : tasks.size()));return tasks != null ? tasks.stream() : null;}).toList());diff --git a/manager/src/main/java/org/openremote/manager/simulator/SimulatorService.java b/manager/src/main/java/org/openremote/manager/simulator/SimulatorService.javaindex f2216a909..1d23cfeeb 100644--- a/manager/src/main/java/org/openremote/manager/simulator/SimulatorService.java+++ b/manager/src/main/java/org/openremote/manager/simulator/SimulatorService.java@@ -114,7 +114,7 @@ public class SimulatorService extends RouteBuilder implements ContainerService {.filter(body().isInstanceOf(RequestSimulatorState.class)).process(exchange -> {RequestSimulatorState event = exchange.getIn().getBody(RequestSimulatorState.class);- LOG.finer("Handling from client: " + event);+ LOG.finest("Handling from client: " + event);String sessionKey = getSessionKey(exchange);@@ -124,7 +124,7 @@ public class SimulatorService extends RouteBuilder implements ContainerService {}protected void publishSimulatorState(String sessionKey, String agentId) {- LOG.finer("Attempting to publish simulator state: Agent ID=" + agentId);+ LOG.finest("Attempting to publish simulator state: Agent ID=" + agentId);Protocol<?> protocol = agentService.getProtocolInstance(agentId);diff --git a/manager/src/main/java/org/openremote/manager/syslog/SyslogService.java b/manager/src/main/java/org/openremote/manager/syslog/SyslogService.javaindex 7b134f936..2adeb6ae7 100644--- a/manager/src/main/java/org/openremote/manager/syslog/SyslogService.java+++ b/manager/src/main/java/org/openremote/manager/syslog/SyslogService.java@@ -294,7 +294,7 @@ public class SyslogService extends Handler implements ContainerService {batch.clear();if (transientEvents.size() == 0)return;- LOG.finer("Flushing syslog batch: " + transientEvents.size());+ LOG.finest("Flushing syslog batch: " + transientEvents.size());try {persistenceService.doTransaction(em -> {try {diff --git a/manager/src/main/java/org/openremote/manager/web/ManagerFileServlet.java b/manager/src/main/java/org/openremote/manager/web/ManagerFileServlet.javaindex e07892af8..b11f4e3ce 100644--- a/manager/src/main/java/org/openremote/manager/web/ManagerFileServlet.java+++ b/manager/src/main/java/org/openremote/manager/web/ManagerFileServlet.java@@ -123,7 +123,7 @@ public class ManagerFileServlet extends FileServlet {String requestPath = exchange.getRequestPath();Matcher staticMatcher = requestPattern.matcher(requestPath);if (staticMatcher.matches()) {- LOG.finer("Serving static resource: " + requestPath);+ LOG.finest("Serving static resource: " + requestPath);String remaining = staticMatcher.group(1);String relativePath = remaining == null || remaining.length() == 0 ? "/" : remaining;exchange.setRelativePath(relativePath);diff --git a/manager/src/main/java/org/openremote/manager/web/ManagerWebService.java b/manager/src/main/java/org/openremote/manager/web/ManagerWebService.javaindex 3b9187abc..6a1b4cfb2 100644--- a/manager/src/main/java/org/openremote/manager/web/ManagerWebService.java+++ b/manager/src/main/java/org/openremote/manager/web/ManagerWebService.java@@ -226,7 +226,7 @@ public class ManagerWebService extends WebService {"Default app redirect",exchange -> exchange.getRequestPath().equals("/"),exchange -> {- LOG.finer("Handling root request, redirecting client to default app");+ LOG.finest("Handling root request, redirecting client to default app");new RedirectHandler(redirect(exchange, rootRedirectPath)).handleRequest(exchange);}));}diff --git a/manager/src/main/resources/logging-audit.properties b/manager/src/main/resources/logging-audit.propertiesnew file mode 100644index 000000000..58c76d92e--- /dev/null+++ b/manager/src/main/resources/logging-audit.properties@@ -0,0 +1,89 @@+# Log on STDOUT, filesystem and internal syslog service (monitoring in Manager UI)+handlers=java.util.logging.ConsoleHandler, \+ org.openremote.manager.syslog.SyslogService, \+ java.util.logging.FileHandler++###############################################################################+# Console handler+###############################################################################++java.util.logging.ConsoleHandler.level=INFO++# Console format, you can colorize this in IntelliJ IDEA "Run Application " console+# with the GrepConsole plugin and after copying the configuration file of your+# choice to ~/Library/Preferences/IntelliJ*/options/GrepConsole.xml:+#+# - tools/intellijTheme-Default-GrepConsole.xml+# - tools/intellijTheme-Darcula-GrepConsole.xml+#+java.util.logging.ConsoleHandler.formatter=org.openremote.container.util.LogFormatter++###############################################################################+# File handler+###############################################################################++# Set to FINEST to get all enabled log categories on file handler+java.util.logging.FileHandler.level=FINE++# Output file and format+java.util.logging.FileHandler.pattern=/deployment/openremote.log+java.util.logging.FileHandler.formatter=org.openremote.container.util.LogFormatter+# Rotate between 10 log files+java.util.logging.FileHandler.count=10+# 10 mb per file+java.util.logging.FileHandler.limit=10000000+# Set to false to clear log on restart+java.util.logging.FileHandler.append=true++###############################################################################+# Categories and levels+###############################################################################+# The following level convention is used+# FINE = System.Logger.Level.DEBUG - Will log processing times and audit logs+# FINEST = System.Logger.Level.TRACE - Will log everything++# The root logger category, the default for all categories not configured here+.level=INFO++# The root logger category of OpenRemote+org.openremote.level=INFO++# Processing time logging+#org.openremote.container.concurrent.GlobalLock.level=FINE+#org.openremote.manager.asset.AssetProcessingService.level=FINE+#org.openremote.manager.asset.AssetStorageService.level=FINE+#org.openremote.manager.rules.level=FINE++# Audit logging+# Set to fine to log MQTT connections+org.openremote.manager.mqtt.level=FINE+# Set to fine to log WS connections+org.openremote.container.web.socket.WebsocketAdapter.level=FINE+# Set to fine to log HTTP requests for servlet deployments+org.openremote.container.web.RequestLogger.level=FINE+# Set to fine to log all HTTP requests (not just deployments)+#org.openremote.container.web.WebService.level=INFO++++# Third party overrides+org.jboss.resteasy.level=WARNING+org.keycloak.level=WARNING+io.undertow.level=WARNING+org.hibernate.level=WARNING+org.hibernate.cfg.beanvalidation.TypeSafeActivator.level=SEVERE+com.zaxxer.hikari.level=WARNING+javax.management.level=WARNING+org.xnio.level=WARNING+org.apache.camel.management.level=WARNING+org.apache.camel.impl.converter.DefaultTypeConverter.level=WARNING+org.apache.camel.impl.DefaultShutdownStrategy.level=SEVERE+org.jeasy.rules.level=WARNING+org.apache.activemq.audit.level=WARNING++# Set this to FINEST to log outgoing HTTP traffic+#org.apache.http.level=WARNING+#org.apache.http.client.protocol.level=SEVERE++# Set to SEVERE to log invalid access tokens+org.keycloak.adapters.BearerTokenRequestAuthenticator.level=OFFdiff --git a/manager/src/main/resources/logging-dev.properties b/manager/src/main/resources/logging-dev.propertiesindex 7f31da063..0c31dbbac 100644--- a/manager/src/main/resources/logging-dev.properties+++ b/manager/src/main/resources/logging-dev.properties@@ -1,24 +1,12 @@-# Built in development logging configuration; used by default when OR_DEV_MODE=true--###############################################################################-# Output handlers-###############################################################################-# Log on STDOUT and internal syslog service (monitoring in Manager UI)handlers=java.util.logging.ConsoleHandler, \org.openremote.manager.syslog.SyslogService-# Log extra data to file for debug purposes-#handlers=java.util.logging.ConsoleHandler, \-# java.util.logging.FileHandler, \-# org.openremote.manager.syslog.SyslogService-################################################################################ Console handler###############################################################################-# Set to FINEST to get all enabled log categories on console handler-java.util.logging.ConsoleHandler.level=FINER+java.util.logging.ConsoleHandler.level=FINE# Console format, you can colorize this in IntelliJ IDEA "Run Application " console# with the GrepConsole plugin and after copying the configuration file of your@@ -29,78 +17,55 @@ java.util.logging.ConsoleHandler.level=FINER#java.util.logging.ConsoleHandler.formatter=org.openremote.container.util.LogFormatter-###############################################################################-# File handler-###############################################################################--## Set to FINEST to get all enabled log categories on file handler-#java.util.logging.FileHandler.level=FINER-#-## Output file and format-#java.util.logging.FileHandler.pattern=/deployment/openremote.log-#java.util.logging.FileHandler.formatter=org.openremote.container.util.LogFormatter-## Rotate between 10 log files-#java.util.logging.FileHandler.count=10-## 10 mb per file-#java.util.logging.FileHandler.limit=10000000-## Set to false to clear log on restart-#java.util.logging.FileHandler.append=false--###############################################################################-# Categories+# Categories and levels###############################################################################+# The following level convention is used+# FINE = System.Logger.Level.DEBUG - Will log processing times and audit logs+# FINEST = System.Logger.Level.TRACE - Will log everything# The root logger category, the default for all categories not configured here.level=INFO-# The root logger category of OpenRemote, FINE logs much more than INFO+# The root logger category of OpenRemoteorg.openremote.level=FINE-# Rule execution logging-#-# - Use "global java.util.logging.Logger LOG;" in rule RHS to access this logger-# - Set to FINEST to automatically log all fact additions, removals, and updates-# - Set to INFO and prefix your rule name with "-" or "--" to log execution details-org.openremote.rules.Rules.level=FINE+# Processing time logging+#org.openremote.container.concurrent.GlobalLock.level=FINE+#org.openremote.manager.asset.AssetProcessingService.level=FINE+#org.openremote.manager.asset.AssetStorageService.level=FINE+#org.openremote.manager.rules.level=FINE-# Set to INFO to get rules engine statistics periodically, FINEST to dump all facts-org.openremote.rules.RulesEngineStats.level=OFF+# Audit logging+# Set to fine to log MQTT connections+#org.openremote.manager.mqtt.level=FINE+# Set to fine to log WS connections+#org.openremote.container.web.socket.WebsocketAdapter.level=FINE+# Set to fine to log HTTP requests for servlet deployments+#org.openremote.container.web.RequestLogger.level=FINE+# Set to fine to log all HTTP requests (not just deployments)+#org.openremote.container.web.WebService.level=INFO-# Set to INFO or higher to debug internal messaging-org.openremote.container.message.MessageBrokerContext.level=WARNING-# Set to FINE to log full exception stack traces-org.openremote.container.web.WebServiceExceptions.level=FINE-# Set to SEVERE to log invalid access tokens-org.keycloak.adapters.BearerTokenRequestAuthenticator.level=SEVERE--# Set this to FINEST to log outgoing HTTP traffic-org.apache.http.level=WARNING-org.apache.http.impl.conn.DefaultClientConnection.level=WARNING-org.apache.http.client.protocol.level=SEVERE--# Set this to FINEST to log SQL execution-org.hibernate.SQL.level=WARNING-org.hibernate.type.descriptor.sql.BasicBinder.level=WARNING--# Log only attribute event processing begin/end, useful to debug many events-org.openremote.container.web.level=INFO-org.openremote.manager.server.level=INFO--org.openremote.manager.datapoint.level=FINEST--# Low-level debugging overrides, most of them are to stop chatty categories+# Third party overrides+org.jboss.resteasy.level=WARNING+org.keycloak.level=WARNING+io.undertow.level=WARNINGorg.hibernate.level=WARNINGorg.hibernate.cfg.beanvalidation.TypeSafeActivator.level=SEVEREcom.zaxxer.hikari.level=WARNINGjavax.management.level=WARNINGorg.xnio.level=WARNING-org.apache.camel.level=WARNINGorg.apache.camel.management.level=WARNINGorg.apache.camel.impl.converter.DefaultTypeConverter.level=WARNINGorg.apache.camel.impl.DefaultShutdownStrategy.level=SEVEREorg.jeasy.rules.level=WARNING-org.postgresql.jdbc.level=INFOorg.apache.activemq.audit.level=WARNING++# Set this to FINEST to log outgoing HTTP traffic+#org.apache.http.level=WARNING+#org.apache.http.client.protocol.level=SEVERE++# Set to SEVERE to log invalid access tokens+org.keycloak.adapters.BearerTokenRequestAuthenticator.level=OFFdiff --git a/manager/src/main/resources/logging-timings-audit.properties b/manager/src/main/resources/logging-timings-audit.propertiesnew file mode 100644index 000000000..1df0c36ac--- /dev/null+++ b/manager/src/main/resources/logging-timings-audit.properties@@ -0,0 +1,89 @@+# Log on STDOUT, filesystem and internal syslog service (monitoring in Manager UI)+handlers=java.util.logging.ConsoleHandler, \+ org.openremote.manager.syslog.SyslogService, \+ java.util.logging.FileHandler++###############################################################################+# Console handler+###############################################################################++java.util.logging.ConsoleHandler.level=INFO++# Console format, you can colorize this in IntelliJ IDEA "Run Application " console+# with the GrepConsole plugin and after copying the configuration file of your+# choice to ~/Library/Preferences/IntelliJ*/options/GrepConsole.xml:+#+# - tools/intellijTheme-Default-GrepConsole.xml+# - tools/intellijTheme-Darcula-GrepConsole.xml+#+java.util.logging.ConsoleHandler.formatter=org.openremote.container.util.LogFormatter++###############################################################################+# File handler+###############################################################################++# Set to FINEST to get all enabled log categories on file handler+java.util.logging.FileHandler.level=FINE++# Output file and format+java.util.logging.FileHandler.pattern=/deployment/openremote.log+java.util.logging.FileHandler.formatter=org.openremote.container.util.LogFormatter+# Rotate between 10 log files+java.util.logging.FileHandler.count=10+# 10 mb per file+java.util.logging.FileHandler.limit=10000000+# Set to false to clear log on restart+java.util.logging.FileHandler.append=true++###############################################################################+# Categories and levels+###############################################################################+# The following level convention is used+# FINE = System.Logger.Level.DEBUG - Will log processing times and audit logs+# FINEST = System.Logger.Level.TRACE - Will log everything++# The root logger category, the default for all categories not configured here+.level=INFO++# The root logger category of OpenRemote+org.openremote.level=INFO++# Processing time logging+org.openremote.container.concurrent.GlobalLock.level=FINE+org.openremote.manager.asset.AssetProcessingService.level=FINE+org.openremote.manager.asset.AssetStorageService.level=FINE+org.openremote.manager.rules.level=FINE++# Audit logging+# Set to fine to log MQTT connections+org.openremote.manager.mqtt.level=FINE+# Set to fine to log WS connections+org.openremote.container.web.socket.WebsocketAdapter.level=FINE+# Set to fine to log HTTP requests for servlet deployments+org.openremote.container.web.RequestLogger.level=FINE+# Set to fine to log all HTTP requests (not just deployments)+#org.openremote.container.web.WebService.level=INFO++++# Third party overrides+org.jboss.resteasy.level=WARNING+org.keycloak.level=WARNING+io.undertow.level=WARNING+org.hibernate.level=WARNING+org.hibernate.cfg.beanvalidation.TypeSafeActivator.level=SEVERE+com.zaxxer.hikari.level=WARNING+javax.management.level=WARNING+org.xnio.level=WARNING+org.apache.camel.management.level=WARNING+org.apache.camel.impl.converter.DefaultTypeConverter.level=WARNING+org.apache.camel.impl.DefaultShutdownStrategy.level=SEVERE+org.jeasy.rules.level=WARNING+org.apache.activemq.audit.level=WARNING++# Set this to FINEST to log outgoing HTTP traffic+#org.apache.http.level=WARNING+#org.apache.http.client.protocol.level=SEVERE++# Set to SEVERE to log invalid access tokens+org.keycloak.adapters.BearerTokenRequestAuthenticator.level=OFFdiff --git a/manager/src/main/resources/logging-timings.properties b/manager/src/main/resources/logging-timings.propertiesnew file mode 100644index 000000000..54fc983fa--- /dev/null+++ b/manager/src/main/resources/logging-timings.properties@@ -0,0 +1,89 @@+# Log on STDOUT, filesystem and internal syslog service (monitoring in Manager UI)+handlers=java.util.logging.ConsoleHandler, \+ org.openremote.manager.syslog.SyslogService, \+ java.util.logging.FileHandler++###############################################################################+# Console handler+###############################################################################++java.util.logging.ConsoleHandler.level=INFO++# Console format, you can colorize this in IntelliJ IDEA "Run Application " console+# with the GrepConsole plugin and after copying the configuration file of your+# choice to ~/Library/Preferences/IntelliJ*/options/GrepConsole.xml:+#+# - tools/intellijTheme-Default-GrepConsole.xml+# - tools/intellijTheme-Darcula-GrepConsole.xml+#+java.util.logging.ConsoleHandler.formatter=org.openremote.container.util.LogFormatter++###############################################################################+# File handler+###############################################################################++# Set to FINEST to get all enabled log categories on file handler+java.util.logging.FileHandler.level=FINE++# Output file and format+java.util.logging.FileHandler.pattern=/deployment/openremote.log+java.util.logging.FileHandler.formatter=org.openremote.container.util.LogFormatter+# Rotate between 10 log files+java.util.logging.FileHandler.count=10+# 10 mb per file+java.util.logging.FileHandler.limit=10000000+# Set to false to clear log on restart+java.util.logging.FileHandler.append=true++###############################################################################+# Categories and levels+###############################################################################+# The following level convention is used+# FINE = System.Logger.Level.DEBUG - Will log processing times and audit logs+# FINEST = System.Logger.Level.TRACE - Will log everything++# The root logger category, the default for all categories not configured here+.level=INFO++# The root logger category of OpenRemote+org.openremote.level=INFO++# Processing time logging+org.openremote.container.concurrent.GlobalLock.level=FINE+org.openremote.manager.asset.AssetProcessingService.level=FINE+org.openremote.manager.asset.AssetStorageService.level=FINE+org.openremote.manager.rules.level=FINE++# Audit logging+# Set to fine to log MQTT connections+#org.openremote.manager.mqtt.level=FINE+# Set to fine to log WS connections+#org.openremote.container.web.socket.WebsocketAdapter.level=FINE+# Set to fine to log HTTP requests for servlet deployments+#org.openremote.container.web.RequestLogger.level=FINE+# Set to fine to log all HTTP requests (not just deployments)+#org.openremote.container.web.WebService.level=INFO++++# Third party overrides+org.jboss.resteasy.level=WARNING+org.keycloak.level=WARNING+io.undertow.level=WARNING+org.hibernate.level=WARNING+org.hibernate.cfg.beanvalidation.TypeSafeActivator.level=SEVERE+com.zaxxer.hikari.level=WARNING+javax.management.level=WARNING+org.xnio.level=WARNING+org.apache.camel.management.level=WARNING+org.apache.camel.impl.converter.DefaultTypeConverter.level=WARNING+org.apache.camel.impl.DefaultShutdownStrategy.level=SEVERE+org.jeasy.rules.level=WARNING+org.apache.activemq.audit.level=WARNING++# Set this to FINEST to log outgoing HTTP traffic+#org.apache.http.level=WARNING+#org.apache.http.client.protocol.level=SEVERE++# Set to SEVERE to log invalid access tokens+org.keycloak.adapters.BearerTokenRequestAuthenticator.level=OFFdiff --git a/manager/src/main/resources/logging-trace.properties b/manager/src/main/resources/logging-trace.propertiesindex bced75ba7..141fed53f 100644--- a/manager/src/main/resources/logging-trace.properties+++ b/manager/src/main/resources/logging-trace.properties@@ -1,21 +1,12 @@-# A logging configuration to give traceability of where time is being spent-# in the system for identifying potential issues - Uses a file handler to avoid-# generating too much console handler traffic--###############################################################################-# Output handlers-###############################################################################--# Log on STDOUT and internal syslog service (monitoring in Manager UI)+# Log on STDOUT, filesystem and internal syslog service (monitoring in Manager UI)handlers=java.util.logging.ConsoleHandler, \- java.util.logging.FileHandler, \- org.openremote.manager.syslog.SyslogService+ org.openremote.manager.syslog.SyslogService, \+ java.util.logging.FileHandler################################################################################ Console handler###############################################################################-# Set to FINEST to get all enabled log categories on console handlerjava.util.logging.ConsoleHandler.level=INFO# Console format, you can colorize this in IntelliJ IDEA "Run Application " console@@ -32,7 +23,7 @@ java.util.logging.ConsoleHandler.formatter=org.openremote.container.util.LogForm################################################################################ Set to FINEST to get all enabled log categories on file handler-java.util.logging.FileHandler.level=FINEST+java.util.logging.FileHandler.level=FINE# Output file and formatjava.util.logging.FileHandler.pattern=/deployment/openremote.log@@ -42,73 +33,57 @@ java.util.logging.FileHandler.count=10# 10 mb per filejava.util.logging.FileHandler.limit=10000000# Set to false to clear log on restart-java.util.logging.FileHandler.append=false+java.util.logging.FileHandler.append=true###############################################################################-# Categories+# Categories and levels###############################################################################+# The following level convention is used+# FINE = System.Logger.Level.DEBUG - Will log processing times and audit logs+# FINEST = System.Logger.Level.TRACE - Will log everything# The root logger category, the default for all categories not configured here.level=INFO-# The root logger category of OpenRemote, FINE logs much more than INFO-org.openremote.level=INFO--# Rule execution logging-#-# - Use "global java.util.logging.Logger LOG;" in rule RHS to access this logger-# - Set to FINEST to automatically log all fact additions, removals, and updates-# - Set to INFO and prefix your rule name with "-" or "--" to log execution details-org.openremote.rules.Rules.level=INFO+# The root logger category of OpenRemote+org.openremote.level=FINEST-# Set to FINE to get info about each processed event, including consumer and time taken to process-org.openremote.manager.asset.AssetProcessingService.level=FINE+# Processing time logging+#org.openremote.container.concurrent.GlobalLock.level=FINE+#org.openremote.manager.asset.AssetProcessingService.level=FINE+#org.openremote.manager.asset.AssetStorageService.level=FINE+#org.openremote.manager.rules.level=FINE-# Set to FINE to get info about how long a thread holds the global lock-org.openremote.container.concurrent.GlobalLock.level=FINE+# Audit logging+# Set to fine to log MQTT connections+#org.openremote.manager.mqtt.level=FINE+# Set to fine to log WS connections+#org.openremote.container.web.socket.WebsocketAdapter.level=FINE+# Set to fine to log HTTP requests for servlet deployments+#org.openremote.container.web.RequestLogger.level=FINE+# Set to fine to log all HTTP requests (not just deployments)+#org.openremote.container.web.WebService.level=INFO-# Set to FINE to get info about how long each engine fire takes to process-org.openremote.rules.RulesEngine.level=FINE-# Set to FINE to get rules engine statistics periodically, FINEST to dump all facts-org.openremote.rules.RulesEngineStats.level=OFF-# Set to FINE to get CRUD query times (including hydration)-org.openremote.manager.asset.AssetStorageService.level=FINE--# Set to INFO or higher to debug internal messaging-org.openremote.container.message.MessageBrokerContext.level=WARNING--# Set to FINE to log full exception stack traces-org.openremote.container.web.WebServiceExceptions.level=INFO--# Set to SEVERE to log invalid access tokens-org.keycloak.adapters.BearerTokenRequestAuthenticator.level=OFF--# Set this to FINEST to log outgoing HTTP traffic-org.apache.http.level=WARNING-org.apache.http.impl.conn.DefaultClientConnection.level=WARNING-org.apache.http.client.protocol.level=SEVERE--# Set this to FINEST to log SQL execution-org.hibernate.SQL.level=WARNING-org.hibernate.type.descriptor.sql.BasicBinder.level=WARNING--# Log only attribute event processing begin/end, useful to debug many events-#org.openremote.container.web.level=FINE-#org.openremote.manager.server.level=FINE-#org.openremote.manager.server.asset.AssetProcessingService.level=FINE--# Low-level debugging overrides, most of them are to stop chatty categories+# Third party overrides+org.jboss.resteasy.level=WARNING+org.keycloak.level=WARNING+io.undertow.level=WARNINGorg.hibernate.level=WARNINGorg.hibernate.cfg.beanvalidation.TypeSafeActivator.level=SEVEREcom.zaxxer.hikari.level=WARNINGjavax.management.level=WARNINGorg.xnio.level=WARNING-org.apache.camel.level=INFOorg.apache.camel.management.level=WARNINGorg.apache.camel.impl.converter.DefaultTypeConverter.level=WARNINGorg.apache.camel.impl.DefaultShutdownStrategy.level=SEVEREorg.jeasy.rules.level=WARNING-org.postgresql.jdbc.level=INFOorg.apache.activemq.audit.level=WARNING++# Set this to FINEST to log outgoing HTTP traffic+#org.apache.http.level=WARNING+#org.apache.http.client.protocol.level=SEVERE++# Set to SEVERE to log invalid access tokens+org.keycloak.adapters.BearerTokenRequestAuthenticator.level=OFFdiff --git a/manager/src/main/resources/logging.properties b/manager/src/main/resources/logging.propertiesindex e2c69b240..897ba560e 100644--- a/manager/src/main/resources/logging.properties+++ b/manager/src/main/resources/logging.properties@@ -1,19 +1,17 @@-# Built in production logging configuration; used by default when OR_DEV_MODE=false+# A logging configuration to give traceability of where time is being spent+# in the system for identifying potential issues - Uses a file handler to avoid+# generating too much console handler traffic-###############################################################################-# Output handlers-###############################################################################--# Log on STDOUT and internal syslog service (monitoring in Manager UI)+# Log on STDOUT, filesystem and internal syslog service (monitoring in Manager UI)handlers=java.util.logging.ConsoleHandler, \- org.openremote.manager.syslog.SyslogService+ org.openremote.manager.syslog.SyslogService, \+ java.util.logging.FileHandler################################################################################ Console handler###############################################################################-# Set to FINEST to get all enabled log categories on console handler-java.util.logging.ConsoleHandler.level=FINE+java.util.logging.ConsoleHandler.level=INFO# Console format, you can colorize this in IntelliJ IDEA "Run Application " console# with the GrepConsole plugin and after copying the configuration file of your@@ -25,58 +23,71 @@ java.util.logging.ConsoleHandler.level=FINEjava.util.logging.ConsoleHandler.formatter=org.openremote.container.util.LogFormatter###############################################################################-# Categories+# File handler###############################################################################-# The root logger category, the default for all categories not configured here-.level=INFO+# Set to FINEST to get all enabled log categories on file handler+java.util.logging.FileHandler.level=FINE-# The root logger category of OpenRemote, FINE logs much more than INFO-org.openremote.level=INFO+# Output file and format+java.util.logging.FileHandler.pattern=/deployment/openremote.log+java.util.logging.FileHandler.formatter=org.openremote.container.util.LogFormatter+# Rotate between 10 log files+java.util.logging.FileHandler.count=10+# 10 mb per file+java.util.logging.FileHandler.limit=10000000+# Set to false to clear log on restart+java.util.logging.FileHandler.append=true-# Rule execution logging-#-# - Use "global java.util.logging.Logger LOG;" in rule RHS to access this logger-# - Set to FINEST to automatically log all fact additions, removals, and updates-# - Set to INFO and prefix your rule name with "-" or "--" to log execution details-org.openremote.rules.Rules.level=INFO--# Set to INFO to get rules engine statistics periodically, FINEST to dump all facts-org.openremote.rules.RulesEngineStats.level=OFF+###############################################################################+# Categories and levels+###############################################################################+# The following level convention is used+# FINE = System.Logger.Level.DEBUG - Will log processing times and audit logs+# FINEST = System.Logger.Level.TRACE - Will log everything-# Set to INFO or higher to debug internal messaging-org.openremote.container.message.MessageBrokerContext.level=WARNING+# The root logger category, the default for all categories not configured here+.level=INFO-# Set to FINE to log full exception stack traces-org.openremote.container.web.WebServiceExceptions.level=INFO+# The root logger category of OpenRemote+org.openremote.level=INFO-# Set to SEVERE to log invalid access tokens-org.keycloak.adapters.BearerTokenRequestAuthenticator.level=OFF+# Processing time logging+#org.openremote.container.concurrent.GlobalLock.level=FINE+#org.openremote.manager.asset.AssetProcessingService.level=FINE+#org.openremote.manager.asset.AssetStorageService.level=FINE+#org.openremote.manager.rules.level=FINE-# Set this to FINEST to log outgoing HTTP traffic-org.apache.http.level=WARNING-org.apache.http.impl.conn.DefaultClientConnection.level=WARNING-org.apache.http.client.protocol.level=SEVERE+# Audit logging+# Set to fine to log MQTT connections+#org.openremote.manager.mqtt.level=FINE+# Set to fine to log WS connections+#org.openremote.container.web.socket.WebsocketAdapter.level=FINE+# Set to fine to log HTTP requests for servlet deployments+#org.openremote.container.web.RequestLogger.level=FINE+# Set to fine to log all HTTP requests (not just deployments)+#org.openremote.container.web.WebService.level=INFO-# Set this to FINEST to log SQL execution-org.hibernate.SQL.level=WARNING-org.hibernate.type.descriptor.sql.BasicBinder.level=WARNING-# Log only attribute event processing begin/end, useful to debug many events-#org.openremote.container.web.level=FINE-#org.openremote.manager.server.level=FINE-#org.openremote.manager.server.asset.AssetProcessingService.level=FINE-# Low-level debugging overrides, most of them are to stop chatty categories+# Third party overrides+org.jboss.resteasy.level=WARNING+org.keycloak.level=WARNING+io.undertow.level=WARNINGorg.hibernate.level=WARNINGorg.hibernate.cfg.beanvalidation.TypeSafeActivator.level=SEVEREcom.zaxxer.hikari.level=WARNINGjavax.management.level=WARNINGorg.xnio.level=WARNING-org.apache.camel.level=INFOorg.apache.camel.management.level=WARNINGorg.apache.camel.impl.converter.DefaultTypeConverter.level=WARNINGorg.apache.camel.impl.DefaultShutdownStrategy.level=SEVEREorg.jeasy.rules.level=WARNING-org.postgresql.jdbc.level=INFOorg.apache.activemq.audit.level=WARNING++# Set this to FINEST to log outgoing HTTP traffic+#org.apache.http.level=WARNING+#org.apache.http.client.protocol.level=SEVERE++# Set to SEVERE to log invalid access tokens+org.keycloak.adapters.BearerTokenRequestAuthenticator.level=OFFdiff --git a/model/src/main/java/org/openremote/model/asset/Asset.java b/model/src/main/java/org/openremote/model/asset/Asset.javaindex b4466e0d6..5e1da532c 100644--- a/model/src/main/java/org/openremote/model/asset/Asset.java+++ b/model/src/main/java/org/openremote/model/asset/Asset.java@@ -459,7 +459,7 @@ public abstract class Asset<T extends Asset<?>> implements IdentifiableEntity<T>}public String toStringAll() {- return "Asset{" ++ return getClass().getSimpleName() + "{" +"id='" + id + '\'' +", version=" + version +", createdOn=" + createdOn +diff --git a/model/src/main/java/org/openremote/model/event/bus/EventBus.java b/model/src/main/java/org/openremote/model/event/bus/EventBus.javaindex b0946c9b3..f48be7f79 100644--- a/model/src/main/java/org/openremote/model/event/bus/EventBus.java+++ b/model/src/main/java/org/openremote/model/event/bus/EventBus.java@@ -123,7 +123,7 @@ public class EventBus {}}} else if (LOG.isLoggable(Level.FINE)) {- LOG.finer("Dropping vetoed event: " + event);+ LOG.finest("Dropping vetoed event: " + event);}}}diff --git a/model/src/main/java/org/openremote/model/event/shared/RealmFilter.java b/model/src/main/java/org/openremote/model/event/shared/RealmFilter.javaindex 0bf4c8ec3..c22e8ac59 100644--- a/model/src/main/java/org/openremote/model/event/shared/RealmFilter.java+++ b/model/src/main/java/org/openremote/model/event/shared/RealmFilter.java@@ -42,7 +42,7 @@ public class RealmFilter<T extends RealmScopedEvent> extends EventFilter<T> {}@Override- public RealmScopedEvent apply(RealmScopedEvent event) {+ public T apply(T event) {return getName().equals(event.getRealm()) ? event : null;}diff --git a/model/src/main/java/org/openremote/model/protocol/ProtocolUtil.java b/model/src/main/java/org/openremote/model/protocol/ProtocolUtil.javaindex 8c94b4bf7..7b111e143 100644--- a/model/src/main/java/org/openremote/model/protocol/ProtocolUtil.java+++ b/model/src/main/java/org/openremote/model/protocol/ProtocolUtil.java@@ -108,7 +108,7 @@ public final class ProtocolUtil {// value conversionObject finalValue = value;ignoreAndConvertedValue = agentLink.getWriteValueConverter().map(converter -> {- Protocol.LOG.finer("Applying attribute write value converter to attribute: assetId=" + assetId + ", attribute=" + attribute.getName());+ Protocol.LOG.finest("Applying attribute write value converter to attribute: assetId=" + assetId + ", attribute=" + attribute.getName());return applyValueConverter(finalValue, converter);}).orElse(new Pair<>(false, finalValue));@@ -149,7 +149,7 @@ public final class ProtocolUtil {// value filteringagentLink.getValueFilters().ifPresent(valueFilters -> {- Protocol.LOG.finer("Applying attribute value filters to attribute: assetId=" + assetId + ", attribute=" + attribute.getName());+ Protocol.LOG.finest("Applying attribute value filters to attribute: assetId=" + assetId + ", attribute=" + attribute.getName());Object o = ValueUtil.applyValueFilters(value, valueFilters);if (o == null) {Protocol.LOG.info("Value filters generated a null value for attribute: assetId=" + assetId + ", attribute=" + attribute.getName());@@ -159,7 +159,7 @@ public final class ProtocolUtil {// value conversionignoreAndConvertedValue = agentLink.getValueConverter().map(converter -> {- Protocol.LOG.finer("Applying attribute value converter to attribute: assetId=" + assetId + ", attribute=" + attribute.getName());+ Protocol.LOG.finest("Applying attribute value converter to attribute: assetId=" + assetId + ", attribute=" + attribute.getName());return applyValueConverter(valRef.get(), converter);}).orElse(new Pair<>(false, valRef.get()));@@ -178,7 +178,7 @@ public final class ProtocolUtil {Class<?> fromType = valRef.get().getClass();if (toType != fromType) {- Protocol.LOG.finer("Applying built in attribute value conversion: " + fromType + " -> " + toType);+ Protocol.LOG.finest("Applying built in attribute value conversion: " + fromType + " -> " + toType);valRef.set(ValueUtil.getValueCoerced(valRef.get(), toType).orElse(null));if (valRef.get() == null) {diff --git a/profile/deploy.yml b/profile/deploy.ymlindex 9d0d81f62..3a5b50843 100644--- a/profile/deploy.yml+++ b/profile/deploy.yml@@ -122,8 +122,9 @@ services:#devices:# - /dev/ttyACM0#ports:- # - "8000:8000" # Remote debugging port - NOT FOR PRODUCTION USE!!!# - "8080:8080" # Web server port+ # - "8000:8000" # Remote debugging port - NOT FOR PRODUCTION USE!!!+ # - "8085:8085" # JMX port - FOR DIAGNOSTICS ONLY!!!logging:options:# Use very little logging for container STDOUT, this is@@ -299,9 +300,19 @@ services:# -XX:GCLogFileSize=50M -Xloggc:/gc.log# -XX:OnOutOfMemoryError="shutdown -r" -d64# -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/dump.hprof}-- # Custom JVM tool options (for remote debugging)- #JAVA_TOOL_OPTIONS: '-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n'+#+# THE FOLLOWING OPTIONS CAN BE USED TO ENABLE JMX; PORT MUST ALSO BE EXPOSED+# ACCESS SHOULD BE RESTRICTED BY FIREWALL TO SPECIFIC IPs FOR DIAGNOSTIC PURPOSES+#+# -Dcom.sun.management.jmxremote=true+# -Dcom.sun.management.jmxremote.ssl=false+# -Dcom.sun.management.jmxremote.authenticate=false+# -Dcom.sun.management.jmxremote.port=8085+# -Dcom.sun.management.jmxremote.rmi.port=8085+# -Djava.rmi.server.hostname=${OR_HOSTNAME:-localhost}++# Custom JVM tool options (for remote debugging)+#JAVA_TOOL_OPTIONS: '-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n'# Keycloak identity providerkeycloak:diff --git a/test/build.gradle b/test/build.gradleindex 1e6d5b748..b58ea2627 100644--- a/test/build.gradle+++ b/test/build.gradle@@ -13,6 +13,9 @@ apply plugin: "signing"dependencies {+ // SLF4J facade+ testImplementation "org.slf4j:slf4j-api:$slf4jVersion"+testImplementation resolveProject(":setup").sourceSets.integration.outputapi resolveProject(":manager")@@ -24,24 +27,24 @@ dependencies {testFixturesRuntimeOnly "net.bytebuddy:byte-buddy:$byteBuddyVersion" // allows mocking of classes (in addition to interfaces)testFixturesRuntimeOnly "org.objenesis:objenesis:$objenesisVersion" // allows mocking of classes without default constructor (together with ByteBuddy or CGLIB)- testImplementation("com.github.calimero:calimero-server:$calimeroVersion") {- // Libraries should not depend on a logging implementation and/or alpha versions!- exclude group: "org.slf4j"- }+ testImplementation "com.github.calimero:calimero-server:$calimeroVersion"testImplementation "com.google.firebase:firebase-admin:$firebaseAdminVersion"testImplementation "org.simplejavamail:simple-java-mail:$simpleJavaMailVersion"testImplementation "org.shredzone.commons:commons-suncalc:$suncalcVersion"}--tasks.withType(Test) {- environment("OR_LOGGING_CONFIG_FILE", "test/src/logging-test.properties")-}+//+//tasks.withType(Test) {+// logging.captureStandardError LogLevel.LIFECYCLE+//}test {+ outputs.upToDateWhen { false }workingDir = findProject(":openremote") != null ? resolveProject("").projectDir : rootProject.projectDiruseJUnitPlatform()+testLogging {+// set options for log level LIFECYCLEevents TestLogEvent.FAILED,TestLogEvent.PASSED,@@ -57,15 +60,16 @@ test {TestLogEvent.FAILED,TestLogEvent.PASSED,TestLogEvent.SKIPPED,+ TestLogEvent.STANDARD_OUT,TestLogEvent.STANDARD_ERRORexceptionFormat TestExceptionFormat.FULL}info.events = debug.eventsinfo.exceptionFormat = debug.exceptionFormat-// afterTest { desc, result ->-// logger.quiet "${desc.className} > ${desc.name} took: ${(result.endTime - result.startTime)}ms"-// }+ afterTest { desc, result ->+ logger.lifecycle "${desc.className} > ${desc.name} took: ${(result.endTime - result.startTime)}ms"+ }afterSuite { desc, result ->if (!desc.parent) { // will match the outermost suitediff --git a/test/src/logging-test.properties b/test/src/logging-test.propertiesdeleted file mode 100644index 73301f676..000000000--- a/test/src/logging-test.properties+++ /dev/null@@ -1,91 +0,0 @@-# Logging config for tests--###############################################################################-# Output handlers-###############################################################################--# Log on STDOUT and internal syslog service (monitoring in Manager UI)-handlers=java.util.logging.ConsoleHandler, \- org.openremote.manager.syslog.SyslogService--# Log extra data to file for debug purposes-#handlers=java.util.logging.ConsoleHandler, \-# java.util.logging.FileHandler \-# org.openremote.manager.syslog.SyslogService--###############################################################################-# Console handler-###############################################################################--# Set to FINEST to get all enabled log categories on console handler-java.util.logging.ConsoleHandler.level=FINEST--# Console format, you can colorize this in IntelliJ IDEA "Run Application " console-# with the GrepConsole plugin and after copying the configuration file of your-# choice to ~/Library/Preferences/IntelliJ*/options/GrepConsole.xml:-#-# - tools/intellijTheme-Default-GrepConsole.xml-# - tools/intellijTheme-Darcula-GrepConsole.xml-#-java.util.logging.ConsoleHandler.formatter=org.openremote.container.util.LogFormatter--###############################################################################-# Categories-###############################################################################--# The root logger category, the default for all categories not configured here-.level=INFO--# The root logger category of OpenRemote, FINER logs much more than INFO-org.openremote.level=FINER--# Increase agent logging for fault finding-org.openremote.agent.level=FINEST--# Rule execution logging-#-# - Use "global java.util.logging.Logger LOG;" in rule RHS to access this logger-# - Set to FINEST to automatically log all fact additions, removals, and updates-# - Set to INFO and prefix your rule name with "-" or "--" to log execution details-org.openremote.rules.Rules.level=FINE--# Set to INFO to get rules engine statistics periodically, FINEST to dump all facts-org.openremote.rules.RulesEngineStats.level=OFF--# Set to INFO or higher to debug internal messaging-org.openremote.container.message.MessageBrokerContext.level=WARNING--# Set to FINE to log full exception stack traces-org.openremote.container.web.WebServiceExceptions.level=FINE--# Set to SEVERE to log invalid access tokens-org.keycloak.adapters.BearerTokenRequestAuthenticator.level=SEVERE--# Set this to FINEST to log outgoing HTTP traffic-org.apache.http.level=WARNING-org.apache.http.impl.conn.DefaultClientConnection.level=WARNING-org.apache.http.client.protocol.level=SEVERE--# Set this to FINEST to log SQL execution-org.hibernate.SQL.level=WARNING-org.hibernate.type.descriptor.sql.BasicBinder.level=WARNING--# Log only attribute event processing begin/end, useful to debug many events-org.openremote.container.web.level=INFO-org.openremote.manager.server.level=INFO--org.openremote.manager.datapoint.level=FINEST--# Low-level debugging overrides, most of them are to stop chatty categories-org.hibernate.level=WARNING-org.hibernate.cfg.beanvalidation.TypeSafeActivator.level=SEVERE-com.zaxxer.hikari.level=WARNING-javax.management.level=WARNING-org.xnio.level=WARNING-org.apache.camel.level=WARNING-org.apache.camel.management.level=WARNING-org.apache.camel.impl.converter.DefaultTypeConverter.level=WARNING-org.apache.camel.impl.DefaultShutdownStrategy.level=SEVERE-org.jeasy.rules.level=WARNING-org.postgresql.jdbc.level=INFO-org.apache.activemq.audit.level=WARNINGdiff --git a/test/src/test/groovy/org/openremote/test/energy/ForecastSolarServiceTest.groovy b/test/src/test/groovy/org/openremote/test/energy/ForecastSolarServiceTest.groovyindex 49d93d05c..6f678772e 100644--- a/test/src/test/groovy/org/openremote/test/energy/ForecastSolarServiceTest.groovy+++ b/test/src/test/groovy/org/openremote/test/energy/ForecastSolarServiceTest.groovy@@ -132,8 +132,9 @@ class ForecastSolarServiceTest extends Specification implements ManagerContainerdef config = defaultConfig()config << [(OR_FORECAST_SOLAR_API_KEY): "test-key"]- if (!ForecastSolarService.resteasyClient.configuration.isRegistered(mockServer)) {- ForecastSolarService.resteasyClient.register(mockServer, Integer.MAX_VALUE)+ ForecastSolarService.initClient()+ if (!ForecastSolarService.resteasyClient.get().configuration.isRegistered(mockServer)) {+ ForecastSolarService.resteasyClient.get().register(mockServer, Integer.MAX_VALUE)}def container = startContainer(config, defaultServices())@@ -224,5 +225,10 @@ class ForecastSolarServiceTest extends Specification implements ManagerContainerconditions.eventually {assert forecastSolarService.calculationFutures.get(newSolarAsset2.getId()) == null}++ cleanup: "remove mock"+ if (ForecastSolarService.resteasyClient.get() != null) {+ ForecastSolarService.resteasyClient.set(null)+ }}}diff --git a/test/src/test/groovy/org/openremote/test/energy/ForecastWindServiceTest.groovy b/test/src/test/groovy/org/openremote/test/energy/ForecastWindServiceTest.groovyindex 599611223..73d6c6a9e 100644--- a/test/src/test/groovy/org/openremote/test/energy/ForecastWindServiceTest.groovy+++ b/test/src/test/groovy/org/openremote/test/energy/ForecastWindServiceTest.groovy@@ -3,6 +3,7 @@ package org.openremote.test.energyimport org.openremote.manager.asset.AssetProcessingServiceimport org.openremote.manager.asset.AssetStorageServiceimport org.openremote.manager.datapoint.AssetPredictedDatapointService+import org.openremote.manager.energy.ForecastSolarServiceimport org.openremote.manager.energy.ForecastWindServiceimport org.openremote.manager.setup.SetupServiceimport org.openremote.model.asset.Asset@@ -642,8 +643,9 @@ class ForecastWindServiceTest extends Specification implements ManagerContainerTdef config = defaultConfig()config << [(OR_OPEN_WEATHER_API_APP_ID): "test-key"]- if (!ForecastWindService.resteasyClient.configuration.isRegistered(mockServer)) {- ForecastWindService.resteasyClient.register(mockServer, Integer.MAX_VALUE)+ ForecastWindService.initClient()+ if (!ForecastWindService.resteasyClient.get().configuration.isRegistered(mockServer)) {+ ForecastWindService.resteasyClient.get().register(mockServer, Integer.MAX_VALUE)}def container = startContainer(config, defaultServices())@@ -770,5 +772,10 @@ class ForecastWindServiceTest extends Specification implements ManagerContainerTassert assetPredictedDatapointService.getDatapoints(new AttributeRef(newWindAsset3.getId(), ElectricityProducerWindAsset.POWER.getName())).size() > 0assert assetPredictedDatapointService.getDatapoints(new AttributeRef(newWindAsset3.getId(), ElectricityProducerWindAsset.POWER_FORECAST.getName())).size() > 0}++ cleanup: "remove mock"+ if (ForecastSolarService.resteasyClient.get() != null) {+ ForecastSolarService.resteasyClient.set(null)+ }}}diff --git a/test/src/test/groovy/org/openremote/test/protocol/controller/ControllerProtocolTest.groovy b/test/src/test/groovy/org/openremote/test/protocol/controller/ControllerProtocolTest.groovydeleted file mode 100644index c47c206e7..000000000--- a/test/src/test/groovy/org/openremote/test/protocol/controller/ControllerProtocolTest.groovy+++ /dev/null@@ -1,332 +0,0 @@-/*- * Copyright 2017, OpenRemote Inc.- *- * See the CONTRIBUTORS.txt file in the distribution for a- * full listing of individual contributors.- *- * This program is free software: you can redistribute it and/or modify- * it under the terms of the GNU Affero General Public License as- * published by the Free Software Foundation, either version 3 of the- * License, or (at your option) any later version.- *- * This program is distributed in the hope that it will be useful,- * but WITHOUT ANY WARRANTY; without even the implied warranty of- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the- * GNU Affero General Public License for more details.- *- * You should have received a copy of the GNU Affero General Public License- * along with this program. If not, see <http://www.gnu.org/licenses/>.- */-package org.openremote.test.protocol.controller--import org.jboss.resteasy.spi.ResteasyUriInfo-import org.jboss.resteasy.util.BasicAuthHelper-import org.openremote.agent.protocol.controller.ControllerAgent-import org.openremote.agent.protocol.controller.ControllerAgentLink-import org.openremote.agent.protocol.controller.ControllerProtocol-import org.openremote.manager.agent.AgentService-import org.openremote.manager.asset.AssetProcessingService-import org.openremote.manager.asset.AssetStorageService-import org.openremote.model.Constants-import org.openremote.model.asset.impl.ThingAsset-import org.openremote.model.attribute.Attribute-import org.openremote.model.asset.agent.ConnectionStatus-import org.openremote.model.attribute.AttributeEvent-import org.openremote.model.attribute.AttributeRef-import org.openremote.model.attribute.MetaItem-import com.fasterxml.jackson.databind.node.ObjectNode-import org.openremote.model.util.ValueUtil-import org.openremote.test.ManagerContainerTrait-import spock.lang.Ignore-import spock.lang.Specification-import spock.util.concurrent.PollingConditions--import javax.ws.rs.client.ClientRequestContext-import javax.ws.rs.client.ClientRequestFilter-import javax.ws.rs.core.HttpHeaders-import javax.ws.rs.core.MediaType-import javax.ws.rs.core.Response-import javax.ws.rs.core.UriInfo--import static org.openremote.model.value.ValueType.*-import static org.openremote.model.value.MetaItemType.*--@Ignore // Controller protocol doesn't cancel scheduled tasks and this test intermittently fails-class ControllerProtocolTest extends Specification implements ManagerContainerTrait {- def CONTROLLER_AGENT_NAME_1 = "Test controller 1"- def CONTROLLER_AGENT_NAME_2 = "Test controller 2"- def CONTROLLER_AGENT_NAME_3 = "Test controller 3"-- @SuppressWarnings("GroovyAccessibility")- def "Check Controller connection"() {- given: "a mock controller"- def mockController = new ClientRequestFilter() {- private int commandCount = 0- private int pollCount = 0-- @Override- void filter(ClientRequestContext requestContext) throws IOException, ConnectException {- def requestUri = requestContext.uri- def requestPath = requestUri.scheme + "://" + requestUri.host + (requestUri.port.toString().size() != 0 ? (":" + requestUri.port) : "") + requestUri.path-- def pollingReq = requestUri.path ==~ /\/controller\/rest\/devices\/MyDevice\/polling\/OR3ControllerProtocol_[0-9a-zA-Z]*_[0-9a-zA-Z]*/-- if(pollingReq) {- UriInfo uriInfo = new ResteasyUriInfo(requestContext.uri)- def queryParams = uriInfo.getQueryParameters(true)-- if (queryParams.get("name").size() == 2 && queryParams.getFirst("name") == "my_sensor1" && queryParams.get("name").get(1) == "my_sensor2"){- requestContext.abortWith(- Response.ok("[{\"name\": \"my_sensor1\", \"value\": \"newValue1\"},{\"name\": \"my_sensor2\", \"value\": \"newValue2\"}]", MediaType.APPLICATION_JSON).build()- )- pollCount++- return- } else if (queryParams.get("name").size() == 2 && queryParams.getFirst("name") == "my_sensor1b" && queryParams.get("name").get(1) == "my_sensor2"){- requestContext.abortWith(- Response.ok("[{\"name\": \"my_sensor2\", \"value\": \"newValue2\"}]", MediaType.APPLICATION_JSON).build()- )- pollCount++- return- } else if (queryParams.get("name").size() == 1 && queryParams.getFirst("name") == "my_sensor1a"){- requestContext.abortWith(- Response.ok("[{\"name\": \"my_sensor1a\", \"value\": \"newValue1a\"}]", MediaType.APPLICATION_JSON).build()- )- pollCount++- return- } else {- requestContext.abortWith(Response.serverError().build())- return- }- } else {- switch (requestPath) {- case "http://mockapi:8688/controller":- requestContext.abortWith(Response.ok().build())- return- break- case "http://basicauthmockapi:8688/controller":- def authHeader = requestContext.getHeaderString(HttpHeaders.AUTHORIZATION)- if (authHeader != null) {- def usernameAndPassword = BasicAuthHelper.parseHeader(authHeader)- if (usernameAndPassword != null- && usernameAndPassword[0] == "testuser"- && usernameAndPassword[1] == "password1") {- requestContext.abortWith(Response.ok().build())- return- }- } else {- requestContext.abortWith(Response.status(Response.Status.UNAUTHORIZED).build())- return- }- break- case "http://disconnectedmockapi:8688/controller":- throw new ConnectException("Server not available")- return- break- }-- if(requestContext.method == "POST") {- switch (requestPath) {- case "http://mockapi:8688/controller/rest/devices/DeviceName2/commands":- UriInfo uriInfo = new ResteasyUriInfo(requestContext.uri)- def queryParams = uriInfo.getQueryParameters(true)- if (queryParams.get("name").size() == 1 && queryParams.getFirst("name") == "my_command") {- requestContext.abortWith(- Response.ok().build()- )- commandCount++- return- } else {- requestContext.abortWith(Response.serverError().build())- return- }- break- case "http://mockapi:8688/controller/rest/devices/MyDevice/commands":- UriInfo uriInfo = new ResteasyUriInfo(requestContext.uri)- def queryParams = uriInfo.getQueryParameters(true)- if (queryParams.get("name").size() == 1 && queryParams.getFirst("name") == "my_command") {- String bodyStr = (String)requestContext.getEntity()- ObjectNode body = ValueUtil.parse(bodyStr).orElse(null)-- if (body != null && body.get("parameter").isPresent() && body.get("parameter").orElse(null).toString() == "a_parameter") {- requestContext.abortWith(Response.ok().build())- commandCount++- return- } else {- requestContext.abortWith(Response.serverError().build())- return- }- } else {- requestContext.abortWith(Response.serverError().build())- return- }- break- }- }- }-- requestContext.abortWith(Response.serverError().build())- }- }-- and: "expected conditions"- def conditions = new PollingConditions(timeout: 20, initialDelay: 1)-- and: "the container starts"- def container = startContainer(defaultConfig(), defaultServices())- def assetStorageService = container.getService(AssetStorageService.class)- def assetProcessingService = container.getService(AssetProcessingService.class)- def agentService = container.getService(AgentService.class)-- when: "the web target builder is configured to use the mock server"- if (!controllerProtocol.client.configuration.isRegistered(mockController)) {- controllerProtocol.client.register(mockController, Integer.MAX_VALUE)- }-- and: "a Controller agent1 is created"- def agent1 = new ControllerAgent(CONTROLLER_AGENT_NAME_1)- .setRealm(Constants.MASTER_REALM)- .setControllerURI("http://mockapi:8688/controller")-- agent1 = assetStorageService.merge(agent1)-- then: "the protocol instance should authenticate and start pinging the server and the connection status should become CONNECTED"- conditions.eventually {- assert agentService.getAgent(agent1.id) != null- assert agentService.getAgent(agent1.id).getAgentStatus().orElse(null) == ConnectionStatus.CONNECTED- assert (ControllerProtocol)agentService.getProtocolInstance(agent1.id) != null- assert ((ControllerProtocol)agentService.getProtocolInstance(agent1.id)).controllerHeartbeat.isCancelled()- }-- when: "an asset is created with attributes linked to the controller agent"- def asset = new ThingAsset("Test Asset")- .setParent(agent1)- .addOrReplaceAttributes(- // attribute that sends requests to the server using PUT with dynamic body and custom header to override parent- new Attribute<>("sensor", TEXT)- .addMeta(- new MetaItem<>(AGENT_LINK, new ControllerAgentLink(agent1.id, "MyDevice")- .setSensorName("my_sensor1a")),- new MetaItem<>(READ_ONLY)- ),- new Attribute<>("command", TEXT)- .addMeta(- new MetaItem<>(AGENT_LINK, new ControllerAgentLink(agent1.id, "MyDevice")- .setCommandName("my_command"))- )- )-- and: "the asset is merged into the asset service"- asset = assetStorageService.merge(asset)-- then: "multiple pollings should have occurred"- conditions.eventually {- assert mockController.pollCount > 2- }-- then:- conditions.eventually {- def newAsset = assetStorageService.find(asset.getId(), true)- assert controllerProtocol.controllersMap.get(controllerRef).getSensorsListForDevice("MyDevice").size() == 1- assert controllerProtocol.pollingSensorList.size() == 1- assert mockController.commandCount == 0- assert mockController.pollCount > 0- assert newAsset.getAttribute("sensor").flatMap({it.getValue()}).orElse("") == "newValue1a"- }-- when: "another agent is created that is linked to an unavailable controller"- def agent2 = new ControllerAgent(CONTROLLER_AGENT_NAME_1)- .setRealm(Constants.MASTER_REALM)- .setControllerURI("http://mockapi:8688/controller")-- agent2 = assetStorageService.merge(agent2)-- then: "the new agent should be DISCONNECTED but the old agent should still show as CONNECTED"- conditions.eventually {- assert agentService.getAgent(agent1.id) != null- assert agentService.getAgent(agent2.id) != null- assert agentService.getAgent(agent1.id).getAgentStatus().orElse(null) == ConnectionStatus.CONNECTED- assert agentService.getAgent(agent2.id).getAgentStatus().orElse(null) == ConnectionStatus.DISCONNECTED- assert (ControllerProtocol)agentService.getProtocolInstance(agent1.id) != null- assert (ControllerProtocol)agentService.getProtocolInstance(agent2.id) != null- assert ((ControllerProtocol)agentService.getProtocolInstance(agent1.id)).controllerHeartbeat.isCancelled()- assert !((ControllerProtocol)agentService.getProtocolInstance(agent2.id)).controllerHeartbeat.isCancelled()- }-- when: "this new agent is removed and another one added"- assetStorageService.delete([agent2.id])- def agent3 = new ControllerAgent(CONTROLLER_AGENT_NAME_3)- .setRealm(Constants.MASTER_REALM)- .setControllerURI("http://mockapi:8688/controller")- agent3 = assetStorageService.merge(agent3)-- then: "the protocol should authenticate and start pinging the server and the connection status should become CONNECTED"- conditions.eventually {- assert agentService.getAgent(agent1.id) != null- assert agentService.getAgent(agent2.id) == null- assert agentService.getAgent(agent3.id) != null- assert agentService.getAgent(agent1.id).getAgentStatus().orElse(null) == ConnectionStatus.CONNECTED- assert agentService.getAgent(agent3.id).getAgentStatus().orElse(null) == ConnectionStatus.CONNECTED- assert (ControllerProtocol)agentService.getProtocolInstance(agent1.id) != null- assert (ControllerProtocol)agentService.getProtocolInstance(agent2.id) == null- assert (ControllerProtocol)agentService.getProtocolInstance(agent3.id) != null- assert ((ControllerProtocol)agentService.getProtocolInstance(agent1.id)).controllerHeartbeat.isCancelled()- assert ((ControllerProtocol)agentService.getProtocolInstance(agent3.id)).controllerHeartbeat.isCancelled()- }-- when: "an asset is created with attributes linked to the controller agent"- def asset2 = new ThingAsset("Test Asset2")- .setParent(agent3)- .addOrReplaceAttributes(- // attribute that sends requests to the server using PUT with dynamic body and custom header to override parent- new Attribute<>("command", TEXT, "command1")- .addMeta(- new MetaItem<>(AGENT_LINK, new ControllerAgentLink(agent3.id, "DeviceName2")- .setCommandsMap(new HashMap<String, List<String>>([- ("command1") : ["my_command"],- ("command2") : ["wrong"]- ]))- )- )- )- asset2 = assetStorageService.merge(asset2)-- then: "the asset should be linked to the protocol"- conditions.eventually {- assert controllerProtocol.linkedAttributes.containsKey(new AttributeRef(asset2.id, CONTROLLER_AGENT_NAME_3))- }-- when: "a linked attribute value is updated"- def attributeEvent = new AttributeEvent(asset2.id,- "command",- "command1")- assetProcessingService.sendAttributeEvent(attributeEvent)-- then:- conditions.eventually {- assert mockController.commandCount == 1- }-- and: "another linked attribute value is updated with no value"- def attributeEvent2 = new AttributeEvent(asset.id,- "command",- null)- assetProcessingService.sendAttributeEvent(attributeEvent2)-- then:- conditions.eventually {- assert mockController.commandCount == 1- }-- and: "another linked attribute value is updated with a value"- def attributeEvent3 = new AttributeEvent(asset.id,- "command",- "a_parameter")- assetProcessingService.sendAttributeEvent(attributeEvent3)-- then:- conditions.eventually {- assert mockController.commandCount == 2- assert true- }- }-}diff --git a/test/src/test/groovy/org/openremote/test/protocol/http/HttpClientProtocolTest.groovy b/test/src/test/groovy/org/openremote/test/protocol/http/HttpClientProtocolTest.groovyindex 28175e3b7..a978bc63e 100644--- a/test/src/test/groovy/org/openremote/test/protocol/http/HttpClientProtocolTest.groovy+++ b/test/src/test/groovy/org/openremote/test/protocol/http/HttpClientProtocolTest.groovy@@ -25,6 +25,7 @@ import org.jboss.resteasy.util.BasicAuthHelperimport org.openremote.agent.protocol.http.HTTPAgentimport org.openremote.agent.protocol.http.HTTPAgentLinkimport org.openremote.agent.protocol.http.HTTPProtocol+import org.openremote.agent.protocol.websocket.WebsocketAgentProtocolimport org.openremote.container.web.OAuthServerResponseimport org.openremote.manager.agent.AgentServiceimport org.openremote.manager.asset.AssetProcessingService@@ -255,8 +256,9 @@ class HttpClientProtocolTest extends Specification implements ManagerContainerTrdef agentService = container.getService(AgentService.class)when: "the web target builder is configured to use the mock server"- if (!HTTPProtocol.client.configuration.isRegistered(mockServer)) {- HTTPProtocol.client.register(mockServer, Integer.MAX_VALUE)+ HTTPProtocol.initClient()+ if (!HTTPProtocol.client.get().configuration.isRegistered(mockServer)) {+ HTTPProtocol.client.get().register(mockServer, Integer.MAX_VALUE)}and: "a HTTP client agent is created"@@ -542,5 +544,10 @@ class HttpClientProtocolTest extends Specification implements ManagerContainerTrconditions.eventually {assert mockServer.successCount == 1}++ cleanup: "remove mock"+ if (HTTPProtocol.client.get() != null) {+ HTTPProtocol.client.set(null)+ }}}diff --git a/test/src/test/groovy/org/openremote/test/protocol/websocket/WebsocketClientProtocolTest.groovy b/test/src/test/groovy/org/openremote/test/protocol/websocket/WebsocketClientProtocolTest.groovyindex f3eb18cd4..c6a7f68e5 100644--- a/test/src/test/groovy/org/openremote/test/protocol/websocket/WebsocketClientProtocolTest.groovy+++ b/test/src/test/groovy/org/openremote/test/protocol/websocket/WebsocketClientProtocolTest.groovy@@ -43,13 +43,9 @@ import org.openremote.model.event.shared.SharedEventimport org.openremote.model.query.AssetQueryimport org.openremote.model.query.filter.StringPredicateimport org.openremote.model.util.ValueUtil-import org.openremote.model.value.JsonPathFilter-import org.openremote.model.value.RegexValueFilter-import org.openremote.model.value.SubStringValueFilter-import org.openremote.model.value.ValueFilter-import org.openremote.model.value.ValueType-import org.openremote.test.ManagerContainerTrait+import org.openremote.model.value.*import org.openremote.setup.integration.ManagerTestSetup+import org.openremote.test.ManagerContainerTraitimport spock.lang.Sharedimport spock.lang.Specificationimport spock.util.concurrent.PollingConditions@@ -134,8 +130,9 @@ class WebsocketClientProtocolTest extends Specification implements ManagerContaidef clientEventService = container.getService(ClientEventService.class)when: "the web target builder is configured to use the mock HTTP server (to test subscriptions)"- if (!WebsocketAgentProtocol.resteasyClient.configuration.isRegistered(mockServer)) {- WebsocketAgentProtocol.resteasyClient.register(mockServer, Integer.MAX_VALUE)+ WebsocketAgentProtocol.initClient()+ if (!WebsocketAgentProtocol.resteasyClient.get().configuration.isRegistered(mockServer)) {+ WebsocketAgentProtocol.resteasyClient.get().register(mockServer, Integer.MAX_VALUE)}and: "a Websocket client agent is created to connect to this tests manager"@@ -309,5 +306,10 @@ class WebsocketClientProtocolTest extends Specification implements ManagerContaiasset = assetStorageService.find(asset.getId(), true)assert asset.getAttribute("readCo2Level").flatMap{it.getValue()}.orElse(null) == 600d}++ cleanup: "remove mock"+ if (WebsocketAgentProtocol.resteasyClient.get() != null) {+ WebsocketAgentProtocol.resteasyClient.set(null)+ }}}diff --git a/test/src/test/groovy/org/openremote/test/rules/BasicRulesFactsTest.groovy b/test/src/test/groovy/org/openremote/test/rules/BasicRulesFactsTest.groovyindex fd126cdb0..ac287a0cb 100644--- a/test/src/test/groovy/org/openremote/test/rules/BasicRulesFactsTest.groovy+++ b/test/src/test/groovy/org/openremote/test/rules/BasicRulesFactsTest.groovy@@ -44,11 +44,6 @@ class BasicRulesFactsTest extends Specification {RulesFacts rulesFactsTimerService timerService- def setupSpec() {- // Init logging config- Container.LOG.info("Running test...")- }-def setup() {given: "some rule facts"assetsFacade = Mock(AssetsFacade)diff --git a/test/src/testFixtures/groovy/org/openremote/test/ContainerTrait.groovy b/test/src/testFixtures/groovy/org/openremote/test/ContainerTrait.groovyindex a588e599d..c464cf3f8 100644--- a/test/src/testFixtures/groovy/org/openremote/test/ContainerTrait.groovy+++ b/test/src/testFixtures/groovy/org/openremote/test/ContainerTrait.groovy@@ -56,6 +56,8 @@ import org.openremote.model.rules.GlobalRulesetimport org.openremote.model.rules.Rulesetimport org.openremote.model.rules.RealmRulesetimport org.openremote.model.security.User+import org.slf4j.Logger+import org.slf4j.LoggerFactoryimport javax.persistence.TypedQueryimport javax.websocket.ClientEndpointConfig@@ -75,6 +77,8 @@ import static org.openremote.model.Constants.MASTER_REALM_ADMIN_USERtrait ContainerTrait {+ Logger LOG = LoggerFactory.getLogger(ContainerTrait.class)+Container startContainer(Map<String, String> config, Iterable<ContainerService> services) {// Reset and start clock in case any previous tests stopped/modified it (pseudo clock is static so shared between tests)@@ -112,7 +116,7 @@ trait ContainerTrait {if (configsMatch && servicesMatch) {try {- println("Services and config matches already running container so checking state")+ LOG.info("Services and config matches already running container so checking state")def counter = 0// Reset users - just delete ones that weren't there before (if tests change user roles etc. then the test should force stop the container in cleanup)@@ -124,7 +128,7 @@ trait ContainerTrait {throw new IllegalStateException("Users have been modified so cannot do simple purge")}- println("Purging ${newUsers.size()} new user(s)")+ LOG.info("Purging ${newUsers.size()} new user(s)")newUsers.forEach {user ->// Never delete the master admin userif (user.getUsername() != MASTER_REALM_ADMIN_USER && user.getRealm() != MASTER_REALM) {@@ -137,7 +141,7 @@ trait ContainerTrait {if (container.hasService(GatewayClientService.class)) {def gatewayClientService = container.getService(GatewayClientService.class)def gatewayConnections = getGatewayConnections()- println("Purging ${gatewayConnections.size()} gateway connection(s)")+ LOG.info("Purging ${gatewayConnections.size()} gateway connection(s)")gatewayClientService.deleteConnections(gatewayConnections.stream().map { it.localRealm }.collect(Collectors.toList()))}@@ -150,7 +154,7 @@ trait ContainerTrait {def rulesetStorageService = container.getService(RulesetStorageService.class)if (!assetRulesets.isEmpty()) {- println("Purging ${assetRulesets.size()} asset ruleset(s)")+ LOG.info("Purging ${assetRulesets.size()} asset ruleset(s)")assetRulesets.forEach {rulesetStorageService.delete(AssetRuleset.class, it.id)def assetEngine = rulesService.assetEngines.get(((AssetRuleset) it).assetId)@@ -165,7 +169,7 @@ trait ContainerTrait {}}if (!realmRulesets.isEmpty()) {- println("Purging ${realmRulesets.size()} realm ruleset(s)")+ LOG.info("Purging ${realmRulesets.size()} realm ruleset(s)")realmRulesets.forEach {rulesetStorageService.delete(RealmRuleset.class, it.id)def realmEngine = rulesService.realmEngines.get(((RealmRuleset) it).realm)@@ -180,7 +184,7 @@ trait ContainerTrait {}}if (!globalRulesets.isEmpty()) {- println("Purging ${globalRulesets.size()} global ruleset(s)")+ LOG.info("Purging ${globalRulesets.size()} global ruleset(s)")globalRulesets.forEach {rulesetStorageService.delete(GlobalRuleset.class, it.id)def rulesStopped = false@@ -210,7 +214,7 @@ trait ContainerTrait {// Wait for system to settle downdef assetProcessingService = container.hasService(AssetProcessingService.class) ? container.getService(AssetProcessingService.class) : nullif (assetProcessingService != null) {- println("Waiting for the system to settle down")+ LOG.info("Waiting for the system to settle down")def j=0while (j < 100 && !noEventProcessedIn(assetProcessingService, 300)) {Thread.sleep(100)@@ -224,7 +228,7 @@ trait ContainerTrait {def assetStorageService = container.getService(AssetStorageService.class)if (!currentAssets.isEmpty()) {- println("Purging ${currentAssets.size()} asset(s)")+ LOG.info("Purging ${currentAssets.size()} asset(s)")assetStorageService.delete(currentAssets, true)}@@ -239,14 +243,14 @@ trait ContainerTrait {}if (!TestFixture.assets.isEmpty()) {- println("Re-inserting ${TestFixture.assets.size()} asset(s)")+ LOG.info("Re-inserting ${TestFixture.assets.size()} asset(s)")TestFixture.assets.forEach { a ->a.version = 0assetStorageService.merge(a, true)}}if (!TestFixture.userAssets.isEmpty()) {- println("Re-linking ${TestFixture.userAssets.size()} user asset(s)")+ LOG.info("Re-linking ${TestFixture.userAssets.size()} user asset(s)")TestFixture.userAssets.groupBy {it.id.userId}.values().forEach { ua ->assetStorageService.storeUserAssetLinks(ua)}@@ -258,25 +262,25 @@ trait ContainerTrait {def rulesetStorageService = container.getService(RulesetStorageService.class)if (!TestFixture.assetRulesets.isEmpty()) {- println("Re-inserting ${TestFixture.assetRulesets.size()} asset ruleset(s)")+ LOG.info("Re-inserting ${TestFixture.assetRulesets.size()} asset ruleset(s)")TestFixture.assetRulesets.forEach { rulesetStorageService.merge(it) }}if (!TestFixture.realmRulesets.isEmpty()) {- println("Re-inserting ${TestFixture.realmRulesets.size()} realm ruleset(s)")+ LOG.info("Re-inserting ${TestFixture.realmRulesets.size()} realm ruleset(s)")TestFixture.realmRulesets.forEach { rulesetStorageService.merge(it) }}if (!TestFixture.globalRulesets.isEmpty()) {- println("Re-inserting ${TestFixture.globalRulesets.size()} global ruleset(s)")+ LOG.info("Re-inserting ${TestFixture.globalRulesets.size()} global ruleset(s)")TestFixture.globalRulesets.forEach { rulesetStorageService.merge(it) }}}} catch (IllegalStateException e) {- System.out.println("Failed to clean the existing container so creating a new one")+ LOG.info("Failed to clean the existing container so creating a new one")stopContainer()TestFixture.container = null}} else {- System.out.println("Request to start container with different config and/or services as already running container so restarting")+ LOG.info("Request to start container with different config and/or services as already running container so restarting")stopContainer()TestFixture.container = null}@@ -314,43 +318,43 @@ trait ContainerTrait {int i=0if (agentService != null) {- println("Waiting for agents to be deployed")+ LOG.info("Waiting for agents to be deployed")i=0while (i < 100 && TestFixture.assets.stream().filter { it instanceof Agent }.any { !agentService.agentMap.containsKey(it.id) }) {Thread.sleep(100)i++}- println("Agents are deployed")+ LOG.info("Agents are deployed")}if (rulesService != null) {- println("Waiting for global rulesets to be deployed")+ LOG.info("Waiting for global rulesets to be deployed")i=0while (i < 100 && TestFixture.globalRulesets.stream().filter { it.enabled }.any { rulesService.globalEngine == null || !rulesService.globalEngine.deployments.containsKey(it.id) }) {Thread.sleep(100)i++}- println("Global rulesets are deployed")+ LOG.info("Global rulesets are deployed")- println("Waiting for realm rulesets to be deployed")+ LOG.info("Waiting for realm rulesets to be deployed")i=0while (i < 100 && TestFixture.realmRulesets.stream().filter { it.enabled }.any { !rulesService.realmEngines.containsKey(it.realm) || !rulesService.realmEngines.get(it.realm).deployments.containsKey(it.id) }) {Thread.sleep(100)i++}- println("Realm rulesets are deployed")+ LOG.info("Realm rulesets are deployed")- println("Waiting for asset rulesets to be deployed")+ LOG.info("Waiting for asset rulesets to be deployed")i=0while (i < 100 && TestFixture.assetRulesets.stream().filter { it.enabled }.any { !rulesService.assetEngines.containsKey(it.assetId) || !rulesService.assetEngines.get(it.assetId).deployments.containsKey(it.id) }) {Thread.sleep(100)i++}- println("Asset rulesets are deployed")+ LOG.info("Asset rulesets are deployed")}if (assetProcessingService != null) {- println("Waiting for the system to settle down")+ LOG.info("Waiting for the system to settle down")def j=0while (j < 100 && !noEventProcessedIn(assetProcessingService, 300)) {Thread.sleep(100)diff --git a/yarn.lock b/yarn.lockindex ab088aa87..778f37b6f 100644--- a/yarn.lock+++ b/yarn.lock@@ -6313,13 +6313,13 @@ __metadata:linkType: hard"json5@npm:^1.0.1":- version: 1.0.1- resolution: "json5@npm:1.0.1"+ version: 1.0.2+ resolution: "json5@npm:1.0.2"dependencies:minimist: ^1.2.0bin:json5: lib/cli.js- checksum: e76ea23dbb8fc1348c143da628134a98adf4c5a4e8ea2adaa74a80c455fc2cdf0e2e13e6398ef819bfe92306b610ebb2002668ed9fc1af386d593691ef346fc3+ checksum: 866458a8c58a95a49bef3adba929c625e82532bcff1fe93f01d29cb02cac7c3fe1f4b79951b7792c2da9de0b32871a8401a6e3c5b36778ad852bf5b8a61165d7languageName: nodelinkType: hard@@ -6532,9 +6532,9 @@ __metadata:linkType: hard"luxon@npm:^1.21.3":- version: 1.28.0- resolution: "luxon@npm:1.28.0"- checksum: 5250cb9f138b6048eeb0b3a9044a4ac994d0058f680c72a0da4b6aeaec8612460385639cba2b1052ef6d5564879e9ed144d686f26d9d97b38ab920d82e18281c+ version: 1.28.1+ resolution: "luxon@npm:1.28.1"+ checksum: 2c62999adea79645fd1e931d685f61aeb33eda7f39fbf79b84261a233b62f9590f48336654ee9efd405848bd9e13dc7fe087c701b7126187201a88998dc68b04languageName: nodelinkType: hard