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
Moved ConnectorComponent over to be Asset based (client is broken)
Rich Turner0b2add827f58
diff --git a/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2Component.java b/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2Component.javaindex 9316137fe..2d6585593 100644--- a/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2Component.java+++ b/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2Component.java@@ -19,13 +19,13 @@*/package org.openremote.agent.controller2;-import elemental.json.Json;import org.apache.camel.Endpoint;import org.apache.camel.impl.UriEndpointComponent;+import org.openremote.manager.shared.asset.Asset;import org.openremote.manager.shared.attribute.AttributeType;import org.openremote.manager.shared.connector.ConnectorComponent;import org.openremote.manager.shared.connector.ConnectorUtil;-import org.openremote.manager.shared.device.InventoryCapabilities;+import org.openremote.manager.shared.connector.ChildAssetSupport;import org.openremote.manager.shared.attribute.Attributes;import java.net.URI;@@ -112,57 +112,52 @@ public class Controller2Component extends UriEndpointComponent implements Connec}@Override- public boolean supportsAgentDiscovery() {- return false;+ public ChildAssetSupport getChildSupport(Asset parentAsset) {+ return null;}@Override- public Attributes getAgentSettings() {- return agentSettings;+ public boolean supportsChildDiscovery(Asset parentAsset) {+ return false;}@Override- public Attributes getAgentDiscoverySettings() {+ public Attributes getChildDiscoverySettings(Asset parentAsset) {return null;}@Override- public InventoryCapabilities getCapabilities(Attributes agentSettings) {+ public Attributes getChildAssetSettings(Asset parentAsset) {return null;}@Override- public String getAgentStatusUri(Attributes agentSettings) {+ public String getChildDiscoveryUri(Asset parentAsset, Attributes discoverySettings) {return null;}@Override- public String getDeviceInventoryUri(Attributes agentSettings) {- return null;+ public boolean supportsMonitoring(Asset asset) {+ return false;}@Override- public String getDeviceDiscoveryUri(Attributes agentSettings) {+ public String getChildInventoryUri(Asset asset) {return null;}@Override- public String getDevicesUri(Attributes agentSettings) {+ public String getAssetUri(Asset asset) {return null;}@Override- public String getDeviceMonitorUri(Attributes agentSettings) {+ public String getAssetMonitorUri(Asset asset) {return null;}@Override- public String getAgentDiscoveryUri(Attributes discoverySettings) {+ public Asset createAsset(Asset parent, Attributes assetSettings) {return null;}-- @Override- public boolean supportsDeviceMonitoring(Attributes agentSettings) {- return true;- }}diff --git a/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2InventoryConsumer.java b/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2InventoryConsumer.javaindex 59b97a497..a0d4784e0 100644--- a/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2InventoryConsumer.java+++ b/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2InventoryConsumer.java@@ -6,10 +6,10 @@ import org.openremote.manager.shared.device.Device;import java.util.logging.Logger;-import static org.openremote.manager.shared.device.DeviceInventory.Action.ADD;-import static org.openremote.manager.shared.device.DeviceInventory.Action.REMOVE;-import static org.openremote.manager.shared.device.DeviceInventory.Action.UPDATE;-import static org.openremote.manager.shared.device.DeviceInventory.HEADER_DEVICE_ACTION;+import static org.openremote.manager.shared.connector.ConnectorComponent.ACTION_CREATE;+import static org.openremote.manager.shared.connector.ConnectorComponent.ACTION_DELETE;+import static org.openremote.manager.shared.connector.ConnectorComponent.ACTION_UPDATE;+import static org.openremote.manager.shared.connector.ConnectorComponent.HEADER_DEVICE_ACTION;public class Controller2InventoryConsumer extends Controller2Consumer implements Controller2Adapter.DeviceListener {@@ -40,7 +40,7 @@ public class Controller2InventoryConsumer extends Controller2Consumer implementsLOG.fine("Starting new exchange for added device '" + device.getUri() + "'");Exchange exchange = getEndpoint().createExchange();- exchange.getIn().setHeader(HEADER_DEVICE_ACTION, ADD);+ exchange.getIn().setHeader(HEADER_DEVICE_ACTION, ACTION_CREATE);exchange.getIn().setBody(device);processExchange(exchange);}@@ -56,7 +56,7 @@ public class Controller2InventoryConsumer extends Controller2Consumer implementsLOG.fine("Starting new exchange for removed device '" + device.getUri() + "'");Exchange exchange = getEndpoint().createExchange();- exchange.getIn().setHeader(HEADER_DEVICE_ACTION, REMOVE);+ exchange.getIn().setHeader(HEADER_DEVICE_ACTION, ACTION_DELETE);exchange.getIn().setBody(device);processExchange(exchange);}@@ -70,7 +70,7 @@ public class Controller2InventoryConsumer extends Controller2Consumer implementsLOG.fine("Starting new exchange for updated device '" + device.getUri() + "'");Exchange exchange = getEndpoint().createExchange();- exchange.getIn().setHeader(HEADER_DEVICE_ACTION, UPDATE);+ exchange.getIn().setHeader(HEADER_DEVICE_ACTION, ACTION_UPDATE);exchange.getIn().setBody(device);processExchange(exchange);}diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/ConnectorImpl.java b/manager/client/src/main/java/org/openremote/manager/client/admin/agent/ConnectorImpl.javadeleted file mode 100644index a13fb01de..000000000--- a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/ConnectorImpl.java+++ /dev/null@@ -1,129 +0,0 @@-/*- * Copyright 2016, 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.manager.client.admin.agent;--import org.openremote.manager.shared.agent.Agent;-import org.openremote.manager.shared.attribute.Attribute;-import org.openremote.manager.shared.attribute.Attributes;-import org.openremote.manager.shared.connector.Connector;--public class ConnectorImpl implements Connector {- protected String type;- protected String displayName;- protected boolean agentDiscovery;- protected Attributes agentSettings;- protected Attributes discoverySettings;-- public ConnectorImpl() {- }-- public ConnectorImpl(String type, String displayName, boolean agentDiscovery, Attributes agentSettings, Attributes discoverySettings) {- this.type = type;- this.displayName = displayName;- this.agentDiscovery = agentDiscovery;- this.agentSettings = agentSettings;- this.discoverySettings = discoverySettings;- }-- public String getType() {- return type;- }-- public String getDisplayName() {- return displayName;- }-- @Override- public boolean supportsAgentDiscovery() {- return agentDiscovery;- }-- @Override- public Attributes getAgentDiscoverySettings() {- return discoverySettings;- }-- @Override- public Attributes getAgentSettings() {- return agentSettings;- }-- public void setType(String type) {- this.type = type;- }-- public void setDisplayName(String displayName) {- this.displayName = displayName;- }-- public void setAgentDiscovery(boolean agentDiscovery) {- this.agentDiscovery = agentDiscovery;- }-- public void setAgentSettings(Attributes agentSettings) {- this.agentSettings = agentSettings;- }-- public void setDiscoverySettings(Attributes discoverySettings) {- this.discoverySettings = discoverySettings;- }-- /**- * Copy all settings which have a value into the {@link Agent}, keeping the value- * of each attribute but not the attribute metadata.- */- public void writeSettings(Agent agent) {- if (getAgentSettings() == null) {- agent.setConnectorSettings(null);- return;- }- Attributes settings = getAgentSettings();- Attributes agentConnectorSettings = new Attributes();- for (Attribute attribute : settings.get()) {- if (attribute.getValue() == null)- continue;- Attribute agentConnectorAttribute = new Attribute(attribute.getName(), attribute.getType());- agentConnectorAttribute.setValue(attribute.getValue());- agentConnectorSettings.add(agentConnectorAttribute);- }- agent.setConnectorSettings(agentConnectorSettings.getJsonObject());- }-- /**- * Read the value for each settings attribute from the {@link Agent}, skipping any- * unknown attribute or attribute that doesn't have the right type. The- * {@link Agent#connectorSettings} can be "cleaned up" so they match a {@link Connector}- * by calling {@link #readSettings(Agent)} followed by {@link #writeSettings(Agent)}.- */- public void readSettings(Agent agent) {- if (agent.getConnectorSettings() == null)- return;-- Attributes settings = getAgentSettings();- Attributes agentConnectorSettings = new Attributes(agent.getConnectorSettings());- for (Attribute agentConnectorAttribute : agentConnectorSettings.get()) {- Attribute settingsAttribute = settings.get(agentConnectorAttribute.getName());- if (settingsAttribute != null- && settingsAttribute.getType().equals(agentConnectorAttribute.getType())) {- settingsAttribute.setValue(agentConnectorAttribute.getValue());- }- }- }-}diff --git a/manager/server/src/main/java/org/openremote/manager/server/agent/ConnectorResourceImpl.java b/manager/server/src/main/java/org/openremote/manager/server/agent/ConnectorResourceImpl.javaindex 430d8853d..f9870fcc8 100644--- a/manager/server/src/main/java/org/openremote/manager/server/agent/ConnectorResourceImpl.java+++ b/manager/server/src/main/java/org/openremote/manager/server/agent/ConnectorResourceImpl.java@@ -19,9 +19,11 @@*/package org.openremote.manager.server.agent;+import org.openremote.container.util.IdentifierUtil;import org.openremote.container.web.WebResource;+import org.openremote.manager.shared.asset.AssetInfo;+import org.openremote.manager.shared.attribute.Attributes;import org.openremote.manager.shared.connector.ConnectorComponent;-import org.openremote.manager.shared.connector.Connector;import org.openremote.manager.shared.connector.ConnectorResource;import org.openremote.manager.shared.http.RequestParams;@@ -37,14 +39,41 @@ public class ConnectorResourceImpl extends WebResource implements ConnectorResou}@Override- public Connector[] getConnectors(@BeanParam RequestParams requestParams) {- Collection<Connector> connectors = connectorService.getConnectors().values();-- return connectors.toArray(new Connector[connectors.size()]);-// return connectors-// .stream()-// .map(c -> new ConnectorImpl(c.getType(), c.getDisplayName(), c.supportsAgentDiscovery(), c.getAgentSettings(), c.getAgentDiscoverySettings()))-// .toArray(size -> new Connector[size]);+ public AssetInfo[] getConnectors(@BeanParam RequestParams requestParams) {+ Collection<ConnectorComponent> connectors = connectorService.getConnectors().values();+ return connectors+ .stream()+ .map(c -> new AssetInfo(IdentifierUtil.getEncodedHash(c.getType().getBytes()), c.getDisplayName(), c.getType(), null))+ .toArray(size -> new AssetInfo[size]);}++ @Override+ public AssetInfo getConnector(@BeanParam RequestParams requestParams, String connectorId) {+ Collection<ConnectorComponent> connectors = connectorService.getConnectors().values();+ ConnectorComponent connector = connectors+ .stream()+ .filter(c -> IdentifierUtil.getEncodedHash(c.getType().getBytes()).equals(connectorId))+ .findFirst()+ .orElse(null);+ return connector == null ? null : new AssetInfo(connectorId, connector.getDisplayName(), connector.getType(), null);+ }++ @Override+ public AssetInfo[] getChildren(@BeanParam RequestParams requestParams, String parentId) {+ // TODO: Implement Connector Resource getChildren+ return new AssetInfo[0];+ }++ @Override+ public Attributes getAssetSettings(@BeanParam RequestParams requestParams, String parentId) {+ // TODO: Implement Connector Resource getAssetSettings+ return null;+ }++ @Override+ public Attributes getAssetDiscoverySettings(@BeanParam RequestParams requestParams, String parentId) {+ // TODO: Implement Connector Resource getAssetDiscoverySettings+ return null;+ }}diff --git a/manager/server/src/main/java/org/openremote/manager/server/agent/ConnectorService.java b/manager/server/src/main/java/org/openremote/manager/server/agent/ConnectorService.javaindex abcf7677f..7d02e5596 100644--- a/manager/server/src/main/java/org/openremote/manager/server/agent/ConnectorService.java+++ b/manager/server/src/main/java/org/openremote/manager/server/agent/ConnectorService.java@@ -26,7 +26,6 @@ import org.openremote.container.Container;import org.openremote.container.ContainerService;import org.openremote.container.message.MessageBrokerService;import org.openremote.container.web.WebService;-import org.openremote.manager.shared.connector.Connector;import org.openremote.manager.shared.connector.ConnectorComponent;import java.util.LinkedHashMap;@@ -38,7 +37,7 @@ public class ConnectorService implements ContainerService {private static final Logger LOG = Logger.getLogger(ConnectorService.class.getName());- final protected Map<String, Connector> connectors = new LinkedHashMap<>();+ final protected Map<String, ConnectorComponent> connectors = new LinkedHashMap<>();@Overridepublic void init(Container container) throws Exception {@@ -63,12 +62,12 @@ public class ConnectorService implements ContainerService {}- public Map<String, Connector> getConnectors() {+ public Map<String, ConnectorComponent> getConnectors() {return connectors;}- public Connector getConnectorByType(String connectorType) {- for (Connector connector : connectors.values()) {+ public ConnectorComponent getConnectorByType(String connectorType) {+ for (ConnectorComponent connector : connectors.values()) {if (connector.getType().equals(connectorType))return connector;}@@ -84,7 +83,7 @@ public class ConnectorService implements ContainerService {if (component instanceof ConnectorComponent) {ConnectorComponent connector = (ConnectorComponent)component;- for (Connector existingConnector : connectors.values()) {+ for (ConnectorComponent existingConnector : connectors.values()) {if (existingConnector.getType().equals(connector.getType())) {throw new IllegalStateException("Duplicate connector types are not allowed: " + connector.getType()diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/device/DeviceInventory.java b/manager/shared/src/main/java/org/openremote/manager/shared/asset/AssetUtil.javasimilarity index 75%rename from manager/shared/src/main/java/org/openremote/manager/shared/device/DeviceInventory.javarename to manager/shared/src/main/java/org/openremote/manager/shared/asset/AssetUtil.javaindex ed42425d7..db69edcc0 100644--- a/manager/shared/src/main/java/org/openremote/manager/shared/device/DeviceInventory.java+++ b/manager/shared/src/main/java/org/openremote/manager/shared/asset/AssetUtil.java@@ -1,31 +1,24 @@-/*- * Copyright 2016, 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.manager.shared.device;--public class DeviceInventory {-- public enum Action {- ADD,- REMOVE,- UPDATE- }-- public static final String HEADER_DEVICE_ACTION = DeviceInventory.class.getCanonicalName() + ".DEVICE_ACTION";-}+/*+ * Copyright 2016, 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.manager.shared.asset;++//TODO: This class should provide helper methods for constructing known asset types+public class AssetUtil {+}diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/device/InventoryCapabilities.java b/manager/shared/src/main/java/org/openremote/manager/shared/connector/ChildAssetSupport.javasimilarity index 58%rename from manager/shared/src/main/java/org/openremote/manager/shared/device/InventoryCapabilities.javarename to manager/shared/src/main/java/org/openremote/manager/shared/connector/ChildAssetSupport.javaindex 18ee17923..6eccbd239 100644--- a/manager/shared/src/main/java/org/openremote/manager/shared/device/InventoryCapabilities.java+++ b/manager/shared/src/main/java/org/openremote/manager/shared/connector/ChildAssetSupport.java@@ -17,33 +17,39 @@* 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.manager.shared.device;+package org.openremote.manager.shared.connector;/*** Describes the capabilities that an agent connectors's inventory* offers; inventory read is mandatory. This is how device provisioning* should be achieved.*/-public class InventoryCapabilities {- protected boolean inventoryCreate;- protected boolean inventoryUpdate;- protected boolean inventoryDelete;+public class ChildAssetSupport {+ protected boolean create;+ protected boolean read;+ protected boolean update;+ protected boolean delete;- public InventoryCapabilities(boolean inventoryCreate, boolean inventoryUpdate, boolean inventoryDelete) {- this.inventoryCreate = inventoryCreate;- this.inventoryUpdate = inventoryUpdate;- this.inventoryDelete = inventoryDelete;+ public ChildAssetSupport(boolean create, boolean read, boolean update, boolean delete) {+ this.create = create;+ this.read = read;+ this.update = update;+ this.delete = delete;}- public boolean isInventoryCreate() {- return inventoryCreate;+ public boolean isCreate() {+ return create;}- public boolean isInventoryUpdate() {- return inventoryUpdate;+ public boolean isRead() {+ return read;}- public boolean isInventoryDelete() {- return inventoryDelete;+ public boolean isUpdate() {+ return update;+ }++ public boolean isDelete() {+ return delete;}}diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/connector/Connector.java b/manager/shared/src/main/java/org/openremote/manager/shared/connector/Connector.javadeleted file mode 100644index 3a675e4ea..000000000--- a/manager/shared/src/main/java/org/openremote/manager/shared/connector/Connector.java+++ /dev/null@@ -1,62 +0,0 @@-/*- * Copyright 2016, 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.manager.shared.connector;--import com.fasterxml.jackson.annotation.JsonInclude;-import com.fasterxml.jackson.annotation.JsonProperty;-import com.fasterxml.jackson.databind.annotation.JsonSerialize;-import org.openremote.manager.shared.attribute.Attributes;--@JsonSerialize-public interface Connector {- /**- * Get the unique type descriptor for this connector component- */- @JsonProperty- String getType();-- /**- * Get the friendly display name for this connector component- */- @JsonProperty- String getDisplayName();-- /**- * Indicates whether or not this connector component supports- * discovery of Agents (connector instances).- */- @JsonProperty- boolean supportsAgentDiscovery();-- /**- * Get the attributes defining the configurable settings for- * agent discovery on this connector (if discovery not supported or- * no settings required then return null or empty attributes).- */- @JsonProperty- Attributes getAgentDiscoverySettings();-- /**- * Get the attributes defining the configurable settings for- * an agent that uses this connector.- */- @JsonProperty- Attributes getAgentSettings();-}diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorComponent.java b/manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorComponent.javaindex 1ad577d96..bfad1bc32 100644--- a/manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorComponent.java+++ b/manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorComponent.java@@ -19,15 +19,14 @@*/package org.openremote.manager.shared.connector;-import com.fasterxml.jackson.annotation.JsonInclude;+import com.fasterxml.jackson.annotation.JsonProperty;import com.fasterxml.jackson.databind.annotation.JsonSerialize;+import org.openremote.manager.shared.asset.Asset;import org.openremote.manager.shared.attribute.Attributes;-import org.openremote.manager.shared.device.InventoryCapabilities;import org.openremote.manager.shared.agent.AgentStatus;import org.openremote.manager.shared.device.Device;-@JsonSerialize(as = Connector.class)-public interface ConnectorComponent extends Connector {+public interface ConnectorComponent {public static final String HEADER_DISCOVERY_START = ConnectorComponent.class.getCanonicalName() + ".HEADER_DISCOVERY_START";public static final String HEADER_DISCOVERY_STOP = ConnectorComponent.class.getCanonicalName() + ".HEADER_DISCOVERY_STOP";public static final String HEADER_INVENTORY_ACTION = ConnectorComponent.class.getCanonicalName() + ".HEADER_INVENTORY_ACTION";@@ -41,42 +40,80 @@ public interface ConnectorComponent extends Connector {public static final String ACTION_WRITE = "WRITE";/**- * Optional endpoint URI for performing agent discovery. If implemented- * when agent discovery is required then a route will be created requiring- * a consumer from this endpoint which should generate messages for any- * agents that the connector discovers using the discovery settings provided.+ * Get the unique type descriptor for this connector component+ */+ String getType();++ /**+ * Get the friendly display name for this connector component+ */+ String getDisplayName();++ /**+ * Get CRUD support for child assets of the supplied parent asset. A null+ * response indicates that this asset doesn't support child assets (this can+ * also be indicated with the appropriate values in the returned {@link ChildAssetSupport}.*- * {@link Attributes} produced should be valid agent settings. A message should- * contain either a single {@link Attributes} object (one message per discovered- * agent) or an array of {@link Attributes} objects (multiple agents per message).- * Discovery should run as long as this route is running.+ * If parentAsset is null then response indicates child CRUD support at the+ * root (in connector terms this usually means agent asset CRUD).+ */+ ChildAssetSupport getChildSupport(Asset parentAsset);++ /**+ * Indicates whether or not this connector component supports child discovery+ * of the supplied parent asset.+ *+ * If parentAsset is null then response indicates whether child discovery is+ * supported at the root (in connector terms this usually means is agent asset+ * discovery supported).*/- String getAgentDiscoveryUri(Attributes discoverySettings);+ boolean supportsChildDiscovery(Asset parentAsset);/**- * Get device inventory capabilities of the supplied agent.+ * Get the settings mask for discovering child assets of the supplied+ * parent asset. This is used by clients for user entry of discovery settings.+ *+ * If parentAsset is null then child discovery is being requested at the root+ * (in connector terms this usually means discovering agent assets).*/- InventoryCapabilities getCapabilities(Attributes agentSettings);+ Attributes getChildDiscoverySettings(Asset parentAsset);/**- * Indicates whether or not this connector component supports monitoring of devices.- * If device monitoring is supported then {@link #getDeviceMonitorUri(Attributes)} must- * return the Endpoint URI for the device monitor.+ * Get the settings mask for creating/updating a child asset of the supplied+ * parent asset. This is used by clients for user entry of child assets.+ *+ * If parentAsset is null then child is being provisioned at the root+ * (in connector terms this usually means creating agent asset).*/- boolean supportsDeviceMonitoring(Attributes agentSettings);+ Attributes getChildAssetSettings(Asset parentAsset);/**- * Optional endpoint URI for consuming changes in the connector's status;- * messages should be output with the body set to an appropriate {@link AgentStatus}- * value.+ * Endpoint URI for performing child asset discovery. If implemented+ * when child discovery is required then a route will be created requiring+ * a consumer from this endpoint which should generate messages for any+ * child assets that the connector discovers based on the supplied parent asset+ * and discovery settings.*- * If not supported then just return null.+ * Messages output by the consumer should contain either a single {@link Asset} object or+ * an array of {@link Asset} objects. The outputted assets should have IDs and be linked+ * to their parent(s) thus allowing child discovery to return a hierarchy of assets.+ *+ * Discovery should run as long as this route is running.*/- String getAgentStatusUri(Attributes agentSettings);+ String getChildDiscoveryUri(Asset parentAsset, Attributes discoverySettings);/**- * Mandatory endpoint URI for performing device CRUD. The capabilities supported by a particular- * agent/connector are determined by the response from {@link #getCapabilities(Attributes)}.+ * Indicates whether or not this connector component supports monitoring of the supplied+ * asset.+ *+ * If asset monitoring is supported then {@link #getAssetMonitorUri(Asset)} must+ * return the Endpoint URI for the asset monitor.+ */+ boolean supportsMonitoring(Asset asset);++ /**+ * Endpoint URI for performing asset CRUD. The capabilities supported by a particular+ * connector for this asset are determined by the response from {@link #getChildSupport(Asset)}.** Support for reading devices from the inventory is mandatory, all other capabilities are* optional and are agent/connector dependent.@@ -85,61 +122,51 @@ public interface ConnectorComponent extends Connector {* by the {@link #HEADER_INVENTORY_ACTION} message header.** {@Link #ACTION_CREATE}, {@Link #ACTION_UPDATE}, {@Link #ACTION_DELETE} operations- * should consume a {@link Device}[]. In the case of {@link #ACTION_DELETE} then only the- * device URI(s) should be required. The reply message body should contain an integer indicating+ * should consume a {@link Asset}[]. In the case of {@link #ACTION_DELETE} then only the+ * asset ID should be required. The reply message body should contain an integer indicating* the status of the request (conforming to the HTTP Status code specification).*- * {@link #ACTION_READ} operations should consume a {@link Device}[] where only the device- * URI(s) should be required, if no devices are supplied then all devices should be returned.- * The reply message body should contain a {@link Device}[] of the requested devices.- *- */- String getDeviceInventoryUri(Attributes agentSettings);-- /**- * Optional endpoint URI for performing device discovery. If implemented- * when device discovery is required then a route will be created requiring- * a consumer from this endpoint which should generate messages for any- * devices that the connector discovers from the specified agent.- *- * {@link Attributes} produced should be valid devices (URI and Type). A message should- * contain either a single {@link Attributes} object (one message per discovered device)- * or an array of {@link Attributes} objects (multiple devices per message).- *- * Discovery should run as long as this route is running.+ * {@link #ACTION_READ} operations should consume a {@link Asset}[] where only the ID should+ * be required, if no assets are supplied then all child assets should be returned.+ * The reply message body should contain a {@link Asset}[] of the requested devices.*- * If not supported then just return null.*/- String getDeviceDiscoveryUri(Attributes agentSettings);+ String getChildInventoryUri(Asset asset);/**- * Mandatory endpoint URI for: -- * Reading from device resources- * Writing to device resources- * Subscribing/Un-subscribing to device changes+ * Endpoint URI for: -+ * Reading/Writing from/to assets+ * Subscribing/Un-subscribing to asset changes*- * A single endpoint is used for all devices that belong to the specified- * agent. This endpoint is expected to support the InOut MEP with the+ * This endpoint is expected to support the InOut MEP with the* {@link #HEADER_DEVICE_ACTION} message header indicating the action to* perform/data to return on messages to be consumed by this endpoint.** {@link #ACTION_SUBSCRIBE}, {@link #ACTION_UNSUBSCRIBE} operations should consume a- * {@link Device}[] where only the device URI(s) should be required. The reply message body+ * {@link Asset}[] where only the ID(s) should be required. The reply message body* should contain an integer indicating the status of the request (conforming to the HTTP- * Status code specification). Agents/Connectors that support device subscriptions must return- * a valid endpoint URI from {@link #getDeviceMonitorUri(Attributes)}.+ * Status code specification). Connectors that support asset subscriptions must return+ * a valid endpoint URI from {@link #getAssetMonitorUri(Asset)}.+ *+ * Assets of a connector can share an endpoint which is indicated by returning the same+ * endpoint URI.*/- String getDevicesUri(Attributes agentSettings);+ String getAssetUri(Asset asset);/**- * Optional endpoint URI for consuming device changes from the specified agent;- * subscribing to device changes is done separately using the devices Endpoint URI.+ * Endpoint URI for consuming asset changes as reported by the connector.*- * A subscribed device should be monitored by the connector for any resource value- * changes; these changes should then be output in a message body as {@link Device}[]- * containing the modified device(s) and resource(s).+ * A subscribed asset should be monitored by the connector for any resource value+ * changes; these changes should then be output in a message body as {@link Asset}[]+ * containing the modified attributes.*- * If not supported (i.e. devices require polling) then just return null.+ * If not supported then just return null.+ */+ String getAssetMonitorUri(Asset asset);++ /**+ * Generate the asset represented by the supplied asset settings, the connector is responsible+ * for setting the asset ID and asset type as well as any attributes and metadata that are required.*/- String getDeviceMonitorUri(Attributes agentSettings);+ Asset createAsset(Asset parent, Attributes assetSettings);}diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorResource.java b/manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorResource.javaindex 9e161dd42..7278cdd66 100644--- a/manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorResource.java+++ b/manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorResource.java@@ -20,25 +20,51 @@package org.openremote.manager.shared.connector;import jsinterop.annotations.JsType;+import org.openremote.manager.shared.asset.AssetInfo;+import org.openremote.manager.shared.attribute.Attributes;import org.openremote.manager.shared.http.RequestParams;import org.openremote.manager.shared.http.SuccessStatusCode;-import javax.ws.rs.BeanParam;-import javax.ws.rs.GET;-import javax.ws.rs.Path;-import javax.ws.rs.Produces;+import javax.annotation.security.RolesAllowed;+import javax.ws.rs.*;import static javax.ws.rs.core.MediaType.APPLICATION_JSON;@Path("connector")@JsType(isNative = true)public interface ConnectorResource {+ @GET+ @Produces(APPLICATION_JSON)+ @SuccessStatusCode(200)+ // TODO Implement admin roles on server+ //@RolesAllowed({"read:admin"})+ AssetInfo[] getConnectors(@BeanParam RequestParams requestParams);@GET@Produces(APPLICATION_JSON)@SuccessStatusCode(200)+ @Path("{connectorId}")// TODO Implement admin roles on server//@RolesAllowed({"read:admin"})- Connector[] getConnectors(@BeanParam RequestParams requestParams);+ AssetInfo getConnector(@BeanParam RequestParams requestParams, @PathParam("connectorId")String connectorId);+ @GET+ @Path("{assetId}/children")+ @Produces(APPLICATION_JSON)+ @SuccessStatusCode(200)+ // TODO Implement admin roles on server+ //@RolesAllowed({"read:assets"})+ AssetInfo[] getChildren(@BeanParam RequestParams requestParams, @PathParam("assetId") String parentId);++ @GET+ @Path("settings/new/{parentAssetId}")+ @Produces(APPLICATION_JSON)+ @SuccessStatusCode(200)+ Attributes getAssetSettings(@BeanParam RequestParams requestParams, @PathParam("parentAssetId") String parentId);++ @GET+ @Path("settings/discovery/{parentAssetId}")+ @Produces(APPLICATION_JSON)+ @SuccessStatusCode(200)+ Attributes getAssetDiscoverySettings(@BeanParam RequestParams requestParams, @PathParam("parentAssetId") String parentId);}diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorUtil.java b/manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorUtil.javaindex 1de1a5157..be2f1496c 100644--- a/manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorUtil.java+++ b/manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorUtil.java@@ -127,4 +127,46 @@ public class ConnectorUtil {//// return new Attribute(connectorAttribute.getName(), connectorAttribute.getType(), value);// }++// /**+// * Copy all settings which have a value into the {@link Agent}, keeping the value+// * of each attribute but not the attribute metadata.+// */+// public void writeSettings(Agent agent) {+// if (getAgentSettings() == null) {+// agent.setConnectorSettings(null);+// return;+// }+// Attributes settings = getAgentSettings();+// Attributes agentConnectorSettings = new Attributes();+// for (Attribute attribute : settings.get()) {+// if (attribute.getValue() == null)+// continue;+// Attribute agentConnectorAttribute = new Attribute(attribute.getName(), attribute.getType());+// agentConnectorAttribute.setValue(attribute.getValue());+// agentConnectorSettings.add(agentConnectorAttribute);+// }+// agent.setConnectorSettings(agentConnectorSettings.getJsonObject());+// }+//+// /**+// * Read the value for each settings attribute from the {@link Agent}, skipping any+// * unknown attribute or attribute that doesn't have the right type. The+// * {@link Agent#connectorSettings} can be "cleaned up" so they match a {@link Connector}+// * by calling {@link #readSettings(Agent)} followed by {@link #writeSettings(Agent)}.+// */+// public void readSettings(Agent agent) {+// if (agent.getConnectorSettings() == null)+// return;+//+// Attributes settings = getAgentSettings();+// Attributes agentConnectorSettings = new Attributes(agent.getConnectorSettings());+// for (Attribute agentConnectorAttribute : agentConnectorSettings.get()) {+// Attribute settingsAttribute = settings.get(agentConnectorAttribute.getName());+// if (settingsAttribute != null+// && settingsAttribute.getType().equals(agentConnectorAttribute.getType())) {+// settingsAttribute.setValue(agentConnectorAttribute.getValue());+// }+// }+// }}diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/device/Device.java b/manager/shared/src/main/java/org/openremote/manager/shared/device/Device.javaindex bb034f51b..06c1a07a1 100644--- a/manager/shared/src/main/java/org/openremote/manager/shared/device/Device.java+++ b/manager/shared/src/main/java/org/openremote/manager/shared/device/Device.java@@ -1,5 +1,7 @@package org.openremote.manager.shared.device;+import com.fasterxml.jackson.annotation.JsonProperty;+import com.fasterxml.jackson.annotation.JsonTypeInfo;import elemental.json.Json;import elemental.json.JsonArray;import elemental.json.JsonObject;@@ -19,6 +21,7 @@ import org.openremote.manager.shared.asset.AssetType;* and mapping purposes.**/+public class Device extends Asset {protected static final String URI_KEY = "uri";protected static final String RESOURCES_KEY = "resources";@@ -32,6 +35,7 @@ public class Device extends Asset {public void setType(String type) {}+ @JsonPropertypublic String getUri() {if (attributes == null) {return null;@@ -40,6 +44,7 @@ public class Device extends Asset {return attributes.getString(URI_KEY);}+ @JsonPropertypublic void setUri(String uri) {if (attributes == null) {attributes = Json.createObject();@@ -48,6 +53,7 @@ public class Device extends Asset {attributes.put(URI_KEY, uri);}+ @JsonPropertypublic DeviceResource[] getResources(){if (attributes == null || !attributes.hasKey(RESOURCES_KEY)) {@@ -65,6 +71,7 @@ public class Device extends Asset {return resources;}+ @JsonPropertypublic void setResources(DeviceResource[] resources){if (attributes == null) {attributes = Json.createObject();@@ -84,6 +91,7 @@ public class Device extends Asset {attributes.put(RESOURCES_KEY, resourcesArr);}+ @JsonPropertypublic CapabilityRef[] getCapabilities() {if (attributes == null || !attributes.hasKey(CAPABILITIES_KEY)) {return null;@@ -100,6 +108,7 @@ public class Device extends Asset {return capabilities;}+ @JsonPropertypublic void setCapabilities(CapabilityRef[] capabilities){if (attributes == null) {attributes = Json.createObject();@@ -118,4 +127,4 @@ public class Device extends Asset {attributes.put(CAPABILITIES_KEY, capabilitiesArr);}-}+}\ No newline at end of filediff --git a/test/src/test/groovy/org/openremote/test/controller2/Controller2Service.java b/test/src/test/groovy/org/openremote/test/controller2/Controller2Service.javaindex 3c116edb5..b93fb9ee5 100644--- a/test/src/test/groovy/org/openremote/test/controller2/Controller2Service.java+++ b/test/src/test/groovy/org/openremote/test/controller2/Controller2Service.java@@ -2,7 +2,6 @@ package org.openremote.test.controller2;import org.apache.camel.ProducerTemplate;import org.apache.camel.builder.RouteBuilder;-import org.openremote.agent.controller2.Controller2Component;import org.openremote.container.Container;import org.openremote.container.ContainerService;import org.openremote.container.message.MessageBrokerContext;@@ -12,10 +11,10 @@ import org.openremote.manager.shared.device.Device;import java.util.ArrayList;import java.util.List;-import static org.openremote.manager.shared.device.DeviceInventory.Action.ADD;-import static org.openremote.manager.shared.device.DeviceInventory.Action.REMOVE;-import static org.openremote.manager.shared.device.DeviceInventory.Action.UPDATE;-import static org.openremote.manager.shared.device.DeviceInventory.HEADER_DEVICE_ACTION;+import static org.openremote.manager.shared.connector.AssetInventory.Action.ADD;+import static org.openremote.manager.shared.connector.AssetInventory.Action.REMOVE;+import static org.openremote.manager.shared.connector.AssetInventory.Action.UPDATE;+import static org.openremote.manager.shared.connector.AssetInventory.HEADER_DEVICE_ACTION;// TODO This is an example service for testing, replaced later with production codepublic class Controller2Service implements ContainerService {