Remove monitor operations from controller api.

revert-dabc3590
NuwanSameera 9 years ago
parent 1606c365e6
commit 4ad62b1dc1

@ -80,3 +80,4 @@ public interface AndroidSenseControllerService {
@QueryParam("from") long from, @QueryParam("to") long to); @QueryParam("from") long from, @QueryParam("to") long to);
} }

@ -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.dataservice.commons.SortByField;
import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException; import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException;
import org.wso2.carbon.context.PrivilegedCarbonContext; 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.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.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.service.impl.util.SensorRecord;
import org.wso2.carbon.device.mgt.iot.androidsense.plugin.constants.AndroidSenseConstants; 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.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.service.IoTServerStartupListener;
import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException; import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException;

@ -50,14 +50,6 @@ public interface ArduinoControllerService {
Response switchBulb(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol, Response switchBulb(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol,
@FormParam("state") String state); @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") @Path("device/sensor")
@POST @POST
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)

@ -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.APIUtil;
import org.wso2.carbon.device.mgt.iot.arduino.service.impl.util.ArduinoServiceUtils; 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.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.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam; 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.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -95,23 +92,6 @@ public class ArduinoControllerServiceImpl implements ArduinoControllerService {
return Response.status(Response.Status.OK.getStatusCode()).build(); 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 @Override
@Path("device/sensor") @Path("device/sensor")
@POST @POST
@ -120,9 +100,6 @@ public class ArduinoControllerServiceImpl implements ArduinoControllerService {
String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
String deviceId = dataMsg.deviceId; String deviceId = dataMsg.deviceId;
float pinData = dataMsg.value; float pinData = dataMsg.value;
SensorDataManager.getInstance().setSensorRecord(deviceId, ArduinoConstants.SENSOR_TEMPERATURE,
String.valueOf(pinData),
Calendar.getInstance().getTimeInMillis());
if (!ArduinoServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) { if (!ArduinoServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) {
log.warn("An error occured whilst trying to publish pin data of Arduino with ID [" + log.warn("An error occured whilst trying to publish pin data of Arduino with ID [" +
deviceId + "] of owner [" + owner + "]"); deviceId + "] of owner [" + owner + "]");
@ -169,9 +146,6 @@ public class ArduinoControllerServiceImpl implements ArduinoControllerService {
String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
String deviceId = dataMsg.deviceId; String deviceId = dataMsg.deviceId;
float temperature = dataMsg.value; float temperature = dataMsg.value;
SensorDataManager.getInstance().setSensorRecord(deviceId, ArduinoConstants.SENSOR_TEMPERATURE,
String.valueOf(temperature),
Calendar.getInstance().getTimeInMillis());
if (!ArduinoServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) { if (!ArduinoServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) {
log.warn("An error occured whilst trying to publish temperature data of Arduino with ID [" + deviceId + log.warn("An error occured whilst trying to publish temperature data of Arduino with ID [" + deviceId +
"] of owner [" + owner + "]"); "] of owner [" + owner + "]");

@ -51,14 +51,6 @@ public interface RaspberryPiControllerService {
description = "Switch on/off Raspberry Pi agent's bulb. (On / Off)") description = "Switch on/off Raspberry Pi agent's bulb. (On / Off)")
Response switchBulb(@PathParam("deviceId") String deviceId, @FormParam("state") String state); 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") @Path("device/push_temperature")
@POST @POST
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)

@ -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.analytics.datasource.commons.exception.AnalyticsException;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; 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.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.DeviceData;
import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.dto.SensorRecord; 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.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.APIUtil;
import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.util.RaspberrypiServiceUtils; 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.raspberrypi.plugin.constants.RaspberrypiConstants;
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.service.IoTServerStartupListener;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -98,35 +96,6 @@ public class RaspberryPiControllerServiceImpl implements RaspberryPiControllerSe
return Response.ok().build(); 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") @Path("device/push_temperature")
@POST @POST
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ -148,9 +117,6 @@ public class RaspberryPiControllerServiceImpl implements RaspberryPiControllerSe
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Received Pin Data Value: " + temperature + " degrees C"); 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)) { if (!RaspberrypiServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) {
log.warn("An error occured whilst trying to publish temperature data of raspberrypi with ID [" + log.warn("An error occured whilst trying to publish temperature data of raspberrypi with ID [" +
deviceId + "] of owner [" + owner + "]"); deviceId + "] of owner [" + owner + "]");

@ -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.APIManagementProviderService;
import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey; import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey;
import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException; 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.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; 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.APIUtil;
import org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl.util.RaspberrypiServiceUtils; 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.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.TransportHandlerException;
import org.wso2.carbon.device.mgt.iot.transport.mqtt.MQTTTransportHandler; import org.wso2.carbon.device.mgt.iot.transport.mqtt.MQTTTransportHandler;
import org.wso2.carbon.identity.jwt.client.extension.JWTClient; import org.wso2.carbon.identity.jwt.client.extension.JWTClient;
@ -161,8 +159,7 @@ public class RaspberryPiMQTTConnector extends MQTTTransportHandler {
} else if (receivedMessage.contains("TEMPERATURE")) { } else if (receivedMessage.contains("TEMPERATURE")) {
String temperatureValue = receivedMessage.split(":")[1]; String temperatureValue = receivedMessage.split(":")[1];
SensorDataManager.getInstance().setSensorRecord(deviceId, RaspberrypiConstants.SENSOR_TEMPERATURE,
temperatureValue, Calendar.getInstance().getTimeInMillis());
} }
} }
} }

@ -78,25 +78,6 @@ public interface VirtualFireAlarmControllerService {
Response switchBuzzer(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol, Response switchBuzzer(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol,
@FormParam("state") String state); @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 * 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' * received data from the device is stored in a 'DeviceRecord' under the device's ID in the 'SensorDataManager'

@ -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.exception.KeystoreException;
import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService; import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; 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.mqtt.MqttConfig;
import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig; 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.service.IoTServerStartupListener;
import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException; import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.dto.DeviceData; 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 javax.ws.rs.core.Response;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar;
import java.util.List; import java.util.List;
import java.util.concurrent.ConcurrentHashMap; 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 // holds a mapping of the IP addresses to Device-IDs for HTTP communication
private ConcurrentHashMap<String, String> deviceToIpMap = new ConcurrentHashMap<>(); private ConcurrentHashMap<String, String> deviceToIpMap = new ConcurrentHashMap<>();
<<<<<<< HEAD
@POST @POST
@Path("device/register/{deviceId}/{ip}/{port}") @Path("device/register/{deviceId}/{ip}/{port}")
public Response registerDeviceIP(@PathParam("deviceId") String deviceId, @PathParam("ip") String deviceIP, public Response registerDeviceIP(@PathParam("deviceId") String deviceId, @PathParam("ip") String deviceIP,
@PathParam("port") String devicePort, @Context HttpServletRequest request) { @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; String result;
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Got register call from IP: " + deviceIP + " for Device ID: " + deviceId); 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 @POST
@Path("device/temperature") @Path("device/temperature")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ -341,9 +158,6 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo
" is already registered under some other IP. Re-registration required"); " is already registered under some other IP. Re-registration required");
return Response.status(Response.Status.CONFLICT).build(); 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)) { if (!VirtualFireAlarmServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} }
@ -442,7 +256,6 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo
return Response.serverError().build(); return Response.serverError().build();
} }
<<<<<<< HEAD
@Path("device/stats/{deviceId}/sensors/{sensorName}") @Path("device/stats/{deviceId}/sensors/{sensorName}")
@GET @GET
@Consumes("application/json") @Consumes("application/json")
@ -451,29 +264,26 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo
@PathParam("sensorName") String sensor, @PathParam("sensorName") String sensor,
@QueryParam("username") String user, @QueryParam("from") long from, @QueryParam("username") String user, @QueryParam("from") long from,
@QueryParam("to") long to) { @QueryParam("to") long to) {
======= String fromDate = String.valueOf(from);
public Response getVirtualFirealarmStats(String deviceId, String sensor, String user, long from, long to) { String toDate = String.valueOf(to);
String fromDate = String.valueOf(from); String query = "owner:" + user + " AND deviceId:" + deviceId + " AND deviceType:" +
String toDate = String.valueOf(to); VirtualFireAlarmConstants.DEVICE_TYPE + " AND time : [" + fromDate + " TO " + toDate + "]";
String query = "owner:" + user + " AND deviceId:" + deviceId + " AND deviceType:" + String sensorTableName = getSensorEventTableName(sensor);
VirtualFireAlarmConstants.DEVICE_TYPE + " AND time : [" + fromDate + " TO " + toDate + "]"; try {
String sensorTableName = getSensorEventTableName(sensor); if (sensorTableName != null) {
>>>>>>> 8a7d4bb6e0a9b94b8a5c9ca8d6d21c3924b2c677 List<SortByField> sortByFields = new ArrayList<>();
try { SortByField sortByField = new SortByField("time", SORT.ASC, false);
if (sensorTableName != null) { sortByFields.add(sortByField);
List<SortByField> sortByFields = new ArrayList<>(); List<SensorRecord> sensorRecords = APIUtil.getAllEventsForDevice(sensorTableName, query, sortByFields);
SortByField sortByField = new SortByField("time", SORT.ASC, false); return Response.status(Response.Status.OK.getStatusCode()).entity(sensorRecords).build();
sortByFields.add(sortByField); }
List<SensorRecord> sensorRecords = APIUtil.getAllEventsForDevice(sensorTableName, query, sortByFields); } catch (AnalyticsException e) {
return Response.status(Response.Status.OK.getStatusCode()).entity(sensorRecords).build(); 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) { return Response.status(Response.Status.BAD_REQUEST).build();
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();
}
private boolean waitForServerStartup() { private boolean waitForServerStartup() {
while (!IoTServerStartupListener.isServerReady()) { while (!IoTServerStartupListener.isServerReady()) {

@ -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.APIManagementProviderService;
import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey; import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey;
import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException; 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.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; 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.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.TransportHandlerException;
import org.wso2.carbon.device.mgt.iot.transport.mqtt.MQTTTransportHandler; import org.wso2.carbon.device.mgt.iot.transport.mqtt.MQTTTransportHandler;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.exception.VirtualFireAlarmException; 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")) { } else if (actualMessage.contains("TEMPERATURE")) {
String temperatureValue = actualMessage.split(":")[1]; String temperatureValue = actualMessage.split(":")[1];
SensorDataManager.getInstance().setSensorRecord(deviceId, VirtualFireAlarmConstants.SENSOR_TEMP,
temperatureValue,
Calendar.getInstance().getTimeInMillis());
} }
} catch (VirtualFireAlarmException e) { } catch (VirtualFireAlarmException e) {
String errorMsg = String errorMsg =

@ -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.XmppConfig;
import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppServerClient; 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.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.TransportHandlerException;
import org.wso2.carbon.device.mgt.iot.transport.xmpp.XMPPTransportHandler; import org.wso2.carbon.device.mgt.iot.transport.xmpp.XMPPTransportHandler;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants;
@ -182,10 +181,6 @@ public class VirtualFireAlarmXMPPConnector extends XMPPTransportHandler {
break; break;
case "CONTROL-REPLY": case "CONTROL-REPLY":
String tempVal = actualMessage.split(":")[1]; String tempVal = actualMessage.split(":")[1];
SensorDataManager.getInstance().setSensorRecord(deviceId,
VirtualFireAlarmConstants.SENSOR_TEMP,
tempVal,
Calendar.getInstance().getTimeInMillis());
break; break;
default: default:

Loading…
Cancel
Save