From 4ad62b1dc175372c0dcbce4acb55356d70973127 Mon Sep 17 00:00:00 2001 From: NuwanSameera Date: Tue, 19 Apr 2016 17:16:58 +0530 Subject: [PATCH] Remove monitor operations from controller api. --- .../impl/AndroidSenseControllerService.java | 1 + .../AndroidSenseControllerServiceImpl.java | 7 - .../impl/ArduinoControllerService.java | 8 - .../impl/ArduinoControllerServiceImpl.java | 26 -- .../impl/RaspberryPiControllerService.java | 8 - .../RaspberryPiControllerServiceImpl.java | 34 --- .../transport/RaspberryPiMQTTConnector.java | 5 +- .../VirtualFireAlarmControllerService.java | 19 -- ...VirtualFireAlarmControllerServiceImpl.java | 226 ++---------------- .../VirtualFireAlarmMQTTConnector.java | 5 - .../VirtualFireAlarmXMPPConnector.java | 5 - 11 files changed, 20 insertions(+), 324 deletions(-) diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseControllerService.java b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseControllerService.java index 4d63e66b0..2a574f8e6 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseControllerService.java +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseControllerService.java @@ -80,3 +80,4 @@ public interface AndroidSenseControllerService { @QueryParam("from") long from, @QueryParam("to") long to); } + diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseControllerServiceImpl.java b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseControllerServiceImpl.java index 5e3d31c5a..0db0b2610 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseControllerServiceImpl.java +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseControllerServiceImpl.java @@ -24,18 +24,11 @@ import org.wso2.carbon.analytics.dataservice.commons.SORT; import org.wso2.carbon.analytics.dataservice.commons.SortByField; import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException; -import org.wso2.carbon.device.mgt.analytics.data.publisher.service.EventsPublisherService; -import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature; import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.transport.AndroidSenseMQTTConnector; import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.APIUtil; -import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.DeviceData; -import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.SensorData; import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.SensorRecord; import org.wso2.carbon.device.mgt.iot.androidsense.plugin.constants.AndroidSenseConstants; import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig; -import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException; -import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager; import org.wso2.carbon.device.mgt.iot.service.IoTServerStartupListener; import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException; diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoControllerService.java b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoControllerService.java index 02e39d88b..f82ff603a 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoControllerService.java +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoControllerService.java @@ -50,14 +50,6 @@ public interface ArduinoControllerService { Response switchBulb(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol, @FormParam("state") String state); - @Path("device/{deviceId}/temperature") - @GET - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Feature(code = "temperature", name = "Temperature", type = "monitor", description = "Request temperature reading " + - "from Arduino agent") - Response requestTemperature(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol); - @Path("device/sensor") @POST @Consumes(MediaType.APPLICATION_JSON) diff --git a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoControllerServiceImpl.java b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoControllerServiceImpl.java index 6434c7b65..ce40e39ef 100644 --- a/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoControllerServiceImpl.java +++ b/components/iot-plugins/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoControllerServiceImpl.java @@ -29,8 +29,6 @@ import org.wso2.carbon.device.mgt.iot.arduino.service.impl.dto.SensorRecord; import org.wso2.carbon.device.mgt.iot.arduino.service.impl.util.APIUtil; import org.wso2.carbon.device.mgt.iot.arduino.service.impl.util.ArduinoServiceUtils; import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants; -import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException; -import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.Consumes; import javax.ws.rs.FormParam; @@ -44,7 +42,6 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.ArrayList; -import java.util.Calendar; import java.util.HashMap; import java.util.LinkedList; import java.util.List; @@ -95,23 +92,6 @@ public class ArduinoControllerServiceImpl implements ArduinoControllerService { return Response.status(Response.Status.OK.getStatusCode()).build(); } - @Override - @Path("device/{deviceId}/temperature") - @GET - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public Response requestTemperature(@PathParam("deviceId") String deviceId, - @QueryParam("protocol") String protocol) { - - try { - org.wso2.carbon.device.mgt.iot.sensormgt.SensorRecord sensorRecord = - SensorDataManager.getInstance().getSensorRecord(deviceId, ArduinoConstants.SENSOR_TEMPERATURE); - return Response.status(Response.Status.OK.getStatusCode()).entity(sensorRecord).build(); - } catch (DeviceControllerException e) { - return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); - } - } - @Override @Path("device/sensor") @POST @@ -120,9 +100,6 @@ public class ArduinoControllerServiceImpl implements ArduinoControllerService { String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String deviceId = dataMsg.deviceId; float pinData = dataMsg.value; - SensorDataManager.getInstance().setSensorRecord(deviceId, ArduinoConstants.SENSOR_TEMPERATURE, - String.valueOf(pinData), - Calendar.getInstance().getTimeInMillis()); if (!ArduinoServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) { log.warn("An error occured whilst trying to publish pin data of Arduino with ID [" + deviceId + "] of owner [" + owner + "]"); @@ -169,9 +146,6 @@ public class ArduinoControllerServiceImpl implements ArduinoControllerService { String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String deviceId = dataMsg.deviceId; float temperature = dataMsg.value; - SensorDataManager.getInstance().setSensorRecord(deviceId, ArduinoConstants.SENSOR_TEMPERATURE, - String.valueOf(temperature), - Calendar.getInstance().getTimeInMillis()); if (!ArduinoServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) { log.warn("An error occured whilst trying to publish temperature data of Arduino with ID [" + deviceId + "] of owner [" + owner + "]"); diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiControllerService.java b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiControllerService.java index 12d5f4389..5ac51e24f 100644 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiControllerService.java +++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiControllerService.java @@ -51,14 +51,6 @@ public interface RaspberryPiControllerService { description = "Switch on/off Raspberry Pi agent's bulb. (On / Off)") Response switchBulb(@PathParam("deviceId") String deviceId, @FormParam("state") String state); - @Path("device/{deviceId}/readtemperature") - @GET - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Feature(code = "readtemperature", name = "Temperature", type = "monitor", - description = "Request temperature reading from Raspberry Pi agent") - Response requestTemperature(@PathParam("deviceId") String deviceId); - @Path("device/push_temperature") @POST @Consumes(MediaType.APPLICATION_JSON) diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiControllerServiceImpl.java b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiControllerServiceImpl.java index 756882345..cecde2d43 100644 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiControllerServiceImpl.java +++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiControllerServiceImpl.java @@ -25,14 +25,12 @@ import org.wso2.carbon.analytics.dataservice.commons.SortByField; import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig; -import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException; import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.dto.DeviceData; import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.dto.SensorRecord; import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.transport.RaspberryPiMQTTConnector; import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.util.APIUtil; import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.util.RaspberrypiServiceUtils; import org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.constants.RaspberrypiConstants; -import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager; import org.wso2.carbon.device.mgt.iot.service.IoTServerStartupListener; import javax.servlet.http.HttpServletRequest; @@ -98,35 +96,6 @@ public class RaspberryPiControllerServiceImpl implements RaspberryPiControllerSe return Response.ok().build(); } - @Path("device/{deviceId}/readtemperature") - @GET - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public Response requestTemperature(@PathParam("deviceId") String deviceId) { - org.wso2.carbon.device.mgt.iot.sensormgt.SensorRecord sensorRecord = null; - if (log.isDebugEnabled()) { - log.debug("Sending request to read raspberrypi-temperature of device [" + deviceId + "] via "); - } - try { - String deviceHTTPEndpoint = deviceToIpMap.get(deviceId); - if (deviceHTTPEndpoint == null) { - return Response.status(Response.Status.PRECONDITION_FAILED.getStatusCode()).build(); - } - String temperatureValue = RaspberrypiServiceUtils.sendCommandViaHTTP(deviceHTTPEndpoint, - RaspberrypiConstants - .TEMPERATURE_CONTEXT, - false); - SensorDataManager.getInstance().setSensorRecord(deviceId, RaspberrypiConstants.SENSOR_TEMPERATURE, - temperatureValue, Calendar.getInstance() - .getTimeInMillis()); - sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, - RaspberrypiConstants.SENSOR_TEMPERATURE); - } catch (DeviceManagementException | DeviceControllerException e) { - return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); - } - return Response.ok().entity(sensorRecord).build(); - } - @Path("device/push_temperature") @POST @Consumes(MediaType.APPLICATION_JSON) @@ -148,9 +117,6 @@ public class RaspberryPiControllerServiceImpl implements RaspberryPiControllerSe if (log.isDebugEnabled()) { log.debug("Received Pin Data Value: " + temperature + " degrees C"); } - SensorDataManager.getInstance().setSensorRecord(deviceId, RaspberrypiConstants.SENSOR_TEMPERATURE, - String.valueOf(temperature), - Calendar.getInstance().getTimeInMillis()); if (!RaspberrypiServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) { log.warn("An error occured whilst trying to publish temperature data of raspberrypi with ID [" + deviceId + "] of owner [" + owner + "]"); diff --git a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/transport/RaspberryPiMQTTConnector.java b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/transport/RaspberryPiMQTTConnector.java index d5bf225be..ff0c7e1ca 100644 --- a/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/transport/RaspberryPiMQTTConnector.java +++ b/components/iot-plugins/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/transport/RaspberryPiMQTTConnector.java @@ -25,7 +25,6 @@ import org.eclipse.paho.client.mqttv3.MqttMessage; import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService; import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey; import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException; -import org.wso2.carbon.base.MultitenantConstants; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; @@ -35,7 +34,6 @@ import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig; import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.util.APIUtil; import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.util.RaspberrypiServiceUtils; import org.wso2.carbon.device.mgt.iot.raspberrypi.plugin.constants.RaspberrypiConstants; -import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager; import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException; import org.wso2.carbon.device.mgt.iot.transport.mqtt.MQTTTransportHandler; import org.wso2.carbon.identity.jwt.client.extension.JWTClient; @@ -161,8 +159,7 @@ public class RaspberryPiMQTTConnector extends MQTTTransportHandler { } else if (receivedMessage.contains("TEMPERATURE")) { String temperatureValue = receivedMessage.split(":")[1]; - SensorDataManager.getInstance().setSensorRecord(deviceId, RaspberrypiConstants.SENSOR_TEMPERATURE, - temperatureValue, Calendar.getInstance().getTimeInMillis()); + } } } diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerService.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerService.java index a46762b21..ba2694742 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerService.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerService.java @@ -78,25 +78,6 @@ public interface VirtualFireAlarmControllerService { Response switchBuzzer(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol, @FormParam("state") String state); - /** - * This is an API called/used from within the Server(Front-End) or by a device Owner. It sends a control command - * to the VirtualFirealarm device to 'tell what's its current temperature reading'. The method also takes in the - * protocol to be used to connect-to and send the command to the device. - * - * @param deviceId the ID of the VirtualFirealarm device on which the temperature reading is be read-from. - * @param protocol the protocol (HTTP, MQTT, XMPP) to be used to connect-to & send the message to the device. - * @return an instance of the 'SensorRecord' object that holds the last updated temperature of the VirtualFirealarm - * whose temperature reading was requested. - */ - @GET - @Path("device/{deviceId}/temperature") - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Feature(code = "temperature", name = "Temperature", type = "monitor", - description = "Request Temperature reading from Virtual Fire Alarm") - Response requestTemperature(@PathParam("deviceId") String deviceId, - @QueryParam("protocol") String protocol); - /** * This is an API called/used by the VirtualFirealarm device to publish its temperature to the IoT-Server. The * received data from the device is stored in a 'DeviceRecord' under the device's ID in the 'SensorDataManager' diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerServiceImpl.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerServiceImpl.java index f49a2606e..f3e9d796d 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerServiceImpl.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerServiceImpl.java @@ -27,11 +27,8 @@ import org.wso2.carbon.certificate.mgt.core.dto.SCEPResponse; import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException; import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService; import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature; import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig; import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig; -import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException; -import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager; import org.wso2.carbon.device.mgt.iot.service.IoTServerStartupListener; import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.dto.DeviceData; @@ -60,7 +57,6 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.io.InputStream; import java.util.ArrayList; -import java.util.Calendar; import java.util.List; import java.util.concurrent.ConcurrentHashMap; @@ -87,142 +83,10 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo // holds a mapping of the IP addresses to Device-IDs for HTTP communication private ConcurrentHashMap deviceToIpMap = new ConcurrentHashMap<>(); -<<<<<<< HEAD @POST @Path("device/register/{deviceId}/{ip}/{port}") public Response registerDeviceIP(@PathParam("deviceId") String deviceId, @PathParam("ip") String deviceIP, @PathParam("port") String devicePort, @Context HttpServletRequest request) { -======= - private boolean waitForServerStartup() { - while (!IoTServerStartupListener.isServerReady()) { - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - return true; - } - } - return false; - } - - /** - * Fetches the `SecurityManager` specific to this VirtualFirealarm controller service. - * - * @return the 'SecurityManager' instance bound to the 'securityManager' variable of this service. - */ - @SuppressWarnings("Unused") - public SecurityManager getSecurityManager() { - return securityManager; - } - - /** - * Sets the `securityManager` variable of this VirtualFirealarm controller service. - * - * @param securityManager a 'SecurityManager' object that handles the encryption, decryption, signing and validation - * of incoming messages from VirtualFirealarm device-types. - */ - @SuppressWarnings("Unused") - public void setSecurityManager(SecurityManager securityManager) { - this.securityManager = securityManager; - securityManager.initVerificationManager(); - } - - /** - * Fetches the `VirtualFireAlarmXMPPConnector` specific to this VirtualFirealarm controller service. - * - * @return the 'VirtualFireAlarmXMPPConnector' instance bound to the 'virtualFireAlarmXMPPConnector' variable of - * this service. - */ - @SuppressWarnings("Unused") - public VirtualFireAlarmXMPPConnector getVirtualFireAlarmXMPPConnector() { - return virtualFireAlarmXMPPConnector; - } - - /** - * Sets the `virtualFireAlarmXMPPConnector` variable of this VirtualFirealarm controller service. - * - * @param virtualFireAlarmXMPPConnector a 'VirtualFireAlarmXMPPConnector' object that handles all XMPP related - * communications of any connected VirtualFirealarm device-type - */ - @SuppressWarnings("Unused") - public void setVirtualFireAlarmXMPPConnector( - final VirtualFireAlarmXMPPConnector virtualFireAlarmXMPPConnector) { - Runnable connector = new Runnable() { - public void run() { - if (waitForServerStartup()) { - return; - } - VirtualFireAlarmControllerServiceImpl.this.virtualFireAlarmXMPPConnector = virtualFireAlarmXMPPConnector; - - if (XmppConfig.getInstance().isEnabled()) { - Runnable xmppStarter = new Runnable() { - @Override - public void run() { - virtualFireAlarmXMPPConnector.initConnector(); - virtualFireAlarmXMPPConnector.connect(); - } - }; - - Thread xmppStarterThread = new Thread(xmppStarter); - xmppStarterThread.setDaemon(true); - xmppStarterThread.start(); - } else { - log.warn("XMPP disabled in 'devicemgt-config.xml'. Hence, VirtualFireAlarmXMPPConnector not started."); - } - } - }; - Thread connectorThread = new Thread(connector); - connectorThread.setDaemon(true); - connectorThread.start(); - } - - /** - * Fetches the `VirtualFireAlarmMQTTConnector` specific to this VirtualFirealarm controller service. - * - * @return the 'VirtualFireAlarmMQTTConnector' instance bound to the 'virtualFireAlarmMQTTConnector' variable of - * this service. - */ - @SuppressWarnings("Unused") - public VirtualFireAlarmMQTTConnector getVirtualFireAlarmMQTTConnector() { - return virtualFireAlarmMQTTConnector; - } - - /** - * Sets the `virtualFireAlarmMQTTConnector` variable of this VirtualFirealarm controller service. - * - * @param virtualFireAlarmMQTTConnector a 'VirtualFireAlarmMQTTConnector' object that handles all MQTT related - * communications of any connected VirtualFirealarm device-type - */ - @SuppressWarnings("Unused") - public void setVirtualFireAlarmMQTTConnector( - final VirtualFireAlarmMQTTConnector virtualFireAlarmMQTTConnector) { - Runnable connector = new Runnable() { - public void run() { - if (waitForServerStartup()) { - return; - } - VirtualFireAlarmControllerServiceImpl.this.virtualFireAlarmMQTTConnector = virtualFireAlarmMQTTConnector; - //The delay is added for the server starts up. - try { - Thread.sleep(5000); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - if (MqttConfig.getInstance().isEnabled()) { - synchronized (virtualFireAlarmMQTTConnector) { - virtualFireAlarmMQTTConnector.connect(); - } - } else { - log.warn("MQTT disabled in 'devicemgt-config.xml'. Hence, VirtualFireAlarmMQTTConnector not started."); - } - } - }; - Thread connectorThread = new Thread(connector); - connectorThread.setDaemon(true); - connectorThread.start(); - } - - public Response registerDeviceIP(String deviceId, String deviceIP, String devicePort, HttpServletRequest request) { ->>>>>>> 8a7d4bb6e0a9b94b8a5c9ca8d6d21c3924b2c677 String result; if (log.isDebugEnabled()) { log.debug("Got register call from IP: " + deviceIP + " for Device ID: " + deviceId); @@ -277,53 +141,6 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo } } -<<<<<<< HEAD - @GET - @Path("device/{deviceId}/temperature") - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public Response requestTemperature(@PathParam("deviceId") String deviceId, - @QueryParam("protocol") String protocol) { - SensorRecord sensorRecord = null; -======= - public Response requestTemperature(String deviceId, String protocol) { - org.wso2.carbon.device.mgt.iot.sensormgt.SensorRecord sensorRecord = null; ->>>>>>> 8a7d4bb6e0a9b94b8a5c9ca8d6d21c3924b2c677 - String protocolString = protocol.toUpperCase(); - if (log.isDebugEnabled()) { - log.debug("Sending request to read virtual-firealarm-temperature of device " + - "[" + deviceId + "] via " + protocolString); - } - try { - switch (protocolString) { - case HTTP_PROTOCOL: - String deviceHTTPEndpoint = deviceToIpMap.get(deviceId); - if (deviceHTTPEndpoint == null) { - return Response.status(Response.Status.PRECONDITION_FAILED).build(); - } - String temperatureValue = VirtualFireAlarmServiceUtils.sendCommandViaHTTP( - deviceHTTPEndpoint, VirtualFireAlarmConstants.TEMPERATURE_CONTEXT, false); - SensorDataManager.getInstance().setSensorRecord(deviceId, VirtualFireAlarmConstants.SENSOR_TEMP, - temperatureValue, - Calendar.getInstance().getTimeInMillis()); - break; - case XMPP_PROTOCOL: - String xmppResource = VirtualFireAlarmConstants.TEMPERATURE_CONTEXT.replace("/", ""); - virtualFireAlarmMQTTConnector.publishDeviceData(deviceId, xmppResource, ""); - break; - default: - String mqttResource = VirtualFireAlarmConstants.TEMPERATURE_CONTEXT.replace("/", ""); - virtualFireAlarmMQTTConnector.publishDeviceData(deviceId, mqttResource, ""); - break; - } - sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, VirtualFireAlarmConstants - .SENSOR_TEMP); - return Response.ok().entity(sensorRecord).build(); - } catch (DeviceManagementException | DeviceControllerException | TransportHandlerException e) { - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); - } - } - @POST @Path("device/temperature") @Consumes(MediaType.APPLICATION_JSON) @@ -341,9 +158,6 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo " is already registered under some other IP. Re-registration required"); return Response.status(Response.Status.CONFLICT).build(); } - SensorDataManager.getInstance().setSensorRecord(deviceId, VirtualFireAlarmConstants.SENSOR_TEMP, - String.valueOf(temperature), - Calendar.getInstance().getTimeInMillis()); if (!VirtualFireAlarmServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) { return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } @@ -442,7 +256,6 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo return Response.serverError().build(); } -<<<<<<< HEAD @Path("device/stats/{deviceId}/sensors/{sensorName}") @GET @Consumes("application/json") @@ -451,29 +264,26 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo @PathParam("sensorName") String sensor, @QueryParam("username") String user, @QueryParam("from") long from, @QueryParam("to") long to) { -======= - public Response getVirtualFirealarmStats(String deviceId, String sensor, String user, long from, long to) { - String fromDate = String.valueOf(from); - String toDate = String.valueOf(to); - String query = "owner:" + user + " AND deviceId:" + deviceId + " AND deviceType:" + - VirtualFireAlarmConstants.DEVICE_TYPE + " AND time : [" + fromDate + " TO " + toDate + "]"; - String sensorTableName = getSensorEventTableName(sensor); ->>>>>>> 8a7d4bb6e0a9b94b8a5c9ca8d6d21c3924b2c677 - try { - if (sensorTableName != null) { - List sortByFields = new ArrayList<>(); - SortByField sortByField = new SortByField("time", SORT.ASC, false); - sortByFields.add(sortByField); - List sensorRecords = APIUtil.getAllEventsForDevice(sensorTableName, query, sortByFields); - return Response.status(Response.Status.OK.getStatusCode()).entity(sensorRecords).build(); + String fromDate = String.valueOf(from); + String toDate = String.valueOf(to); + String query = "owner:" + user + " AND deviceId:" + deviceId + " AND deviceType:" + + VirtualFireAlarmConstants.DEVICE_TYPE + " AND time : [" + fromDate + " TO " + toDate + "]"; + String sensorTableName = getSensorEventTableName(sensor); + try { + if (sensorTableName != null) { + List sortByFields = new ArrayList<>(); + SortByField sortByField = new SortByField("time", SORT.ASC, false); + sortByFields.add(sortByField); + List sensorRecords = APIUtil.getAllEventsForDevice(sensorTableName, query, sortByFields); + return Response.status(Response.Status.OK.getStatusCode()).entity(sensorRecords).build(); + } + } catch (AnalyticsException e) { + String errorMsg = "Error on retrieving stats on table " + sensorTableName + " with query " + query; + log.error(errorMsg); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(errorMsg).build(); } - } catch (AnalyticsException e) { - String errorMsg = "Error on retrieving stats on table " + sensorTableName + " with query " + query; - log.error(errorMsg); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(errorMsg).build(); + return Response.status(Response.Status.BAD_REQUEST).build(); } - return Response.status(Response.Status.BAD_REQUEST).build(); - } private boolean waitForServerStartup() { while (!IoTServerStartupListener.isServerReady()) { diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/transport/VirtualFireAlarmMQTTConnector.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/transport/VirtualFireAlarmMQTTConnector.java index 6cbd9af81..c9c1a4b79 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/transport/VirtualFireAlarmMQTTConnector.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/transport/VirtualFireAlarmMQTTConnector.java @@ -25,14 +25,12 @@ import org.eclipse.paho.client.mqttv3.MqttMessage; import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService; import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey; import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException; -import org.wso2.carbon.base.MultitenantConstants; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig; -import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager; import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException; import org.wso2.carbon.device.mgt.iot.transport.mqtt.MQTTTransportHandler; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.exception.VirtualFireAlarmException; @@ -208,9 +206,6 @@ public class VirtualFireAlarmMQTTConnector extends MQTTTransportHandler { } else if (actualMessage.contains("TEMPERATURE")) { String temperatureValue = actualMessage.split(":")[1]; - SensorDataManager.getInstance().setSensorRecord(deviceId, VirtualFireAlarmConstants.SENSOR_TEMP, - temperatureValue, - Calendar.getInstance().getTimeInMillis()); } } catch (VirtualFireAlarmException e) { String errorMsg = diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/transport/VirtualFireAlarmXMPPConnector.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/transport/VirtualFireAlarmXMPPConnector.java index 39588caef..fc6ea6ca1 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/transport/VirtualFireAlarmXMPPConnector.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/transport/VirtualFireAlarmXMPPConnector.java @@ -26,7 +26,6 @@ import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppAccount; import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig; import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppServerClient; import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException; -import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager; import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException; import org.wso2.carbon.device.mgt.iot.transport.xmpp.XMPPTransportHandler; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants; @@ -182,10 +181,6 @@ public class VirtualFireAlarmXMPPConnector extends XMPPTransportHandler { break; case "CONTROL-REPLY": String tempVal = actualMessage.split(":")[1]; - SensorDataManager.getInstance().setSensorRecord(deviceId, - VirtualFireAlarmConstants.SENSOR_TEMP, - tempVal, - Calendar.getInstance().getTimeInMillis()); break; default: