Device simulator DMF target delete aware (#508)

* Device simulator DMF target delete aware

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Remove else.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
Kai Zimmermann
2017-05-12 14:42:20 +02:00
committed by GitHub
parent 80f4761fff
commit 803f33ce17
2 changed files with 34 additions and 4 deletions

View File

@@ -64,6 +64,20 @@ public class DeviceSimulatorRepository {
return devices.get(new DeviceKey(tenant.toLowerCase(), id)); return devices.get(new DeviceKey(tenant.toLowerCase(), id));
} }
/**
* Removes a device from the simulation.
*
* @param tenant
* the tenant of the simulated device
* @param id
* the ID of the device
* @return the simulated device or <code>null</code> if it was not in the
* repository
*/
public AbstractSimulatedDevice remove(final String tenant, final String id) {
return devices.remove(new DeviceKey(tenant.toLowerCase(), id));
}
/** /**
* Clears all stored devices. * Clears all stored devices.
*/ */

View File

@@ -14,6 +14,7 @@ import org.eclipse.hawkbit.dmf.amqp.api.EventTopic;
import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey; import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey;
import org.eclipse.hawkbit.dmf.amqp.api.MessageType; import org.eclipse.hawkbit.dmf.amqp.api.MessageType;
import org.eclipse.hawkbit.dmf.json.model.DownloadAndUpdateRequest; import org.eclipse.hawkbit.dmf.json.model.DownloadAndUpdateRequest;
import org.eclipse.hawkbit.simulator.DeviceSimulatorRepository;
import org.eclipse.hawkbit.simulator.DeviceSimulatorUpdater; import org.eclipse.hawkbit.simulator.DeviceSimulatorUpdater;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -41,6 +42,8 @@ public class SpReceiverService extends ReceiverService {
private final DeviceSimulatorUpdater deviceUpdater; private final DeviceSimulatorUpdater deviceUpdater;
private final DeviceSimulatorRepository repository;
/** /**
* Constructor. * Constructor.
* *
@@ -52,13 +55,17 @@ public class SpReceiverService extends ReceiverService {
* to send messages * to send messages
* @param deviceUpdater * @param deviceUpdater
* simulator service for updates * simulator service for updates
* @param repository
* to manage simulated devices
*/ */
@Autowired @Autowired
public SpReceiverService(final RabbitTemplate rabbitTemplate, final AmqpProperties amqpProperties, public SpReceiverService(final RabbitTemplate rabbitTemplate, final AmqpProperties amqpProperties,
final SpSenderService spSenderService, final DeviceSimulatorUpdater deviceUpdater) { final SpSenderService spSenderService, final DeviceSimulatorUpdater deviceUpdater,
final DeviceSimulatorRepository repository) {
super(rabbitTemplate, amqpProperties); super(rabbitTemplate, amqpProperties);
this.spSenderService = spSenderService; this.spSenderService = spSenderService;
this.deviceUpdater = deviceUpdater; this.deviceUpdater = deviceUpdater;
this.repository = repository;
} }
/** /**
@@ -71,21 +78,30 @@ public class SpReceiverService extends ReceiverService {
* the action type * the action type
* @param thingId * @param thingId
* the thing id in message header * the thing id in message header
* @param tenant
* the device belongs to
*/ */
@RabbitListener(queues = "${hawkbit.device.simulator.amqp.receiverConnectorQueueFromSp}", containerFactory = "listenerContainerFactory") @RabbitListener(queues = "${hawkbit.device.simulator.amqp.receiverConnectorQueueFromSp}", containerFactory = "listenerContainerFactory")
public void recieveMessageSp(final Message message, @Header(MessageHeaderKey.TYPE) final String type, public void recieveMessageSp(final Message message, @Header(MessageHeaderKey.TYPE) final String type,
@Header(MessageHeaderKey.THING_ID) final String thingId) { @Header(MessageHeaderKey.THING_ID) final String thingId,
@Header(MessageHeaderKey.TENANT) final String tenant) {
checkContentTypeJson(message); checkContentTypeJson(message);
delegateMessage(message, type, thingId); delegateMessage(message, type, thingId, tenant);
} }
private void delegateMessage(final Message message, final String type, final String thingId) { private void delegateMessage(final Message message, final String type, final String thingId, final String tenant) {
final MessageType messageType = MessageType.valueOf(type); final MessageType messageType = MessageType.valueOf(type);
if (MessageType.EVENT.equals(messageType)) { if (MessageType.EVENT.equals(messageType)) {
handleEventMessage(message, thingId); handleEventMessage(message, thingId);
return; return;
} }
if (MessageType.THING_DELETED.equals(messageType)) {
repository.remove(tenant, thingId);
return;
}
LOGGER.info("No valid message type property."); LOGGER.info("No valid message type property.");
} }