From f29c66e24dc735678019d2b86655e71ce475e73d Mon Sep 17 00:00:00 2001 From: Shabirmean Date: Fri, 18 Dec 2015 19:58:36 +0530 Subject: [PATCH] Changes to the VIrtualFireAlarm agent and added "server-name" to the configs file --- .../iot/arduino/service/ArduinoService.java | 5 ++--- .../api/DigitalDisplayManagerService.java | 3 ++- .../droneanalyzer/service/DroneService.java | 7 +++--- .../service/RaspberryPiService.java | 4 ++-- .../mqtt/FireAlarmMQTTCommunicator.java | 3 ++- .../agent/core/AgentConfiguration.java | 9 ++++++++ .../agent/core/AgentConstants.java | 7 +++--- .../agent/core/AgentManager.java | 4 +++- .../agent/core/AgentUtilOperations.java | 22 ++++++++++--------- .../service/VirtualFireAlarmService.java | 5 +++-- .../mqtt/MqttControlPublisher.java | 6 ++--- .../carbon/device/mgt/iot/util/ZipUtil.java | 11 +++++----- .../advanced_agent/deviceConfig.properties | 1 + .../resources/agent/deviceConfig.properties | 1 + 14 files changed, 54 insertions(+), 34 deletions(-) diff --git a/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/ArduinoService.java b/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/ArduinoService.java index a0bc3be694..33afec0138 100644 --- a/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/ArduinoService.java +++ b/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/ArduinoService.java @@ -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.ZipUtil; -import javax.jws.WebService; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.ws.rs.Consumes; @@ -414,8 +413,8 @@ public class ArduinoService { ZipUtil ziputil = new ZipUtil(); - ZipArchive zipFile = ziputil.downloadSketch(owner, SUPER_TENANT, sketchType, deviceId, deviceName, accessToken, - refreshToken); + ZipArchive zipFile = ziputil.createZipFile(owner, SUPER_TENANT, sketchType, deviceId, deviceName, accessToken, + refreshToken); zipFile.setDeviceId(deviceId); return zipFile; } diff --git a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/DigitalDisplayManagerService.java b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/DigitalDisplayManagerService.java index 0dee8e2aaf..39f5ebf044 100644 --- a/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/DigitalDisplayManagerService.java +++ b/components/device-mgt-iot-digitaldisplay/org.wso2.carbon.device.mgt.iot.digitaldisplay.api/src/main/java/org/wso2/carbon/device/mgt/iot/digitaldisplay/api/DigitalDisplayManagerService.java @@ -223,7 +223,8 @@ public class DigitalDisplayManagerService { ZipUtil ziputil = new ZipUtil(); ZipArchive zipFile = null; 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) { return Response.status(500).entity("Error occurred while creating zip file").build(); } diff --git a/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/DroneService.java b/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/DroneService.java index f820c09fc0..e2b21bf811 100644 --- a/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/DroneService.java +++ b/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/service/DroneService.java @@ -259,7 +259,8 @@ public class DroneService { ZipUtil ziputil = new ZipUtil(); ZipArchive zipFile = null; 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) { return Response.status(500).entity("Error occurred while creating zip file").build(); } @@ -332,8 +333,8 @@ public class DroneService { throw new DeviceManagementException(msg); } ZipUtil ziputil = new ZipUtil(); - ZipArchive zipFile = ziputil.downloadSketch(owner, SUPER_TENANT, sketchType, deviceId, deviceName, - accessToken, refreshToken); + ZipArchive zipFile = ziputil.createZipFile(owner, SUPER_TENANT, sketchType, deviceId, deviceName, + accessToken, refreshToken); zipFile.setDeviceId(deviceId); return zipFile; } diff --git a/components/device-mgt-iot-raspberrypi/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/RaspberryPiService.java b/components/device-mgt-iot-raspberrypi/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/RaspberryPiService.java index f4805d274a..9568766383 100644 --- a/components/device-mgt-iot-raspberrypi/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/RaspberryPiService.java +++ b/components/device-mgt-iot-raspberrypi/org.wso2.carbon.device.mgt.iot.raspberrypi.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/RaspberryPiService.java @@ -373,8 +373,8 @@ public class RaspberryPiService { } ZipUtil ziputil = new ZipUtil(); - ZipArchive zipFile = ziputil.downloadSketch(owner, SUPER_TENANT, sketchType, deviceId, deviceName, accessToken, - refreshToken); + ZipArchive zipFile = ziputil.createZipFile(owner, SUPER_TENANT, sketchType, deviceId, deviceName, accessToken, + refreshToken); zipFile.setDeviceId(deviceId); return zipFile; } diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/communication/mqtt/FireAlarmMQTTCommunicator.java b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/communication/mqtt/FireAlarmMQTTCommunicator.java index d2c1a45e0f..877df3cc8d 100644 --- a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/communication/mqtt/FireAlarmMQTTCommunicator.java +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/communication/mqtt/FireAlarmMQTTCommunicator.java @@ -129,7 +129,8 @@ public class FireAlarmMQTTCommunicator extends MQTTTransportHandler { log.info(AgentConstants.LOG_APPENDER + replyTemperature); String tempPublishTopic = String.format( - AgentConstants.MQTT_PUBLISH_TOPIC, deviceOwner, deviceID); + AgentConstants.MQTT_PUBLISH_TOPIC, + agentManager.getAgentConfigs().getServerName(), deviceOwner, deviceID); replyMessage = AgentConstants.TEMPERATURE_CONTROL + ":" + currentTemperature; try { diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentConfiguration.java b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentConfiguration.java index 0c13de0f47..e36b161cbb 100644 --- a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentConfiguration.java +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentConfiguration.java @@ -24,6 +24,7 @@ package org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.core; * downloading the device agent from the IoT-Server. */ public class AgentConfiguration { + private String serverName; private String deviceOwner; private String deviceId; private String deviceName; @@ -38,6 +39,14 @@ public class AgentConfiguration { private String refreshToken; private int dataPushInterval; + public String getServerName() { + return serverName; + } + + public void setServerName(String serverName) { + this.serverName = serverName; + } + public String getDeviceOwner() { return deviceOwner; } diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentConstants.java b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentConstants.java index 5bebbbbe33..fbe9a4c355 100644 --- a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentConstants.java +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentConstants.java @@ -27,7 +27,6 @@ public class AgentConstants { IoT-Server specific information --------------------------------------------------------------------------------------- */ 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_REGISTER_API_EP = "/register"; 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_QUALITY_OF_SERVICE = 0; - public static final String MQTT_SUBSCRIBE_TOPIC = "wso2/iot/%s/" + DEVICE_TYPE + "/%s"; - public static final String MQTT_PUBLISH_TOPIC = "wso2/iot/%s/" + DEVICE_TYPE + "/%s/publisher"; + public static final String MQTT_SUBSCRIBE_TOPIC = "%s/%s/" + DEVICE_TYPE + "/%s"; + public static final String MQTT_PUBLISH_TOPIC = "%s/%s/" + DEVICE_TYPE + "/%s/publisher"; /* --------------------------------------------------------------------------------------- XMPP Connection specific information --------------------------------------------------------------------------------------- */ @@ -68,6 +67,7 @@ public class AgentConstants { 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 SERVER_NAME_PROPERTY = "server-name"; public static final String DEVICE_OWNER_PROPERTY = "owner"; public static final String DEVICE_ID_PROPERTY = "deviceId"; 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 --------------------------------------------------------------------------------------- */ + public static final String DEFAULT_SERVER_NAME = "WSO2IoTServer"; public static final String DEFAULT_DEVICE_OWNER = "admin"; public static final String DEFAULT_DEVICE_ID = "1234567890"; public static final String DEFAULT_DEVICE_NAME = "admin_1234567890"; diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentManager.java b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentManager.java index d8e731542e..0e77eefa6e 100644 --- a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentManager.java +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentManager.java @@ -78,7 +78,7 @@ public class AgentManager { this.agentConfigs = AgentUtilOperations.readIoTServerConfigs(); // Initialise IoT-Server URL endpoints from the configuration read from file - AgentUtilOperations.initializeHTTPEndPoints(); + AgentUtilOperations.initializeServerEndPoints(); String analyticsPageContext = String.format(AgentConstants.DEVICE_ANALYTICS_PAGE_URL, agentConfigs.getDeviceId(), @@ -107,6 +107,7 @@ public class AgentManager { String xmppServer = xmppIPPortMap.get("Host"); int xmppPort = Integer.parseInt(xmppIPPortMap.get("Port")); + TransportHandler xmppCommunicator = new FireAlarmXMPPCommunicator(xmppServer, xmppPort); agentCommunicator.put(AgentConstants.XMPP_PROTOCOL, xmppCommunicator); @@ -115,6 +116,7 @@ public class AgentManager { ", provided in the configuration file is invalid."); } String mqttTopic = String.format(AgentConstants.MQTT_SUBSCRIBE_TOPIC, + agentConfigs.getServerName(), agentConfigs.getDeviceOwner(), agentConfigs.getDeviceId()); diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentUtilOperations.java b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentUtilOperations.java index 2115d7df7c..f42291bc0b 100644 --- a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentUtilOperations.java +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentUtilOperations.java @@ -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.LogFactory; 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.exception.AgentCoreOperationException; 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.FileNotFoundException; @@ -79,6 +79,8 @@ public class AgentUtilOperations { //load a properties file from class path, inside static method properties.load(propertiesInputStream); + iotServerConfigs.setServerName(properties.getProperty( + AgentConstants.SERVER_NAME_PROPERTY)); iotServerConfigs.setDeviceOwner(properties.getProperty( AgentConstants.DEVICE_OWNER_PROPERTY)); iotServerConfigs.setDeviceId(properties.getProperty( @@ -106,6 +108,8 @@ public class AgentUtilOperations { iotServerConfigs.setDataPushInterval(Integer.parseInt(properties.getProperty( AgentConstants.PUSH_INTERVAL_PROPERTY))); + log.info(AgentConstants.LOG_APPENDER + "Server name: " + + iotServerConfigs.getServerName()); log.info(AgentConstants.LOG_APPENDER + "Device Owner: " + iotServerConfigs.getDeviceOwner()); log.info(AgentConstants.LOG_APPENDER + "Device ID: " + iotServerConfigs.getDeviceId()); @@ -149,9 +153,8 @@ public class AgentUtilOperations { propertiesInputStream.close(); } catch (IOException e) { log.error(AgentConstants.LOG_APPENDER + - "Error occurred whilst trying to close InputStream " + - "resource used to read the '" + propertiesFileName + - "' file"); + "Error occurred whilst trying to close InputStream resource used to read the '" + + propertiesFileName + "' file"); } } } @@ -169,6 +172,7 @@ public class AgentUtilOperations { AgentConfiguration iotServerConfigs = new AgentConfiguration(); + iotServerConfigs.setDeviceOwner(AgentConstants.DEFAULT_SERVER_NAME); iotServerConfigs.setDeviceOwner(AgentConstants.DEFAULT_DEVICE_OWNER); iotServerConfigs.setDeviceId(AgentConstants.DEFAULT_DEVICE_ID); iotServerConfigs.setDeviceName(AgentConstants.DEFAULT_DEVICE_NAME); @@ -195,12 +199,12 @@ public class AgentUtilOperations { * retrieve the deviceIP of the network-interface read * from the configs file */ - public static void initializeHTTPEndPoints() { + public static void initializeServerEndPoints() { AgentManager agentManager = AgentManager.getInstance(); - String apimEndpoint = agentManager.getAgentConfigs().getHTTP_ServerEndpoint(); + String serverEndpoint = agentManager.getAgentConfigs().getHTTPS_ServerEndpoint(); String backEndContext = agentManager.getAgentConfigs().getControllerContext(); - String deviceControllerAPIEndpoint = apimEndpoint + backEndContext; + String deviceControllerAPIEndpoint = serverEndpoint + backEndContext; String deviceEnrollmentEndpoint = deviceControllerAPIEndpoint + AgentConstants.DEVICE_ENROLLMENT_API_EP; @@ -275,7 +279,7 @@ public class AgentUtilOperations { try { - if (verification){ + if (verification) { actualMessage = CommunicationUtils.decryptMessage(encryptedMessage, devicePrivateKey); } else { String errorMsg = "Could not verify payload signature. The message was not signed by a valid client"; @@ -292,7 +296,5 @@ public class AgentUtilOperations { } - - } diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/VirtualFireAlarmService.java b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/VirtualFireAlarmService.java index 0c77b1e8df..128f9a2561 100644 --- a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/VirtualFireAlarmService.java +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/VirtualFireAlarmService.java @@ -382,6 +382,7 @@ public class VirtualFireAlarmService { * @param sketchType * @return */ + //TODO:: Needs to go to "common.war" cz all the devices have this @Path("manager/device/{sketch_type}/download") @GET @Produces(MediaType.APPLICATION_JSON) @@ -496,8 +497,8 @@ public class VirtualFireAlarmService { ZipUtil ziputil = new ZipUtil(); - ZipArchive zipFile = ziputil.downloadSketch(owner, SUPER_TENANT, sketchType, deviceId, deviceName, - accessToken, refreshToken); + ZipArchive zipFile = ziputil.createZipFile(owner, SUPER_TENANT, sketchType, deviceId, deviceName, + accessToken, refreshToken); zipFile.setDeviceId(deviceId); return zipFile; } diff --git a/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/controlqueue/mqtt/MqttControlPublisher.java b/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/controlqueue/mqtt/MqttControlPublisher.java index 7d01dac51f..cc43bf28b0 100644 --- a/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/controlqueue/mqtt/MqttControlPublisher.java +++ b/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/controlqueue/mqtt/MqttControlPublisher.java @@ -27,6 +27,7 @@ import org.eclipse.paho.client.mqttv3.MqttClient; import org.eclipse.paho.client.mqttv3.MqttConnectOptions; import org.eclipse.paho.client.mqttv3.MqttException; 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.exception.DeviceControllerException; @@ -101,10 +102,9 @@ public class MqttControlPublisher implements ControlQueueConnector, MqttCallback "' is acceptable"); } + String serverName = DeviceManagementConfigurationManager.getInstance().getDeviceManagementServerInfo().getName(); String publishTopic = - "wso2" + File.separator + "iot" + File.separator + owner + File.separator + - deviceType + File.separator - + deviceId; + serverName + File.separator + owner + File.separator + deviceType + File.separator + deviceId; String payLoad = key + ":" + value; log.info("Pubish-Topic: " + publishTopic); diff --git a/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/util/ZipUtil.java b/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/util/ZipUtil.java index 4b18d6e648..9dcbc3fec4 100644 --- a/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/util/ZipUtil.java +++ b/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/util/ZipUtil.java @@ -33,9 +33,9 @@ import java.util.Map; public class ZipUtil { - public ZipArchive downloadSketch(String owner, String tenantDomain, String deviceType, - String deviceId, String deviceName, String token, - String refreshToken) + public ZipArchive createZipFile(String owner, String tenantDomain, String deviceType, + String deviceId, String deviceName, String token, + String refreshToken) throws DeviceManagementException { if (owner == null || deviceType == null) { @@ -44,10 +44,10 @@ public class ZipUtil { String sep = File.separator; String sketchFolder = "repository" + sep + "resources" + sep + "sketches"; - String archivesPath = CarbonUtils.getCarbonHome() + sep + sketchFolder + sep + "archives" - + sep + deviceId; + String archivesPath = CarbonUtils.getCarbonHome() + sep + sketchFolder + sep + "archives" + sep + deviceId; String templateSketchPath = sketchFolder + sep + deviceType; + String serverName = DeviceManagementConfigurationManager.getInstance().getDeviceManagementServerInfo().getName(); String iotServerIP = System.getProperty("carbon.local.ip"); // bind.address String httpsServerPort = System.getProperty("httpsPort"); String httpServerPort = System.getProperty("httpPort"); @@ -75,6 +75,7 @@ public class ZipUtil { xmppEndpoint = xmppEndpoint + ":" + XmppConfig.getInstance().getSERVER_CONNECTION_PORT(); Map contextParams = new HashMap(); + contextParams.put("SERVER_NAME", serverName); contextParams.put("DEVICE_OWNER", owner); contextParams.put("DEVICE_ID", deviceId); contextParams.put("DEVICE_NAME", deviceName); diff --git a/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/advanced_agent/deviceConfig.properties b/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/advanced_agent/deviceConfig.properties index f76a969f72..afd900c45d 100644 --- a/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/advanced_agent/deviceConfig.properties +++ b/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/advanced_agent/deviceConfig.properties @@ -16,6 +16,7 @@ # #[Device-Configurations] +server-name=${SERVER_NAME} owner=${DEVICE_OWNER} deviceId=${DEVICE_ID} device-name=${DEVICE_NAME} diff --git a/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/agent/deviceConfig.properties b/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/agent/deviceConfig.properties index f76a969f72..afd900c45d 100644 --- a/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/agent/deviceConfig.properties +++ b/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/agent/deviceConfig.properties @@ -16,6 +16,7 @@ # #[Device-Configurations] +server-name=${SERVER_NAME} owner=${DEVICE_OWNER} deviceId=${DEVICE_ID} device-name=${DEVICE_NAME}