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.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;
}

@ -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();
}

@ -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;
}

@ -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;
}

@ -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 {

@ -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;
}

@ -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";

@ -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());

@ -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 {
}
}

@ -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;
}

@ -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);

@ -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<String, String> contextParams = new HashMap<String, String>();
contextParams.put("SERVER_NAME", serverName);
contextParams.put("DEVICE_OWNER", owner);
contextParams.put("DEVICE_ID", deviceId);
contextParams.put("DEVICE_NAME", deviceName);

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

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

Loading…
Cancel
Save