Changes to the VIrtualFireAlarm agent and added "server-name" to the configs file

Shabirmean 9 years ago
parent 9dbb9cdfa1
commit f29c66e24d

@ -39,7 +39,6 @@ import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager;
import org.wso2.carbon.device.mgt.iot.util.ZipArchive; import org.wso2.carbon.device.mgt.iot.util.ZipArchive;
import org.wso2.carbon.device.mgt.iot.util.ZipUtil; import org.wso2.carbon.device.mgt.iot.util.ZipUtil;
import javax.jws.WebService;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
@ -414,8 +413,8 @@ public class ArduinoService {
ZipUtil ziputil = new ZipUtil(); ZipUtil ziputil = new ZipUtil();
ZipArchive zipFile = ziputil.downloadSketch(owner, SUPER_TENANT, sketchType, deviceId, deviceName, accessToken, ZipArchive zipFile = ziputil.createZipFile(owner, SUPER_TENANT, sketchType, deviceId, deviceName, accessToken,
refreshToken); refreshToken);
zipFile.setDeviceId(deviceId); zipFile.setDeviceId(deviceId);
return zipFile; return zipFile;
} }

@ -223,7 +223,8 @@ public class DigitalDisplayManagerService {
ZipUtil ziputil = new ZipUtil(); ZipUtil ziputil = new ZipUtil();
ZipArchive zipFile = null; ZipArchive zipFile = null;
try { try {
zipFile = ziputil.downloadSketch(owner, SUPER_TENANT, sketchType, deviceId, customDeviceName, token, refreshToken); zipFile = ziputil.createZipFile(owner, SUPER_TENANT, sketchType, deviceId, customDeviceName, token,
refreshToken);
} catch (DeviceManagementException ex) { } catch (DeviceManagementException ex) {
return Response.status(500).entity("Error occurred while creating zip file").build(); return Response.status(500).entity("Error occurred while creating zip file").build();
} }

@ -259,7 +259,8 @@ public class DroneService {
ZipUtil ziputil = new ZipUtil(); ZipUtil ziputil = new ZipUtil();
ZipArchive zipFile = null; ZipArchive zipFile = null;
try { try {
zipFile = ziputil.downloadSketch(owner, SUPER_TENANT, sketchType, deviceId, customDeviceName, token, refreshToken); zipFile = ziputil.createZipFile(owner, SUPER_TENANT, sketchType, deviceId, customDeviceName, token,
refreshToken);
} catch (DeviceManagementException ex) { } catch (DeviceManagementException ex) {
return Response.status(500).entity("Error occurred while creating zip file").build(); return Response.status(500).entity("Error occurred while creating zip file").build();
} }
@ -332,8 +333,8 @@ public class DroneService {
throw new DeviceManagementException(msg); throw new DeviceManagementException(msg);
} }
ZipUtil ziputil = new ZipUtil(); ZipUtil ziputil = new ZipUtil();
ZipArchive zipFile = ziputil.downloadSketch(owner, SUPER_TENANT, sketchType, deviceId, deviceName, ZipArchive zipFile = ziputil.createZipFile(owner, SUPER_TENANT, sketchType, deviceId, deviceName,
accessToken, refreshToken); accessToken, refreshToken);
zipFile.setDeviceId(deviceId); zipFile.setDeviceId(deviceId);
return zipFile; return zipFile;
} }

@ -373,8 +373,8 @@ public class RaspberryPiService {
} }
ZipUtil ziputil = new ZipUtil(); ZipUtil ziputil = new ZipUtil();
ZipArchive zipFile = ziputil.downloadSketch(owner, SUPER_TENANT, sketchType, deviceId, deviceName, accessToken, ZipArchive zipFile = ziputil.createZipFile(owner, SUPER_TENANT, sketchType, deviceId, deviceName, accessToken,
refreshToken); refreshToken);
zipFile.setDeviceId(deviceId); zipFile.setDeviceId(deviceId);
return zipFile; return zipFile;
} }

@ -129,7 +129,8 @@ public class FireAlarmMQTTCommunicator extends MQTTTransportHandler {
log.info(AgentConstants.LOG_APPENDER + replyTemperature); log.info(AgentConstants.LOG_APPENDER + replyTemperature);
String tempPublishTopic = String.format( String tempPublishTopic = String.format(
AgentConstants.MQTT_PUBLISH_TOPIC, deviceOwner, deviceID); AgentConstants.MQTT_PUBLISH_TOPIC,
agentManager.getAgentConfigs().getServerName(), deviceOwner, deviceID);
replyMessage = AgentConstants.TEMPERATURE_CONTROL + ":" + currentTemperature; replyMessage = AgentConstants.TEMPERATURE_CONTROL + ":" + currentTemperature;
try { try {

@ -24,6 +24,7 @@ package org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.core;
* downloading the device agent from the IoT-Server. * downloading the device agent from the IoT-Server.
*/ */
public class AgentConfiguration { public class AgentConfiguration {
private String serverName;
private String deviceOwner; private String deviceOwner;
private String deviceId; private String deviceId;
private String deviceName; private String deviceName;
@ -38,6 +39,14 @@ public class AgentConfiguration {
private String refreshToken; private String refreshToken;
private int dataPushInterval; private int dataPushInterval;
public String getServerName() {
return serverName;
}
public void setServerName(String serverName) {
this.serverName = serverName;
}
public String getDeviceOwner() { public String getDeviceOwner() {
return deviceOwner; return deviceOwner;
} }

@ -27,7 +27,6 @@ public class AgentConstants {
IoT-Server specific information IoT-Server specific information
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
public static final String DEVICE_CONTROLLER_API_EP = "/virtual_firealarm/controller"; public static final String DEVICE_CONTROLLER_API_EP = "/virtual_firealarm/controller";
// public static final String DEVICE_ENROLLMENT_API_EP = "/scep?operation=%s";
public static final String DEVICE_ENROLLMENT_API_EP = "/scep"; public static final String DEVICE_ENROLLMENT_API_EP = "/scep";
public static final String DEVICE_REGISTER_API_EP = "/register"; public static final String DEVICE_REGISTER_API_EP = "/register";
public static final String DEVICE_PUSH_TEMPERATURE_API_EP = "/push_temperature"; public static final String DEVICE_PUSH_TEMPERATURE_API_EP = "/push_temperature";
@ -58,8 +57,8 @@ public class AgentConstants {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
public static final int DEFAULT_MQTT_RECONNECTION_INTERVAL = 2; // time in seconds public static final int DEFAULT_MQTT_RECONNECTION_INTERVAL = 2; // time in seconds
public static final int DEFAULT_MQTT_QUALITY_OF_SERVICE = 0; public static final int DEFAULT_MQTT_QUALITY_OF_SERVICE = 0;
public static final String MQTT_SUBSCRIBE_TOPIC = "wso2/iot/%s/" + DEVICE_TYPE + "/%s"; public static final String MQTT_SUBSCRIBE_TOPIC = "%s/%s/" + DEVICE_TYPE + "/%s";
public static final String MQTT_PUBLISH_TOPIC = "wso2/iot/%s/" + DEVICE_TYPE + "/%s/publisher"; public static final String MQTT_PUBLISH_TOPIC = "%s/%s/" + DEVICE_TYPE + "/%s/publisher";
/* --------------------------------------------------------------------------------------- /* ---------------------------------------------------------------------------------------
XMPP Connection specific information XMPP Connection specific information
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
@ -68,6 +67,7 @@ public class AgentConstants {
Device/Agent specific properties to be read from the 'deviceConfig.properties' file Device/Agent specific properties to be read from the 'deviceConfig.properties' file
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
public static final String AGENT_PROPERTIES_FILE_NAME = "deviceConfig.properties"; public static final String AGENT_PROPERTIES_FILE_NAME = "deviceConfig.properties";
public static final String SERVER_NAME_PROPERTY = "server-name";
public static final String DEVICE_OWNER_PROPERTY = "owner"; public static final String DEVICE_OWNER_PROPERTY = "owner";
public static final String DEVICE_ID_PROPERTY = "deviceId"; public static final String DEVICE_ID_PROPERTY = "deviceId";
public static final String DEVICE_NAME_PROPERTY = "device-name"; public static final String DEVICE_NAME_PROPERTY = "device-name";
@ -85,6 +85,7 @@ public class AgentConstants {
/* --------------------------------------------------------------------------------------- /* ---------------------------------------------------------------------------------------
Default values for the Device/Agent specific configurations listed above Default values for the Device/Agent specific configurations listed above
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
public static final String DEFAULT_SERVER_NAME = "WSO2IoTServer";
public static final String DEFAULT_DEVICE_OWNER = "admin"; public static final String DEFAULT_DEVICE_OWNER = "admin";
public static final String DEFAULT_DEVICE_ID = "1234567890"; public static final String DEFAULT_DEVICE_ID = "1234567890";
public static final String DEFAULT_DEVICE_NAME = "admin_1234567890"; public static final String DEFAULT_DEVICE_NAME = "admin_1234567890";

@ -78,7 +78,7 @@ public class AgentManager {
this.agentConfigs = AgentUtilOperations.readIoTServerConfigs(); this.agentConfigs = AgentUtilOperations.readIoTServerConfigs();
// Initialise IoT-Server URL endpoints from the configuration read from file // Initialise IoT-Server URL endpoints from the configuration read from file
AgentUtilOperations.initializeHTTPEndPoints(); AgentUtilOperations.initializeServerEndPoints();
String analyticsPageContext = String.format(AgentConstants.DEVICE_ANALYTICS_PAGE_URL, String analyticsPageContext = String.format(AgentConstants.DEVICE_ANALYTICS_PAGE_URL,
agentConfigs.getDeviceId(), agentConfigs.getDeviceId(),
@ -107,6 +107,7 @@ public class AgentManager {
String xmppServer = xmppIPPortMap.get("Host"); String xmppServer = xmppIPPortMap.get("Host");
int xmppPort = Integer.parseInt(xmppIPPortMap.get("Port")); int xmppPort = Integer.parseInt(xmppIPPortMap.get("Port"));
TransportHandler xmppCommunicator = new FireAlarmXMPPCommunicator(xmppServer, xmppPort); TransportHandler xmppCommunicator = new FireAlarmXMPPCommunicator(xmppServer, xmppPort);
agentCommunicator.put(AgentConstants.XMPP_PROTOCOL, xmppCommunicator); agentCommunicator.put(AgentConstants.XMPP_PROTOCOL, xmppCommunicator);
@ -115,6 +116,7 @@ public class AgentManager {
", provided in the configuration file is invalid."); ", provided in the configuration file is invalid.");
} }
String mqttTopic = String.format(AgentConstants.MQTT_SUBSCRIBE_TOPIC, String mqttTopic = String.format(AgentConstants.MQTT_SUBSCRIBE_TOPIC,
agentConfigs.getServerName(),
agentConfigs.getDeviceOwner(), agentConfigs.getDeviceOwner(),
agentConfigs.getDeviceId()); agentConfigs.getDeviceId());

@ -21,10 +21,10 @@ package org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.core;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.json.JSONObject; import org.json.JSONObject;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.transport.TransportHandlerException;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.enrollment.EnrollmentManager; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.enrollment.EnrollmentManager;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.exception.AgentCoreOperationException; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.exception.AgentCoreOperationException;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.transport.CommunicationUtils; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.transport.CommunicationUtils;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.transport.TransportHandlerException;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -79,6 +79,8 @@ public class AgentUtilOperations {
//load a properties file from class path, inside static method //load a properties file from class path, inside static method
properties.load(propertiesInputStream); properties.load(propertiesInputStream);
iotServerConfigs.setServerName(properties.getProperty(
AgentConstants.SERVER_NAME_PROPERTY));
iotServerConfigs.setDeviceOwner(properties.getProperty( iotServerConfigs.setDeviceOwner(properties.getProperty(
AgentConstants.DEVICE_OWNER_PROPERTY)); AgentConstants.DEVICE_OWNER_PROPERTY));
iotServerConfigs.setDeviceId(properties.getProperty( iotServerConfigs.setDeviceId(properties.getProperty(
@ -106,6 +108,8 @@ public class AgentUtilOperations {
iotServerConfigs.setDataPushInterval(Integer.parseInt(properties.getProperty( iotServerConfigs.setDataPushInterval(Integer.parseInt(properties.getProperty(
AgentConstants.PUSH_INTERVAL_PROPERTY))); AgentConstants.PUSH_INTERVAL_PROPERTY)));
log.info(AgentConstants.LOG_APPENDER + "Server name: " +
iotServerConfigs.getServerName());
log.info(AgentConstants.LOG_APPENDER + "Device Owner: " + log.info(AgentConstants.LOG_APPENDER + "Device Owner: " +
iotServerConfigs.getDeviceOwner()); iotServerConfigs.getDeviceOwner());
log.info(AgentConstants.LOG_APPENDER + "Device ID: " + iotServerConfigs.getDeviceId()); log.info(AgentConstants.LOG_APPENDER + "Device ID: " + iotServerConfigs.getDeviceId());
@ -149,9 +153,8 @@ public class AgentUtilOperations {
propertiesInputStream.close(); propertiesInputStream.close();
} catch (IOException e) { } catch (IOException e) {
log.error(AgentConstants.LOG_APPENDER + log.error(AgentConstants.LOG_APPENDER +
"Error occurred whilst trying to close InputStream " + "Error occurred whilst trying to close InputStream resource used to read the '" +
"resource used to read the '" + propertiesFileName + propertiesFileName + "' file");
"' file");
} }
} }
} }
@ -169,6 +172,7 @@ public class AgentUtilOperations {
AgentConfiguration iotServerConfigs = new AgentConfiguration(); AgentConfiguration iotServerConfigs = new AgentConfiguration();
iotServerConfigs.setDeviceOwner(AgentConstants.DEFAULT_SERVER_NAME);
iotServerConfigs.setDeviceOwner(AgentConstants.DEFAULT_DEVICE_OWNER); iotServerConfigs.setDeviceOwner(AgentConstants.DEFAULT_DEVICE_OWNER);
iotServerConfigs.setDeviceId(AgentConstants.DEFAULT_DEVICE_ID); iotServerConfigs.setDeviceId(AgentConstants.DEFAULT_DEVICE_ID);
iotServerConfigs.setDeviceName(AgentConstants.DEFAULT_DEVICE_NAME); iotServerConfigs.setDeviceName(AgentConstants.DEFAULT_DEVICE_NAME);
@ -195,12 +199,12 @@ public class AgentUtilOperations {
* retrieve the deviceIP of the network-interface read * retrieve the deviceIP of the network-interface read
* from the configs file * from the configs file
*/ */
public static void initializeHTTPEndPoints() { public static void initializeServerEndPoints() {
AgentManager agentManager = AgentManager.getInstance(); AgentManager agentManager = AgentManager.getInstance();
String apimEndpoint = agentManager.getAgentConfigs().getHTTP_ServerEndpoint(); String serverEndpoint = agentManager.getAgentConfigs().getHTTPS_ServerEndpoint();
String backEndContext = agentManager.getAgentConfigs().getControllerContext(); String backEndContext = agentManager.getAgentConfigs().getControllerContext();
String deviceControllerAPIEndpoint = apimEndpoint + backEndContext; String deviceControllerAPIEndpoint = serverEndpoint + backEndContext;
String deviceEnrollmentEndpoint = String deviceEnrollmentEndpoint =
deviceControllerAPIEndpoint + AgentConstants.DEVICE_ENROLLMENT_API_EP; deviceControllerAPIEndpoint + AgentConstants.DEVICE_ENROLLMENT_API_EP;
@ -275,7 +279,7 @@ public class AgentUtilOperations {
try { try {
if (verification){ if (verification) {
actualMessage = CommunicationUtils.decryptMessage(encryptedMessage, devicePrivateKey); actualMessage = CommunicationUtils.decryptMessage(encryptedMessage, devicePrivateKey);
} else { } else {
String errorMsg = "Could not verify payload signature. The message was not signed by a valid client"; String errorMsg = "Could not verify payload signature. The message was not signed by a valid client";
@ -292,7 +296,5 @@ public class AgentUtilOperations {
} }
} }

@ -382,6 +382,7 @@ public class VirtualFireAlarmService {
* @param sketchType * @param sketchType
* @return * @return
*/ */
//TODO:: Needs to go to "common.war" cz all the devices have this
@Path("manager/device/{sketch_type}/download") @Path("manager/device/{sketch_type}/download")
@GET @GET
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@ -496,8 +497,8 @@ public class VirtualFireAlarmService {
ZipUtil ziputil = new ZipUtil(); ZipUtil ziputil = new ZipUtil();
ZipArchive zipFile = ziputil.downloadSketch(owner, SUPER_TENANT, sketchType, deviceId, deviceName, ZipArchive zipFile = ziputil.createZipFile(owner, SUPER_TENANT, sketchType, deviceId, deviceName,
accessToken, refreshToken); accessToken, refreshToken);
zipFile.setDeviceId(deviceId); zipFile.setDeviceId(deviceId);
return zipFile; return zipFile;
} }

@ -27,6 +27,7 @@ import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions; import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttException; import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage; import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.wso2.carbon.device.mgt.iot.config.server.DeviceManagementConfigurationManager;
import org.wso2.carbon.device.mgt.iot.controlqueue.ControlQueueConnector; import org.wso2.carbon.device.mgt.iot.controlqueue.ControlQueueConnector;
import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException; import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException;
@ -101,10 +102,9 @@ public class MqttControlPublisher implements ControlQueueConnector, MqttCallback
"' is acceptable"); "' is acceptable");
} }
String serverName = DeviceManagementConfigurationManager.getInstance().getDeviceManagementServerInfo().getName();
String publishTopic = String publishTopic =
"wso2" + File.separator + "iot" + File.separator + owner + File.separator + serverName + File.separator + owner + File.separator + deviceType + File.separator + deviceId;
deviceType + File.separator
+ deviceId;
String payLoad = key + ":" + value; String payLoad = key + ":" + value;
log.info("Pubish-Topic: " + publishTopic); log.info("Pubish-Topic: " + publishTopic);

@ -33,9 +33,9 @@ import java.util.Map;
public class ZipUtil { public class ZipUtil {
public ZipArchive downloadSketch(String owner, String tenantDomain, String deviceType, public ZipArchive createZipFile(String owner, String tenantDomain, String deviceType,
String deviceId, String deviceName, String token, String deviceId, String deviceName, String token,
String refreshToken) String refreshToken)
throws DeviceManagementException { throws DeviceManagementException {
if (owner == null || deviceType == null) { if (owner == null || deviceType == null) {
@ -44,10 +44,10 @@ public class ZipUtil {
String sep = File.separator; String sep = File.separator;
String sketchFolder = "repository" + sep + "resources" + sep + "sketches"; String sketchFolder = "repository" + sep + "resources" + sep + "sketches";
String archivesPath = CarbonUtils.getCarbonHome() + sep + sketchFolder + sep + "archives" String archivesPath = CarbonUtils.getCarbonHome() + sep + sketchFolder + sep + "archives" + sep + deviceId;
+ sep + deviceId;
String templateSketchPath = sketchFolder + sep + deviceType; String templateSketchPath = sketchFolder + sep + deviceType;
String serverName = DeviceManagementConfigurationManager.getInstance().getDeviceManagementServerInfo().getName();
String iotServerIP = System.getProperty("carbon.local.ip"); // bind.address String iotServerIP = System.getProperty("carbon.local.ip"); // bind.address
String httpsServerPort = System.getProperty("httpsPort"); String httpsServerPort = System.getProperty("httpsPort");
String httpServerPort = System.getProperty("httpPort"); String httpServerPort = System.getProperty("httpPort");
@ -75,6 +75,7 @@ public class ZipUtil {
xmppEndpoint = xmppEndpoint + ":" + XmppConfig.getInstance().getSERVER_CONNECTION_PORT(); xmppEndpoint = xmppEndpoint + ":" + XmppConfig.getInstance().getSERVER_CONNECTION_PORT();
Map<String, String> contextParams = new HashMap<String, String>(); Map<String, String> contextParams = new HashMap<String, String>();
contextParams.put("SERVER_NAME", serverName);
contextParams.put("DEVICE_OWNER", owner); contextParams.put("DEVICE_OWNER", owner);
contextParams.put("DEVICE_ID", deviceId); contextParams.put("DEVICE_ID", deviceId);
contextParams.put("DEVICE_NAME", deviceName); contextParams.put("DEVICE_NAME", deviceName);

@ -16,6 +16,7 @@
# #
#[Device-Configurations] #[Device-Configurations]
server-name=${SERVER_NAME}
owner=${DEVICE_OWNER} owner=${DEVICE_OWNER}
deviceId=${DEVICE_ID} deviceId=${DEVICE_ID}
device-name=${DEVICE_NAME} device-name=${DEVICE_NAME}

@ -16,6 +16,7 @@
# #
#[Device-Configurations] #[Device-Configurations]
server-name=${SERVER_NAME}
owner=${DEVICE_OWNER} owner=${DEVICE_OWNER}
deviceId=${DEVICE_ID} deviceId=${DEVICE_ID}
device-name=${DEVICE_NAME} device-name=${DEVICE_NAME}

Loading…
Cancel
Save